MBFIWrapper.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/MBFIWrapper.h -------------------------------*- 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. //
  14. // This class keeps track of branch frequencies of newly created blocks and
  15. // tail-merged blocks. Used by the TailDuplication and MachineBlockPlacement.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CODEGEN_MBFIWRAPPER_H
  19. #define LLVM_CODEGEN_MBFIWRAPPER_H
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/Support/BlockFrequency.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include <optional>
  24. namespace llvm {
  25. class MachineBasicBlock;
  26. class MachineBlockFrequencyInfo;
  27. class MBFIWrapper {
  28. public:
  29. MBFIWrapper(const MachineBlockFrequencyInfo &I) : MBFI(I) {}
  30. BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
  31. void setBlockFreq(const MachineBasicBlock *MBB, BlockFrequency F);
  32. std::optional<uint64_t>
  33. getBlockProfileCount(const MachineBasicBlock *MBB) const;
  34. raw_ostream &printBlockFreq(raw_ostream &OS,
  35. const MachineBasicBlock *MBB) const;
  36. raw_ostream &printBlockFreq(raw_ostream &OS,
  37. const BlockFrequency Freq) const;
  38. void view(const Twine &Name, bool isSimple = true);
  39. uint64_t getEntryFreq() const;
  40. const MachineBlockFrequencyInfo &getMBFI() { return MBFI; }
  41. private:
  42. const MachineBlockFrequencyInfo &MBFI;
  43. DenseMap<const MachineBasicBlock *, BlockFrequency> MergedBBFreq;
  44. };
  45. } // end namespace llvm
  46. #endif // LLVM_CODEGEN_MBFIWRAPPER_H
  47. #ifdef __GNUC__
  48. #pragma GCC diagnostic pop
  49. #endif