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