xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MIRSampleProfile.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 //===----- MIRSampleProfile.h: SampleFDO Support in MIR ---*- 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 file contains the supoorting functions for machine level Sample FDO
10 // loader. This is used in Flow Sensitive SampelFDO.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H
15 #define LLVM_CODEGEN_MIRSAMPLEPROFILE_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/Support/Discriminator.h"
20 #include <memory>
21 #include <string>
22 
23 namespace llvm {
24 class AnalysisUsage;
25 class MachineBlockFrequencyInfo;
26 class MachineFunction;
27 class Module;
28 
29 using namespace sampleprof;
30 
31 class MIRProfileLoader;
32 class MIRProfileLoaderPass : public MachineFunctionPass {
33   MachineFunction *MF;
34   std::string ProfileFileName;
35   FSDiscriminatorPass P;
36   unsigned LowBit;
37   unsigned HighBit;
38 
39 public:
40   static char ID;
41   /// FS bits will only use the '1' bits in the Mask.
42   MIRProfileLoaderPass(std::string FileName = "",
43                        std::string RemappingFileName = "",
44                        FSDiscriminatorPass P = FSDiscriminatorPass::Pass1);
45 
46   /// getMachineFunction - Return the last machine function computed.
47   const MachineFunction *getMachineFunction() const { return MF; }
48 
49   StringRef getPassName() const override { return "SampleFDO loader in MIR"; }
50 
51 private:
52   void init(MachineFunction &MF);
53   bool runOnMachineFunction(MachineFunction &) override;
54   bool doInitialization(Module &M) override;
55   void getAnalysisUsage(AnalysisUsage &AU) const override;
56 
57   std::unique_ptr<MIRProfileLoader> MIRSampleLoader;
58   /// Hold the information of the basic block frequency.
59   MachineBlockFrequencyInfo *MBFI;
60 };
61 
62 } // namespace llvm
63 
64 #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H
65