Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1312,7 +1312,9 @@ /*DropTypeTests=*/true)); }); - if (Level != PassBuilder::OptimizationLevel::O0) { + if (CodeGenOpts.InstrumentFunctions || + CodeGenOpts.InstrumentFunctionsAfterInlining || + CodeGenOpts.InstrumentFunctionEntryBare) { PB.registerPipelineStartEPCallback( [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { MPM.addPass(createModuleToFunctionPassAdaptor( Index: llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h =================================================================== --- llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h +++ llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h @@ -19,8 +19,6 @@ namespace llvm { -class Function; - struct EntryExitInstrumenterPass : public PassInfoMixin { EntryExitInstrumenterPass(bool PostInlining) : PostInlining(PostInlining) {} @@ -28,6 +26,8 @@ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); bool PostInlining; + + static bool isRequired() { return true; } }; } // namespace llvm Index: llvm/test/Transforms/EntryExitInstrumenter/mcount.ll =================================================================== --- llvm/test/Transforms/EntryExitInstrumenter/mcount.ll +++ llvm/test/Transforms/EntryExitInstrumenter/mcount.ll @@ -1,4 +1,7 @@ -; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument)" -S < %s | FileCheck %s +; RUN: opt --O0 --ee-instrument --inline --post-inline-ee-instrument -S < %s | FileCheck %s + +; Check if the pass is enabbled on both -O0 and higher optimization levels +; RUN: opt --O2 --ee-instrument --post-inline-ee-instrument -S < %s | FileCheck --check-prefix=OPT %s ; Running the passes twice should not result in more instrumentation. ; RUN: opt -passes="function(ee-instrument),function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument),function(post-inline-ee-instrument)" -S < %s | FileCheck %s @@ -18,6 +21,15 @@ ; CHECK-NEXT: %1 = call i8* @llvm.returnaddress(i32 0) ; CHECK-NEXT: call void @__cyg_profile_func_exit(i8* bitcast (void ()* @leaf_function to i8*), i8* %1) ; CHECK-NEXT: ret void + +; OPT-LABEL: define void @leaf_function() +; OPT: entry: +; OPT-NEXT: call void @mcount() +; OPT-NEXT: %0 = call i8* @llvm.returnaddress(i32 0) +; OPT-NEXT: call void @__cyg_profile_func_enter(i8* bitcast (void ()* @leaf_function to i8*), i8* %0) +; OPT-NEXT: %1 = call i8* @llvm.returnaddress(i32 0) +; OPT-NEXT: call void @__cyg_profile_func_exit(i8* bitcast (void ()* @leaf_function to i8*), i8* %1) +; OPT-NEXT: ret void } @@ -42,6 +54,16 @@ ; CHECK-NEXT: call void @__cyg_profile_func_exit(i8* bitcast (void ()* @root_function to i8*), i8* %3) ; CHECK-NEXT: ret void + +; OPT-LABEL: define void @root_function() +; OPT: entry: +; OPT-NEXT: call void @mcount() + +; OPT-NEXT: %0 = call i8* @llvm.returnaddress(i32 0) +; OPT-NEXT: call void @__cyg_profile_func_enter(i8* bitcast (void ()* @root_function to i8*), i8* %0) +; OPT-NEXT: %1 = call i8* @llvm.returnaddress(i32 0) +; OPT-NEXT: call void @__cyg_profile_func_exit(i8* bitcast (void ()* @root_function to i8*), i8* %1) +; OPT-NEXT: ret void }