https://github.com/pasko updated https://github.com/llvm/llvm-project/pull/92171
>From df3f8dfc47cd8d7b220ed712dc7c2cab1c563f50 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Mon, 6 May 2024 19:48:59 +0200 Subject: [PATCH 1/3] wip: Move instrumentation passes This change is not ready for landing yet. Move EntryExitInstrumenter(PostInlining=true) to as late as possible and EntryExitInstrumenter(PostInlining=false) to an early pre-inlining stage (but skip for ThinLTO post-link). --- clang/lib/CodeGen/BackendUtil.cpp | 21 ++----- llvm/include/llvm/InitializePasses.h | 2 + llvm/include/llvm/LinkAllPasses.h | 2 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 3 - llvm/include/llvm/Transforms/Utils.h | 9 +++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/Transforms/Scalar/Scalar.cpp | 2 + .../Utils/EntryExitInstrumenter.cpp | 62 +++++++++++++++++++ llvm/tools/llc/llc.cpp | 2 + llvm/tools/opt/optdriver.cpp | 2 + 10 files changed, 89 insertions(+), 19 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 22c3f8642ad8e..f6ff605bcef87 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -987,22 +987,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( /*DropTypeTests=*/true)); }); - if (CodeGenOpts.InstrumentFunctions || - CodeGenOpts.InstrumentFunctionEntryBare || - CodeGenOpts.InstrumentFunctionsAfterInlining || - CodeGenOpts.InstrumentForProfiling) { - PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - }); - PB.registerOptimizerLastEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/true))); - }); - } - // Register callbacks to schedule sanitizer passes at the appropriate part // of the pipeline. if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) @@ -1016,6 +1000,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (!IsThinLTOPostLink) { addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); addKCFIPass(TargetTriple, LangOpts, PB); + PB.registerPipelineStartEPCallback( + [](ModulePassManager &MPM, OptimizationLevel Level) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + }); } if (std::optional<GCOVOptions> Options = diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 9ba75d491c1c9..e970706e8202d 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -101,6 +101,7 @@ void initializeEarlyMachineLICMPass(PassRegistry&); void initializeEarlyTailDuplicatePass(PassRegistry&); void initializeEdgeBundlesPass(PassRegistry&); void initializeEHContGuardCatchretPass(PassRegistry &); +void initializeEntryExitInstrumenterPass(PassRegistry&); void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&); void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&); void initializeExpandMemCmpLegacyPassPass(PassRegistry &); @@ -230,6 +231,7 @@ void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &); void initializePostDomPrinterWrapperPassPass(PassRegistry &); void initializePostDomViewerWrapperPassPass(PassRegistry &); void initializePostDominatorTreeWrapperPassPass(PassRegistry&); +void initializePostInlineEntryExitInstrumenterPass(PassRegistry&); void initializePostMachineSchedulerPass(PassRegistry&); void initializePostRAHazardRecognizerPass(PassRegistry&); void initializePostRAMachineSinkingPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 30e7c22f31460..b432040b052a9 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -113,6 +113,8 @@ namespace { (void)llvm::createTLSVariableHoistPass(); (void) llvm::createConstantHoistingPass(); (void)llvm::createCodeGenPrepareLegacyPass(); + (void) llvm::createEntryExitInstrumenterPass(); + (void) llvm::createPostInlineEntryExitInstrumenterPass(); (void) llvm::createEarlyCSEPass(); (void) llvm::createGVNPass(); (void) llvm::createPostDomTree(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 2e94a19502131..b34f6e82fb7be 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -670,9 +670,6 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses( !Opt.DisablePartialLibcallInlining) addPass(PartiallyInlineLibCallsPass()); - // Instrument function entry and exit, e.g. with calls to mcount(). - addPass(EntryExitInstrumenterPass(/*PostInlining=*/true)); - // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index c6a6a05f3fddb..c3cb2908c8049 100644 --- a/llvm/include/llvm/Transforms/Utils.h +++ b/llvm/include/llvm/Transforms/Utils.h @@ -36,6 +36,15 @@ extern char &LowerInvokePassID; FunctionPass *createLowerSwitchPass(); extern char &LowerSwitchID; +//===----------------------------------------------------------------------===// +// +// EntryExitInstrumenter pass - Instrument function entry/exit with calls to +// mcount(), @__cyg_profile_func_{enter,exit} and the like. There are two +// variants, intended to run pre- and post-inlining, respectively. +// +FunctionPass *createEntryExitInstrumenterPass(); +FunctionPass *createPostInlineEntryExitInstrumenterPass(); + //===----------------------------------------------------------------------===// // // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index 8832b51333d91..6f19db623fe33 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -871,6 +871,9 @@ void TargetPassConfig::addIRPasses() { // passes since it emits those kinds of intrinsics. addPass(createExpandVectorPredicationPass()); + // TODO: comment + addPass(createPostInlineEntryExitInstrumenterPass()); + // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index 400b15284c1b8..cb37579f25051 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -48,4 +48,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeSpeculativeExecutionLegacyPassPass(Registry); initializeStraightLineStrengthReduceLegacyPassPass(Registry); initializePlaceBackedgeSafepointsLegacyPassPass(Registry); + initializeEntryExitInstrumenterPass(Registry); + initializePostInlineEntryExitInstrumenterPass(Registry); } diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 59a7dd1a00ed4..6326f2231f1dd 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -15,7 +15,10 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/InitializePasses.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/Pass.h" +#include "llvm/Transforms/Utils.h" using namespace llvm; @@ -135,6 +138,65 @@ static bool runOnFunction(Function &F, bool PostInlining) { return Changed; } +namespace { +struct EntryExitInstrumenter : public FunctionPass { + static char ID; + EntryExitInstrumenter() : FunctionPass(ID) { + initializeEntryExitInstrumenterPass(*PassRegistry::getPassRegistry()); + } + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addPreserved<GlobalsAAWrapperPass>(); + AU.addPreserved<DominatorTreeWrapperPass>(); + } + bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); } +}; +char EntryExitInstrumenter::ID = 0; + +struct PostInlineEntryExitInstrumenter : public FunctionPass { + static char ID; + PostInlineEntryExitInstrumenter() : FunctionPass(ID) { + initializePostInlineEntryExitInstrumenterPass( + *PassRegistry::getPassRegistry()); + } + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addPreserved<GlobalsAAWrapperPass>(); + AU.addPreserved<DominatorTreeWrapperPass>(); + } + bool runOnFunction(Function &F) override { return ::runOnFunction(F, true); } +}; +char PostInlineEntryExitInstrumenter::ID = 0; +} + +INITIALIZE_PASS_BEGIN( + EntryExitInstrumenter, "ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", + false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_END( + EntryExitInstrumenter, "ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", + false, false) + +INITIALIZE_PASS_BEGIN( + PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() " + "(post inlining)", + false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_END( + PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() " + "(post inlining)", + false, false) + +FunctionPass *llvm::createEntryExitInstrumenterPass() { + return new EntryExitInstrumenter(); +} + +FunctionPass *llvm::createPostInlineEntryExitInstrumenterPass() { + return new PostInlineEntryExitInstrumenter(); +} + PreservedAnalyses llvm::EntryExitInstrumenterPass::run(Function &F, FunctionAnalysisManager &AM) { if (!runOnFunction(F, PostInlining)) diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index b292f70ba89de..16fd7fcec2486 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -335,6 +335,8 @@ int main(int argc, char **argv) { initializeCodeGen(*Registry); initializeLoopStrengthReducePass(*Registry); initializeLowerIntrinsicsPass(*Registry); + initializeEntryExitInstrumenterPass(*Registry); + initializePostInlineEntryExitInstrumenterPass(*Registry); initializeUnreachableBlockElimLegacyPassPass(*Registry); initializeConstantHoistingLegacyPassPass(*Registry); initializeScalarOpts(*Registry); diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index 948148bb80498..dc15329515718 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -439,6 +439,8 @@ extern "C" int optMain( initializeIndirectBrExpandLegacyPassPass(Registry); initializeInterleavedLoadCombinePass(Registry); initializeInterleavedAccessPass(Registry); + initializeEntryExitInstrumenterPass(Registry); + initializePostInlineEntryExitInstrumenterPass(Registry); initializeUnreachableBlockElimLegacyPassPass(Registry); initializeExpandReductionsPass(Registry); initializeExpandVectorPredicationPass(Registry); >From 3ea4de1615d6ed3cba1a1fa4c0327f98921e0b1d Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 15 May 2024 13:27:36 +0200 Subject: [PATCH 2/3] Address the first round of review comments --- clang/lib/CodeGen/BackendUtil.cpp | 6 ----- llvm/include/llvm/LinkAllPasses.h | 1 - llvm/include/llvm/Passes/CodeGenPassBuilder.h | 3 +++ llvm/include/llvm/Transforms/Utils.h | 4 +-- llvm/lib/Passes/PassBuilderPipelines.cpp | 15 +++++++++++ llvm/lib/Transforms/Scalar/Scalar.cpp | 1 - .../Utils/EntryExitInstrumenter.cpp | 27 ------------------- llvm/tools/llc/llc.cpp | 1 - llvm/tools/opt/optdriver.cpp | 1 - 9 files changed, 20 insertions(+), 39 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index f6ff605bcef87..fc9b8206361d2 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -85,7 +85,6 @@ #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Scalar/JumpThreading.h" #include "llvm/Transforms/Utils/Debugify.h" -#include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/ModuleUtils.h" #include <memory> #include <optional> @@ -1000,11 +999,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (!IsThinLTOPostLink) { addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); addKCFIPass(TargetTriple, LangOpts, PB); - PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - }); } if (std::optional<GCOVOptions> Options = diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index b432040b052a9..311d38e8a751f 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -113,7 +113,6 @@ namespace { (void)llvm::createTLSVariableHoistPass(); (void) llvm::createConstantHoistingPass(); (void)llvm::createCodeGenPrepareLegacyPass(); - (void) llvm::createEntryExitInstrumenterPass(); (void) llvm::createPostInlineEntryExitInstrumenterPass(); (void) llvm::createEarlyCSEPass(); (void) llvm::createGVNPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index b34f6e82fb7be..2e94a19502131 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -670,6 +670,9 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses( !Opt.DisablePartialLibcallInlining) addPass(PartiallyInlineLibCallsPass()); + // Instrument function entry and exit, e.g. with calls to mcount(). + addPass(EntryExitInstrumenterPass(/*PostInlining=*/true)); + // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index c3cb2908c8049..677cc3d128c3a 100644 --- a/llvm/include/llvm/Transforms/Utils.h +++ b/llvm/include/llvm/Transforms/Utils.h @@ -40,9 +40,9 @@ extern char &LowerSwitchID; // // EntryExitInstrumenter pass - Instrument function entry/exit with calls to // mcount(), @__cyg_profile_func_{enter,exit} and the like. There are two -// variants, intended to run pre- and post-inlining, respectively. +// variants, intended to run pre- and post-inlining, respectively. Only the +// post-inlining variant is used with the legacy pass manager. // -FunctionPass *createEntryExitInstrumenterPass(); FunctionPass *createPostInlineEntryExitInstrumenterPass(); //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 90ba3b541553e..9e00e4f30270a 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -127,6 +127,7 @@ #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/CountVisits.h" +#include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/InjectTLIMappings.h" #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" #include "llvm/Transforms/Utils/Mem2Reg.h" @@ -1028,6 +1029,14 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, Phase != ThinOrFullLTOPhase::ThinLTOPostLink) MPM.addPass(SampleProfileProbePass(TM)); + // Instrument function entry and exit before all inlining. + if (Phase != ThinOrFullLTOPhase::ThinLTOPostLink && + Phase != ThinOrFullLTOPhase::FullLTOPostLink && + Phase != ThinOrFullLTOPhase::None) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + } + bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse); // In ThinLTO mode, when flattened profile is used, all the available @@ -2045,6 +2054,12 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level, /*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, PGOOpt->FS); + // Instrument function entry and exit before all inlining. + if (LTOPreLink) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + } + invokePipelineStartEPCallbacks(MPM, Level); if (PGOOpt && PGOOpt->DebugInfoForProfiling) diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index cb37579f25051..cb1456b146325 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -48,6 +48,5 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeSpeculativeExecutionLegacyPassPass(Registry); initializeStraightLineStrengthReduceLegacyPassPass(Registry); initializePlaceBackedgeSafepointsLegacyPassPass(Registry); - initializeEntryExitInstrumenterPass(Registry); initializePostInlineEntryExitInstrumenterPass(Registry); } diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 6326f2231f1dd..d12c540f9a4d0 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -139,19 +139,6 @@ static bool runOnFunction(Function &F, bool PostInlining) { } namespace { -struct EntryExitInstrumenter : public FunctionPass { - static char ID; - EntryExitInstrumenter() : FunctionPass(ID) { - initializeEntryExitInstrumenterPass(*PassRegistry::getPassRegistry()); - } - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addPreserved<GlobalsAAWrapperPass>(); - AU.addPreserved<DominatorTreeWrapperPass>(); - } - bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); } -}; -char EntryExitInstrumenter::ID = 0; - struct PostInlineEntryExitInstrumenter : public FunctionPass { static char ID; PostInlineEntryExitInstrumenter() : FunctionPass(ID) { @@ -167,16 +154,6 @@ struct PostInlineEntryExitInstrumenter : public FunctionPass { char PostInlineEntryExitInstrumenter::ID = 0; } -INITIALIZE_PASS_BEGIN( - EntryExitInstrumenter, "ee-instrument", - "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", - false, false) -INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_END( - EntryExitInstrumenter, "ee-instrument", - "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", - false, false) - INITIALIZE_PASS_BEGIN( PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", "Instrument function entry/exit with calls to e.g. mcount() " @@ -189,10 +166,6 @@ INITIALIZE_PASS_END( "(post inlining)", false, false) -FunctionPass *llvm::createEntryExitInstrumenterPass() { - return new EntryExitInstrumenter(); -} - FunctionPass *llvm::createPostInlineEntryExitInstrumenterPass() { return new PostInlineEntryExitInstrumenter(); } diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 16fd7fcec2486..e7bf192192b67 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -335,7 +335,6 @@ int main(int argc, char **argv) { initializeCodeGen(*Registry); initializeLoopStrengthReducePass(*Registry); initializeLowerIntrinsicsPass(*Registry); - initializeEntryExitInstrumenterPass(*Registry); initializePostInlineEntryExitInstrumenterPass(*Registry); initializeUnreachableBlockElimLegacyPassPass(*Registry); initializeConstantHoistingLegacyPassPass(*Registry); diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index dc15329515718..d322666b207d0 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -439,7 +439,6 @@ extern "C" int optMain( initializeIndirectBrExpandLegacyPassPass(Registry); initializeInterleavedLoadCombinePass(Registry); initializeInterleavedAccessPass(Registry); - initializeEntryExitInstrumenterPass(Registry); initializePostInlineEntryExitInstrumenterPass(Registry); initializeUnreachableBlockElimLegacyPassPass(Registry); initializeExpandReductionsPass(Registry); >From c3d3637249b016a46771ecf8571a903bd6b1d1c1 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 16 May 2024 14:59:35 +0200 Subject: [PATCH 3/3] Address 2nd round of comments --- llvm/include/llvm/InitializePasses.h | 1 - llvm/lib/Passes/PassBuilderPipelines.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index e970706e8202d..c4c1825bbf09e 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -101,7 +101,6 @@ void initializeEarlyMachineLICMPass(PassRegistry&); void initializeEarlyTailDuplicatePass(PassRegistry&); void initializeEdgeBundlesPass(PassRegistry&); void initializeEHContGuardCatchretPass(PassRegistry &); -void initializeEntryExitInstrumenterPass(PassRegistry&); void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&); void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&); void initializeExpandMemCmpLegacyPassPass(PassRegistry &); diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 9e00e4f30270a..4fc6d84934727 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -396,6 +396,11 @@ static bool isLTOPreLink(ThinOrFullLTOPhase Phase) { Phase == ThinOrFullLTOPhase::FullLTOPreLink; } +static bool isLTOPostLink(ThinOrFullLTOPhase Phase) { + return Phase == ThinOrFullLTOPhase::ThinLTOPostLink || + Phase == ThinOrFullLTOPhase::FullLTOPostLink; +} + // TODO: Investigate the cost/benefit of tail call elimination on debugging. FunctionPassManager PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level, @@ -1030,9 +1035,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(SampleProfileProbePass(TM)); // Instrument function entry and exit before all inlining. - if (Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - Phase != ThinOrFullLTOPhase::FullLTOPostLink && - Phase != ThinOrFullLTOPhase::None) { + if (!isLTOPostLink(Phase)) { MPM.addPass(createModuleToFunctionPassAdaptor( EntryExitInstrumenterPass(/*PostInlining=*/false))); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits