xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MIRSampleProfile.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1349cc55cSDimitry Andric //===----- MIRSampleProfile.h: SampleFDO Support in MIR ---*- c++ -*-------===//
2349cc55cSDimitry Andric //
3349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6349cc55cSDimitry Andric //
7349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
8349cc55cSDimitry Andric //
9349cc55cSDimitry Andric // This file contains the supoorting functions for machine level Sample FDO
10349cc55cSDimitry Andric // loader. This is used in Flow Sensitive SampelFDO.
11349cc55cSDimitry Andric //
12349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
13349cc55cSDimitry Andric 
14349cc55cSDimitry Andric #ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H
15349cc55cSDimitry Andric #define LLVM_CODEGEN_MIRSAMPLEPROFILE_H
16349cc55cSDimitry Andric 
17*81ad6265SDimitry Andric #include "llvm/ADT/StringRef.h"
18349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h"
19*81ad6265SDimitry Andric #include "llvm/Support/Discriminator.h"
20*81ad6265SDimitry Andric #include <memory>
21*81ad6265SDimitry Andric #include <string>
22349cc55cSDimitry Andric 
23349cc55cSDimitry Andric namespace llvm {
24*81ad6265SDimitry Andric class AnalysisUsage;
25*81ad6265SDimitry Andric class MachineBlockFrequencyInfo;
26*81ad6265SDimitry Andric class MachineFunction;
27*81ad6265SDimitry Andric class Module;
28349cc55cSDimitry Andric 
29349cc55cSDimitry Andric using namespace sampleprof;
30349cc55cSDimitry Andric 
31349cc55cSDimitry Andric class MIRProfileLoader;
32349cc55cSDimitry Andric class MIRProfileLoaderPass : public MachineFunctionPass {
33349cc55cSDimitry Andric   MachineFunction *MF;
34349cc55cSDimitry Andric   std::string ProfileFileName;
35349cc55cSDimitry Andric   FSDiscriminatorPass P;
36349cc55cSDimitry Andric   unsigned LowBit;
37349cc55cSDimitry Andric   unsigned HighBit;
38349cc55cSDimitry Andric 
39349cc55cSDimitry Andric public:
40349cc55cSDimitry Andric   static char ID;
41349cc55cSDimitry Andric   /// FS bits will only use the '1' bits in the Mask.
42349cc55cSDimitry Andric   MIRProfileLoaderPass(std::string FileName = "",
43349cc55cSDimitry Andric                        std::string RemappingFileName = "",
44349cc55cSDimitry Andric                        FSDiscriminatorPass P = FSDiscriminatorPass::Pass1);
45349cc55cSDimitry Andric 
46349cc55cSDimitry Andric   /// getMachineFunction - Return the last machine function computed.
47349cc55cSDimitry Andric   const MachineFunction *getMachineFunction() const { return MF; }
48349cc55cSDimitry Andric 
49349cc55cSDimitry Andric   StringRef getPassName() const override { return "SampleFDO loader in MIR"; }
50349cc55cSDimitry Andric 
51349cc55cSDimitry Andric private:
52349cc55cSDimitry Andric   void init(MachineFunction &MF);
53349cc55cSDimitry Andric   bool runOnMachineFunction(MachineFunction &) override;
54349cc55cSDimitry Andric   bool doInitialization(Module &M) override;
55349cc55cSDimitry Andric   void getAnalysisUsage(AnalysisUsage &AU) const override;
56349cc55cSDimitry Andric 
57349cc55cSDimitry Andric   std::unique_ptr<MIRProfileLoader> MIRSampleLoader;
58349cc55cSDimitry Andric   /// Hold the information of the basic block frequency.
59349cc55cSDimitry Andric   MachineBlockFrequencyInfo *MBFI;
60349cc55cSDimitry Andric };
61349cc55cSDimitry Andric 
62349cc55cSDimitry Andric } // namespace llvm
63349cc55cSDimitry Andric 
64349cc55cSDimitry Andric #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H
65