LazyMachineBlockFrequencyInfo.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*--===//
  2. ///
  3. /// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. /// See https://llvm.org/LICENSE.txt for license information.
  5. /// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. ///
  7. ///===---------------------------------------------------------------------===//
  8. /// \file
  9. /// This is an alternative analysis pass to MachineBlockFrequencyInfo. The
  10. /// difference is that with this pass the block frequencies are not computed
  11. /// when the analysis pass is executed but rather when the BFI result is
  12. /// explicitly requested by the analysis client.
  13. ///
  14. ///===---------------------------------------------------------------------===//
  15. #ifndef LLVM_CODEGEN_LAZYMACHINEBLOCKFREQUENCYINFO_H
  16. #define LLVM_CODEGEN_LAZYMACHINEBLOCKFREQUENCYINFO_H
  17. #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
  18. #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
  19. #include "llvm/CodeGen/MachineDominators.h"
  20. #include "llvm/CodeGen/MachineLoopInfo.h"
  21. namespace llvm {
  22. /// This is an alternative analysis pass to MachineBlockFrequencyInfo.
  23. /// The difference is that with this pass, the block frequencies are not
  24. /// computed when the analysis pass is executed but rather when the BFI result
  25. /// is explicitly requested by the analysis client.
  26. ///
  27. /// This works by checking querying if MBFI is available and otherwise
  28. /// generating MBFI on the fly. In this case the passes required for (LI, DT)
  29. /// are also queried before being computed on the fly.
  30. ///
  31. /// Note that it is expected that we wouldn't need this functionality for the
  32. /// new PM since with the new PM, analyses are executed on demand.
  33. class LazyMachineBlockFrequencyInfoPass : public MachineFunctionPass {
  34. private:
  35. /// If generated on the fly this own the instance.
  36. mutable std::unique_ptr<MachineBlockFrequencyInfo> OwnedMBFI;
  37. /// If generated on the fly this own the instance.
  38. mutable std::unique_ptr<MachineLoopInfo> OwnedMLI;
  39. /// If generated on the fly this own the instance.
  40. mutable std::unique_ptr<MachineDominatorTree> OwnedMDT;
  41. /// The function.
  42. MachineFunction *MF = nullptr;
  43. /// Calculate MBFI and all other analyses that's not available and
  44. /// required by BFI.
  45. MachineBlockFrequencyInfo &calculateIfNotAvailable() const;
  46. public:
  47. static char ID;
  48. LazyMachineBlockFrequencyInfoPass();
  49. /// Compute and return the block frequencies.
  50. MachineBlockFrequencyInfo &getBFI() { return calculateIfNotAvailable(); }
  51. /// Compute and return the block frequencies.
  52. const MachineBlockFrequencyInfo &getBFI() const {
  53. return calculateIfNotAvailable();
  54. }
  55. void getAnalysisUsage(AnalysisUsage &AU) const override;
  56. bool runOnMachineFunction(MachineFunction &F) override;
  57. void releaseMemory() override;
  58. void print(raw_ostream &OS, const Module *M) const override;
  59. };
  60. }
  61. #endif