1*349cc55cSDimitry Andric //===----- MIRSampleProfile.h: SampleFDO Support in MIR ---*- c++ -*-------===// 2*349cc55cSDimitry Andric // 3*349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*349cc55cSDimitry Andric // 7*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 8*349cc55cSDimitry Andric // 9*349cc55cSDimitry Andric // This file contains the supoorting functions for machine level Sample FDO 10*349cc55cSDimitry Andric // loader. This is used in Flow Sensitive SampelFDO. 11*349cc55cSDimitry Andric // 12*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 13*349cc55cSDimitry Andric 14*349cc55cSDimitry Andric #ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H 15*349cc55cSDimitry Andric #define LLVM_CODEGEN_MIRSAMPLEPROFILE_H 16*349cc55cSDimitry Andric 17*349cc55cSDimitry Andric #include "llvm/Analysis/ProfileSummaryInfo.h" 18*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h" 19*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" 20*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" 21*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineDominators.h" 22*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 23*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h" 24*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineInstr.h" 25*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineLoopInfo.h" 26*349cc55cSDimitry Andric #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" 27*349cc55cSDimitry Andric #include "llvm/CodeGen/MachinePostDominators.h" 28*349cc55cSDimitry Andric #include "llvm/CodeGen/Passes.h" 29*349cc55cSDimitry Andric #include "llvm/IR/DebugInfoMetadata.h" 30*349cc55cSDimitry Andric #include "llvm/IR/Function.h" 31*349cc55cSDimitry Andric #include "llvm/IR/Module.h" 32*349cc55cSDimitry Andric #include "llvm/InitializePasses.h" 33*349cc55cSDimitry Andric #include "llvm/ProfileData/InstrProf.h" 34*349cc55cSDimitry Andric #include "llvm/ProfileData/SampleProf.h" 35*349cc55cSDimitry Andric #include "llvm/ProfileData/SampleProfReader.h" 36*349cc55cSDimitry Andric 37*349cc55cSDimitry Andric #include <cassert> 38*349cc55cSDimitry Andric 39*349cc55cSDimitry Andric namespace llvm { 40*349cc55cSDimitry Andric 41*349cc55cSDimitry Andric using namespace sampleprof; 42*349cc55cSDimitry Andric 43*349cc55cSDimitry Andric class MIRProfileLoader; 44*349cc55cSDimitry Andric class MIRProfileLoaderPass : public MachineFunctionPass { 45*349cc55cSDimitry Andric MachineFunction *MF; 46*349cc55cSDimitry Andric std::string ProfileFileName; 47*349cc55cSDimitry Andric FSDiscriminatorPass P; 48*349cc55cSDimitry Andric unsigned LowBit; 49*349cc55cSDimitry Andric unsigned HighBit; 50*349cc55cSDimitry Andric 51*349cc55cSDimitry Andric public: 52*349cc55cSDimitry Andric static char ID; 53*349cc55cSDimitry Andric /// FS bits will only use the '1' bits in the Mask. 54*349cc55cSDimitry Andric MIRProfileLoaderPass(std::string FileName = "", 55*349cc55cSDimitry Andric std::string RemappingFileName = "", 56*349cc55cSDimitry Andric FSDiscriminatorPass P = FSDiscriminatorPass::Pass1); 57*349cc55cSDimitry Andric 58*349cc55cSDimitry Andric /// getMachineFunction - Return the last machine function computed. 59*349cc55cSDimitry Andric const MachineFunction *getMachineFunction() const { return MF; } 60*349cc55cSDimitry Andric 61*349cc55cSDimitry Andric StringRef getPassName() const override { return "SampleFDO loader in MIR"; } 62*349cc55cSDimitry Andric 63*349cc55cSDimitry Andric private: 64*349cc55cSDimitry Andric void init(MachineFunction &MF); 65*349cc55cSDimitry Andric bool runOnMachineFunction(MachineFunction &) override; 66*349cc55cSDimitry Andric bool doInitialization(Module &M) override; 67*349cc55cSDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override; 68*349cc55cSDimitry Andric 69*349cc55cSDimitry Andric std::unique_ptr<MIRProfileLoader> MIRSampleLoader; 70*349cc55cSDimitry Andric /// Hold the information of the basic block frequency. 71*349cc55cSDimitry Andric MachineBlockFrequencyInfo *MBFI; 72*349cc55cSDimitry Andric }; 73*349cc55cSDimitry Andric 74*349cc55cSDimitry Andric } // namespace llvm 75*349cc55cSDimitry Andric 76*349cc55cSDimitry Andric #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H 77