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