From: Arthur Eubanks Date: Thu, 28 May 2020 21:38:05 +0000 (-0700) Subject: Revert "Run Coverage pass before other *San passes under new pass manager, round 2" X-Git-Tag: llvmorg-12-init~4798 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3fb8446f2ec3953348f3c773004cf2aa28a8c04;p=platform%2Fupstream%2Fllvm.git Revert "Run Coverage pass before other *San passes under new pass manager, round 2" This reverts commit 922fa2fce38b0bd97921b91ff1cdc57f18d3569c. --- diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index dd50163..e746aef 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -32,7 +32,6 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSummaryIndex.h" -#include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/LTO/LTOBackend.h" #include "llvm/MC/MCAsmInfo.h" @@ -1002,15 +1001,6 @@ static void addSanitizersAtO0(ModulePassManager &MPM, const Triple &TargetTriple, const LangOptions &LangOpts, const CodeGenOptions &CodeGenOpts) { - if (CodeGenOpts.SanitizeCoverageType || - CodeGenOpts.SanitizeCoverageIndirectCalls || - CodeGenOpts.SanitizeCoverageTraceCmp) { - auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); - MPM.addPass(ModuleSanitizerCoveragePass( - SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, - CodeGenOpts.SanitizeCoverageBlacklistFiles)); - } - auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) { MPM.addPass(RequireAnalysisPass()); bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); @@ -1259,20 +1249,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { FPM.addPass(BoundsCheckingPass()); }); - - if (CodeGenOpts.SanitizeCoverageType || - CodeGenOpts.SanitizeCoverageIndirectCalls || - CodeGenOpts.SanitizeCoverageTraceCmp) { - PB.registerOptimizerLastEPCallback( - [this](ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { - auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); - MPM.addPass(ModuleSanitizerCoveragePass( - SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, - CodeGenOpts.SanitizeCoverageBlacklistFiles)); - }); - } - if (LangOpts.Sanitize.has(SanitizerKind::Memory)) { int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins; bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Memory); @@ -1281,19 +1257,17 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( MPM.addPass(MemorySanitizerPass({TrackOrigins, Recover, false})); }); PB.registerOptimizerLastEPCallback( - [TrackOrigins, Recover](ModulePassManager &MPM, + [TrackOrigins, Recover](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - MemorySanitizerPass({TrackOrigins, Recover, false}))); + FPM.addPass(MemorySanitizerPass({TrackOrigins, Recover, false})); }); } if (LangOpts.Sanitize.has(SanitizerKind::Thread)) { PB.registerPipelineStartEPCallback( [](ModulePassManager &MPM) { MPM.addPass(ThreadSanitizerPass()); }); PB.registerOptimizerLastEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { - MPM.addPass( - createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); + [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + FPM.addPass(ThreadSanitizerPass()); }); } if (LangOpts.Sanitize.has(SanitizerKind::Address)) { @@ -1304,11 +1278,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Address); bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope; PB.registerOptimizerLastEPCallback( - [Recover, UseAfterScope](ModulePassManager &MPM, + [Recover, UseAfterScope](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { - MPM.addPass( - createModuleToFunctionPassAdaptor(AddressSanitizerPass( - /*CompileKernel=*/false, Recover, UseAfterScope))); + FPM.addPass(AddressSanitizerPass( + /*CompileKernel=*/false, Recover, UseAfterScope)); }); bool ModuleUseAfterScope = asanUseGlobalsGC(TargetTriple, CodeGenOpts); bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator; @@ -1352,6 +1325,15 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( } } + if (CodeGenOpts.SanitizeCoverageType || + CodeGenOpts.SanitizeCoverageIndirectCalls || + CodeGenOpts.SanitizeCoverageTraceCmp) { + auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); + MPM.addPass(ModuleSanitizerCoveragePass( + SancovOpts, CodeGenOpts.SanitizeCoverageWhitelistFiles, + CodeGenOpts.SanitizeCoverageBlacklistFiles)); + } + if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) { bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress); MPM.addPass(HWAddressSanitizerPass( diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index d5a70c2..391d144 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -600,7 +600,7 @@ public: /// is not triggered at O0. Extensions to the O0 pipeline should append their /// passes to the end of the overall pipeline. void registerOptimizerLastEPCallback( - const std::function &C) { + const std::function &C) { OptimizerLastEPCallbacks.push_back(C); } @@ -728,7 +728,7 @@ private: CGSCCOptimizerLateEPCallbacks; SmallVector, 2> VectorizerStartEPCallbacks; - SmallVector, 2> + SmallVector, 2> OptimizerLastEPCallbacks; // Module callbacks SmallVector, 2> diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 1b1701c..0999f78 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1073,12 +1073,12 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline( if (PTO.Coroutines) OptimizePM.addPass(CoroCleanupPass()); + for (auto &C : OptimizerLastEPCallbacks) + C(OptimizePM, Level); + // Add the core optimizing pipeline. MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); - for (auto &C : OptimizerLastEPCallbacks) - C(MPM, Level); - if (PTO.CallGraphProfile) MPM.addPass(CGProfilePass()); diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index c99ad2f..2e84ca4 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -194,7 +194,7 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, }); if (tryParsePipelineText(PB, OptimizerLastEPPipeline)) PB.registerOptimizerLastEPCallback( - [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM, + [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM, PassBuilder::OptimizationLevel) { ExitOnError Err("Unable to parse OptimizerLastEP pipeline: "); Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass,