15fdaaf7fSRong Xu //===-------- MIRSampleProfile.cpp: MIRSampleFDO (For FSAFDO) -------------===// 25fdaaf7fSRong Xu // 35fdaaf7fSRong Xu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45fdaaf7fSRong Xu // See https://llvm.org/LICENSE.txt for license information. 55fdaaf7fSRong Xu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65fdaaf7fSRong Xu // 75fdaaf7fSRong Xu //===----------------------------------------------------------------------===// 85fdaaf7fSRong Xu // 95fdaaf7fSRong Xu // This file provides the implementation of the MIRSampleProfile loader, mainly 105fdaaf7fSRong Xu // for flow sensitive SampleFDO. 115fdaaf7fSRong Xu // 125fdaaf7fSRong Xu //===----------------------------------------------------------------------===// 135fdaaf7fSRong Xu 145fdaaf7fSRong Xu #include "llvm/CodeGen/MIRSampleProfile.h" 155fdaaf7fSRong Xu #include "llvm/ADT/DenseMap.h" 165fdaaf7fSRong Xu #include "llvm/ADT/DenseSet.h" 175fdaaf7fSRong Xu #include "llvm/Analysis/BlockFrequencyInfoImpl.h" 185fdaaf7fSRong Xu #include "llvm/IR/Function.h" 195fdaaf7fSRong Xu #include "llvm/Support/CommandLine.h" 205fdaaf7fSRong Xu #include "llvm/Support/Debug.h" 215fdaaf7fSRong Xu #include "llvm/Support/raw_ostream.h" 225fdaaf7fSRong Xu #include "llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h" 235fdaaf7fSRong Xu #include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h" 245fdaaf7fSRong Xu 255fdaaf7fSRong Xu using namespace llvm; 265fdaaf7fSRong Xu using namespace sampleprof; 275fdaaf7fSRong Xu using namespace llvm::sampleprofutil; 285fdaaf7fSRong Xu using ProfileCount = Function::ProfileCount; 295fdaaf7fSRong Xu 305fdaaf7fSRong Xu #define DEBUG_TYPE "fs-profile-loader" 315fdaaf7fSRong Xu 325fdaaf7fSRong Xu static cl::opt<bool> ShowFSBranchProb( 335fdaaf7fSRong Xu "show-fs-branchprob", cl::Hidden, cl::init(false), 345fdaaf7fSRong Xu cl::desc("Print setting flow sensitive branch probabilities")); 355fdaaf7fSRong Xu static cl::opt<unsigned> FSProfileDebugProbDiffThreshold( 365fdaaf7fSRong Xu "fs-profile-debug-prob-diff-threshold", cl::init(10), 375fdaaf7fSRong Xu cl::desc("Only show debug message if the branch probility is greater than " 385fdaaf7fSRong Xu "this value (in percentage).")); 395fdaaf7fSRong Xu 405fdaaf7fSRong Xu static cl::opt<unsigned> FSProfileDebugBWThreshold( 415fdaaf7fSRong Xu "fs-profile-debug-bw-threshold", cl::init(10000), 425fdaaf7fSRong Xu cl::desc("Only show debug message if the source branch weight is greater " 435fdaaf7fSRong Xu " than this value.")); 445fdaaf7fSRong Xu 455fdaaf7fSRong Xu static cl::opt<bool> ViewBFIBefore("fs-viewbfi-before", cl::Hidden, 465fdaaf7fSRong Xu cl::init(false), 475fdaaf7fSRong Xu cl::desc("View BFI before MIR loader")); 485fdaaf7fSRong Xu static cl::opt<bool> ViewBFIAfter("fs-viewbfi-after", cl::Hidden, 495fdaaf7fSRong Xu cl::init(false), 505fdaaf7fSRong Xu cl::desc("View BFI after MIR loader")); 515fdaaf7fSRong Xu 525fdaaf7fSRong Xu char MIRProfileLoaderPass::ID = 0; 535fdaaf7fSRong Xu 545fdaaf7fSRong Xu INITIALIZE_PASS_BEGIN(MIRProfileLoaderPass, DEBUG_TYPE, 555fdaaf7fSRong Xu "Load MIR Sample Profile", 565fdaaf7fSRong Xu /* cfg = */ false, /* is_analysis = */ false) 575fdaaf7fSRong Xu INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfo) 585fdaaf7fSRong Xu INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) 595fdaaf7fSRong Xu INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree) 605fdaaf7fSRong Xu INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) 615fdaaf7fSRong Xu INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass) 625fdaaf7fSRong Xu INITIALIZE_PASS_END(MIRProfileLoaderPass, DEBUG_TYPE, "Load MIR Sample Profile", 635fdaaf7fSRong Xu /* cfg = */ false, /* is_analysis = */ false) 645fdaaf7fSRong Xu 655fdaaf7fSRong Xu char &llvm::MIRProfileLoaderPassID = MIRProfileLoaderPass::ID; 665fdaaf7fSRong Xu 675fdaaf7fSRong Xu FunctionPass *llvm::createMIRProfileLoaderPass(std::string File, 685fdaaf7fSRong Xu std::string RemappingFile, 695fdaaf7fSRong Xu FSDiscriminatorPass P) { 705fdaaf7fSRong Xu return new MIRProfileLoaderPass(File, RemappingFile, P); 715fdaaf7fSRong Xu } 725fdaaf7fSRong Xu 735fdaaf7fSRong Xu namespace llvm { 745fdaaf7fSRong Xu 755fdaaf7fSRong Xu // Internal option used to control BFI display only after MBP pass. 765fdaaf7fSRong Xu // Defined in CodeGen/MachineBlockFrequencyInfo.cpp: 775fdaaf7fSRong Xu // -view-block-layout-with-bfi={none | fraction | integer | count} 785fdaaf7fSRong Xu extern cl::opt<GVDAGType> ViewBlockLayoutWithBFI; 795fdaaf7fSRong Xu 805fdaaf7fSRong Xu // Command line option to specify the name of the function for CFG dump 815fdaaf7fSRong Xu // Defined in Analysis/BlockFrequencyInfo.cpp: -view-bfi-func-name= 825fdaaf7fSRong Xu extern cl::opt<std::string> ViewBlockFreqFuncName; 835fdaaf7fSRong Xu 845fdaaf7fSRong Xu namespace afdo_detail { 855fdaaf7fSRong Xu template <> struct IRTraits<MachineBasicBlock> { 865fdaaf7fSRong Xu using InstructionT = MachineInstr; 875fdaaf7fSRong Xu using BasicBlockT = MachineBasicBlock; 885fdaaf7fSRong Xu using FunctionT = MachineFunction; 895fdaaf7fSRong Xu using BlockFrequencyInfoT = MachineBlockFrequencyInfo; 905fdaaf7fSRong Xu using LoopT = MachineLoop; 915fdaaf7fSRong Xu using LoopInfoPtrT = MachineLoopInfo *; 925fdaaf7fSRong Xu using DominatorTreePtrT = MachineDominatorTree *; 935fdaaf7fSRong Xu using PostDominatorTreePtrT = MachinePostDominatorTree *; 945fdaaf7fSRong Xu using PostDominatorTreeT = MachinePostDominatorTree; 955fdaaf7fSRong Xu using OptRemarkEmitterT = MachineOptimizationRemarkEmitter; 965fdaaf7fSRong Xu using OptRemarkAnalysisT = MachineOptimizationRemarkAnalysis; 975fdaaf7fSRong Xu using PredRangeT = iterator_range<std::vector<MachineBasicBlock *>::iterator>; 985fdaaf7fSRong Xu using SuccRangeT = iterator_range<std::vector<MachineBasicBlock *>::iterator>; 995fdaaf7fSRong Xu static Function &getFunction(MachineFunction &F) { return F.getFunction(); } 1005fdaaf7fSRong Xu static const MachineBasicBlock *getEntryBB(const MachineFunction *F) { 1015fdaaf7fSRong Xu return GraphTraits<const MachineFunction *>::getEntryNode(F); 1025fdaaf7fSRong Xu } 1035fdaaf7fSRong Xu static PredRangeT getPredecessors(MachineBasicBlock *BB) { 1045fdaaf7fSRong Xu return BB->predecessors(); 1055fdaaf7fSRong Xu } 1065fdaaf7fSRong Xu static SuccRangeT getSuccessors(MachineBasicBlock *BB) { 1075fdaaf7fSRong Xu return BB->successors(); 1085fdaaf7fSRong Xu } 1095fdaaf7fSRong Xu }; 1105fdaaf7fSRong Xu } // namespace afdo_detail 1115fdaaf7fSRong Xu 1125fdaaf7fSRong Xu class MIRProfileLoader final 1135fdaaf7fSRong Xu : public SampleProfileLoaderBaseImpl<MachineBasicBlock> { 1145fdaaf7fSRong Xu public: 1155fdaaf7fSRong Xu void setInitVals(MachineDominatorTree *MDT, MachinePostDominatorTree *MPDT, 1165fdaaf7fSRong Xu MachineLoopInfo *MLI, MachineBlockFrequencyInfo *MBFI, 1175fdaaf7fSRong Xu MachineOptimizationRemarkEmitter *MORE) { 1185fdaaf7fSRong Xu DT = MDT; 1195fdaaf7fSRong Xu PDT = MPDT; 1205fdaaf7fSRong Xu LI = MLI; 1215fdaaf7fSRong Xu BFI = MBFI; 1225fdaaf7fSRong Xu ORE = MORE; 1235fdaaf7fSRong Xu } 1245fdaaf7fSRong Xu void setFSPass(FSDiscriminatorPass Pass) { 1255fdaaf7fSRong Xu P = Pass; 1265fdaaf7fSRong Xu LowBit = getFSPassBitBegin(P); 1275fdaaf7fSRong Xu HighBit = getFSPassBitEnd(P); 1285fdaaf7fSRong Xu assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit"); 1295fdaaf7fSRong Xu } 1305fdaaf7fSRong Xu 1315fdaaf7fSRong Xu MIRProfileLoader(StringRef Name, StringRef RemapName) 1325fdaaf7fSRong Xu : SampleProfileLoaderBaseImpl(std::string(Name), std::string(RemapName)) { 1335fdaaf7fSRong Xu } 1345fdaaf7fSRong Xu 1355fdaaf7fSRong Xu void setBranchProbs(MachineFunction &F); 1365fdaaf7fSRong Xu bool runOnFunction(MachineFunction &F); 1375fdaaf7fSRong Xu bool doInitialization(Module &M); 1385fdaaf7fSRong Xu bool isValid() const { return ProfileIsValid; } 1395fdaaf7fSRong Xu 1405fdaaf7fSRong Xu protected: 1415fdaaf7fSRong Xu friend class SampleCoverageTracker; 1425fdaaf7fSRong Xu 1435fdaaf7fSRong Xu /// Hold the information of the basic block frequency. 1445fdaaf7fSRong Xu MachineBlockFrequencyInfo *BFI; 1455fdaaf7fSRong Xu 1465fdaaf7fSRong Xu /// PassNum is the sequence number this pass is called, start from 1. 1475fdaaf7fSRong Xu FSDiscriminatorPass P; 1485fdaaf7fSRong Xu 1495fdaaf7fSRong Xu // LowBit in the FS discriminator used by this instance. Note the number is 1505fdaaf7fSRong Xu // 0-based. Base discrimnator use bit 0 to bit 11. 1515fdaaf7fSRong Xu unsigned LowBit; 1525fdaaf7fSRong Xu // HighwBit in the FS discriminator used by this instance. Note the number 1535fdaaf7fSRong Xu // is 0-based. 1545fdaaf7fSRong Xu unsigned HighBit; 1555fdaaf7fSRong Xu 1565fdaaf7fSRong Xu bool ProfileIsValid = true; 1575fdaaf7fSRong Xu }; 1585fdaaf7fSRong Xu 1595fdaaf7fSRong Xu template <> 1605fdaaf7fSRong Xu void SampleProfileLoaderBaseImpl< 1615fdaaf7fSRong Xu MachineBasicBlock>::computeDominanceAndLoopInfo(MachineFunction &F) {} 1625fdaaf7fSRong Xu 1635fdaaf7fSRong Xu void MIRProfileLoader::setBranchProbs(MachineFunction &F) { 1645fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "\nPropagation complete. Setting branch probs\n"); 1655fdaaf7fSRong Xu for (auto &BI : F) { 1665fdaaf7fSRong Xu MachineBasicBlock *BB = &BI; 1675fdaaf7fSRong Xu if (BB->succ_size() < 2) 1685fdaaf7fSRong Xu continue; 1695fdaaf7fSRong Xu const MachineBasicBlock *EC = EquivalenceClass[BB]; 1705fdaaf7fSRong Xu uint64_t BBWeight = BlockWeights[EC]; 1715fdaaf7fSRong Xu uint64_t SumEdgeWeight = 0; 172*cba40c4eSKazu Hirata for (MachineBasicBlock *Succ : BB->successors()) { 1735fdaaf7fSRong Xu Edge E = std::make_pair(BB, Succ); 1745fdaaf7fSRong Xu SumEdgeWeight += EdgeWeights[E]; 1755fdaaf7fSRong Xu } 1765fdaaf7fSRong Xu 1775fdaaf7fSRong Xu if (BBWeight != SumEdgeWeight) { 1785fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "BBweight is not equal to SumEdgeWeight: BBWWeight=" 1795fdaaf7fSRong Xu << BBWeight << " SumEdgeWeight= " << SumEdgeWeight 1805fdaaf7fSRong Xu << "\n"); 1815fdaaf7fSRong Xu BBWeight = SumEdgeWeight; 1825fdaaf7fSRong Xu } 1835fdaaf7fSRong Xu if (BBWeight == 0) { 1845fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "SKIPPED. All branch weights are zero.\n"); 1855fdaaf7fSRong Xu continue; 1865fdaaf7fSRong Xu } 1875fdaaf7fSRong Xu 1885fdaaf7fSRong Xu #ifndef NDEBUG 1895fdaaf7fSRong Xu uint64_t BBWeightOrig = BBWeight; 1905fdaaf7fSRong Xu #endif 1915fdaaf7fSRong Xu uint32_t MaxWeight = std::numeric_limits<uint32_t>::max(); 1925fdaaf7fSRong Xu uint32_t Factor = 1; 1935fdaaf7fSRong Xu if (BBWeight > MaxWeight) { 1945fdaaf7fSRong Xu Factor = BBWeight / MaxWeight + 1; 1955fdaaf7fSRong Xu BBWeight /= Factor; 1965fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "Scaling weights by " << Factor << "\n"); 1975fdaaf7fSRong Xu } 1985fdaaf7fSRong Xu 1995fdaaf7fSRong Xu for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), 2005fdaaf7fSRong Xu SE = BB->succ_end(); 2015fdaaf7fSRong Xu SI != SE; ++SI) { 2025fdaaf7fSRong Xu MachineBasicBlock *Succ = *SI; 2035fdaaf7fSRong Xu Edge E = std::make_pair(BB, Succ); 2045fdaaf7fSRong Xu uint64_t EdgeWeight = EdgeWeights[E]; 2055fdaaf7fSRong Xu EdgeWeight /= Factor; 2065fdaaf7fSRong Xu 2075fdaaf7fSRong Xu assert(BBWeight >= EdgeWeight && 2085fdaaf7fSRong Xu "BBweight is larger than EdgeWeight -- should not happen.\n"); 2095fdaaf7fSRong Xu 2105fdaaf7fSRong Xu BranchProbability OldProb = BFI->getMBPI()->getEdgeProbability(BB, SI); 2115fdaaf7fSRong Xu BranchProbability NewProb(EdgeWeight, BBWeight); 2125fdaaf7fSRong Xu if (OldProb == NewProb) 2135fdaaf7fSRong Xu continue; 2145fdaaf7fSRong Xu BB->setSuccProbability(SI, NewProb); 2155fdaaf7fSRong Xu #ifndef NDEBUG 2165fdaaf7fSRong Xu if (!ShowFSBranchProb) 2175fdaaf7fSRong Xu continue; 2185fdaaf7fSRong Xu bool Show = false; 2195fdaaf7fSRong Xu BranchProbability Diff; 2205fdaaf7fSRong Xu if (OldProb > NewProb) 2215fdaaf7fSRong Xu Diff = OldProb - NewProb; 2225fdaaf7fSRong Xu else 2235fdaaf7fSRong Xu Diff = NewProb - OldProb; 2245fdaaf7fSRong Xu Show = (Diff >= BranchProbability(FSProfileDebugProbDiffThreshold, 100)); 2255fdaaf7fSRong Xu Show &= (BBWeightOrig >= FSProfileDebugBWThreshold); 2265fdaaf7fSRong Xu 2275fdaaf7fSRong Xu auto DIL = BB->findBranchDebugLoc(); 2285fdaaf7fSRong Xu auto SuccDIL = Succ->findBranchDebugLoc(); 2295fdaaf7fSRong Xu if (Show) { 2305fdaaf7fSRong Xu dbgs() << "Set branch fs prob: MBB (" << BB->getNumber() << " -> " 2315fdaaf7fSRong Xu << Succ->getNumber() << "): "; 2325fdaaf7fSRong Xu if (DIL) 2335fdaaf7fSRong Xu dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":" 2345fdaaf7fSRong Xu << DIL->getColumn(); 2355fdaaf7fSRong Xu if (SuccDIL) 2365fdaaf7fSRong Xu dbgs() << "-->" << SuccDIL->getFilename() << ":" << SuccDIL->getLine() 2375fdaaf7fSRong Xu << ":" << SuccDIL->getColumn(); 2385fdaaf7fSRong Xu dbgs() << " W=" << BBWeightOrig << " " << OldProb << " --> " << NewProb 2395fdaaf7fSRong Xu << "\n"; 2405fdaaf7fSRong Xu } 2415fdaaf7fSRong Xu #endif 2425fdaaf7fSRong Xu } 2435fdaaf7fSRong Xu } 2445fdaaf7fSRong Xu } 2455fdaaf7fSRong Xu 2465fdaaf7fSRong Xu bool MIRProfileLoader::doInitialization(Module &M) { 2475fdaaf7fSRong Xu auto &Ctx = M.getContext(); 2485fdaaf7fSRong Xu 2495fdaaf7fSRong Xu auto ReaderOrErr = sampleprof::SampleProfileReader::create(Filename, Ctx, P, 2505fdaaf7fSRong Xu RemappingFilename); 2515fdaaf7fSRong Xu if (std::error_code EC = ReaderOrErr.getError()) { 2525fdaaf7fSRong Xu std::string Msg = "Could not open profile: " + EC.message(); 2535fdaaf7fSRong Xu Ctx.diagnose(DiagnosticInfoSampleProfile(Filename, Msg)); 2545fdaaf7fSRong Xu return false; 2555fdaaf7fSRong Xu } 2565fdaaf7fSRong Xu 2575fdaaf7fSRong Xu Reader = std::move(ReaderOrErr.get()); 2585fdaaf7fSRong Xu Reader->setModule(&M); 2595fdaaf7fSRong Xu ProfileIsValid = (Reader->read() == sampleprof_error::success); 2605fdaaf7fSRong Xu Reader->getSummary(); 2615fdaaf7fSRong Xu 2625fdaaf7fSRong Xu return true; 2635fdaaf7fSRong Xu } 2645fdaaf7fSRong Xu 2655fdaaf7fSRong Xu bool MIRProfileLoader::runOnFunction(MachineFunction &MF) { 2665fdaaf7fSRong Xu Function &Func = MF.getFunction(); 2675fdaaf7fSRong Xu clearFunctionData(false); 2685fdaaf7fSRong Xu Samples = Reader->getSamplesFor(Func); 2695fdaaf7fSRong Xu if (!Samples || Samples->empty()) 2705fdaaf7fSRong Xu return false; 2715fdaaf7fSRong Xu 2725fdaaf7fSRong Xu if (getFunctionLoc(MF) == 0) 2735fdaaf7fSRong Xu return false; 2745fdaaf7fSRong Xu 2755fdaaf7fSRong Xu DenseSet<GlobalValue::GUID> InlinedGUIDs; 2765fdaaf7fSRong Xu bool Changed = computeAndPropagateWeights(MF, InlinedGUIDs); 2775fdaaf7fSRong Xu 2785fdaaf7fSRong Xu // Set the new BPI, BFI. 2795fdaaf7fSRong Xu setBranchProbs(MF); 2805fdaaf7fSRong Xu 2815fdaaf7fSRong Xu return Changed; 2825fdaaf7fSRong Xu } 2835fdaaf7fSRong Xu 2845fdaaf7fSRong Xu } // namespace llvm 2855fdaaf7fSRong Xu 2861e586bccSAdrian Prantl MIRProfileLoaderPass::MIRProfileLoaderPass(std::string FileName, 2871e586bccSAdrian Prantl std::string RemappingFileName, 2881e586bccSAdrian Prantl FSDiscriminatorPass P) 2891e586bccSAdrian Prantl : MachineFunctionPass(ID), ProfileFileName(FileName), P(P), 2901e586bccSAdrian Prantl MIRSampleLoader( 2911e586bccSAdrian Prantl std::make_unique<MIRProfileLoader>(FileName, RemappingFileName)) { 2921e586bccSAdrian Prantl LowBit = getFSPassBitBegin(P); 2931e586bccSAdrian Prantl HighBit = getFSPassBitEnd(P); 2941e586bccSAdrian Prantl assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit"); 2951e586bccSAdrian Prantl } 2961e586bccSAdrian Prantl 2975fdaaf7fSRong Xu bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) { 2985fdaaf7fSRong Xu if (!MIRSampleLoader->isValid()) 2995fdaaf7fSRong Xu return false; 3005fdaaf7fSRong Xu 3015fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "MIRProfileLoader pass working on Func: " 3025fdaaf7fSRong Xu << MF.getFunction().getName() << "\n"); 3035fdaaf7fSRong Xu MBFI = &getAnalysis<MachineBlockFrequencyInfo>(); 3045fdaaf7fSRong Xu MIRSampleLoader->setInitVals( 3055fdaaf7fSRong Xu &getAnalysis<MachineDominatorTree>(), 3065fdaaf7fSRong Xu &getAnalysis<MachinePostDominatorTree>(), &getAnalysis<MachineLoopInfo>(), 3075fdaaf7fSRong Xu MBFI, &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE()); 3085fdaaf7fSRong Xu 3095fdaaf7fSRong Xu MF.RenumberBlocks(); 3105fdaaf7fSRong Xu if (ViewBFIBefore && ViewBlockLayoutWithBFI != GVDT_None && 3115fdaaf7fSRong Xu (ViewBlockFreqFuncName.empty() || 3125fdaaf7fSRong Xu MF.getFunction().getName().equals(ViewBlockFreqFuncName))) { 3135fdaaf7fSRong Xu MBFI->view("MIR_Prof_loader_b." + MF.getName(), false); 3145fdaaf7fSRong Xu } 3155fdaaf7fSRong Xu 3165fdaaf7fSRong Xu bool Changed = MIRSampleLoader->runOnFunction(MF); 3175fdaaf7fSRong Xu 3185fdaaf7fSRong Xu if (ViewBFIAfter && ViewBlockLayoutWithBFI != GVDT_None && 3195fdaaf7fSRong Xu (ViewBlockFreqFuncName.empty() || 3205fdaaf7fSRong Xu MF.getFunction().getName().equals(ViewBlockFreqFuncName))) { 3215fdaaf7fSRong Xu MBFI->view("MIR_prof_loader_a." + MF.getName(), false); 3225fdaaf7fSRong Xu } 3235fdaaf7fSRong Xu 3245fdaaf7fSRong Xu return Changed; 3255fdaaf7fSRong Xu } 3265fdaaf7fSRong Xu 3275fdaaf7fSRong Xu bool MIRProfileLoaderPass::doInitialization(Module &M) { 3285fdaaf7fSRong Xu LLVM_DEBUG(dbgs() << "MIRProfileLoader pass working on Module " << M.getName() 3295fdaaf7fSRong Xu << "\n"); 3305fdaaf7fSRong Xu 3315fdaaf7fSRong Xu MIRSampleLoader->setFSPass(P); 3325fdaaf7fSRong Xu return MIRSampleLoader->doInitialization(M); 3335fdaaf7fSRong Xu } 3345fdaaf7fSRong Xu 3355fdaaf7fSRong Xu void MIRProfileLoaderPass::getAnalysisUsage(AnalysisUsage &AU) const { 3365fdaaf7fSRong Xu AU.setPreservesAll(); 3375fdaaf7fSRong Xu AU.addRequired<MachineBlockFrequencyInfo>(); 3385fdaaf7fSRong Xu AU.addRequired<MachineDominatorTree>(); 3395fdaaf7fSRong Xu AU.addRequired<MachinePostDominatorTree>(); 3405fdaaf7fSRong Xu AU.addRequiredTransitive<MachineLoopInfo>(); 3415fdaaf7fSRong Xu AU.addRequired<MachineOptimizationRemarkEmitterPass>(); 3425fdaaf7fSRong Xu MachineFunctionPass::getAnalysisUsage(AU); 3435fdaaf7fSRong Xu } 344