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 "llvm/Support/raw_ostream.h"
20 #include <optional>
21 
22 namespace llvm {
23 
24 class MachineBasicBlock;
25 class MachineBlockFrequencyInfo;
26 
27 class MBFIWrapper {
28  public:
29   MBFIWrapper(const MachineBlockFrequencyInfo &I) : MBFI(I) {}
30 
31   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
32   void setBlockFreq(const MachineBasicBlock *MBB, BlockFrequency F);
33   std::optional<uint64_t>
34   getBlockProfileCount(const MachineBasicBlock *MBB) const;
35 
36   raw_ostream &printBlockFreq(raw_ostream &OS,
37                               const MachineBasicBlock *MBB) const;
38   raw_ostream &printBlockFreq(raw_ostream &OS,
39                               const BlockFrequency Freq) const;
40   void view(const Twine &Name, bool isSimple = true);
41   uint64_t getEntryFreq() const;
42   const MachineBlockFrequencyInfo &getMBFI() { return MBFI; }
43 
44  private:
45   const MachineBlockFrequencyInfo &MBFI;
46   DenseMap<const MachineBasicBlock *, BlockFrequency> MergedBBFreq;
47 };
48 
49 } // end namespace llvm
50 
51 #endif // LLVM_CODEGEN_MBFIWRAPPER_H
52