https://github.com/pasko updated https://github.com/llvm/llvm-project/pull/92171
>From df3f8dfc47cd8d7b220ed712dc7c2cab1c563f50 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Mon, 6 May 2024 19:48:59 +0200 Subject: [PATCH 01/16] wip: Move instrumentation passes This change is not ready for landing yet. Move EntryExitInstrumenter(PostInlining=true) to as late as possible and EntryExitInstrumenter(PostInlining=false) to an early pre-inlining stage (but skip for ThinLTO post-link). --- clang/lib/CodeGen/BackendUtil.cpp | 21 ++----- llvm/include/llvm/InitializePasses.h | 2 + llvm/include/llvm/LinkAllPasses.h | 2 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 3 - llvm/include/llvm/Transforms/Utils.h | 9 +++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/Transforms/Scalar/Scalar.cpp | 2 + .../Utils/EntryExitInstrumenter.cpp | 62 +++++++++++++++++++ llvm/tools/llc/llc.cpp | 2 + llvm/tools/opt/optdriver.cpp | 2 + 10 files changed, 89 insertions(+), 19 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 22c3f8642ad8e..f6ff605bcef87 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -987,22 +987,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( /*DropTypeTests=*/true)); }); - if (CodeGenOpts.InstrumentFunctions || - CodeGenOpts.InstrumentFunctionEntryBare || - CodeGenOpts.InstrumentFunctionsAfterInlining || - CodeGenOpts.InstrumentForProfiling) { - PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - }); - PB.registerOptimizerLastEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/true))); - }); - } - // Register callbacks to schedule sanitizer passes at the appropriate part // of the pipeline. if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) @@ -1016,6 +1000,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (!IsThinLTOPostLink) { addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); addKCFIPass(TargetTriple, LangOpts, PB); + PB.registerPipelineStartEPCallback( + [](ModulePassManager &MPM, OptimizationLevel Level) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + }); } if (std::optional<GCOVOptions> Options = diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 9ba75d491c1c9..e970706e8202d 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -101,6 +101,7 @@ void initializeEarlyMachineLICMPass(PassRegistry&); void initializeEarlyTailDuplicatePass(PassRegistry&); void initializeEdgeBundlesPass(PassRegistry&); void initializeEHContGuardCatchretPass(PassRegistry &); +void initializeEntryExitInstrumenterPass(PassRegistry&); void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&); void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&); void initializeExpandMemCmpLegacyPassPass(PassRegistry &); @@ -230,6 +231,7 @@ void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &); void initializePostDomPrinterWrapperPassPass(PassRegistry &); void initializePostDomViewerWrapperPassPass(PassRegistry &); void initializePostDominatorTreeWrapperPassPass(PassRegistry&); +void initializePostInlineEntryExitInstrumenterPass(PassRegistry&); void initializePostMachineSchedulerPass(PassRegistry&); void initializePostRAHazardRecognizerPass(PassRegistry&); void initializePostRAMachineSinkingPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 30e7c22f31460..b432040b052a9 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -113,6 +113,8 @@ namespace { (void)llvm::createTLSVariableHoistPass(); (void) llvm::createConstantHoistingPass(); (void)llvm::createCodeGenPrepareLegacyPass(); + (void) llvm::createEntryExitInstrumenterPass(); + (void) llvm::createPostInlineEntryExitInstrumenterPass(); (void) llvm::createEarlyCSEPass(); (void) llvm::createGVNPass(); (void) llvm::createPostDomTree(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 2e94a19502131..b34f6e82fb7be 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -670,9 +670,6 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses( !Opt.DisablePartialLibcallInlining) addPass(PartiallyInlineLibCallsPass()); - // Instrument function entry and exit, e.g. with calls to mcount(). - addPass(EntryExitInstrumenterPass(/*PostInlining=*/true)); - // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index c6a6a05f3fddb..c3cb2908c8049 100644 --- a/llvm/include/llvm/Transforms/Utils.h +++ b/llvm/include/llvm/Transforms/Utils.h @@ -36,6 +36,15 @@ extern char &LowerInvokePassID; FunctionPass *createLowerSwitchPass(); extern char &LowerSwitchID; +//===----------------------------------------------------------------------===// +// +// EntryExitInstrumenter pass - Instrument function entry/exit with calls to +// mcount(), @__cyg_profile_func_{enter,exit} and the like. There are two +// variants, intended to run pre- and post-inlining, respectively. +// +FunctionPass *createEntryExitInstrumenterPass(); +FunctionPass *createPostInlineEntryExitInstrumenterPass(); + //===----------------------------------------------------------------------===// // // BreakCriticalEdges - Break all of the critical edges in the CFG by inserting diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index 8832b51333d91..6f19db623fe33 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -871,6 +871,9 @@ void TargetPassConfig::addIRPasses() { // passes since it emits those kinds of intrinsics. addPass(createExpandVectorPredicationPass()); + // TODO: comment + addPass(createPostInlineEntryExitInstrumenterPass()); + // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index 400b15284c1b8..cb37579f25051 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -48,4 +48,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeSpeculativeExecutionLegacyPassPass(Registry); initializeStraightLineStrengthReduceLegacyPassPass(Registry); initializePlaceBackedgeSafepointsLegacyPassPass(Registry); + initializeEntryExitInstrumenterPass(Registry); + initializePostInlineEntryExitInstrumenterPass(Registry); } diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 59a7dd1a00ed4..6326f2231f1dd 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -15,7 +15,10 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/InitializePasses.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/Pass.h" +#include "llvm/Transforms/Utils.h" using namespace llvm; @@ -135,6 +138,65 @@ static bool runOnFunction(Function &F, bool PostInlining) { return Changed; } +namespace { +struct EntryExitInstrumenter : public FunctionPass { + static char ID; + EntryExitInstrumenter() : FunctionPass(ID) { + initializeEntryExitInstrumenterPass(*PassRegistry::getPassRegistry()); + } + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addPreserved<GlobalsAAWrapperPass>(); + AU.addPreserved<DominatorTreeWrapperPass>(); + } + bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); } +}; +char EntryExitInstrumenter::ID = 0; + +struct PostInlineEntryExitInstrumenter : public FunctionPass { + static char ID; + PostInlineEntryExitInstrumenter() : FunctionPass(ID) { + initializePostInlineEntryExitInstrumenterPass( + *PassRegistry::getPassRegistry()); + } + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addPreserved<GlobalsAAWrapperPass>(); + AU.addPreserved<DominatorTreeWrapperPass>(); + } + bool runOnFunction(Function &F) override { return ::runOnFunction(F, true); } +}; +char PostInlineEntryExitInstrumenter::ID = 0; +} + +INITIALIZE_PASS_BEGIN( + EntryExitInstrumenter, "ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", + false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_END( + EntryExitInstrumenter, "ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", + false, false) + +INITIALIZE_PASS_BEGIN( + PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() " + "(post inlining)", + false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_END( + PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", + "Instrument function entry/exit with calls to e.g. mcount() " + "(post inlining)", + false, false) + +FunctionPass *llvm::createEntryExitInstrumenterPass() { + return new EntryExitInstrumenter(); +} + +FunctionPass *llvm::createPostInlineEntryExitInstrumenterPass() { + return new PostInlineEntryExitInstrumenter(); +} + PreservedAnalyses llvm::EntryExitInstrumenterPass::run(Function &F, FunctionAnalysisManager &AM) { if (!runOnFunction(F, PostInlining)) diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index b292f70ba89de..16fd7fcec2486 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -335,6 +335,8 @@ int main(int argc, char **argv) { initializeCodeGen(*Registry); initializeLoopStrengthReducePass(*Registry); initializeLowerIntrinsicsPass(*Registry); + initializeEntryExitInstrumenterPass(*Registry); + initializePostInlineEntryExitInstrumenterPass(*Registry); initializeUnreachableBlockElimLegacyPassPass(*Registry); initializeConstantHoistingLegacyPassPass(*Registry); initializeScalarOpts(*Registry); diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index 948148bb80498..dc15329515718 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -439,6 +439,8 @@ extern "C" int optMain( initializeIndirectBrExpandLegacyPassPass(Registry); initializeInterleavedLoadCombinePass(Registry); initializeInterleavedAccessPass(Registry); + initializeEntryExitInstrumenterPass(Registry); + initializePostInlineEntryExitInstrumenterPass(Registry); initializeUnreachableBlockElimLegacyPassPass(Registry); initializeExpandReductionsPass(Registry); initializeExpandVectorPredicationPass(Registry); >From 3ea4de1615d6ed3cba1a1fa4c0327f98921e0b1d Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 15 May 2024 13:27:36 +0200 Subject: [PATCH 02/16] Address the first round of review comments --- clang/lib/CodeGen/BackendUtil.cpp | 6 ----- llvm/include/llvm/LinkAllPasses.h | 1 - llvm/include/llvm/Passes/CodeGenPassBuilder.h | 3 +++ llvm/include/llvm/Transforms/Utils.h | 4 +-- llvm/lib/Passes/PassBuilderPipelines.cpp | 15 +++++++++++ llvm/lib/Transforms/Scalar/Scalar.cpp | 1 - .../Utils/EntryExitInstrumenter.cpp | 27 ------------------- llvm/tools/llc/llc.cpp | 1 - llvm/tools/opt/optdriver.cpp | 1 - 9 files changed, 20 insertions(+), 39 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index f6ff605bcef87..fc9b8206361d2 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -85,7 +85,6 @@ #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Scalar/JumpThreading.h" #include "llvm/Transforms/Utils/Debugify.h" -#include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/ModuleUtils.h" #include <memory> #include <optional> @@ -1000,11 +999,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (!IsThinLTOPostLink) { addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); addKCFIPass(TargetTriple, LangOpts, PB); - PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - }); } if (std::optional<GCOVOptions> Options = diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index b432040b052a9..311d38e8a751f 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -113,7 +113,6 @@ namespace { (void)llvm::createTLSVariableHoistPass(); (void) llvm::createConstantHoistingPass(); (void)llvm::createCodeGenPrepareLegacyPass(); - (void) llvm::createEntryExitInstrumenterPass(); (void) llvm::createPostInlineEntryExitInstrumenterPass(); (void) llvm::createEarlyCSEPass(); (void) llvm::createGVNPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index b34f6e82fb7be..2e94a19502131 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -670,6 +670,9 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses( !Opt.DisablePartialLibcallInlining) addPass(PartiallyInlineLibCallsPass()); + // Instrument function entry and exit, e.g. with calls to mcount(). + addPass(EntryExitInstrumenterPass(/*PostInlining=*/true)); + // Add scalarization of target's unsupported masked memory intrinsics pass. // the unsupported intrinsic will be replaced with a chain of basic blocks, // that stores/loads element one-by-one if the appropriate mask bit is set. diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index c3cb2908c8049..677cc3d128c3a 100644 --- a/llvm/include/llvm/Transforms/Utils.h +++ b/llvm/include/llvm/Transforms/Utils.h @@ -40,9 +40,9 @@ extern char &LowerSwitchID; // // EntryExitInstrumenter pass - Instrument function entry/exit with calls to // mcount(), @__cyg_profile_func_{enter,exit} and the like. There are two -// variants, intended to run pre- and post-inlining, respectively. +// variants, intended to run pre- and post-inlining, respectively. Only the +// post-inlining variant is used with the legacy pass manager. // -FunctionPass *createEntryExitInstrumenterPass(); FunctionPass *createPostInlineEntryExitInstrumenterPass(); //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 90ba3b541553e..9e00e4f30270a 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -127,6 +127,7 @@ #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/CountVisits.h" +#include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/InjectTLIMappings.h" #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" #include "llvm/Transforms/Utils/Mem2Reg.h" @@ -1028,6 +1029,14 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, Phase != ThinOrFullLTOPhase::ThinLTOPostLink) MPM.addPass(SampleProfileProbePass(TM)); + // Instrument function entry and exit before all inlining. + if (Phase != ThinOrFullLTOPhase::ThinLTOPostLink && + Phase != ThinOrFullLTOPhase::FullLTOPostLink && + Phase != ThinOrFullLTOPhase::None) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + } + bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse); // In ThinLTO mode, when flattened profile is used, all the available @@ -2045,6 +2054,12 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level, /*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, PGOOpt->FS); + // Instrument function entry and exit before all inlining. + if (LTOPreLink) { + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); + } + invokePipelineStartEPCallbacks(MPM, Level); if (PGOOpt && PGOOpt->DebugInfoForProfiling) diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index cb37579f25051..cb1456b146325 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -48,6 +48,5 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeSpeculativeExecutionLegacyPassPass(Registry); initializeStraightLineStrengthReduceLegacyPassPass(Registry); initializePlaceBackedgeSafepointsLegacyPassPass(Registry); - initializeEntryExitInstrumenterPass(Registry); initializePostInlineEntryExitInstrumenterPass(Registry); } diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index 6326f2231f1dd..d12c540f9a4d0 100644 --- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -139,19 +139,6 @@ static bool runOnFunction(Function &F, bool PostInlining) { } namespace { -struct EntryExitInstrumenter : public FunctionPass { - static char ID; - EntryExitInstrumenter() : FunctionPass(ID) { - initializeEntryExitInstrumenterPass(*PassRegistry::getPassRegistry()); - } - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addPreserved<GlobalsAAWrapperPass>(); - AU.addPreserved<DominatorTreeWrapperPass>(); - } - bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); } -}; -char EntryExitInstrumenter::ID = 0; - struct PostInlineEntryExitInstrumenter : public FunctionPass { static char ID; PostInlineEntryExitInstrumenter() : FunctionPass(ID) { @@ -167,16 +154,6 @@ struct PostInlineEntryExitInstrumenter : public FunctionPass { char PostInlineEntryExitInstrumenter::ID = 0; } -INITIALIZE_PASS_BEGIN( - EntryExitInstrumenter, "ee-instrument", - "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", - false, false) -INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_END( - EntryExitInstrumenter, "ee-instrument", - "Instrument function entry/exit with calls to e.g. mcount() (pre inlining)", - false, false) - INITIALIZE_PASS_BEGIN( PostInlineEntryExitInstrumenter, "post-inline-ee-instrument", "Instrument function entry/exit with calls to e.g. mcount() " @@ -189,10 +166,6 @@ INITIALIZE_PASS_END( "(post inlining)", false, false) -FunctionPass *llvm::createEntryExitInstrumenterPass() { - return new EntryExitInstrumenter(); -} - FunctionPass *llvm::createPostInlineEntryExitInstrumenterPass() { return new PostInlineEntryExitInstrumenter(); } diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 16fd7fcec2486..e7bf192192b67 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -335,7 +335,6 @@ int main(int argc, char **argv) { initializeCodeGen(*Registry); initializeLoopStrengthReducePass(*Registry); initializeLowerIntrinsicsPass(*Registry); - initializeEntryExitInstrumenterPass(*Registry); initializePostInlineEntryExitInstrumenterPass(*Registry); initializeUnreachableBlockElimLegacyPassPass(*Registry); initializeConstantHoistingLegacyPassPass(*Registry); diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index dc15329515718..d322666b207d0 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -439,7 +439,6 @@ extern "C" int optMain( initializeIndirectBrExpandLegacyPassPass(Registry); initializeInterleavedLoadCombinePass(Registry); initializeInterleavedAccessPass(Registry); - initializeEntryExitInstrumenterPass(Registry); initializePostInlineEntryExitInstrumenterPass(Registry); initializeUnreachableBlockElimLegacyPassPass(Registry); initializeExpandReductionsPass(Registry); >From c3d3637249b016a46771ecf8571a903bd6b1d1c1 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 16 May 2024 14:59:35 +0200 Subject: [PATCH 03/16] Address 2nd round of comments --- llvm/include/llvm/InitializePasses.h | 1 - llvm/lib/Passes/PassBuilderPipelines.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index e970706e8202d..c4c1825bbf09e 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -101,7 +101,6 @@ void initializeEarlyMachineLICMPass(PassRegistry&); void initializeEarlyTailDuplicatePass(PassRegistry&); void initializeEdgeBundlesPass(PassRegistry&); void initializeEHContGuardCatchretPass(PassRegistry &); -void initializeEntryExitInstrumenterPass(PassRegistry&); void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry&); void initializeExpandLargeDivRemLegacyPassPass(PassRegistry&); void initializeExpandMemCmpLegacyPassPass(PassRegistry &); diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 9e00e4f30270a..4fc6d84934727 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -396,6 +396,11 @@ static bool isLTOPreLink(ThinOrFullLTOPhase Phase) { Phase == ThinOrFullLTOPhase::FullLTOPreLink; } +static bool isLTOPostLink(ThinOrFullLTOPhase Phase) { + return Phase == ThinOrFullLTOPhase::ThinLTOPostLink || + Phase == ThinOrFullLTOPhase::FullLTOPostLink; +} + // TODO: Investigate the cost/benefit of tail call elimination on debugging. FunctionPassManager PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level, @@ -1030,9 +1035,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(SampleProfileProbePass(TM)); // Instrument function entry and exit before all inlining. - if (Phase != ThinOrFullLTOPhase::ThinLTOPostLink && - Phase != ThinOrFullLTOPhase::FullLTOPostLink && - Phase != ThinOrFullLTOPhase::None) { + if (!isLTOPostLink(Phase)) { MPM.addPass(createModuleToFunctionPassAdaptor( EntryExitInstrumenterPass(/*PostInlining=*/false))); } >From 5d462260d19bbfa95512c543901bcdbf7f67d214 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Tue, 21 May 2024 15:35:05 +0200 Subject: [PATCH 04/16] Run prelink instrumentation without LTO, plus tests A few more tests to go, still a WIP. Change a number of existing tests to swallow the newly inserted pass name. Add two new tests: * CodeGen/X86/instrument-function-inlined.ll * llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll --- llvm/lib/Passes/PassBuilderPipelines.cpp | 6 ++-- llvm/test/CodeGen/AArch64/O0-pipeline.ll | 1 + llvm/test/CodeGen/AArch64/O3-pipeline.ll | 1 + llvm/test/CodeGen/ARM/O3-pipeline.ll | 1 + llvm/test/CodeGen/LoongArch/O0-pipeline.ll | 1 + llvm/test/CodeGen/LoongArch/opt-pipeline.ll | 1 + llvm/test/CodeGen/PowerPC/O0-pipeline.ll | 1 + llvm/test/CodeGen/PowerPC/O3-pipeline.ll | 1 + llvm/test/CodeGen/RISCV/O0-pipeline.ll | 1 + llvm/test/CodeGen/RISCV/O3-pipeline.ll | 1 + llvm/test/CodeGen/X86/O0-pipeline.ll | 1 + .../X86/instrument-function-inlined.ll | 29 +++++++++++++++++ llvm/test/CodeGen/X86/opt-pipeline.ll | 1 + llvm/test/Other/new-pm-O0-defaults.ll | 5 +-- .../new-pm-thinlto-prelink-pgo-defaults.ll | 3 +- .../pre-inliner-instrumentation.ll | 31 +++++++++++++++++++ 16 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 llvm/test/CodeGen/X86/instrument-function-inlined.ll create mode 100644 llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 4fc6d84934727..6b4a2be590363 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -2058,10 +2058,8 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level, PGOOpt->ProfileRemappingFile, PGOOpt->FS); // Instrument function entry and exit before all inlining. - if (LTOPreLink) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - } + MPM.addPass(createModuleToFunctionPassAdaptor( + EntryExitInstrumenterPass(/*PostInlining=*/false))); invokePipelineStartEPCallbacks(MPM, Level); diff --git a/llvm/test/CodeGen/AArch64/O0-pipeline.ll b/llvm/test/CodeGen/AArch64/O0-pipeline.ll index d1e38b85fa9c3..a0306b8e1e924 100644 --- a/llvm/test/CodeGen/AArch64/O0-pipeline.ll +++ b/llvm/test/CodeGen/AArch64/O0-pipeline.ll @@ -24,6 +24,7 @@ ; CHECK-NEXT: Lower constant intrinsics ; CHECK-NEXT: Remove unreachable blocks from the CFG ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: AArch64 Globals Tagging diff --git a/llvm/test/CodeGen/AArch64/O3-pipeline.ll b/llvm/test/CodeGen/AArch64/O3-pipeline.ll index d3c8e3b7e805c..84e672d14d99d 100644 --- a/llvm/test/CodeGen/AArch64/O3-pipeline.ll +++ b/llvm/test/CodeGen/AArch64/O3-pipeline.ll @@ -62,6 +62,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/CodeGen/ARM/O3-pipeline.ll b/llvm/test/CodeGen/ARM/O3-pipeline.ll index 5914e98549fcc..461920e1c5da1 100644 --- a/llvm/test/CodeGen/ARM/O3-pipeline.ll +++ b/llvm/test/CodeGen/ARM/O3-pipeline.ll @@ -40,6 +40,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll index 84d235d78eb9e..e7228c8cf3e16 100644 --- a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll +++ b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll @@ -28,6 +28,7 @@ ; CHECK-NEXT: Lower constant intrinsics ; CHECK-NEXT: Remove unreachable blocks from the CFG ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Exception handling preparation diff --git a/llvm/test/CodeGen/LoongArch/opt-pipeline.ll b/llvm/test/CodeGen/LoongArch/opt-pipeline.ll index a31eb8d11a35a..7c7dde8a4b9ea 100644 --- a/llvm/test/CodeGen/LoongArch/opt-pipeline.ll +++ b/llvm/test/CodeGen/LoongArch/opt-pipeline.ll @@ -63,6 +63,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/CodeGen/PowerPC/O0-pipeline.ll b/llvm/test/CodeGen/PowerPC/O0-pipeline.ll index 56ed3ffe98642..cd37bee4592d6 100644 --- a/llvm/test/CodeGen/PowerPC/O0-pipeline.ll +++ b/llvm/test/CodeGen/PowerPC/O0-pipeline.ll @@ -27,6 +27,7 @@ ; CHECK-NEXT: Lower constant intrinsics ; CHECK-NEXT: Remove unreachable blocks from the CFG ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Exception handling preparation diff --git a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll index f94f91b38fecc..a564a5517f579 100644 --- a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll +++ b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll @@ -64,6 +64,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/CodeGen/RISCV/O0-pipeline.ll b/llvm/test/CodeGen/RISCV/O0-pipeline.ll index 56bd4bd0c08f0..7f0510a7d3fd7 100644 --- a/llvm/test/CodeGen/RISCV/O0-pipeline.ll +++ b/llvm/test/CodeGen/RISCV/O0-pipeline.ll @@ -28,6 +28,7 @@ ; CHECK-NEXT: Lower constant intrinsics ; CHECK-NEXT: Remove unreachable blocks from the CFG ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Exception handling preparation diff --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll index 4121d11109111..0964ee81fe5d1 100644 --- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll +++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll @@ -64,6 +64,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/CodeGen/X86/O0-pipeline.ll b/llvm/test/CodeGen/X86/O0-pipeline.ll index 11025b0e6bf22..40648adeb91cd 100644 --- a/llvm/test/CodeGen/X86/O0-pipeline.ll +++ b/llvm/test/CodeGen/X86/O0-pipeline.ll @@ -28,6 +28,7 @@ ; CHECK-NEXT: Lower constant intrinsics ; CHECK-NEXT: Remove unreachable blocks from the CFG ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Expand indirectbr instructions diff --git a/llvm/test/CodeGen/X86/instrument-function-inlined.ll b/llvm/test/CodeGen/X86/instrument-function-inlined.ll new file mode 100644 index 0000000000000..432d300871e79 --- /dev/null +++ b/llvm/test/CodeGen/X86/instrument-function-inlined.ll @@ -0,0 +1,29 @@ +; RUN: llc -mtriple=x86_64-- -O0 < %s | FileCheck %s +; RUN: llc -mtriple=x86_64-- -O1 < %s | FileCheck %s +; RUN: llc -mtriple=x86_64-- -O2 < %s | FileCheck %s + +; The codegen should insert post-inlining instrumentation calls and should not +; insert pre-inlining instrumentation. + +; CHECK-NOT: callq __cyg_profile_func_enter + +define void @leaf_function() #0 { +; CHECK-LABEL: leaf_function: +; CHECK: callq __cyg_profile_func_enter_bare +; CHECK: movq leaf_function@GOTPCREL(%rip), %rdi +; CHECK-NEXT: callq __cyg_profile_func_exit + ret void +} + +define void @root_function() #0 { +entry: +; CHECK-LABEL: root_function: +; CHECK: callq __cyg_profile_func_enter_bare +; CHECK-NEXT: callq leaf_function +; CHECK: movq root_function@GOTPCREL(%rip), %rdi +; CHECK-NEXT: callq __cyg_profile_func_exit + call void @leaf_function() + ret void +} + +attributes #0 = { "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" "instrument-function-exit-inlined"="__cyg_profile_func_exit" } diff --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll index 43589dc993dab..c4cbf94e53881 100644 --- a/llvm/test/CodeGen/X86/opt-pipeline.ll +++ b/llvm/test/CodeGen/X86/opt-pipeline.ll @@ -61,6 +61,7 @@ ; CHECK-NEXT: Replace intrinsics with calls to vector library ; CHECK-NEXT: Partially inline calls to library functions ; CHECK-NEXT: Expand vector predication intrinsics +; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining) ; CHECK-NEXT: Scalarize Masked Memory Intrinsics ; CHECK-NEXT: Expand reduction intrinsics ; CHECK-NEXT: Natural Loop Information diff --git a/llvm/test/Other/new-pm-O0-defaults.ll b/llvm/test/Other/new-pm-O0-defaults.ll index d7a4c70eb95cc..846828a774004 100644 --- a/llvm/test/Other/new-pm-O0-defaults.ll +++ b/llvm/test/Other/new-pm-O0-defaults.ll @@ -33,8 +33,9 @@ ; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass ; CHECK-DIS-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DIS-NEXT: Running analysis: ProfileSummaryAnalysis -; CHECK-DEFAULT: Running pass: AlwaysInlinerPass -; CHECK-DEFAULT-NEXT: Running analysis: InnerAnalysisManagerProxy +; CHECK-DEFAULT: Running analysis: InnerAnalysisManagerProxy +; CHECK-PRE-LINK: Running pass: EntryExitInstrumenterPass +; CHECK-PRE-LINK-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DEFAULT-NEXT: Running analysis: ProfileSummaryAnalysis ; CHECK-MATRIX: Running pass: LowerMatrixIntrinsicsPass ; CHECK-MATRIX-NEXT: Running analysis: TargetIRAnalysis diff --git a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll index 09f9f0f48badd..6f4338809553b 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll @@ -30,8 +30,9 @@ ; CHECK-O: Running pass: Annotation2Metadata ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass -; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass +; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass diff --git a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll new file mode 100644 index 0000000000000..152ac57bef6b3 --- /dev/null +++ b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll @@ -0,0 +1,31 @@ +; RUN: opt -passes="default<O1>" -S < %s | FileCheck %s +; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck %s +; RUN: opt -passes="thinlto-pre-link<O2>,thinlto<O3>" -S < %s | FileCheck %s + +target triple = "x86_64-unknown-linux" + +define void @leaf_function() #0 { +entry: + ret void +; CHECK-LABEL: entry: +; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0) +; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0) +; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0) +; CHECK-NEXT: ret void +} + + +define void @root_function() #0 { +entry: + call void @leaf_function() + ret void +; CHECK-LABEL: entry: +; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0) +; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @root_function, ptr %0) +; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0) +; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0) +; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @root_function, ptr %0) +; CHECK-NEXT: ret void +} + +attributes #0 = { "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } >From 5cabc6985fea91a12acce44acc002fd84e4f50ab Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 22 May 2024 16:49:18 +0200 Subject: [PATCH 05/16] Address review comments for the new tests Also tweak more pass manager tests to make them pass. --- llvm/lib/CodeGen/TargetPassConfig.cpp | 2 +- .../X86/instrument-function-inlined.ll | 4 +- llvm/test/Other/new-pass-manager.ll | 5 +- llvm/test/Other/new-pm-O0-defaults.ll | 5 +- llvm/test/Other/new-pm-defaults.ll | 3 +- .../Other/new-pm-thinlto-prelink-defaults.ll | 5 +- ...w-pm-thinlto-prelink-samplepgo-defaults.ll | 1 + .../pre-inliner-instrumentation.ll | 46 ++++++++++++------- 8 files changed, 44 insertions(+), 27 deletions(-) diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index 6f19db623fe33..3658e8320a0cc 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -871,7 +871,7 @@ void TargetPassConfig::addIRPasses() { // passes since it emits those kinds of intrinsics. addPass(createExpandVectorPredicationPass()); - // TODO: comment + // Instrument function entry after all inlining. addPass(createPostInlineEntryExitInstrumenterPass()); // Add scalarization of target's unsupported masked memory intrinsics pass. diff --git a/llvm/test/CodeGen/X86/instrument-function-inlined.ll b/llvm/test/CodeGen/X86/instrument-function-inlined.ll index 432d300871e79..d1764bc70db55 100644 --- a/llvm/test/CodeGen/X86/instrument-function-inlined.ll +++ b/llvm/test/CodeGen/X86/instrument-function-inlined.ll @@ -10,7 +10,7 @@ define void @leaf_function() #0 { ; CHECK-LABEL: leaf_function: ; CHECK: callq __cyg_profile_func_enter_bare -; CHECK: movq leaf_function@GOTPCREL(%rip), %rdi +; CHECK: {{.*}} %rdi ; CHECK-NEXT: callq __cyg_profile_func_exit ret void } @@ -20,7 +20,7 @@ entry: ; CHECK-LABEL: root_function: ; CHECK: callq __cyg_profile_func_enter_bare ; CHECK-NEXT: callq leaf_function -; CHECK: movq root_function@GOTPCREL(%rip), %rdi +; CHECK: {{.*}} %rdi ; CHECK-NEXT: callq __cyg_profile_func_exit call void @leaf_function() ret void diff --git a/llvm/test/Other/new-pass-manager.ll b/llvm/test/Other/new-pass-manager.ll index 904307659ad1f..db0af54fe4ae8 100644 --- a/llvm/test/Other/new-pass-manager.ll +++ b/llvm/test/Other/new-pass-manager.ll @@ -290,8 +290,9 @@ ; RUN: opt -disable-output -disable-verify -verify-analysis-invalidation=0 -debug-pass-manager \ ; RUN: -passes='default<O0>' %s 2>&1 \ ; RUN: | FileCheck %s --check-prefix=CHECK-O0 --check-prefix=%llvmcheckext -; CHECK-O0: Running pass: AlwaysInlinerPass -; CHECK-O0-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}> +; CHECK-O0: Running analysis: InnerAnalysisManagerProxy<{{.*}}> +; CHECK-O0-NEXT: Running pass: EntryExitInstrumenterPass +; CHECK-O0-NEXT: Running pass: AlwaysInlinerPass ; CHECK-O0-NEXT: Running analysis: ProfileSummaryAnalysis ; CHECK-EXT-NEXT: Running pass: {{.*}}Bye ; We don't have checks for CHECK-NOEXT here, but this simplifies the test, while diff --git a/llvm/test/Other/new-pm-O0-defaults.ll b/llvm/test/Other/new-pm-O0-defaults.ll index 846828a774004..e8131ac7fab45 100644 --- a/llvm/test/Other/new-pm-O0-defaults.ll +++ b/llvm/test/Other/new-pm-O0-defaults.ll @@ -30,12 +30,13 @@ ; RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-LTO ; CHECK-DIS: Running analysis: InnerAnalysisManagerProxy +; CHECK-DIS-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass ; CHECK-DIS-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DIS-NEXT: Running analysis: ProfileSummaryAnalysis ; CHECK-DEFAULT: Running analysis: InnerAnalysisManagerProxy -; CHECK-PRE-LINK: Running pass: EntryExitInstrumenterPass -; CHECK-PRE-LINK-NEXT: Running pass: AlwaysInlinerPass +; CHECK-DEFAULT-NEXT: Running pass: EntryExitInstrumenterPass +; CHECK-DEFAULT-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DEFAULT-NEXT: Running analysis: ProfileSummaryAnalysis ; CHECK-MATRIX: Running pass: LowerMatrixIntrinsicsPass ; CHECK-MATRIX-NEXT: Running analysis: TargetIRAnalysis diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll index 51fb93daa4dfa..6f3ea4fd74ddb 100644 --- a/llvm/test/Other/new-pm-defaults.ll +++ b/llvm/test/Other/new-pm-defaults.ll @@ -97,8 +97,9 @@ ; CHECK-O: Running pass: Annotation2Metadata ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass -; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass +; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass diff --git a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll index 6486639e07b49..2f6881b93c062 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll @@ -61,13 +61,14 @@ ; Suppress FileCheck --allow-unused-prefixes=false diagnostics. ; CHECK-NOEXT: {{^}} -; CHECK-O: Running pass: Annotation2Metadata +; CHECK-O: Running pass: Annotation2MetadataPass ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass ; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass -; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass +; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass diff --git a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll index 47bdbfd2d357d..a8db1682437a4 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll @@ -30,6 +30,7 @@ ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-O-NEXT: Running pass: AddDiscriminatorsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass diff --git a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll index 152ac57bef6b3..934a5cfef83c6 100644 --- a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll +++ b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll @@ -1,31 +1,43 @@ -; RUN: opt -passes="default<O1>" -S < %s | FileCheck %s -; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck %s -; RUN: opt -passes="thinlto-pre-link<O2>,thinlto<O3>" -S < %s | FileCheck %s +; RUN: opt -passes="default<O1>" -S < %s | FileCheck -check-prefix=PRELTO %s +; RUN: opt -passes="thinlto-pre-link<O0>,thinlto<O0>" -S < %s | FileCheck -check-prefix=PRELTO %s +; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck -check-prefix=PRELTO %s +; RUN: opt -passes="thinlto<O2>" -S < %s | FileCheck -check-prefix=LTO %s +; RUN: opt -passes="lto<O2>" -S < %s | FileCheck -check-prefix=LTO %s + +; Pre-inline instrumentation should be inserted, but not by LTO/ThinLTO passes. target triple = "x86_64-unknown-linux" define void @leaf_function() #0 { entry: ret void -; CHECK-LABEL: entry: -; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0) -; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0) -; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0) -; CHECK-NEXT: ret void +; PRELTO-LABEL: entry: +; PRELTO-NEXT: %0 ={{( tail)?}} call ptr @llvm.returnaddress(i32 0) +; PRELTO-NEXT: {{( tail)? call void @__cyg_profile_func_enter\(ptr( nonnull)? @leaf_function, ptr %0\)}} +; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_enter +; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit +; PRELTO-NEXT: ret void +; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_exit +; LTO-LABEL: entry: +; LTO-NEXT: ret void } -define void @root_function() #0 { +define void @root_function() #1 { entry: call void @leaf_function() ret void -; CHECK-LABEL: entry: -; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0) -; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @root_function, ptr %0) -; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0) -; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0) -; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @root_function, ptr %0) -; CHECK-NEXT: ret void +; PRELTO-LABEL: entry: +; PRELTO-NEXT: %0 ={{( tail)?}} call ptr @llvm.returnaddress(i32 0) +; PRELTO-NEXT: {{( tail)?}} call void @__cyg_profile_func_enter(ptr{{( nonnull)?}} @root_function, ptr %0) +; PRELTO: {{( tail)?}} call void @__cyg_profile_func_enter +; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit +; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit +; PRELTO-NEXT: ret void +; LTO-LABEL: entry: +; LTO-NEXT: ret void +; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_exit } -attributes #0 = { "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } +attributes #0 = { alwaysinline "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } +attributes #1 = { "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } >From e9c64d5c1a91e98846238c47713e90eccfe8808d Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 22 May 2024 21:02:13 +0200 Subject: [PATCH 06/16] Remove a couple of clang tests --- .../CodeGen/X86/x86_64-instrument-functions.c | 37 ----------------- clang/test/Frontend/gnu-mcount.c | 41 ------------------- 2 files changed, 78 deletions(-) delete mode 100644 clang/test/CodeGen/X86/x86_64-instrument-functions.c delete mode 100644 clang/test/Frontend/gnu-mcount.c diff --git a/clang/test/CodeGen/X86/x86_64-instrument-functions.c b/clang/test/CodeGen/X86/x86_64-instrument-functions.c deleted file mode 100644 index b2cef133ff048..0000000000000 --- a/clang/test/CodeGen/X86/x86_64-instrument-functions.c +++ /dev/null @@ -1,37 +0,0 @@ -// REQUIRES: x86-registered-target -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions -O0 -o - -emit-llvm %s | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions -O2 -o - -emit-llvm %s | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - -emit-llvm %s | FileCheck -check-prefix=NOINLINE %s - -__attribute__((always_inline)) int leaf(int x) { - return x; -// CHECK-LABEL: define {{.*}} @leaf -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile -// CHECK: call void @__cyg_profile_func_exit -// CHECK-NOT: cyg_profile -// CHECK: ret -} - -int root(int x) { - return leaf(x); -// CHECK-LABEL: define {{.*}} @root -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile - -// Inlined from leaf(): -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile -// CHECK: call void @__cyg_profile_func_exit -// CHECK-NOT: cyg_profile - -// CHECK: call void @__cyg_profile_func_exit -// CHECK: ret - -// NOINLINE-LABEL: define {{.*}} @root -// NOINLINE: call void @__cyg_profile_func_enter -// NOINLINE-NOT: cyg_profile -// NOINLINE: call void @__cyg_profile_func_exit -// NOINLINE-NOT: cyg_profile -// NOINLINE: ret -} diff --git a/clang/test/Frontend/gnu-mcount.c b/clang/test/Frontend/gnu-mcount.c deleted file mode 100644 index a6ee4b274593e..0000000000000 --- a/clang/test/Frontend/gnu-mcount.c +++ /dev/null @@ -1,41 +0,0 @@ -// REQUIRES: arm-registered-target,aarch64-registered-target - -// RUN: %clang -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang --target=aarch64-unknown-none-gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI -// RUN: %clang -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU -// RUN: %clang --target=aarch64-unknown-linux -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER -// RUN: %clang -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI -// RUN: %clang -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU -// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-freebsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-FREEBSD -// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-openbsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-netbsd -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang -target armv7-unknown-rtems-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT -// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT - -int f() { - return 0; -} - -// CHECK-LABEL: f -// TODO: add profiling support for arm-baremetal -// UNSUPPORTED-NOT: call void -// CHECK-ARM-EABI: call void @"\01mcount"() -// MCOUNT: call void @mcount() -// UNDER: call void @"\01_mcount"() -// UNDER_UNDER: call void @__mcount() -// CHECK-ARM64-EABI-FREEBSD: call void @.mcount() -// CHECK-ARM-EABI-MEABI-GNU: call void @llvm.arm.gnu.eabi.mcount() >From d095f41a2a9cadba6458c2ed7a9ce01701f553e5 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 22 May 2024 21:06:55 +0200 Subject: [PATCH 07/16] Add one more -O0 check in pre-inliner --- .../EntryExitInstrumenter/pre-inliner-instrumentation.ll | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll index 934a5cfef83c6..6c5b0a4458996 100644 --- a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll +++ b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll @@ -1,3 +1,4 @@ +; RUN: opt -passes="default<O0>" -S < %s | FileCheck -check-prefix=PRELTO %s ; RUN: opt -passes="default<O1>" -S < %s | FileCheck -check-prefix=PRELTO %s ; RUN: opt -passes="thinlto-pre-link<O0>,thinlto<O0>" -S < %s | FileCheck -check-prefix=PRELTO %s ; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck -check-prefix=PRELTO %s >From e5da2997f80ef7a8f1d14c9c1d5fcec08a9d5526 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 23 May 2024 15:58:19 +0200 Subject: [PATCH 08/16] Revert "Remove a couple of clang tests" This reverts commit e9c64d5c1a91e98846238c47713e90eccfe8808d. --- .../CodeGen/X86/x86_64-instrument-functions.c | 37 +++++++++++++++++ clang/test/Frontend/gnu-mcount.c | 41 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 clang/test/CodeGen/X86/x86_64-instrument-functions.c create mode 100644 clang/test/Frontend/gnu-mcount.c diff --git a/clang/test/CodeGen/X86/x86_64-instrument-functions.c b/clang/test/CodeGen/X86/x86_64-instrument-functions.c new file mode 100644 index 0000000000000..b2cef133ff048 --- /dev/null +++ b/clang/test/CodeGen/X86/x86_64-instrument-functions.c @@ -0,0 +1,37 @@ +// REQUIRES: x86-registered-target +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions -O0 -o - -emit-llvm %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions -O2 -o - -emit-llvm %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - -emit-llvm %s | FileCheck -check-prefix=NOINLINE %s + +__attribute__((always_inline)) int leaf(int x) { + return x; +// CHECK-LABEL: define {{.*}} @leaf +// CHECK: call void @__cyg_profile_func_enter +// CHECK-NOT: cyg_profile +// CHECK: call void @__cyg_profile_func_exit +// CHECK-NOT: cyg_profile +// CHECK: ret +} + +int root(int x) { + return leaf(x); +// CHECK-LABEL: define {{.*}} @root +// CHECK: call void @__cyg_profile_func_enter +// CHECK-NOT: cyg_profile + +// Inlined from leaf(): +// CHECK: call void @__cyg_profile_func_enter +// CHECK-NOT: cyg_profile +// CHECK: call void @__cyg_profile_func_exit +// CHECK-NOT: cyg_profile + +// CHECK: call void @__cyg_profile_func_exit +// CHECK: ret + +// NOINLINE-LABEL: define {{.*}} @root +// NOINLINE: call void @__cyg_profile_func_enter +// NOINLINE-NOT: cyg_profile +// NOINLINE: call void @__cyg_profile_func_exit +// NOINLINE-NOT: cyg_profile +// NOINLINE: ret +} diff --git a/clang/test/Frontend/gnu-mcount.c b/clang/test/Frontend/gnu-mcount.c new file mode 100644 index 0000000000000..a6ee4b274593e --- /dev/null +++ b/clang/test/Frontend/gnu-mcount.c @@ -0,0 +1,41 @@ +// REQUIRES: arm-registered-target,aarch64-registered-target + +// RUN: %clang -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang --target=aarch64-unknown-none-gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI +// RUN: %clang -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU +// RUN: %clang --target=aarch64-unknown-linux -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER +// RUN: %clang -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI +// RUN: %clang -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU +// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang --target=aarch64-unknown-freebsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-FREEBSD +// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang --target=aarch64-unknown-openbsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang --target=aarch64-unknown-netbsd -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -target armv7-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang -target armv7-unknown-rtems-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT +// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT + +int f() { + return 0; +} + +// CHECK-LABEL: f +// TODO: add profiling support for arm-baremetal +// UNSUPPORTED-NOT: call void +// CHECK-ARM-EABI: call void @"\01mcount"() +// MCOUNT: call void @mcount() +// UNDER: call void @"\01_mcount"() +// UNDER_UNDER: call void @__mcount() +// CHECK-ARM64-EABI-FREEBSD: call void @.mcount() +// CHECK-ARM-EABI-MEABI-GNU: call void @llvm.arm.gnu.eabi.mcount() >From 1a4e5fbf747027b0b88092b59408944cd5808af6 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 23 May 2024 18:08:20 +0200 Subject: [PATCH 09/16] Address comments in new tests --- .../X86/instrument-function-inlined.ll | 6 +-- .../pre-inliner-instrumentation.ll | 52 ++++++++++--------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/llvm/test/CodeGen/X86/instrument-function-inlined.ll b/llvm/test/CodeGen/X86/instrument-function-inlined.ll index d1764bc70db55..3ef73bc65add1 100644 --- a/llvm/test/CodeGen/X86/instrument-function-inlined.ll +++ b/llvm/test/CodeGen/X86/instrument-function-inlined.ll @@ -10,8 +10,7 @@ define void @leaf_function() #0 { ; CHECK-LABEL: leaf_function: ; CHECK: callq __cyg_profile_func_enter_bare -; CHECK: {{.*}} %rdi -; CHECK-NEXT: callq __cyg_profile_func_exit +; CHECK: callq __cyg_profile_func_exit ret void } @@ -20,8 +19,7 @@ entry: ; CHECK-LABEL: root_function: ; CHECK: callq __cyg_profile_func_enter_bare ; CHECK-NEXT: callq leaf_function -; CHECK: {{.*}} %rdi -; CHECK-NEXT: callq __cyg_profile_func_exit +; CHECK: callq __cyg_profile_func_exit call void @leaf_function() ret void } diff --git a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll index 6c5b0a4458996..89e12a2971290 100644 --- a/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll +++ b/llvm/test/Transforms/EntryExitInstrumenter/pre-inliner-instrumentation.ll @@ -1,9 +1,11 @@ -; RUN: opt -passes="default<O0>" -S < %s | FileCheck -check-prefix=PRELTO %s -; RUN: opt -passes="default<O1>" -S < %s | FileCheck -check-prefix=PRELTO %s -; RUN: opt -passes="thinlto-pre-link<O0>,thinlto<O0>" -S < %s | FileCheck -check-prefix=PRELTO %s -; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck -check-prefix=PRELTO %s -; RUN: opt -passes="thinlto<O2>" -S < %s | FileCheck -check-prefix=LTO %s -; RUN: opt -passes="lto<O2>" -S < %s | FileCheck -check-prefix=LTO %s +; RUN: opt -passes="default<O0>" -S < %s | FileCheck -check-prefix=INSTRUMENT %s +; RUN: opt -passes="default<O1>" -S < %s | FileCheck -check-prefix=INSTRUMENT %s +; RUN: opt -passes="thinlto-pre-link<O0>" -S < %s | FileCheck -check-prefix=INSTRUMENT %s +; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck -check-prefix=INSTRUMENT %s +; RUN: opt -passes="thinlto<O0>" -S < %s | FileCheck -check-prefix=NOINSTRUMENT %s +; RUN: opt -passes="thinlto<O2>" -S < %s | FileCheck -check-prefix=NOINSTRUMENT %s +; RUN: opt -passes="lto<O0>" -S < %s | FileCheck -check-prefix=NOINSTRUMENT %s +; RUN: opt -passes="lto<O2>" -S < %s | FileCheck -check-prefix=NOINSTRUMENT %s ; Pre-inline instrumentation should be inserted, but not by LTO/ThinLTO passes. @@ -12,15 +14,15 @@ target triple = "x86_64-unknown-linux" define void @leaf_function() #0 { entry: ret void -; PRELTO-LABEL: entry: -; PRELTO-NEXT: %0 ={{( tail)?}} call ptr @llvm.returnaddress(i32 0) -; PRELTO-NEXT: {{( tail)? call void @__cyg_profile_func_enter\(ptr( nonnull)? @leaf_function, ptr %0\)}} -; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_enter -; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit -; PRELTO-NEXT: ret void -; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_exit -; LTO-LABEL: entry: -; LTO-NEXT: ret void +; INSTRUMENT-LABEL: entry: +; INSTRUMENT-NEXT: %0 ={{.*}} call ptr @llvm.returnaddress(i32 0) +; INSTRUMENT-NEXT: {{.* call void @__cyg_profile_func_enter\(ptr( nonnull)? @leaf_function, ptr %0\)}} +; NOINSTRUMENT-NOT: {{.*}} call void @__cyg_profile_func_enter +; INSTRUMENT: {{.*}} call void @__cyg_profile_func_exit +; INSTRUMENT-NEXT: ret void +; NOINSTRUMENT-NOT: {{.*}} call void @__cyg_profile_func_exit +; NOINSTRUMENT-LABEL: entry: +; NOINSTRUMENT-NEXT: ret void } @@ -28,16 +30,16 @@ define void @root_function() #1 { entry: call void @leaf_function() ret void -; PRELTO-LABEL: entry: -; PRELTO-NEXT: %0 ={{( tail)?}} call ptr @llvm.returnaddress(i32 0) -; PRELTO-NEXT: {{( tail)?}} call void @__cyg_profile_func_enter(ptr{{( nonnull)?}} @root_function, ptr %0) -; PRELTO: {{( tail)?}} call void @__cyg_profile_func_enter -; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit -; PRELTO: {{( tail)?}} call void @__cyg_profile_func_exit -; PRELTO-NEXT: ret void -; LTO-LABEL: entry: -; LTO-NEXT: ret void -; LTO-NOT: {{( tail)?}} call void @__cyg_profile_func_exit +; INSTRUMENT-LABEL: entry: +; INSTRUMENT-NEXT: %0 ={{.*}} call ptr @llvm.returnaddress(i32 0) +; INSTRUMENT-NEXT: {{.*}} call void @__cyg_profile_func_enter(ptr{{( nonnull)?}} @root_function, ptr %0) +; INSTRUMENT: {{.*}} call void @__cyg_profile_func_enter +; INSTRUMENT: {{.*}} call void @__cyg_profile_func_exit +; INSTRUMENT: {{.*}} call void @__cyg_profile_func_exit +; INSTRUMENT-NEXT: ret void +; NOINSTRUMENT-LABEL: entry: +; NOINSTRUMENT: ret void +; NOINSTRUMENT-NOT: {{.*}} call void @__cyg_profile_func_exit } attributes #0 = { alwaysinline "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" } >From fd92b902bbcf63b5eab8f1acadb943cef4429f86 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 23 May 2024 20:27:58 +0200 Subject: [PATCH 10/16] For recovered tests in Clang only check attributes and disable llvm passes --- .../CodeGen/X86/x86_64-instrument-functions.c | 26 +++----- clang/test/Frontend/gnu-mcount.c | 64 ++++++++++--------- 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/clang/test/CodeGen/X86/x86_64-instrument-functions.c b/clang/test/CodeGen/X86/x86_64-instrument-functions.c index 215e629a604f7..6b09d8e7c93a9 100644 --- a/clang/test/CodeGen/X86/x86_64-instrument-functions.c +++ b/clang/test/CodeGen/X86/x86_64-instrument-functions.c @@ -1,14 +1,11 @@ // REQUIRES: x86-registered-target -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finstrument-functions -O0 -o - -emit-llvm %s | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finstrument-functions -O2 -o - -emit-llvm %s | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -finstrument-functions-after-inlining -O2 -o - -emit-llvm %s | FileCheck -check-prefix=NOINLINE %s +// RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-unknown-unknown -finstrument-functions -O0 -o - -emit-llvm %s | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-unknown-unknown -finstrument-functions -O2 -o - -emit-llvm %s | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-unknown-unknown -finstrument-functions-after-inlining -O2 -o - -emit-llvm %s | FileCheck -check-prefix=NOINLINE %s __attribute__((always_inline)) int leaf(int x) { return x; // CHECK-LABEL: define {{.*}} @leaf -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile -// CHECK: call void @__cyg_profile_func_exit // CHECK-NOT: cyg_profile // CHECK: ret } @@ -16,22 +13,15 @@ __attribute__((always_inline)) int leaf(int x) { int root(int x) { return leaf(x); // CHECK-LABEL: define {{.*}} @root -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile - -// Inlined from leaf(): -// CHECK: call void @__cyg_profile_func_enter -// CHECK-NOT: cyg_profile -// CHECK: call void @__cyg_profile_func_exit // CHECK-NOT: cyg_profile - -// CHECK: call void @__cyg_profile_func_exit // CHECK: ret // NOINLINE-LABEL: define {{.*}} @root -// NOINLINE: call void @__cyg_profile_func_enter -// NOINLINE-NOT: cyg_profile -// NOINLINE: call void @__cyg_profile_func_exit // NOINLINE-NOT: cyg_profile // NOINLINE: ret } + +// CHECK: attributes #0 = { alwaysinline {{.*}} "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" +// CHECK: attributes #1 = { {{.*}} "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" +// NOINLINE: attributes #0 = { alwaysinline {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" +// NOINLINE: attributes #1 = { {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" diff --git a/clang/test/Frontend/gnu-mcount.c b/clang/test/Frontend/gnu-mcount.c index a6ee4b274593e..965c0010b549d 100644 --- a/clang/test/Frontend/gnu-mcount.c +++ b/clang/test/Frontend/gnu-mcount.c @@ -1,30 +1,32 @@ // REQUIRES: arm-registered-target,aarch64-registered-target -// RUN: %clang -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang --target=aarch64-unknown-none-gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI -// RUN: %clang -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU -// RUN: %clang --target=aarch64-unknown-linux -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER -// RUN: %clang -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI -// RUN: %clang -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU -// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-freebsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-FREEBSD -// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-openbsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER -// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang --target=aarch64-unknown-netbsd -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER -// RUN: %clang -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED -// RUN: %clang -target armv7-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang -target armv7-unknown-rtems-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT -// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT -// RUN: %clang --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-none-gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-linux -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-freebsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-FREEBSD +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-openbsd -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-netbsd -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNDER_UNDER +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,UNSUPPORTED +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang -Xclang -disable-llvm-passes -target armv7-unknown-rtems-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,MCOUNT +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT +// RUN: %clang -Xclang -disable-llvm-passes --target=aarch64-unknown-rtems -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,MCOUNT + +// Correct function name should be used for mcount instrumentation call. int f() { return 0; @@ -33,9 +35,9 @@ int f() { // CHECK-LABEL: f // TODO: add profiling support for arm-baremetal // UNSUPPORTED-NOT: call void -// CHECK-ARM-EABI: call void @"\01mcount"() -// MCOUNT: call void @mcount() -// UNDER: call void @"\01_mcount"() -// UNDER_UNDER: call void @__mcount() -// CHECK-ARM64-EABI-FREEBSD: call void @.mcount() -// CHECK-ARM-EABI-MEABI-GNU: call void @llvm.arm.gnu.eabi.mcount() +// CHECK-ARM-EABI: attributes #0 = {{.*}} "instrument-function-entry-inlined"="\01mcount" +// MCOUNT: attributes #0 = {{.*}} "instrument-function-entry-inlined"="mcount" +// UNDER: attributes #0 = {{.*}} "instrument-function-entry-inlined"="\01_mcount" +// UNDER_UNDER: attributes #0 = {{.*}} "instrument-function-entry-inlined"="__mcount" +// CHECK-ARM64-EABI-FREEBSD: attributes #0 = {{.*}} "instrument-function-entry-inlined"=".mcount" +// CHECK-ARM-EABI-MEABI-GNU: attributes #0 = {{.*}} "instrument-function-entry-inlined"="llvm.arm.gnu.eabi.mcount" >From b65cec9d35451944175ed37b44135e5cfa3002c1 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Fri, 24 May 2024 19:58:40 +0200 Subject: [PATCH 11/16] Convert more Clang tests to only check attributes --- .../CodeGen/X86/x86_64-instrument-functions.c | 21 ++--- clang/test/CodeGen/instrument-objc-method.m | 15 ++-- clang/test/CodeGen/lto-newpm-pipeline.c | 6 +- clang/test/CodeGen/mcount-aix.c | 22 ++--- clang/test/CodeGen/mcount.c | 84 +++++++++---------- 5 files changed, 64 insertions(+), 84 deletions(-) diff --git a/clang/test/CodeGen/X86/x86_64-instrument-functions.c b/clang/test/CodeGen/X86/x86_64-instrument-functions.c index 6b09d8e7c93a9..d71e839a61813 100644 --- a/clang/test/CodeGen/X86/x86_64-instrument-functions.c +++ b/clang/test/CodeGen/X86/x86_64-instrument-functions.c @@ -5,23 +5,16 @@ __attribute__((always_inline)) int leaf(int x) { return x; -// CHECK-LABEL: define {{.*}} @leaf -// CHECK-NOT: cyg_profile -// CHECK: ret +// CHECK-LABEL: define {{.*}} @leaf(i32 noundef %x) #0 { } int root(int x) { return leaf(x); -// CHECK-LABEL: define {{.*}} @root -// CHECK-NOT: cyg_profile -// CHECK: ret - -// NOINLINE-LABEL: define {{.*}} @root -// NOINLINE-NOT: cyg_profile -// NOINLINE: ret +// CHECK-LABEL: define {{.*}} @root(i32 noundef %x) #1 { +// NOINLINE-LABEL: define {{.*}} @root(i32 noundef %x) #1 { } -// CHECK: attributes #0 = { alwaysinline {{.*}} "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" -// CHECK: attributes #1 = { {{.*}} "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" -// NOINLINE: attributes #0 = { alwaysinline {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" -// NOINLINE: attributes #1 = { {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" +// CHECK: attributes #0 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" +// CHECK: attributes #1 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" +// NOINLINE: attributes #0 = { {{.*}}"instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" +// NOINLINE: attributes #1 = { {{.*}}"instrument-function-entry-inlined"="__cyg_profile_func_enter" "instrument-function-exit-inlined"="__cyg_profile_func_exit" diff --git a/clang/test/CodeGen/instrument-objc-method.m b/clang/test/CodeGen/instrument-objc-method.m index 7758e001e514f..8133ecacb9c66 100644 --- a/clang/test/CodeGen/instrument-objc-method.m +++ b/clang/test/CodeGen/instrument-objc-method.m @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare | FileCheck -check-prefix=BARE %s +// RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare | FileCheck -check-prefix=BARE %s @interface ObjCClass @end @@ -9,26 +9,25 @@ @implementation ObjCClass // CHECK: @"\01+[ObjCClass initialize]" // CHECK: call void @__cyg_profile_func_enter // CHECK: call void @__cyg_profile_func_exit -// BARE: @"\01+[ObjCClass initialize]" -// BARE: call void @__cyg_profile_func_enter +// BARE: @"\01+[ObjCClass initialize]"{{\(.*\)}} #0 + (void)initialize { } // CHECK: @"\01+[ObjCClass load]" // CHECK-NOT: call void @__cyg_profile_func_enter -// BARE: @"\01+[ObjCClass load]" -// BARE-NOT: call void @__cyg_profile_func_enter +// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1 + (void)load __attribute__((no_instrument_function)) { } // CHECK: @"\01-[ObjCClass dealloc]" // CHECK-NOT: call void @__cyg_profile_func_enter -// BARE: @"\01-[ObjCClass dealloc]" -// BARE-NOT: call void @__cyg_profile_func_enter +// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1 - (void)dealloc __attribute__((no_instrument_function)) { } // CHECK: declare void @__cyg_profile_func_enter(ptr, ptr) // CHECK: declare void @__cyg_profile_func_exit(ptr, ptr) -// BARE: declare void @__cyg_profile_func_enter_bare +// BARE-NOT: declare void @__cyg_profile_func_enter_bare +// BARE: attributes #0 = { {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" +// BARE-NOT: attributes #1 = { {{.*}} "__cyg_profile_func_enter_bare" @end diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c index f58757efbf686..ea9784a76f923 100644 --- a/clang/test/CodeGen/lto-newpm-pipeline.c +++ b/clang/test/CodeGen/lto-newpm-pipeline.c @@ -27,8 +27,9 @@ // CHECK-FULL-O0: Running pass: VerifierPass // CHECK-FULL-O0-NEXT: Running analysis: VerifierAnalysis -// CHECK-FULL-O0-NEXT: Running pass: AlwaysInlinerPass // CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy +// CHECK-FULL-O0-NEXT: Running pass: EntryExitInstrumenterPass +// CHECK-FULL-O0-NEXT: Running pass: AlwaysInlinerPass // CHECK-FULL-O0-NEXT: Running analysis: ProfileSummaryAnalysis // CHECK-FULL-O0-NEXT: Running pass: CoroConditionalWrapper // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass @@ -40,8 +41,9 @@ // CHECK-THIN-O0: Running pass: VerifierPass // CHECK-THIN-O0-NEXT: Running analysis: VerifierAnalysis -// CHECK-THIN-O0-NEXT: Running pass: AlwaysInlinerPass // CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy +// CHECK-THIN-O0-NEXT: Running pass: EntryExitInstrumenterPass +// CHECK-THIN-O0-NEXT: Running pass: AlwaysInlinerPass // CHECK-THIN-O0-NEXT: Running analysis: ProfileSummaryAnalysis // CHECK-THIN-O0-NEXT: Running pass: CoroConditionalWrapper // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass diff --git a/clang/test/CodeGen/mcount-aix.c b/clang/test/CodeGen/mcount-aix.c index 17ce0af476dbb..b6a15336578db 100644 --- a/clang/test/CodeGen/mcount-aix.c +++ b/clang/test/CodeGen/mcount-aix.c @@ -1,25 +1,13 @@ // RUN: %clang_cc1 -pg -triple powerpc-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s -// RUN: %clang_cc1 -pg -triple powerpc64-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK64 +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s void foo() { +// CHECK: define void @foo() #0 { } void bar() { +// CHECK: define void @bar() #0 { foo(); } -// CHECK: @[[GLOB0:[0-9]+]] = internal global i32 0 -// CHECK: @[[GLOB1:[0-9]+]] = internal global i32 0 -// CHECK64: @[[GLOB0:[0-9]+]] = internal global i64 0 -// CHECK64: @[[GLOB1:[0-9]+]] = internal global i64 0 -// CHECK-LABEL: @foo( -// CHECK-NEXT: entry: -// CHECK-NEXT: call void @__mcount(ptr @[[GLOB0]]) -// CHECK64-LABEL: @foo( -// CHECK64-NEXT: entry: -// CHECK64-NEXT: call void @__mcount(ptr @[[GLOB0]]) -// CHECK-LABEL: @bar( -// CHECK-NEXT: entry: -// CHECK-NEXT: call void @__mcount(ptr @[[GLOB1]]) -// CHECK64-LABEL: @bar( -// CHECK64-NEXT: entry: -// CHECK64-NEXT: call void @__mcount(ptr @[[GLOB1]]) + +// CHECK: attributes #0 = { {{.*}}"instrument-function-entry-inlined"="__mcount" diff --git a/clang/test/CodeGen/mcount.c b/clang/test/CodeGen/mcount.c index bdd609c1dfc58..e5b842d670450 100644 --- a/clang/test/CodeGen/mcount.c +++ b/clang/test/CodeGen/mcount.c @@ -1,60 +1,58 @@ -// RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -O2 -o - %s | FileCheck %s -// RUN: %clang_cc1 -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple i386-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple loongarch32 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple loongarch64 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple mips-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s -// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-MCOUNT +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple i386-unknown-unknown -emit-llvm -O2 -o - %s | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple i386-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple loongarch32 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple loongarch64 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple mips-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple mips64-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple mips64el-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv32-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv64-elf -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv32-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv64-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv64-freebsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple riscv64-openbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s +// RUN: %clang_cc1 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-MCOUNT int bar(void) { +// CHECK: define dso_local i32 @bar() #0 { return 0; } int foo(void) { +// CHECK: define dso_local i32 @foo() #0 { return bar(); } int __attribute__((no_instrument_function)) no_instrument(void) { +// CHECK: define dso_local i32 @no_instrument() #1 { return foo(); } int main(void) { +// CHECK: define dso_local i32 @main() #0 { return no_instrument(); } -// CHECK: call void @mcount -// CHECK: call void @mcount -// CHECK: call void @mcount -// CHECK-NOT: call void @mcount -// CHECK-PREFIXED: call void @_mcount -// CHECK-PREFIXED: call void @_mcount -// CHECK-PREFIXED: call void @_mcount -// CHECK-PREFIXED-NOT: call void @_mcount -// CHECK-DOUBLE-PREFIXED: call void @__mcount -// CHECK-DOUBLE-PREFIXED: call void @__mcount -// CHECK-DOUBLE-PREFIXED: call void @__mcount -// CHECK-DOUBLE-PREFIXED-NOT: call void @__mcount -// NO-MCOUNT-NOT: call void @{{.*}}mcount -// NO-MCOUNT1-NOT: call void @{{.*}}mcount +// CHECK: attributes #0 = { {{.*}} "instrument-function-entry-inlined"="mcount" +// CHECK-NOT: attributes #1 = { {{.*}}"mcount" +// CHECK-PREFIXED: attributes #0 = { {{.*}} "instrument-function-entry-inlined"="_mcount" +// CHECK-PREFIXED-NOT: attributes #1 = { {{.*}}"_mcount" +// CHECK-DOUBLE-PREFIXED: attributes #0 = { {{.*}} "instrument-function-entry-inlined"="__mcount" +// CHECK-DOUBLE-PREFIXED-NOT: attributes #1 = { {{.*}}"__mcount" +// NO-MCOUNT-NOT: attributes{{.*}}mcount +// NO-MCOUNT1-NOT: attributes{{.*}}mcount >From 1abdb8602d3ef60a339227087b473274e1739626 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Mon, 27 May 2024 14:32:50 +0200 Subject: [PATCH 12/16] Run clang/test/CodeGen/... instrumentation tests only with -disable-llvm-passes --- clang/test/CodeGen/instrument-objc-method.m | 27 +++++++++------------ clang/test/CodeGen/mcount-aix.c | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/clang/test/CodeGen/instrument-objc-method.m b/clang/test/CodeGen/instrument-objc-method.m index 8133ecacb9c66..cfc0a0a98bec6 100644 --- a/clang/test/CodeGen/instrument-objc-method.m +++ b/clang/test/CodeGen/instrument-objc-method.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck -check-prefix=PREINLINE %s // RUN: %clang_cc1 -disable-llvm-passes -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare | FileCheck -check-prefix=BARE %s @interface ObjCClass @@ -6,28 +6,25 @@ @interface ObjCClass @implementation ObjCClass -// CHECK: @"\01+[ObjCClass initialize]" -// CHECK: call void @__cyg_profile_func_enter -// CHECK: call void @__cyg_profile_func_exit +// PREINLINE: @"\01+[ObjCClass initialize]"{{\(.*\)}} #0 // BARE: @"\01+[ObjCClass initialize]"{{\(.*\)}} #0 + (void)initialize { } -// CHECK: @"\01+[ObjCClass load]" -// CHECK-NOT: call void @__cyg_profile_func_enter -// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1 +// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 +// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2 + (void)load __attribute__((no_instrument_function)) { } -// CHECK: @"\01-[ObjCClass dealloc]" -// CHECK-NOT: call void @__cyg_profile_func_enter -// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1 +// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2 +// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2 - (void)dealloc __attribute__((no_instrument_function)) { } -// CHECK: declare void @__cyg_profile_func_enter(ptr, ptr) -// CHECK: declare void @__cyg_profile_func_exit(ptr, ptr) -// BARE-NOT: declare void @__cyg_profile_func_enter_bare -// BARE: attributes #0 = { {{.*}} "instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" -// BARE-NOT: attributes #1 = { {{.*}} "__cyg_profile_func_enter_bare" +// PREINLINE: attributes #0 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter" +// PREINLINE-NOT: attributes #0 = { {{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare" +// PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter" +// BARE: attributes #0 = { {{.*}}"instrument-function-entry-inlined"="__cyg_profile_func_enter_bare" +// BARE-NOT: attributes #0 = { {{.*}}"__cyg_profile_func_enter" +// BARE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter_bare" @end diff --git a/clang/test/CodeGen/mcount-aix.c b/clang/test/CodeGen/mcount-aix.c index b6a15336578db..275af35bcce20 100644 --- a/clang/test/CodeGen/mcount-aix.c +++ b/clang/test/CodeGen/mcount-aix.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -pg -triple powerpc-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s // RUN: %clang_cc1 -disable-llvm-passes -pg -triple powerpc64-ibm-aix7.2.0.0 -emit-llvm %s -o - | FileCheck %s void foo() { >From 27359fec6a5128de7d710d3f2865562bad82db45 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Mon, 27 May 2024 15:07:21 +0200 Subject: [PATCH 13/16] Move EntryExitInstrumenterPass to EarlyFPM --- llvm/lib/Passes/PassBuilderPipelines.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 3a7634f90c078..cae340a19fb60 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -397,11 +397,6 @@ static bool isLTOPreLink(ThinOrFullLTOPhase Phase) { Phase == ThinOrFullLTOPhase::FullLTOPreLink; } -static bool isLTOPostLink(ThinOrFullLTOPhase Phase) { - return Phase == ThinOrFullLTOPhase::ThinLTOPostLink || - Phase == ThinOrFullLTOPhase::FullLTOPostLink; -} - // TODO: Investigate the cost/benefit of tail call elimination on debugging. FunctionPassManager PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level, @@ -1039,12 +1034,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, Phase != ThinOrFullLTOPhase::ThinLTOPostLink) MPM.addPass(SampleProfileProbePass(TM)); - // Instrument function entry and exit before all inlining. - if (!isLTOPostLink(Phase)) { - MPM.addPass(createModuleToFunctionPassAdaptor( - EntryExitInstrumenterPass(/*PostInlining=*/false))); - } - bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse); // In ThinLTO mode, when flattened profile is used, all the available @@ -1081,6 +1070,9 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(CoroEarlyPass()); FunctionPassManager EarlyFPM; + if (Phase != ThinOrFullLTOPhase::FullLTOPostLink) { + EarlyFPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false)); + } // Lower llvm.expect to metadata before attempting transforms. // Compare/branch metadata may alter the behavior of passes like // SimplifyCFG. >From bee1fb21515ff07ef70a0cd7ba197facbcd28296 Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Wed, 29 May 2024 22:37:06 +0200 Subject: [PATCH 14/16] remove unnecessary condition --- llvm/lib/Passes/PassBuilderPipelines.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index cae340a19fb60..926515c9508a9 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1070,9 +1070,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, MPM.addPass(CoroEarlyPass()); FunctionPassManager EarlyFPM; - if (Phase != ThinOrFullLTOPhase::FullLTOPostLink) { - EarlyFPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false)); - } + EarlyFPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false)); // Lower llvm.expect to metadata before attempting transforms. // Compare/branch metadata may alter the behavior of passes like // SimplifyCFG. >From e3f20979144c869a30c64784fc8adf82979b976c Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 30 May 2024 15:49:36 +0200 Subject: [PATCH 15/16] Adjust passes in tests --- llvm/test/Other/new-pm-defaults.ll | 4 ++-- llvm/test/Other/new-pm-thinlto-prelink-defaults.ll | 4 ++-- llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll | 4 ++-- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll index 6f3ea4fd74ddb..489aed40c190b 100644 --- a/llvm/test/Other/new-pm-defaults.ll +++ b/llvm/test/Other/new-pm-defaults.ll @@ -97,11 +97,11 @@ ; CHECK-O: Running pass: Annotation2Metadata ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass -; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy -; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass +; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis diff --git a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll index 2f6881b93c062..42ef49f8f7c7e 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-defaults.ll @@ -66,11 +66,11 @@ ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass ; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass -; CHECK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy -; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass +; CHECK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis diff --git a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll index 6f4338809553b..e74f88c1a3bf9 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll @@ -30,11 +30,11 @@ ; CHECK-O: Running pass: Annotation2Metadata ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass -; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy -; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass +; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis diff --git a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll index a8db1682437a4..210a4ef1f7664 100644 --- a/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll @@ -30,10 +30,10 @@ ; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-O-NEXT: Running pass: AddDiscriminatorsPass ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass -; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis ; CHECK-O-NEXT: Running pass: CoroEarlyPass +; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass ; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis >From 3579930d3977ef0896eb3767293e652683a2510c Mon Sep 17 00:00:00 2001 From: Egor Pasko <pa...@chromium.org> Date: Thu, 30 May 2024 16:32:26 +0200 Subject: [PATCH 16/16] Whitespace beautify --- llvm/test/CodeGen/X86/instrument-function-inlined.ll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/test/CodeGen/X86/instrument-function-inlined.ll b/llvm/test/CodeGen/X86/instrument-function-inlined.ll index 3ef73bc65add1..5255639a511b0 100644 --- a/llvm/test/CodeGen/X86/instrument-function-inlined.ll +++ b/llvm/test/CodeGen/X86/instrument-function-inlined.ll @@ -10,7 +10,7 @@ define void @leaf_function() #0 { ; CHECK-LABEL: leaf_function: ; CHECK: callq __cyg_profile_func_enter_bare -; CHECK: callq __cyg_profile_func_exit +; CHECK: callq __cyg_profile_func_exit ret void } @@ -19,7 +19,7 @@ entry: ; CHECK-LABEL: root_function: ; CHECK: callq __cyg_profile_func_enter_bare ; CHECK-NEXT: callq leaf_function -; CHECK: callq __cyg_profile_func_exit +; CHECK: callq __cyg_profile_func_exit call void @leaf_function() ret void } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits