diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index c9b54e0fa81..468ce1d40e4 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -123,7 +123,7 @@ void initializeEarlyIfConverterPass(PassRegistry&); void initializeEdgeBundlesPass(PassRegistry&); void initializeExpandPostRAPass(PassRegistry&); void initializeAAResultsWrapperPassPass(PassRegistry &); -void initializeGCOVProfilerPass(PassRegistry&); +void initializeGCOVProfilerLegacyPassPass(PassRegistry&); void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&); void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&); void initializePGOIndirectCallPromotionLegacyPassPass(PassRegistry&); diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 9c6050504b6..f7ace857a37 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -68,85 +68,95 @@ GCOVOptions GCOVOptions::getDefault() { } namespace { - class GCOVFunction; +class GCOVFunction; - class GCOVProfiler : public ModulePass { - public: - static char ID; - GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {} - GCOVProfiler(const GCOVOptions &Opts) : ModulePass(ID), Options(Opts) { - assert((Options.EmitNotes || Options.EmitData) && - "GCOVProfiler asked to do nothing?"); - ReversedVersion[0] = Options.Version[3]; - ReversedVersion[1] = Options.Version[2]; - ReversedVersion[2] = Options.Version[1]; - ReversedVersion[3] = Options.Version[0]; - ReversedVersion[4] = '\0'; - initializeGCOVProfilerPass(*PassRegistry::getPassRegistry()); - } - const char *getPassName() const override { - return "GCOV Profiler"; - } +class GCOVProfiler { +public: + GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {} + GCOVProfiler(const GCOVOptions &Opts) : Options(Opts) { + assert((Options.EmitNotes || Options.EmitData) && + "GCOVProfiler asked to do nothing?"); + ReversedVersion[0] = Options.Version[3]; + ReversedVersion[1] = Options.Version[2]; + ReversedVersion[2] = Options.Version[1]; + ReversedVersion[3] = Options.Version[0]; + ReversedVersion[4] = '\0'; + } + bool runOnModule(Module &M); - private: - bool runOnModule(Module &M) override; +private: + // Create the .gcno files for the Module based on DebugInfo. + void emitProfileNotes(); - // Create the .gcno files for the Module based on DebugInfo. - void emitProfileNotes(); + // Modify the program to track transitions along edges and call into the + // profiling runtime to emit .gcda files when run. + bool emitProfileArcs(); - // Modify the program to track transitions along edges and call into the - // profiling runtime to emit .gcda files when run. - bool emitProfileArcs(); + // Get pointers to the functions in the runtime library. + Constant *getStartFileFunc(); + Constant *getIncrementIndirectCounterFunc(); + Constant *getEmitFunctionFunc(); + Constant *getEmitArcsFunc(); + Constant *getSummaryInfoFunc(); + Constant *getDeleteWriteoutFunctionListFunc(); + Constant *getDeleteFlushFunctionListFunc(); + Constant *getEndFileFunc(); - // Get pointers to the functions in the runtime library. - Constant *getStartFileFunc(); - Constant *getIncrementIndirectCounterFunc(); - Constant *getEmitFunctionFunc(); - Constant *getEmitArcsFunc(); - Constant *getSummaryInfoFunc(); - Constant *getDeleteWriteoutFunctionListFunc(); - Constant *getDeleteFlushFunctionListFunc(); - Constant *getEndFileFunc(); + // Create or retrieve an i32 state value that is used to represent the + // pred block number for certain non-trivial edges. + GlobalVariable *getEdgeStateValue(); - // Create or retrieve an i32 state value that is used to represent the - // pred block number for certain non-trivial edges. - GlobalVariable *getEdgeStateValue(); + // Produce a table of pointers to counters, by predecessor and successor + // block number. + GlobalVariable *buildEdgeLookupTable(Function *F, GlobalVariable *Counter, + const UniqueVector &Preds, + const UniqueVector &Succs); - // Produce a table of pointers to counters, by predecessor and successor - // block number. - GlobalVariable *buildEdgeLookupTable(Function *F, - GlobalVariable *Counter, - const UniqueVector&Preds, - const UniqueVector&Succs); + // Add the function to write out all our counters to the global destructor + // list. + Function * + insertCounterWriteout(ArrayRef>); + Function *insertFlush(ArrayRef>); + void insertIndirectCounterIncrement(); - // Add the function to write out all our counters to the global destructor - // list. - Function *insertCounterWriteout(ArrayRef >); - Function *insertFlush(ArrayRef >); - void insertIndirectCounterIncrement(); + std::string mangleName(const DICompileUnit *CU, const char *NewStem); - std::string mangleName(const DICompileUnit *CU, const char *NewStem); + GCOVOptions Options; - GCOVOptions Options; + // Reversed, NUL-terminated copy of Options.Version. + char ReversedVersion[5]; + // Checksum, produced by hash of EdgeDestinations + SmallVector FileChecksums; - // Reversed, NUL-terminated copy of Options.Version. - char ReversedVersion[5]; - // Checksum, produced by hash of EdgeDestinations - SmallVector FileChecksums; + Module *M; + LLVMContext *Ctx; + SmallVector, 16> Funcs; +}; - Module *M; - LLVMContext *Ctx; - SmallVector, 16> Funcs; - }; +class GCOVProfilerLegacyPass : public ModulePass { +public: + static char ID; + GCOVProfilerLegacyPass() + : GCOVProfilerLegacyPass(GCOVOptions::getDefault()) {} + GCOVProfilerLegacyPass(const GCOVOptions &Opts) + : ModulePass(ID), Profiler(Opts) { + initializeGCOVProfilerLegacyPassPass(*PassRegistry::getPassRegistry()); + } + const char *getPassName() const override { return "GCOV Profiler"; } + + bool runOnModule(Module &M) override { return Profiler.runOnModule(M); } + +private: + GCOVProfiler Profiler; +}; } -char GCOVProfiler::ID = 0; -INITIALIZE_PASS(GCOVProfiler, "insert-gcov-profiling", +char GCOVProfilerLegacyPass::ID = 0; +INITIALIZE_PASS(GCOVProfilerLegacyPass, "insert-gcov-profiling", "Insert instrumentation for GCOV profiling", false, false) ModulePass *llvm::createGCOVProfilerPass(const GCOVOptions &Options) { - return new GCOVProfiler(Options); + return new GCOVProfilerLegacyPass(Options); } static StringRef getFunctionName(const DISubprogram *SP) { diff --git a/lib/Transforms/Instrumentation/Instrumentation.cpp b/lib/Transforms/Instrumentation/Instrumentation.cpp index 372ec616c18..2963d08752c 100644 --- a/lib/Transforms/Instrumentation/Instrumentation.cpp +++ b/lib/Transforms/Instrumentation/Instrumentation.cpp @@ -59,7 +59,7 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) { initializeAddressSanitizerPass(Registry); initializeAddressSanitizerModulePass(Registry); initializeBoundsCheckingPass(Registry); - initializeGCOVProfilerPass(Registry); + initializeGCOVProfilerLegacyPassPass(Registry); initializePGOInstrumentationGenLegacyPassPass(Registry); initializePGOInstrumentationUseLegacyPassPass(Registry); initializePGOIndirectCallPromotionLegacyPassPass(Registry);