xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MIRSampleProfile.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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/Analysis/ProfileSummaryInfo.h"
18 #include "llvm/CodeGen/MachineBasicBlock.h"
19 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
20 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
21 #include "llvm/CodeGen/MachineDominators.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/MachineFunctionPass.h"
24 #include "llvm/CodeGen/MachineInstr.h"
25 #include "llvm/CodeGen/MachineLoopInfo.h"
26 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
27 #include "llvm/CodeGen/MachinePostDominators.h"
28 #include "llvm/CodeGen/Passes.h"
29 #include "llvm/IR/DebugInfoMetadata.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/Module.h"
32 #include "llvm/InitializePasses.h"
33 #include "llvm/ProfileData/InstrProf.h"
34 #include "llvm/ProfileData/SampleProf.h"
35 #include "llvm/ProfileData/SampleProfReader.h"
36 
37 #include <cassert>
38 
39 namespace llvm {
40 
41 using namespace sampleprof;
42 
43 class MIRProfileLoader;
44 class MIRProfileLoaderPass : public MachineFunctionPass {
45   MachineFunction *MF;
46   std::string ProfileFileName;
47   FSDiscriminatorPass P;
48   unsigned LowBit;
49   unsigned HighBit;
50 
51 public:
52   static char ID;
53   /// FS bits will only use the '1' bits in the Mask.
54   MIRProfileLoaderPass(std::string FileName = "",
55                        std::string RemappingFileName = "",
56                        FSDiscriminatorPass P = FSDiscriminatorPass::Pass1);
57 
58   /// getMachineFunction - Return the last machine function computed.
59   const MachineFunction *getMachineFunction() const { return MF; }
60 
61   StringRef getPassName() const override { return "SampleFDO loader in MIR"; }
62 
63 private:
64   void init(MachineFunction &MF);
65   bool runOnMachineFunction(MachineFunction &) override;
66   bool doInitialization(Module &M) override;
67   void getAnalysisUsage(AnalysisUsage &AU) const override;
68 
69   std::unique_ptr<MIRProfileLoader> MIRSampleLoader;
70   /// Hold the information of the basic block frequency.
71   MachineBlockFrequencyInfo *MBFI;
72 };
73 
74 } // namespace llvm
75 
76 #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H
77