2222#include " llvm/Support/DebugCounter.h"
2323#include " llvm/Transforms/Scalar.h"
2424#include " llvm/Transforms/Utils/BasicBlockUtils.h"
25+ #include " llvm/Analysis/OptimizationRemarkEmitter.h"
2526#include < optional>
2627
2728using namespace llvm ;
@@ -33,7 +34,8 @@ DEBUG_COUNTER(PILCounter, "partially-inline-libcalls-transform",
3334
3435static 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
104106static 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}
0 commit comments