Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -118,19 +118,19 @@ void initializeDominanceFrontierWrapperPassPass(PassRegistry&); void initializeDominatorTreeWrapperPassPass(PassRegistry&); void initializeEarlyIfConverterPass(PassRegistry&); -void initializeEdgeBundlesPass(PassRegistry&); -void initializeExpandPostRAPass(PassRegistry&); +void initializeEdgeBundlesPass(PassRegistry &); +void initializeExpandPostRAPass(PassRegistry &); void initializeAAResultsWrapperPassPass(PassRegistry &); -void initializeGCOVProfilerPass(PassRegistry&); -void initializePGOInstrumentationGenPass(PassRegistry&); -void initializePGOInstrumentationUsePass(PassRegistry&); -void initializeInstrProfilingPass(PassRegistry&); -void initializeAddressSanitizerPass(PassRegistry&); -void initializeAddressSanitizerModulePass(PassRegistry&); -void initializeMemorySanitizerPass(PassRegistry&); -void initializeThreadSanitizerPass(PassRegistry&); -void initializeSanitizerCoverageModulePass(PassRegistry&); -void initializeDataFlowSanitizerPass(PassRegistry&); +void initializeGCOVProfilerPass(PassRegistry &); +void initializePGOInstrumentationGenPass(PassRegistry &); +void initializePGOInstrumentationUsePass(PassRegistry &); +void initializeInstrProfilingLegacyWrapperPassPass(PassRegistry &); +void initializeAddressSanitizerPass(PassRegistry &); +void initializeAddressSanitizerModulePass(PassRegistry &); +void initializeMemorySanitizerPass(PassRegistry &); +void initializeThreadSanitizerPass(PassRegistry &); +void initializeSanitizerCoverageModulePass(PassRegistry &); +void initializeDataFlowSanitizerPass(PassRegistry &); void initializeScalarizerPass(PassRegistry&); void initializeEarlyCSELegacyPassPass(PassRegistry &); void initializeEliminateAvailableExternallyPass(PassRegistry&); Index: include/llvm/LinkAllPasses.h =================================================================== --- include/llvm/LinkAllPasses.h +++ include/llvm/LinkAllPasses.h @@ -85,19 +85,19 @@ (void) llvm::createDependenceAnalysisPass(); (void) llvm::createDivergenceAnalysisPass(); (void) llvm::createDomOnlyPrinterPass(); - (void) llvm::createDomPrinterPass(); - (void) llvm::createDomOnlyViewerPass(); - (void) llvm::createDomViewerPass(); - (void) llvm::createGCOVProfilerPass(); - (void) llvm::createPGOInstrumentationGenPass(); - (void) llvm::createPGOInstrumentationUsePass(); - (void) llvm::createInstrProfilingPass(); - (void) llvm::createFunctionImportPass(); - (void) llvm::createFunctionInliningPass(); - (void) llvm::createAlwaysInlinerPass(); - (void) llvm::createGlobalDCEPass(); - (void) llvm::createGlobalOptimizerPass(); - (void) llvm::createGlobalsAAWrapperPass(); + (void)llvm::createDomPrinterPass(); + (void)llvm::createDomOnlyViewerPass(); + (void)llvm::createDomViewerPass(); + (void)llvm::createGCOVProfilerPass(); + (void)llvm::createPGOInstrumentationGenPass(); + (void)llvm::createPGOInstrumentationUsePass(); + (void)llvm::createInstrProfilingLegacyPass(); + (void)llvm::createFunctionImportPass(); + (void)llvm::createFunctionInliningPass(); + (void)llvm::createAlwaysInlinerPass(); + (void)llvm::createGlobalDCEPass(); + (void)llvm::createGlobalOptimizerPass(); + (void)llvm::createGlobalsAAWrapperPass(); (void) llvm::createIPConstantPropagationPass(); (void) llvm::createIPSCCPPass(); (void) llvm::createInductiveRangeCheckEliminationPass(); Index: include/llvm/Transforms/Instrumentation.h =================================================================== --- include/llvm/Transforms/Instrumentation.h +++ include/llvm/Transforms/Instrumentation.h @@ -16,6 +16,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/PassManager.h" #include #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID) @@ -95,8 +96,18 @@ std::string InstrProfileOutput; }; +/// Instrumenation based profiling lowering pass. This pass lowers +/// the profile instrumented code generated by FE or the IR based +/// instrumentation pass. +struct InstrProfilingPass : PassInfoMixin { + InstrProfOptions Options; + InstrProfilingPass() : Options() {} + InstrProfilingPass(const InstrProfOptions &O) : Options(O) {} + PreservedAnalyses run(Module &M, AnalysisManager &AM); +}; + /// Insert frontend instrumentation based profiling. -ModulePass *createInstrProfilingPass( +ModulePass *createInstrProfilingLegacyPass( const InstrProfOptions &Options = InstrProfOptions()); // Insert AddressSanitizer (address sanity checking) instrumentation Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ lib/Passes/PassBuilder.cpp @@ -49,10 +49,11 @@ #include "llvm/Transforms/IPO/InferFunctionAttrs.h" #include "llvm/Transforms/IPO/StripDeadPrototypes.h" #include "llvm/Transforms/InstCombine/InstCombine.h" +#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Scalar/ADCE.h" #include "llvm/Transforms/Scalar/EarlyCSE.h" -#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" #include "llvm/Transforms/Scalar/GVN.h" +#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" #include "llvm/Transforms/Scalar/SROA.h" #include "llvm/Transforms/Scalar/SimplifyCFG.h" #include Index: lib/Passes/PassRegistry.def =================================================================== --- lib/Passes/PassRegistry.def +++ lib/Passes/PassRegistry.def @@ -38,6 +38,7 @@ MODULE_PASS("forceattrs", ForceFunctionAttrsPass()) MODULE_PASS("inferattrs", InferFunctionAttrsPass()) MODULE_PASS("invalidate", InvalidateAllAnalysesPass()) +MODULE_PASS("instrprof", InstrProfilingPass()) MODULE_PASS("no-op-module", NoOpModulePass()) MODULE_PASS("print", PrintModulePass(dbgs())) MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs())) Index: lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- lib/Transforms/IPO/PassManagerBuilder.cpp +++ lib/Transforms/IPO/PassManagerBuilder.cpp @@ -220,7 +220,7 @@ // Add the profile lowering pass. InstrProfOptions Options; Options.InstrProfileOutput = PGOInstrGen; - MPM.add(createInstrProfilingPass(Options)); + MPM.add(createInstrProfilingLegacyPass(Options)); } if (!PGOInstrUse.empty()) MPM.add(createPGOInstrumentationUsePass(PGOInstrUse)); Index: lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/InstrProfiling.cpp +++ lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -31,24 +31,12 @@ cl::desc("Enable name string compression"), cl::init(true)); -class InstrProfiling : public ModulePass { +class InstrProfiling { public: - static char ID; - - InstrProfiling() : ModulePass(ID) {} - - InstrProfiling(const InstrProfOptions &Options) - : ModulePass(ID), Options(Options) {} - - const char *getPassName() const override { - return "Frontend instrumentation-based coverage lowering"; - } + InstrProfiling() {} + InstrProfiling(const InstrProfOptions &Options) : Options(Options) {} - bool runOnModule(Module &M) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesCFG(); - } + bool run(Module &M); private: InstrProfOptions Options; @@ -126,18 +114,47 @@ void emitInitialization(); }; +class InstrProfilingLegacyWrapperPass : public ModulePass { + InstrProfiling InstrProf; + +public: + static char ID; + InstrProfilingLegacyWrapperPass() : ModulePass(ID), InstrProf() {} + InstrProfilingLegacyWrapperPass(const InstrProfOptions &Options) + : ModulePass(ID), InstrProf(Options) {} + const char *getPassName() const override { + return "Frontend instrumentation-based coverage lowering"; + } + + bool runOnModule(Module &M) override { return InstrProf.run(M); } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesCFG(); + } +}; + } // anonymous namespace -char InstrProfiling::ID = 0; -INITIALIZE_PASS(InstrProfiling, "instrprof", +PreservedAnalyses InstrProfilingPass::run(Module &M, + AnalysisManager &AM) { + InstrProfiling InstrProf(Options); + if (!InstrProf.run(M)) + return PreservedAnalyses::all(); + + return PreservedAnalyses::none(); +} + +char InstrProfilingLegacyWrapperPass::ID = 0; +INITIALIZE_PASS(InstrProfilingLegacyWrapperPass, "instrprof", "Frontend instrumentation-based coverage lowering.", false, false) -ModulePass *llvm::createInstrProfilingPass(const InstrProfOptions &Options) { - return new InstrProfiling(Options); +ModulePass * +llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) { + return new InstrProfilingLegacyWrapperPass(Options); } -bool InstrProfiling::runOnModule(Module &M) { +bool InstrProfiling::run(Module &M) { bool MadeChange = false; this->M = &M; Index: lib/Transforms/Instrumentation/Instrumentation.cpp =================================================================== --- lib/Transforms/Instrumentation/Instrumentation.cpp +++ lib/Transforms/Instrumentation/Instrumentation.cpp @@ -62,7 +62,7 @@ initializeGCOVProfilerPass(Registry); initializePGOInstrumentationGenPass(Registry); initializePGOInstrumentationUsePass(Registry); - initializeInstrProfilingPass(Registry); + initializeInstrProfilingLegacyWrapperPassPass(Registry); initializeMemorySanitizerPass(Registry); initializeThreadSanitizerPass(Registry); initializeSanitizerCoverageModulePass(Registry); Index: test/Instrumentation/InstrProfiling/PR23499.ll =================================================================== --- test/Instrumentation/InstrProfiling/PR23499.ll +++ test/Instrumentation/InstrProfiling/PR23499.ll @@ -4,6 +4,7 @@ ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s +; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -instrprof -S | FileCheck %s --check-prefix=COFF $_Z3barIvEvv = comdat any Index: test/Instrumentation/InstrProfiling/linkage.ll =================================================================== --- test/Instrumentation/InstrProfiling/linkage.ll +++ test/Instrumentation/InstrProfiling/linkage.ll @@ -2,6 +2,8 @@ ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s --check-prefix=OTHER --check-prefix=COMMON ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s --check-prefix=LINUX --check-prefix=COMMON +; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -passes=instrprof -S | FileCheck %s --check-prefix=OTHER --check-prefix=COMMON +; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefix=LINUX --check-prefix=COMMON @__profn_foo = hidden constant [3 x i8] c"foo" @__profn_foo_weak = weak hidden constant [8 x i8] c"foo_weak" Index: test/Instrumentation/InstrProfiling/no-counters.ll =================================================================== --- test/Instrumentation/InstrProfiling/no-counters.ll +++ test/Instrumentation/InstrProfiling/no-counters.ll @@ -1,6 +1,7 @@ ;; No instrumentation should be emitted if there are no counter increments. ; RUN: opt < %s -instrprof -S | FileCheck %s +; RUN: opt < %s -passes=instrprof -S | FileCheck %s ; CHECK-NOT: @__profc ; CHECK-NOT: @__profd ; CHECK-NOT: @__llvm_profile_runtime Index: test/Instrumentation/InstrProfiling/noruntime.ll =================================================================== --- test/Instrumentation/InstrProfiling/noruntime.ll +++ test/Instrumentation/InstrProfiling/noruntime.ll @@ -1,6 +1,7 @@ ;; Check that we don't emit the runtime hooks if the user provided them. ; RUN: opt < %s -instrprof -S | FileCheck %s +; RUN: opt < %s -passes=instrprof -S | FileCheck %s ; CHECK-NOT: define {{.*}} @__llvm_profile_runtime_user() ; CHECK-NOT: load i32, i32* @__llvm_profile_runtime Index: test/Instrumentation/InstrProfiling/platform.ll =================================================================== --- test/Instrumentation/InstrProfiling/platform.ll +++ test/Instrumentation/InstrProfiling/platform.ll @@ -2,6 +2,7 @@ ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s -check-prefix=MACHO ; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s -check-prefix=LINUX +; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s -check-prefix=LINUX ; RUN: opt < %s -mtriple=x86_64-unknown-freebsd -instrprof -S | FileCheck %s -check-prefix=FREEBSD ; RUN: opt < %s -mtriple=x86_64-scei-ps4 -instrprof -S | FileCheck %s -check-prefix=PS4 ; RUN: opt < %s -mtriple=x86_64-pc-solaris -instrprof -S | FileCheck %s -check-prefix=SOLARIS Index: test/Instrumentation/InstrProfiling/profiling.ll =================================================================== --- test/Instrumentation/InstrProfiling/profiling.ll +++ test/Instrumentation/InstrProfiling/profiling.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -instrprof -S | FileCheck %s +; RUN: opt < %s -passes=instrprof -S | FileCheck %s target triple = "x86_64-apple-macosx10.10.0"