diff --git a/llvm/include/llvm/Analysis/ACPOBWModel.h b/llvm/include/llvm/Analysis/ACPOBWModel.h index 8070eb47de5bd3fedeaa1a18a245658634d3e282..4c75920ae68dff69c87e814717cfa87622853c7e 100644 --- a/llvm/include/llvm/Analysis/ACPOBWModel.h +++ b/llvm/include/llvm/Analysis/ACPOBWModel.h @@ -7,7 +7,7 @@ // Copyright (C) 2025. Huawei Technologies Co., Ltd. All rights reserved. // //==-----------------------------------------------------------------------===// - +#if defined(ENABLE_ACPO) #ifndef LLVM_ANALYSIS_ACPOBWMODEL_H #define LLVM_ANALYSIS_ACPOBWMODEL_H @@ -36,4 +36,5 @@ private: } // end namespace llvm -#endif // LLVM_ANALYSIS_ACPOBWMODEL_H \ No newline at end of file +#endif // LLVM_ANALYSIS_ACPOBWMODEL_H +#endif // ENABLE_ACPO diff --git a/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CFHModel.h b/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CFHModel.h index 798e7d220fb7c9c663111ca788df77c8e8850858..d8d24fb4b6ac58bcc796c7bcc8724bf68b42c353 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CFHModel.h +++ b/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CFHModel.h @@ -1,3 +1,4 @@ +#if defined(ENABLE_ACPO) #ifndef LLVM_TRANSFORMS_ACPOAI4CFHMODEL_H #define LLVM_TRANSFORMS_ACPOAI4CFHMODEL_H @@ -28,4 +29,5 @@ private: }; } // end namespace llvm -#endif \ No newline at end of file +#endif +#endif //Enable_ACPO diff --git a/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h b/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h index c563eec5a404ff2f25e67921ef7772eaab9e3a67..0d51466ed951d868c6a77928473db96931a69e74 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h +++ b/llvm/include/llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #ifndef LLVM_TRANSFORMS_ACPOAI4CMEMOPMODEL_H #define LLVM_TRANSFORMS_ACPOAI4CMEMOPMODEL_H @@ -29,3 +31,4 @@ private: }; } // end namespace llvm #endif +#endif // Enable_ACPO \ No newline at end of file diff --git a/llvm/include/llvm/Transforms/Instrumentation/AI4CAnalysis.h b/llvm/include/llvm/Transforms/Instrumentation/AI4CAnalysis.h index fb0206bbbc6653949dbd0becd5158c7a94b02aae..5a48c8c205365906de70bc7c0af7ca6699592832 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/AI4CAnalysis.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AI4CAnalysis.h @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_AI4CANALYSIS_H #define LLVM_TRANSFORMS_INSTRUMENTATION_AI4CANALYSIS_H @@ -23,4 +25,5 @@ public: }// end name sace llvm -#endif \ No newline at end of file +#endif +#endif // Enable_ACPO \ No newline at end of file diff --git a/llvm/include/llvm/Transforms/Instrumentation/AI4CFHModelRunner.h b/llvm/include/llvm/Transforms/Instrumentation/AI4CFHModelRunner.h index 8fe2d762365ee1eb54f276da167d2b4bc9bef16d..d9d6a704f542fd7dc5e0475ea80a8209e57a3a1d 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/AI4CFHModelRunner.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AI4CFHModelRunner.h @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #ifdef LLVM_HAVE_TF_AOT_AI4CFHCOMPILEDMODEL #ifndef LLVM_ANALYSIS_AI4CFHMODELRUNNER_H @@ -70,4 +72,5 @@ public: } #endif -#endif \ No newline at end of file +#endif +#endif // Enable_ACPO \ No newline at end of file diff --git a/llvm/include/llvm/Transforms/Instrumentation/AI4CMEMOPModelRunner.h b/llvm/include/llvm/Transforms/Instrumentation/AI4CMEMOPModelRunner.h index d3984cd530044af983c80e58638d18ef75961097..5d7d55dbd05aeedf4298d7e95a33178c90f26276 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/AI4CMEMOPModelRunner.h +++ b/llvm/include/llvm/Transforms/Instrumentation/AI4CMEMOPModelRunner.h @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #ifdef LLVM_HAVE_TF_AOT_AI4CMEMOPCOMPILEDMODEL #ifndef LLVM_ANALYSIS_AI4CMEMOPMODELRUNNER_H @@ -97,4 +99,5 @@ public: } // namespace llvm #endif // LLVM_ANALYSIS_AI4CMEMOPMODELRUNNER_H -#endif // LLVM_HAVE_TF_AOT_AI4CMEMOPCOMPILEDMODEL \ No newline at end of file +#endif // LLVM_HAVE_TF_AOT_AI4CMEMOPCOMPILEDMODEL +#endif //Enable_ACPO \ No newline at end of file diff --git a/llvm/include/llvm/Transforms/Utils/ACPOBranchWeightModel.h b/llvm/include/llvm/Transforms/Utils/ACPOBranchWeightModel.h index 05b9c645ff76114c619e9c2f95ff20c086231a51..e7e1dd4b63c6a6f311e121db45fab6eb925225ac 100644 --- a/llvm/include/llvm/Transforms/Utils/ACPOBranchWeightModel.h +++ b/llvm/include/llvm/Transforms/Utils/ACPOBranchWeightModel.h @@ -7,7 +7,7 @@ // Copyright (C) 2025. Huawei Technologies Co., Ltd. All rights reserved. // //===------------------------------------------------------------------------===// - +#if defined(ENABLE_ACPO) #ifndef LLVM_TRANSFORM_UTILS_ACPOBRANCHWEIGHTMODEL_H #define LLVM_TRANSFORM_UTILS_ACPOBRANCHWEIGHTMODEL_H @@ -27,4 +27,5 @@ private: }; } -#endif //LLVM_TRANSFORM_UTILS_ACPOBRANCHWEIGHTMODEL_H \ No newline at end of file +#endif //LLVM_TRANSFORM_UTILS_ACPOBRANCHWEIGHTMODEL_H +#endif // ENABLE_ACPO diff --git a/llvm/lib/Analysis/ACPOBWModel.cpp b/llvm/lib/Analysis/ACPOBWModel.cpp index 6a95b34df97878d44f3063c983e888544cf37cab..28b6ab41be3bb30909e4a853b17bd945f00634de 100644 --- a/llvm/lib/Analysis/ACPOBWModel.cpp +++ b/llvm/lib/Analysis/ACPOBWModel.cpp @@ -13,6 +13,7 @@ // //==-----------------------------------------------------------------------===// +#if defined(ENABLE_ACPO) #include "llvm/Analysis/ACPOBWModel.h" using namespace llvm; @@ -55,4 +56,5 @@ std::unique_ptr ACPOBWModel::getAdviceML() { return Advice; } -std::unique_ptr ACPOBWModel::getAdviceNoML() { return nullptr; } \ No newline at end of file +std::unique_ptr ACPOBWModel::getAdviceNoML() { return nullptr; } +#endif // ENABLE_ACPO diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 3335c314a24344a5eb5a2fe7dc42912e8ac29b26..c9f3512da32b22083c835fb8eeecfafa4a38ed37 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -594,7 +594,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, invokePeepholeEPCallbacks(FPM, Level); +#if defined(ENABLE_ACPO) if (PTO.AI4CAnalysis && !Level.isOptimizingForSize()) FPM.addPass(PGOMemOPSizeOpt()); +#endif // For PGO use pipeline, try to optimize memory intrinsics such as memcpy // using the size value profile. Don't perform this when optimizing for size. @@ -764,6 +766,7 @@ void PassBuilder::addRequiredLTOPreLinkPasses(ModulePassManager &MPM) { MPM.addPass(NameAnonGlobalPass()); } +#if defined(ENABLE_ACPO) void PassBuilder::addAI4CRelatedPassesForO0(ModulePassManager &MPM) { MPM.addPass(AI4CAnalysis()); MPM.addPass(RequireAnalysisPass()); @@ -804,6 +807,7 @@ void PassBuilder::addAI4CRelatedPasses(ModulePassManager &MPM, MPM.addPass(RequireAnalysisPass()); } } +#endif void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level, bool RunProfileGen, @@ -905,6 +909,7 @@ void PassBuilder::addPGOInstrPassesForO0( MPM.addPass(InstrProfiling(Options, IsCS)); } +#if defined(ENABLE_ACPO) void PassBuilder::addACPOBWPasses(ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase LTOPhase, bool skipPreInline) { assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!"); if (!skipPreInline && !DisablePreInliner) { @@ -934,6 +939,7 @@ void PassBuilder::addACPOBWPasses(ModulePassManager &MPM, OptimizationLevel Leve MPM.addPass(ACPOBranchWeightModelPass()); MPM.addPass(RequireAnalysisPass()); } +#endif static InlineParams getInlineParamsFromOptLevel(OptimizationLevel Level) { return getInlineParams(Level.getSpeedupLevel(), Level.getSizeLevel()); @@ -957,8 +963,10 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level, PGOOpt->Action == PGOOptions::SampleUse) IP.HotCallSiteThreshold = 0; +#if defined(ENABLE_ACPO) if (PTO.AI4CAnalysis) IP.EnableDeferral = EnablePGOInlineDeferral; +#endif if (PGOOpt) IP.EnableDeferral = EnablePGOInlineDeferral; @@ -1060,8 +1068,10 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level, PGOOpt->Action == PGOOptions::SampleUse) IP.HotCallSiteThreshold = 0; +#if defined(ENABLE_ACPO) if (PTO.AI4CAnalysis) IP.EnableDeferral = EnablePGOInlineDeferral; +#endif if (PGOOpt) IP.EnableDeferral = EnablePGOInlineDeferral; @@ -1215,10 +1225,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM), PTO.EagerlyInvalidateAnalyses)); +#if defined(ENABLE_ACPO) if (PTO.AI4CAnalysis && Phase != ThinOrFullLTOPhase::ThinLTOPostLink) { addAI4CRelatedPasses(MPM, Level, Phase); MPM.addPass(PGOIndirectCallPromotion(false, false)); } +#endif + // Add all the requested passes for instrumentation PGO, if requested. if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink && (PGOOpt->Action == PGOOptions::IRInstr || @@ -1242,8 +1255,10 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(SyntheticCountsPropagation()); #if defined(ENABLE_AUTOTUNER) +#if defined(ENABLE_ACPO) if (!PGOOpt && EnableACPOBWModel) addACPOBWPasses(MPM, Level, Phase, false); +#endif if (AutoTuningCompileMode) MPM.addPass(AutoTuningCompileModulePass(autotuning::CompileOptionInline)); #endif @@ -1459,8 +1474,10 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level, PGOOpt->ProfileRemappingFile, LTOPhase, PGOOpt->FS); } +#if defined(ENABLE_ACPO) if (!LTOPreLink && !PGOOpt && EnableACPOBWModel) addACPOBWPasses(MPM, Level, LTOPhase, true); +#endif // Re-compute GlobalsAA here prior to function passes. This is particularly // useful as the above will have inlined, DCE'ed, and function-attr @@ -1970,8 +1987,10 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS); } +#if defined(ENABLE_ACPO) if (!PGOOpt && EnableACPOBWModel) addACPOBWPasses(MPM, Level, ThinOrFullLTOPhase::FullLTOPostLink, true); +#endif // Break up allocas FPM.addPass(SROAPass(SROAOptions::ModifyCFG)); @@ -2110,8 +2129,10 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level, if (PGOOpt && PGOOpt->PseudoProbeForProfiling) MPM.addPass(SampleProfileProbePass(TM)); +#if defined(ENABLE_ACPO) if (PTO.AI4CAnalysis) addAI4CRelatedPassesForO0(MPM); +#endif if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr || PGOOpt->Action == PGOOptions::IRUse)) @@ -2199,11 +2220,13 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level, return MPM; } +#if defined(ENABLE_ACPO) ModulePassManager PassBuilder::addAutoTunerLTOPreLinkPasses() { ModulePassManager MPM; addRequiredLTOPreLinkPasses(MPM); return MPM; } +#endif AAManager PassBuilder::buildDefaultAAPipeline() { AAManager AA; diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index ac2738f3f67a519297c9c4668442ce9b1d9e10f3..7dfa618b4506c13a73e679afddbad918ef6ba7d5 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -48,7 +48,9 @@ MODULE_ALIAS_ANALYSIS("globals-aa", GlobalsAA()) #ifndef MODULE_PASS #define MODULE_PASS(NAME, CREATE_PASS) #endif +#if defined(ENABLE_ACPO) MODULE_PASS("ai4c-analysis", AI4CAnalysis()) +#endif MODULE_PASS("always-inline", AlwaysInlinerPass()) MODULE_PASS("attributor", AttributorPass()) MODULE_PASS("annotation2metadata", Annotation2MetadataPass()) @@ -136,7 +138,9 @@ MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass()) MODULE_PASS("memprof-module", ModuleMemProfilerPass()) MODULE_PASS("poison-checking", PoisonCheckingPass()) MODULE_PASS("pseudo-probe-update", PseudoProbeUpdatePass()) +#if defined(ENABLE_ACPO) MODULE_PASS("acpo-branch-weight-model", ACPOBranchWeightModelPass()); +#endif #if defined(ENABLE_AUTOTUNER) MODULE_PASS("autotuning-compile-module", AutoTuningCompileModulePass()) #endif diff --git a/llvm/lib/Transforms/Instrumentation/ACPOAI4CFHModel.cpp b/llvm/lib/Transforms/Instrumentation/ACPOAI4CFHModel.cpp index 499410a9024b4a762b452fb2e26c30836e86b015..b8e1ecf2fdbebdfa0098d998bdcd93d3058c1bbf 100644 --- a/llvm/lib/Transforms/Instrumentation/ACPOAI4CFHModel.cpp +++ b/llvm/lib/Transforms/Instrumentation/ACPOAI4CFHModel.cpp @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #include "llvm/Transforms/Instrumentation/ACPOAI4CFHModel.h" using namespace llvm; @@ -34,4 +36,5 @@ std::unique_ptr ACPOAI4CFHModel::getAdviceML() { } std::unique_ptr ACPOAI4CFHModel::getAdviceNoML() {return nullptr;} +#endif // Enable_ACPP diff --git a/llvm/lib/Transforms/Instrumentation/ACPOAI4CMEMOPModel.cpp b/llvm/lib/Transforms/Instrumentation/ACPOAI4CMEMOPModel.cpp index c2ca8d63dbcc3629bafa05da65e3acaabfd2614d..f39871152fc12da66321b3cb7cd75a1f6e9b26dc 100644 --- a/llvm/lib/Transforms/Instrumentation/ACPOAI4CMEMOPModel.cpp +++ b/llvm/lib/Transforms/Instrumentation/ACPOAI4CMEMOPModel.cpp @@ -1,3 +1,5 @@ +#if defined(ENABLE_ACPO) + #include "llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h" using namespace llvm; @@ -37,3 +39,4 @@ std::unique_ptr ACPOAI4CMEMOPModel::getAdviceML() { std::unique_ptr ACPOAI4CMEMOPModel::getAdviceNoML() { return nullptr; } +#endif //Enable_ACPO \ No newline at end of file diff --git a/llvm/lib/Transforms/Instrumentation/AI4CAnalysis.cpp b/llvm/lib/Transforms/Instrumentation/AI4CAnalysis.cpp index 19c7849c114c85d9a9c5b19e5081fd717545488e..b74cb4a9fcfe027ac8e5c9a2ae7a6aa32b87eea7 100644 --- a/llvm/lib/Transforms/Instrumentation/AI4CAnalysis.cpp +++ b/llvm/lib/Transforms/Instrumentation/AI4CAnalysis.cpp @@ -9,6 +9,7 @@ // This file implement AOT ML model to decide function hotness // //===----------------------------------------------------------------------===// +#if defined(ENABLE_ACPO) #include "llvm/Transforms/Instrumentation/AI4CAnalysis.h" #include "llvm/Analysis/BlockFrequencyInfo.h" @@ -152,3 +153,4 @@ PreservedAnalyses AI4CAnalysis::run(Module &M, ModuleAnalysisManager &MAM) { return PreservedAnalyses::all(); } } +#endif //Enable_ACPO diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp index 919dcecc4ffb5aa83f5035f85c37b77f83b02d8f..98c75f3719a6dca066e063ca0108ecb5ddca890d 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp @@ -20,7 +20,6 @@ #include "llvm/ADT/Twine.h" #include "llvm/Analysis/BlockFrequencyInfo.h" #include "llvm/Analysis/DomTreeUpdater.h" -#include "llvm/Analysis/ModelDataCollector.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/BasicBlock.h" @@ -40,18 +39,22 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/FormattedStream.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h" -#include "llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include #include #include +#if defined(ENABLE_ACPO) +#include "llvm/Analysis/ModelDataCollector.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/Instrumentation/ACPOAI4CMEMOPModel.h" +#endif + using namespace llvm; #define DEBUG_TYPE "pgo-memop-opt" @@ -98,6 +101,7 @@ static cl::opt MemOpMaxOptSize("memop-value-prof-max-opt-size", cl::Hidden, cl::init(128), cl::desc("Optimize the memop size <= this value")); +#if defined(ENABLE_ACPO) cl::opt EnableAI4CMEMOP("enable-ai4c-memop", cl::init(false), cl::Hidden, cl::desc("Leverage AOT ML model to optimize memop.")); @@ -226,6 +230,7 @@ SmallVector getACPOAdvice(Function *F, return SizeIds; } +#endif namespace { @@ -308,11 +313,18 @@ struct MemOp { class MemOPSizeOpt : public InstVisitor { public: +#if defined(ENABLE_ACPO) + MemOPSizeOpt(Function &Func, BlockFrequencyInfo &BFI, + OptimizationRemarkEmitter &ORE, DominatorTree *DT, + TargetLibraryInfo &TLI, ModelDataAI4CMemOPCollector &MDC) + : Func(Func), BFI(BFI), ORE(ORE), DT(DT), TLI(TLI), MDC(MDC), + Changed(false) { +#else MemOPSizeOpt(Function &Func, BlockFrequencyInfo &BFI, OptimizationRemarkEmitter &ORE, DominatorTree *DT, - TargetLibraryInfo &TLI, ModelDataAI4CMemOPCollector &MDC) - : Func(Func), BFI(BFI), ORE(ORE), DT(DT), TLI(TLI), MDC(MDC), - Changed(false) { + TargetLibraryInfo &TLI) + : Func(Func), BFI(BFI), ORE(ORE), DT(DT), TLI(TLI), Changed(false) { +#endif // Enable_ACPO { ValueDataArray = std::make_unique(INSTR_PROF_NUM_BUCKETS); } @@ -360,8 +372,10 @@ private: // The space to read the profile annotation. std::unique_ptr ValueDataArray; bool perform(MemOp MO); +#if defined(ENABLE_ACPO) std::vector> Records; ModelDataAI4CMemOPCollector &MDC; +#endif }; static bool isProfitable(uint64_t Count, uint64_t TotalCount) { @@ -403,12 +417,14 @@ bool MemOPSizeOpt::perform(MemOp MO) { SmallVector RemainingVDs; uint64_t SumForOpt; const char *op_name = MO.getName(TLI); +#if defined(ENABLE_ACPO) if (EnableAI4CMEMOP) { MDC.collectFeatures(&Func, MO.I, op_name); SizeIds = getACPOAdvice(MO.I->getFunction(), &MDC); if (!SizeIds.size()) return false; } else { +#endif if (!getValueProfDataFromInst(*MO.I, IPVK_MemOPSize, MaxNumVals, ValueDataArray.get(), NumVals, TotalCount)) { return false; @@ -502,7 +518,9 @@ bool MemOPSizeOpt::perform(MemOp MO) { LLVM_DEBUG(dbgs() << "Optimize one memory intrinsic call to " << Version << " Versions (covering " << SumForOpt << " out of " << TotalCount << ")\n"); +#if defined(ENABLE_ACPO) } +#endif // mem_op(..., size) // ==> @@ -609,16 +627,26 @@ bool MemOPSizeOpt::perform(MemOp MO) { } } // namespace +#if defined(ENABLE_ACPO) + static bool PGOMemOPSizeOptImpl(Function &F, BlockFrequencyInfo &BFI, + OptimizationRemarkEmitter &ORE, + DominatorTree *DT, TargetLibraryInfo &TLI, + ModelDataAI4CMemOPCollector &MDC) { +#else static bool PGOMemOPSizeOptImpl(Function &F, BlockFrequencyInfo &BFI, OptimizationRemarkEmitter &ORE, - DominatorTree *DT, TargetLibraryInfo &TLI, - ModelDataAI4CMemOPCollector &MDC) { + DominatorTree *DT, TargetLibraryInfo &TLI) { +#endif // ENABLE_ACPO if (DisableMemOPOPT) return false; if (F.hasFnAttribute(Attribute::OptimizeForSize)) return false; +#if defined(ENABLE_ACPO) MemOPSizeOpt MemOPSizeOpt(F, BFI, ORE, DT, TLI, MDC); +#else + MemOPSizeOpt MemOPSizeOpt(F, BFI, ORE, DT, TLI); +#endif MemOPSizeOpt.perform(); return MemOPSizeOpt.isChanged(); } @@ -629,12 +657,16 @@ PreservedAnalyses PGOMemOPSizeOpt::run(Function &F, auto &ORE = FAM.getResult(F); auto *DT = FAM.getCachedResult(F); auto &TLI = FAM.getResult(F); - std::error_code EC; - raw_fd_ostream RawOS(MemOPDumpFile.getValue(), EC, sys::fs::CD_OpenAlways, - sys::fs::FA_Write, sys::fs::OF_Append); - formatted_raw_ostream OS(RawOS); - ModelDataAI4CMemOPCollector MDC(OS, MemOPDumpFile, &FAM); - bool Changed = PGOMemOPSizeOptImpl(F, BFI, ORE, DT, TLI, MDC); +#if defined(ENABLE_ACPO) + std::error_code EC; + raw_fd_ostream RawOS(MemOPDumpFile.getValue(), EC, sys::fs::CD_OpenAlways, + sys::fs::FA_Write, sys::fs::OF_Append); + formatted_raw_ostream OS(RawOS); + ModelDataAI4CMemOPCollector MDC(OS, MemOPDumpFile, &FAM); + bool Changed = PGOMemOPSizeOptImpl(F, BFI, ORE, DT, TLI, MDC); +#else + bool Changed = PGOMemOPSizeOptImpl(F, BFI, ORE, DT, TLI); +#endif if (!Changed) return PreservedAnalyses::all(); auto PA = PreservedAnalyses(); diff --git a/llvm/lib/Transforms/Utils/ACPOBranchWeightModel.cpp b/llvm/lib/Transforms/Utils/ACPOBranchWeightModel.cpp index 2fd034309142d97bd4884396320e6a667aa34188..b54ab86637578d556dba901712bdd48673348ffa 100644 --- a/llvm/lib/Transforms/Utils/ACPOBranchWeightModel.cpp +++ b/llvm/lib/Transforms/Utils/ACPOBranchWeightModel.cpp @@ -11,6 +11,7 @@ // This pass adds the branch weight metadata. // //===----------------------------------------------------------------------===// +#if defined(ENABLE_ACPO) #include "llvm/Transforms/Utils/ACPOBranchWeightModel.h" #include "llvm/Analysis/ACPOBWModel.h" @@ -224,4 +225,5 @@ PreservedAnalyses ACPOBranchWeightModelPass::run(Module &M, ModuleAnalysisManage } else { return PreservedAnalyses::none(); } -} \ No newline at end of file +} +#endif // ENABLE_ACPO