Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame^] | 1 | ///===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*--===// |
| 2 | /// |
| 3 | /// The LLVM Compiler Infrastructure |
| 4 | /// |
| 5 | /// This file is distributed under the University of Illinois Open Source |
| 6 | /// License. See LICENSE.TXT for details. |
| 7 | /// |
| 8 | ///===---------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// This is an alternative analysis pass to MachineBlockFrequencyInfo. The |
| 11 | /// difference is that with this pass the block frequencies are not computed |
| 12 | /// when the analysis pass is executed but rather when the BFI result is |
| 13 | /// explicitly requested by the analysis client. |
| 14 | /// |
| 15 | ///===---------------------------------------------------------------------===// |
| 16 | |
| 17 | #ifndef LLVM_ANALYSIS_LAZYMACHINEBLOCKFREQUENCYINFO_H |
| 18 | #define LLVM_ANALYSIS_LAZYMACHINEBLOCKFREQUENCYINFO_H |
| 19 | |
| 20 | #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" |
| 21 | #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" |
| 22 | #include "llvm/CodeGen/MachineDominators.h" |
| 23 | #include "llvm/CodeGen/MachineLoopInfo.h" |
| 24 | |
| 25 | namespace llvm { |
| 26 | /// \brief This is an alternative analysis pass to MachineBlockFrequencyInfo. |
| 27 | /// The difference is that with this pass, the block frequencies are not |
| 28 | /// computed when the analysis pass is executed but rather when the BFI result |
| 29 | /// is explicitly requested by the analysis client. |
| 30 | /// |
| 31 | /// This works by checking querying if MBFI is available and otherwise |
| 32 | /// generating MBFI on the fly. In this case the passes required for (LI, DT) |
| 33 | /// are also queried before being computed on the fly. |
| 34 | /// |
| 35 | /// Note that it is expected that we wouldn't need this functionality for the |
| 36 | /// new PM since with the new PM, analyses are executed on demand. |
| 37 | |
| 38 | class LazyMachineBlockFrequencyInfoPass : public MachineFunctionPass { |
| 39 | private: |
| 40 | /// If generated on the fly this own the instance. |
| 41 | mutable std::unique_ptr<MachineBlockFrequencyInfo> OwnedMBFI; |
| 42 | |
| 43 | /// If generated on the fly this own the instance. |
| 44 | mutable std::unique_ptr<MachineLoopInfo> OwnedMLI; |
| 45 | |
| 46 | /// If generated on the fly this own the instance. |
| 47 | mutable std::unique_ptr<MachineDominatorTree> OwnedMDT; |
| 48 | |
| 49 | /// The function. |
| 50 | MachineFunction *MF = nullptr; |
| 51 | |
| 52 | /// \brief Calculate MBFI and all other analyses that's not available and |
| 53 | /// required by BFI. |
| 54 | MachineBlockFrequencyInfo &calculateIfNotAvailable() const; |
| 55 | |
| 56 | public: |
| 57 | static char ID; |
| 58 | |
| 59 | LazyMachineBlockFrequencyInfoPass(); |
| 60 | |
| 61 | /// \brief Compute and return the block frequencies. |
| 62 | MachineBlockFrequencyInfo &getBFI() { return calculateIfNotAvailable(); } |
| 63 | |
| 64 | /// \brief Compute and return the block frequencies. |
| 65 | const MachineBlockFrequencyInfo &getBFI() const { |
| 66 | return calculateIfNotAvailable(); |
| 67 | } |
| 68 | |
| 69 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 70 | |
| 71 | bool runOnMachineFunction(MachineFunction &F) override; |
| 72 | void releaseMemory() override; |
| 73 | void print(raw_ostream &OS, const Module *M) const override; |
| 74 | }; |
| 75 | } |
| 76 | #endif |