Author: Teresa Johnson Date: 2023-05-26T17:38:49-07:00 New Revision: f354e971b09c244147ff59eb65b34487755598c0
URL: https://github.com/llvm/llvm-project/commit/f354e971b09c244147ff59eb65b34487755598c0 DIFF: https://github.com/llvm/llvm-project/commit/f354e971b09c244147ff59eb65b34487755598c0.diff LOG: [MemProf] Clean up MemProf instrumentation pass invocation First, removes the invocation of the memprof instrumentation passes from the end of the module simplification pass builder, where it doesn't really belong. However, it turns out that this was never being invoked, as it is guarded by an internal option not used anywhere (even tests). These passes are actually added via clang under the -fmemory-profile option. Changed this to add via the EP callback interface, similar to the sanitizer passes. They are added to the EP for the end of the optimization pipeline, which is roughly where they were being added already (end of the pre-LTO link pipelines and non-LTO optimization pipeline). Ideally we should plumb the output file through to LLVM and set it up there, so I have added a TODO. Differential Revision: https://reviews.llvm.org/D151593 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/lib/Passes/PassBuilderPipelines.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index d62d00a156f1c..d4498ebaf8dea 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -992,6 +992,16 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(InstrProfiling(*Options, false)); }); + // TODO: Consider passing the MemoryProfileOutput to the pass builder via + // the PGOOptions, and set this up there. + if (!CodeGenOpts.MemoryProfileOutput.empty()) { + PB.registerOptimizerLastEPCallback( + [](ModulePassManager &MPM, OptimizationLevel Level) { + MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass())); + MPM.addPass(ModuleMemProfilerPass()); + }); + } + if (IsThinLTO) { MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level); } else if (IsLTO) { @@ -999,11 +1009,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( } else { MPM = PB.buildPerModuleDefaultPipeline(Level); } - - if (!CodeGenOpts.MemoryProfileOutput.empty()) { - MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass())); - MPM.addPass(ModuleMemProfilerPass()); - } } // Add a verifier pass if requested. We don't have to do this if the action diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 05bb4596b988c..34d3b9d7467e8 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -155,9 +155,6 @@ static cl::opt<bool> cl::Hidden, cl::desc("Enable inline deferral during PGO")); -static cl::opt<bool> EnableMemProfiler("enable-mem-prof", cl::Hidden, - cl::desc("Enable memory profiler")); - static cl::opt<bool> EnableModuleInliner("enable-module-inliner", cl::init(false), cl::Hidden, cl::desc("Enable module inliner")); @@ -1122,11 +1119,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(GlobalOptPass()); MPM.addPass(GlobalDCEPass()); - if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) { - MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass())); - MPM.addPass(ModuleMemProfilerPass()); - } - return MPM; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits