| 1 | //===- llvm/CodeGen/MBFIWrapper.h -------------------------------*- 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 | // |
| 9 | // This class keeps track of branch frequencies of newly created blocks and |
| 10 | // tail-merged blocks. Used by the TailDuplication and MachineBlockPlacement. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_MBFIWRAPPER_H |
| 15 | #define LLVM_CODEGEN_MBFIWRAPPER_H |
| 16 | |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | #include "llvm/Support/BlockFrequency.h" |
| 19 | #include <optional> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class MachineBasicBlock; |
| 24 | class MachineBlockFrequencyInfo; |
| 25 | |
| 26 | class MBFIWrapper { |
| 27 | public: |
| 28 | MBFIWrapper(const MachineBlockFrequencyInfo &I) : MBFI(I) {} |
| 29 | |
| 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 | |
| 35 | void view(const Twine &Name, bool isSimple = true); |
| 36 | BlockFrequency getEntryFreq() const; |
| 37 | const MachineBlockFrequencyInfo &getMBFI() const { return MBFI; } |
| 38 | |
| 39 | private: |
| 40 | const MachineBlockFrequencyInfo &MBFI; |
| 41 | DenseMap<const MachineBasicBlock *, BlockFrequency> MergedBBFreq; |
| 42 | }; |
| 43 | |
| 44 | } // end namespace llvm |
| 45 | |
| 46 | #endif // LLVM_CODEGEN_MBFIWRAPPER_H |
| 47 |