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