Skip to content

Commit 5d46226

Browse files
committed
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
1 parent c3d3637 commit 5d46226

16 files changed

+78
-7
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,10 +2058,8 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
20582058
PGOOpt->ProfileRemappingFile, PGOOpt->FS);
20592059

20602060
// Instrument function entry and exit before all inlining.
2061-
if (LTOPreLink) {
2062-
MPM.addPass(createModuleToFunctionPassAdaptor(
2063-
EntryExitInstrumenterPass(/*PostInlining=*/false)));
2064-
}
2061+
MPM.addPass(createModuleToFunctionPassAdaptor(
2062+
EntryExitInstrumenterPass(/*PostInlining=*/false)));
20652063

20662064
invokePipelineStartEPCallbacks(MPM, Level);
20672065

llvm/test/CodeGen/AArch64/O0-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
; CHECK-NEXT: Lower constant intrinsics
2525
; CHECK-NEXT: Remove unreachable blocks from the CFG
2626
; CHECK-NEXT: Expand vector predication intrinsics
27+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
2728
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
2829
; CHECK-NEXT: Expand reduction intrinsics
2930
; CHECK-NEXT: AArch64 Globals Tagging

llvm/test/CodeGen/AArch64/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
; CHECK-NEXT: Replace intrinsics with calls to vector library
6363
; CHECK-NEXT: Partially inline calls to library functions
6464
; CHECK-NEXT: Expand vector predication intrinsics
65+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6566
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
6667
; CHECK-NEXT: Expand reduction intrinsics
6768
; CHECK-NEXT: Natural Loop Information

llvm/test/CodeGen/ARM/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
; CHECK-NEXT: Replace intrinsics with calls to vector library
4141
; CHECK-NEXT: Partially inline calls to library functions
4242
; CHECK-NEXT: Expand vector predication intrinsics
43+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
4344
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
4445
; CHECK-NEXT: Expand reduction intrinsics
4546
; CHECK-NEXT: Natural Loop Information

llvm/test/CodeGen/LoongArch/O0-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
; CHECK-NEXT: Lower constant intrinsics
2929
; CHECK-NEXT: Remove unreachable blocks from the CFG
3030
; CHECK-NEXT: Expand vector predication intrinsics
31+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
3132
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
3233
; CHECK-NEXT: Expand reduction intrinsics
3334
; CHECK-NEXT: Exception handling preparation

llvm/test/CodeGen/LoongArch/opt-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
; CHECK-NEXT: Replace intrinsics with calls to vector library
6464
; CHECK-NEXT: Partially inline calls to library functions
6565
; CHECK-NEXT: Expand vector predication intrinsics
66+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6667
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
6768
; CHECK-NEXT: Expand reduction intrinsics
6869
; CHECK-NEXT: Natural Loop Information

llvm/test/CodeGen/PowerPC/O0-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
; CHECK-NEXT: Lower constant intrinsics
2828
; CHECK-NEXT: Remove unreachable blocks from the CFG
2929
; CHECK-NEXT: Expand vector predication intrinsics
30+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
3031
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
3132
; CHECK-NEXT: Expand reduction intrinsics
3233
; CHECK-NEXT: Exception handling preparation

llvm/test/CodeGen/PowerPC/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
; CHECK-NEXT: Replace intrinsics with calls to vector library
6565
; CHECK-NEXT: Partially inline calls to library functions
6666
; CHECK-NEXT: Expand vector predication intrinsics
67+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6768
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
6869
; CHECK-NEXT: Expand reduction intrinsics
6970
; CHECK-NEXT: Natural Loop Information

llvm/test/CodeGen/RISCV/O0-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
; CHECK-NEXT: Lower constant intrinsics
2929
; CHECK-NEXT: Remove unreachable blocks from the CFG
3030
; CHECK-NEXT: Expand vector predication intrinsics
31+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
3132
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
3233
; CHECK-NEXT: Expand reduction intrinsics
3334
; CHECK-NEXT: Exception handling preparation

llvm/test/CodeGen/RISCV/O3-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
; CHECK-NEXT: Replace intrinsics with calls to vector library
6565
; CHECK-NEXT: Partially inline calls to library functions
6666
; CHECK-NEXT: Expand vector predication intrinsics
67+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6768
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
6869
; CHECK-NEXT: Expand reduction intrinsics
6970
; CHECK-NEXT: Natural Loop Information

llvm/test/CodeGen/X86/O0-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
; CHECK-NEXT: Lower constant intrinsics
2929
; CHECK-NEXT: Remove unreachable blocks from the CFG
3030
; CHECK-NEXT: Expand vector predication intrinsics
31+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
3132
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
3233
; CHECK-NEXT: Expand reduction intrinsics
3334
; CHECK-NEXT: Expand indirectbr instructions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc -mtriple=x86_64-- -O0 < %s | FileCheck %s
2+
; RUN: llc -mtriple=x86_64-- -O1 < %s | FileCheck %s
3+
; RUN: llc -mtriple=x86_64-- -O2 < %s | FileCheck %s
4+
5+
; The codegen should insert post-inlining instrumentation calls and should not
6+
; insert pre-inlining instrumentation.
7+
8+
; CHECK-NOT: callq __cyg_profile_func_enter
9+
10+
define void @leaf_function() #0 {
11+
; CHECK-LABEL: leaf_function:
12+
; CHECK: callq __cyg_profile_func_enter_bare
13+
; CHECK: movq leaf_function@GOTPCREL(%rip), %rdi
14+
; CHECK-NEXT: callq __cyg_profile_func_exit
15+
ret void
16+
}
17+
18+
define void @root_function() #0 {
19+
entry:
20+
; CHECK-LABEL: root_function:
21+
; CHECK: callq __cyg_profile_func_enter_bare
22+
; CHECK-NEXT: callq leaf_function
23+
; CHECK: movq root_function@GOTPCREL(%rip), %rdi
24+
; CHECK-NEXT: callq __cyg_profile_func_exit
25+
call void @leaf_function()
26+
ret void
27+
}
28+
29+
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" }

llvm/test/CodeGen/X86/opt-pipeline.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
; CHECK-NEXT: Replace intrinsics with calls to vector library
6262
; CHECK-NEXT: Partially inline calls to library functions
6363
; CHECK-NEXT: Expand vector predication intrinsics
64+
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6465
; CHECK-NEXT: Scalarize Masked Memory Intrinsics
6566
; CHECK-NEXT: Expand reduction intrinsics
6667
; CHECK-NEXT: Natural Loop Information

llvm/test/Other/new-pm-O0-defaults.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass
3434
; CHECK-DIS-NEXT: Running pass: AlwaysInlinerPass
3535
; CHECK-DIS-NEXT: Running analysis: ProfileSummaryAnalysis
36-
; CHECK-DEFAULT: Running pass: AlwaysInlinerPass
37-
; CHECK-DEFAULT-NEXT: Running analysis: InnerAnalysisManagerProxy
36+
; CHECK-DEFAULT: Running analysis: InnerAnalysisManagerProxy
37+
; CHECK-PRE-LINK: Running pass: EntryExitInstrumenterPass
38+
; CHECK-PRE-LINK-NEXT: Running pass: AlwaysInlinerPass
3839
; CHECK-DEFAULT-NEXT: Running analysis: ProfileSummaryAnalysis
3940
; CHECK-MATRIX: Running pass: LowerMatrixIntrinsicsPass
4041
; CHECK-MATRIX-NEXT: Running analysis: TargetIRAnalysis

llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
; CHECK-O: Running pass: Annotation2Metadata
3131
; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
3232
; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
33-
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3433
; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
34+
; CHECK-O-NEXT: Running pass: EntryExitInstrumenterPass
35+
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3536
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
3637
; CHECK-O-NEXT: Running pass: CoroEarlyPass
3738
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: opt -passes="default<O1>" -S < %s | FileCheck %s
2+
; RUN: opt -passes="thinlto-pre-link<O2>" -S < %s | FileCheck %s
3+
; RUN: opt -passes="thinlto-pre-link<O2>,thinlto<O3>" -S < %s | FileCheck %s
4+
5+
target triple = "x86_64-unknown-linux"
6+
7+
define void @leaf_function() #0 {
8+
entry:
9+
ret void
10+
; CHECK-LABEL: entry:
11+
; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0)
12+
; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0)
13+
; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0)
14+
; CHECK-NEXT: ret void
15+
}
16+
17+
18+
define void @root_function() #0 {
19+
entry:
20+
call void @leaf_function()
21+
ret void
22+
; CHECK-LABEL: entry:
23+
; CHECK-NEXT: %0 = tail call ptr @llvm.returnaddress(i32 0)
24+
; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @root_function, ptr %0)
25+
; CHECK-NEXT: tail call void @__cyg_profile_func_enter(ptr nonnull @leaf_function, ptr %0)
26+
; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @leaf_function, ptr %0)
27+
; CHECK-NEXT: tail call void @__cyg_profile_func_exit(ptr nonnull @root_function, ptr %0)
28+
; CHECK-NEXT: ret void
29+
}
30+
31+
attributes #0 = { "instrument-function-entry"="__cyg_profile_func_enter" "instrument-function-exit"="__cyg_profile_func_exit" }

0 commit comments

Comments
 (0)