From da8241e253ca27a717bd09222f993f314b297d9a Mon Sep 17 00:00:00 2001 From: zhizhouy Date: Tue, 31 Mar 2020 10:23:17 -0700 Subject: [PATCH] [NFC] Do not run CGProfilePass when not using integrated assembler Summary: CGProfilePass is run by default in certain new pass manager optimization pipeline. Assemblers other than llvm as (such as gnu as) cannot recognize the .cgprofile entries generated and emitted from this pass, causing build time error. This patch adds new options in clang CodeGenOpts and PassBuilder options so that we can turn cgprofile off when not using integrated assembler. Reviewers: Bigcheese, xur, george.burgess.iv, chandlerc, manojgupta Reviewed By: manojgupta Subscribers: manojgupta, void, hiraditya, dexonsmith, llvm-commits, tcwang, llozano Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D62627 --- include/llvm/Passes/PassBuilder.h | 4 ++++ lib/Passes/PassBuilder.cpp | 8 +++++++- test/Other/new-pm-cgprofile.ll | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/Other/new-pm-cgprofile.ll diff --git a/include/llvm/Passes/PassBuilder.h b/include/llvm/Passes/PassBuilder.h index 38af8962297..12e914d44ba 100644 --- a/include/llvm/Passes/PassBuilder.h +++ b/include/llvm/Passes/PassBuilder.h @@ -105,6 +105,10 @@ public: /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if /// the number of access is too large. unsigned LicmMssaNoAccForPromotionCap; + + /// Tuning option to enable/disable call graph profile. Its default value is + /// that of the flag: `-enable-npm-call-graph-profile`. + bool CallGraphProfile; }; /// This class provides access to building LLVM's passes. diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 32d0a380ae3..57c510b8cbf 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -237,6 +237,10 @@ static cl::opt EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)")); +static cl::opt EnableCallGraphProfile( + "enable-npm-call-graph-profile", cl::init(true), cl::Hidden, + cl::desc("Enable call graph profile pass for the new PM (default = on)")); + PipelineTuningOptions::PipelineTuningOptions() { LoopInterleaving = EnableLoopInterleaving; LoopVectorization = EnableLoopVectorization; @@ -246,6 +250,7 @@ PipelineTuningOptions::PipelineTuningOptions() { Coroutines = false; LicmMssaOptCap = SetLicmMssaOptCap; LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap; + CallGraphProfile = EnableCallGraphProfile; } extern cl::opt EnableHotColdSplit; @@ -1060,7 +1065,8 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline( // Add the core optimizing pipeline. MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); - MPM.addPass(CGProfilePass()); + if (PTO.CallGraphProfile) + MPM.addPass(CGProfilePass()); // Now we need to do some global optimization transforms. // FIXME: It would seem like these should come first in the optimization diff --git a/test/Other/new-pm-cgprofile.ll b/test/Other/new-pm-cgprofile.ll new file mode 100644 index 00000000000..c7fe31ab570 --- /dev/null +++ b/test/Other/new-pm-cgprofile.ll @@ -0,0 +1,11 @@ +; RUN: opt -debug-pass-manager -passes='default' %s 2>&1 |FileCheck %s --check-prefixes=DEFAULT +; RUN: opt -debug-pass-manager -passes='default' -enable-npm-call-graph-profile=0 %s 2>&1 |FileCheck %s --check-prefixes=OFF +; RUN: opt -debug-pass-manager -passes='default' -enable-npm-call-graph-profile=1 %s 2>&1 |FileCheck %s --check-prefixes=ON +; +; DEFAULT: Running pass: CGProfilePass +; OFF-NOT: Running pass: CGProfilePass +; ON: Running pass: CGProfilePass + +define void @foo() { + ret void +}