14
14
15
15
#include " llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
16
16
#include " llvm/Analysis/DomTreeUpdater.h"
17
+ #include " llvm/Analysis/OptimizationRemarkEmitter.h"
17
18
#include " llvm/Analysis/TargetLibraryInfo.h"
18
19
#include " llvm/Analysis/TargetTransformInfo.h"
19
20
#include " llvm/IR/Dominators.h"
@@ -33,7 +34,8 @@ DEBUG_COUNTER(PILCounter, "partially-inline-libcalls-transform",
33
34
34
35
static bool optimizeSQRT (CallInst *Call, Function *CalledFunc,
35
36
BasicBlock &CurrBB, Function::iterator &BB,
36
- const TargetTransformInfo *TTI, DomTreeUpdater *DTU) {
37
+ const TargetTransformInfo *TTI, DomTreeUpdater *DTU,
38
+ OptimizationRemarkEmitter *ORE) {
37
39
// There is no need to change the IR, since backend will emit sqrt
38
40
// instruction if the call has already been marked read-only.
39
41
if (Call->onlyReadsMemory ())
@@ -103,7 +105,8 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
103
105
104
106
static bool runPartiallyInlineLibCalls (Function &F, TargetLibraryInfo *TLI,
105
107
const TargetTransformInfo *TTI,
106
- DominatorTree *DT) {
108
+ DominatorTree *DT,
109
+ OptimizationRemarkEmitter *ORE) {
107
110
std::optional<DomTreeUpdater> DTU;
108
111
if (DT)
109
112
DTU.emplace (DT, DomTreeUpdater::UpdateStrategy::Lazy);
@@ -140,7 +143,7 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
140
143
case LibFunc_sqrt:
141
144
if (TTI->haveFastSqrt (Call->getType ()) &&
142
145
optimizeSQRT (Call, CalledFunc, *CurrBB, BB, TTI,
143
- DTU ? &*DTU : nullptr ))
146
+ DTU ? &*DTU : nullptr , ORE ))
144
147
break ;
145
148
continue ;
146
149
default :
@@ -160,7 +163,8 @@ PartiallyInlineLibCallsPass::run(Function &F, FunctionAnalysisManager &AM) {
160
163
auto &TLI = AM.getResult <TargetLibraryAnalysis>(F);
161
164
auto &TTI = AM.getResult <TargetIRAnalysis>(F);
162
165
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))
164
168
return PreservedAnalyses::all ();
165
169
PreservedAnalyses PA;
166
170
PA.preserve <DominatorTreeAnalysis>();
@@ -181,6 +185,7 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
181
185
AU.addRequired <TargetLibraryInfoWrapperPass>();
182
186
AU.addRequired <TargetTransformInfoWrapperPass>();
183
187
AU.addPreserved <DominatorTreeWrapperPass>();
188
+ AU.addRequired <OptimizationRemarkEmitterWrapperPass>();
184
189
FunctionPass::getAnalysisUsage (AU);
185
190
}
186
191
@@ -195,7 +200,8 @@ class PartiallyInlineLibCallsLegacyPass : public FunctionPass {
195
200
DominatorTree *DT = nullptr ;
196
201
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
197
202
DT = &DTWP->getDomTree ();
198
- return runPartiallyInlineLibCalls (F, TLI, TTI, DT);
203
+ auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE ();
204
+ return runPartiallyInlineLibCalls (F, TLI, TTI, DT, ORE);
199
205
}
200
206
};
201
207
}
@@ -208,6 +214,7 @@ INITIALIZE_PASS_BEGIN(PartiallyInlineLibCallsLegacyPass,
208
214
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
209
215
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
210
216
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
217
+ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
211
218
INITIALIZE_PASS_END(PartiallyInlineLibCallsLegacyPass,
212
219
" partially-inline-libcalls" ,
213
220
" Partially inline calls to library functions" , false , false )
0 commit comments