LazyMachineBlockFrequencyInfo.h 3.0 KB

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