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
24namespace llvm {
25class AnalysisUsage;
26class MachineBlockFrequencyInfo;
27class MachineFunction;
28class Module;
29
30namespace vfs {
31class FileSystem;
32} // namespace vfs
33
34using namespace sampleprof;
35
36class MIRProfileLoader;
37class MIRProfileLoaderPass : public MachineFunctionPass {
38 MachineFunction *MF;
39 std::string ProfileFileName;
40 FSDiscriminatorPass P;
41 unsigned LowBit;
42 unsigned HighBit;
43
44public:
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
57private:
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

source code of llvm/include/llvm/CodeGen/MIRSampleProfile.h