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*06c3fb27SDimitry Andric #include "llvm/ADT/IntrusiveRefCntPtr.h" 1881ad6265SDimitry Andric #include "llvm/ADT/StringRef.h" 19349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h" 2081ad6265SDimitry Andric #include "llvm/Support/Discriminator.h" 2181ad6265SDimitry Andric #include <memory> 2281ad6265SDimitry Andric #include <string> 23349cc55cSDimitry Andric 24349cc55cSDimitry Andric namespace llvm { 2581ad6265SDimitry Andric class AnalysisUsage; 2681ad6265SDimitry Andric class MachineBlockFrequencyInfo; 2781ad6265SDimitry Andric class MachineFunction; 2881ad6265SDimitry Andric class Module; 29349cc55cSDimitry Andric 30*06c3fb27SDimitry Andric namespace vfs { 31*06c3fb27SDimitry Andric class FileSystem; 32*06c3fb27SDimitry Andric } // namespace vfs 33*06c3fb27SDimitry Andric 34349cc55cSDimitry Andric using namespace sampleprof; 35349cc55cSDimitry Andric 36349cc55cSDimitry Andric class MIRProfileLoader; 37349cc55cSDimitry Andric class MIRProfileLoaderPass : public MachineFunctionPass { 38349cc55cSDimitry Andric MachineFunction *MF; 39349cc55cSDimitry Andric std::string ProfileFileName; 40349cc55cSDimitry Andric FSDiscriminatorPass P; 41349cc55cSDimitry Andric unsigned LowBit; 42349cc55cSDimitry Andric unsigned HighBit; 43349cc55cSDimitry Andric 44349cc55cSDimitry Andric public: 45349cc55cSDimitry Andric static char ID; 46349cc55cSDimitry Andric /// FS bits will only use the '1' bits in the Mask. 47349cc55cSDimitry Andric MIRProfileLoaderPass(std::string FileName = "", 48349cc55cSDimitry Andric std::string RemappingFileName = "", 49*06c3fb27SDimitry Andric FSDiscriminatorPass P = FSDiscriminatorPass::Pass1, 50*06c3fb27SDimitry Andric IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr); 51349cc55cSDimitry Andric 52349cc55cSDimitry Andric /// getMachineFunction - Return the last machine function computed. getMachineFunction()53349cc55cSDimitry Andric const MachineFunction *getMachineFunction() const { return MF; } 54349cc55cSDimitry Andric getPassName()55349cc55cSDimitry Andric StringRef getPassName() const override { return "SampleFDO loader in MIR"; } 56349cc55cSDimitry Andric 57349cc55cSDimitry Andric private: 58349cc55cSDimitry Andric void init(MachineFunction &MF); 59349cc55cSDimitry Andric bool runOnMachineFunction(MachineFunction &) override; 60349cc55cSDimitry Andric bool doInitialization(Module &M) override; 61349cc55cSDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override; 62349cc55cSDimitry Andric 63349cc55cSDimitry Andric std::unique_ptr<MIRProfileLoader> MIRSampleLoader; 64349cc55cSDimitry Andric /// Hold the information of the basic block frequency. 65349cc55cSDimitry Andric MachineBlockFrequencyInfo *MBFI; 66349cc55cSDimitry Andric }; 67349cc55cSDimitry Andric 68349cc55cSDimitry Andric } // namespace llvm 69349cc55cSDimitry Andric 70349cc55cSDimitry Andric #endif // LLVM_CODEGEN_MIRSAMPLEPROFILE_H 71