Skip to content

Commit 3630d9e

Browse files
authored
[PartiallyInlineLibCalls] Add infrastructure for emitting optimization remarks from PartiallyInlineLibCalls (llvm#122654)
I am planning to add some optimization remarks to the `PartiallyInlineLibCalls` pass. However, since this pass does not emit any optimization remarks yet, I have to add the "infrastructure" for that first, which is what this PR is about.
1 parent 6aeffcd commit 3630d9e

File tree

8 files changed

+42
-5
lines changed

8 files changed

+42
-5
lines changed

llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
1616
#include "llvm/Analysis/DomTreeUpdater.h"
17+
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
1718
#include "llvm/Analysis/TargetLibraryInfo.h"
1819
#include "llvm/Analysis/TargetTransformInfo.h"
1920
#include "llvm/IR/Dominators.h"
@@ -33,7 +34,8 @@ DEBUG_COUNTER(PILCounter, "partially-inline-libcalls-transform",
3334

3435
static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
3536
BasicBlock &CurrBB, Function::iterator &BB,
36-
const TargetTransformInfo *TTI, DomTreeUpdater *DTU) {
37+
const TargetTransformInfo *TTI, DomTreeUpdater *DTU,
38+
OptimizationRemarkEmitter *ORE) {
3739
// There is no need to change the IR, since backend will emit sqrt
3840
// instruction if the call has already been marked read-only.
3941
if (Call->onlyReadsMemory())
@@ -103,7 +105,8 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
103105

104106
static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
105107
const TargetTransformInfo *TTI,
106-
DominatorTree *DT) {
108+
DominatorTree *DT,
109+
OptimizationRemarkEmitter *ORE) {
107110
std::optional<DomTreeUpdater> DTU;
108111
if (DT)
109112
DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
@@ -140,7 +143,7 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
140143
case LibFunc_sqrt:
141144
if (TTI->haveFastSqrt(Call->getType()) &&
142145
optimizeSQRT(Call, CalledFunc, *CurrBB, BB, TTI,
143-
DTU ? &*DTU : nullptr))
146+
DTU ? &*DTU : nullptr, ORE))
144147
break;
145148
continue;
146149
default:
@@ -160,7 +163,8 @@ PartiallyInlineLibCallsPass::run(Function &F, FunctionAnalysisManager &AM) {
160163
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
161164
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
162165
auto *DT = AM.getCachedResult<DominatorTreeAnalysis>(F);
163-
if (!runPartiallyInlineLibCalls(F, &TLI, &TTI, DT))
166+
auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
167+
if (!runPartiallyInlineLibCalls(F, &TLI, &TTI, DT, &ORE))
164168
return PreservedAnalyses::all();
165169
PreservedAnalyses PA;
166170
PA.preserve<DominatorTreeAnalysis>();
@@ -181,6 +185,7 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
181185
AU.addRequired<TargetLibraryInfoWrapperPass>();
182186
AU.addRequired<TargetTransformInfoWrapperPass>();
183187
AU.addPreserved<DominatorTreeWrapperPass>();
188+
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
184189
FunctionPass::getAnalysisUsage(AU);
185190
}
186191

@@ -195,7 +200,8 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
195200
DominatorTree *DT = nullptr;
196201
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
197202
DT = &DTWP->getDomTree();
198-
return runPartiallyInlineLibCalls(F, TLI, TTI, DT);
203+
auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
204+
return runPartiallyInlineLibCalls(F, TLI, TTI, DT, ORE);
199205
}
200206
};
201207
}
@@ -208,6 +214,7 @@ INITIALIZE_PASS_BEGIN(PartiallyInlineLibCallsLegacyPass,
208214
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
209215
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
210216
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
217+
INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
211218
INITIALIZE_PASS_END(PartiallyInlineLibCallsLegacyPass,
212219
"partially-inline-libcalls",
213220
"Partially inline calls to library functions", false, false)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
; CHECK-NEXT: Block Frequency Analysis
6060
; CHECK-NEXT: Constant Hoisting
6161
; CHECK-NEXT: Replace intrinsics with calls to vector library
62+
; CHECK-NEXT: Lazy Branch Probability Analysis
63+
; CHECK-NEXT: Lazy Block Frequency Analysis
64+
; CHECK-NEXT: Optimization Remark Emitter
6265
; CHECK-NEXT: Partially inline calls to library functions
6366
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6467
; CHECK-NEXT: Scalarize Masked Memory Intrinsics

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@
224224
; GCN-O1-NEXT: Block Frequency Analysis
225225
; GCN-O1-NEXT: Constant Hoisting
226226
; GCN-O1-NEXT: Replace intrinsics with calls to vector library
227+
; GCN-O1-NEXT: Lazy Branch Probability Analysis
228+
; GCN-O1-NEXT: Lazy Block Frequency Analysis
229+
; GCN-O1-NEXT: Optimization Remark Emitter
227230
; GCN-O1-NEXT: Partially inline calls to library functions
228231
; GCN-O1-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
229232
; GCN-O1-NEXT: Scalarize Masked Memory Intrinsics
@@ -518,6 +521,9 @@
518521
; GCN-O1-OPTS-NEXT: Block Frequency Analysis
519522
; GCN-O1-OPTS-NEXT: Constant Hoisting
520523
; GCN-O1-OPTS-NEXT: Replace intrinsics with calls to vector library
524+
; GCN-O1-OPTS-NEXT: Lazy Branch Probability Analysis
525+
; GCN-O1-OPTS-NEXT: Lazy Block Frequency Analysis
526+
; GCN-O1-OPTS-NEXT: Optimization Remark Emitter
521527
; GCN-O1-OPTS-NEXT: Partially inline calls to library functions
522528
; GCN-O1-OPTS-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
523529
; GCN-O1-OPTS-NEXT: Scalarize Masked Memory Intrinsics
@@ -831,6 +837,9 @@
831837
; GCN-O2-NEXT: Block Frequency Analysis
832838
; GCN-O2-NEXT: Constant Hoisting
833839
; GCN-O2-NEXT: Replace intrinsics with calls to vector library
840+
; GCN-O2-NEXT: Lazy Branch Probability Analysis
841+
; GCN-O2-NEXT: Lazy Block Frequency Analysis
842+
; GCN-O2-NEXT: Optimization Remark Emitter
834843
; GCN-O2-NEXT: Partially inline calls to library functions
835844
; GCN-O2-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
836845
; GCN-O2-NEXT: Scalarize Masked Memory Intrinsics
@@ -1152,6 +1161,9 @@
11521161
; GCN-O3-NEXT: Block Frequency Analysis
11531162
; GCN-O3-NEXT: Constant Hoisting
11541163
; GCN-O3-NEXT: Replace intrinsics with calls to vector library
1164+
; GCN-O3-NEXT: Lazy Branch Probability Analysis
1165+
; GCN-O3-NEXT: Lazy Block Frequency Analysis
1166+
; GCN-O3-NEXT: Optimization Remark Emitter
11551167
; GCN-O3-NEXT: Partially inline calls to library functions
11561168
; GCN-O3-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
11571169
; GCN-O3-NEXT: Scalarize Masked Memory Intrinsics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
; CHECK-NEXT: Block Frequency Analysis
3838
; CHECK-NEXT: Constant Hoisting
3939
; CHECK-NEXT: Replace intrinsics with calls to vector library
40+
; CHECK-NEXT: Lazy Branch Probability Analysis
41+
; CHECK-NEXT: Lazy Block Frequency Analysis
42+
; CHECK-NEXT: Optimization Remark Emitter
4043
; CHECK-NEXT: Partially inline calls to library functions
4144
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
4245
; CHECK-NEXT: Scalarize Masked Memory Intrinsics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
; LAXX-NEXT: Block Frequency Analysis
6161
; LAXX-NEXT: Constant Hoisting
6262
; LAXX-NEXT: Replace intrinsics with calls to vector library
63+
; LAXX-NEXT: Lazy Branch Probability Analysis
64+
; LAXX-NEXT: Lazy Block Frequency Analysis
65+
; LAXX-NEXT: Optimization Remark Emitter
6366
; LAXX-NEXT: Partially inline calls to library functions
6467
; LAXX-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6568
; LAXX-NEXT: Scalarize Masked Memory Intrinsics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
; CHECK-NEXT: Block Frequency Analysis
6262
; CHECK-NEXT: Constant Hoisting
6363
; CHECK-NEXT: Replace intrinsics with calls to vector library
64+
; CHECK-NEXT: Lazy Branch Probability Analysis
65+
; CHECK-NEXT: Lazy Block Frequency Analysis
66+
; CHECK-NEXT: Optimization Remark Emitter
6467
; CHECK-NEXT: Partially inline calls to library functions
6568
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6669
; CHECK-NEXT: Scalarize Masked Memory Intrinsics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
; CHECK-NEXT: Block Frequency Analysis
6464
; CHECK-NEXT: Constant Hoisting
6565
; CHECK-NEXT: Replace intrinsics with calls to vector library
66+
; CHECK-NEXT: Lazy Branch Probability Analysis
67+
; CHECK-NEXT: Lazy Block Frequency Analysis
68+
; CHECK-NEXT: Optimization Remark Emitter
6669
; CHECK-NEXT: Partially inline calls to library functions
6770
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6871
; CHECK-NEXT: Scalarize Masked Memory Intrinsics

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
; CHECK-NEXT: Block Frequency Analysis
5959
; CHECK-NEXT: Constant Hoisting
6060
; CHECK-NEXT: Replace intrinsics with calls to vector library
61+
; CHECK-NEXT: Lazy Branch Probability Analysis
62+
; CHECK-NEXT: Lazy Block Frequency Analysis
63+
; CHECK-NEXT: Optimization Remark Emitter
6164
; CHECK-NEXT: Partially inline calls to library functions
6265
; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (post inlining)
6366
; CHECK-NEXT: Scalarize Masked Memory Intrinsics

0 commit comments

Comments
 (0)