Skip to content

Commit 4aae4e3

Browse files
Mircea Trofinmtrofin
authored andcommitted
[llvm][NFC] CallSite removal from inliner-related files
Summary: This removes CallSite from inliner files. Some dependencies where thus affected. Reviewers: dblaikie, davidxl, craig.topper Subscribers: arsenm, jvesely, nhaehnle, eraman, hiraditya, aheejin, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77991
1 parent 0a54887 commit 4aae4e3

File tree

11 files changed

+205
-243
lines changed

11 files changed

+205
-243
lines changed

llvm/include/llvm/Transforms/IPO/Inliner.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "llvm/Analysis/CallGraphSCCPass.h"
1414
#include "llvm/Analysis/InlineCost.h"
1515
#include "llvm/Analysis/LazyCallGraph.h"
16-
#include "llvm/IR/CallSite.h"
1716
#include "llvm/IR/PassManager.h"
1817
#include "llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h"
1918
#include <utility>
@@ -51,15 +50,7 @@ struct LegacyInlinerBase : public CallGraphSCCPass {
5150
/// This method must be implemented by the subclass to determine the cost of
5251
/// inlining the specified call site. If the cost returned is greater than
5352
/// the current inline threshold, the call site is not inlined.
54-
// FIXME(mtrofin): remove this in favor of the CallBase-based one
55-
virtual InlineCost getInlineCost(CallSite CS) = 0;
56-
57-
/// This method must be implemented by the subclass to determine the cost of
58-
/// inlining the specified call site. If the cost returned is greater than
59-
/// the current inline threshold, the call site is not inlined.
60-
virtual InlineCost getInlineCost(CallBase &CB) {
61-
return getInlineCost(CallSite(&CB));
62-
}
53+
virtual InlineCost getInlineCost(CallBase &CB) = 0;
6354

6455
/// Remove dead functions.
6556
///

llvm/include/llvm/Transforms/Utils/Cloning.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ class InlineFunctionInfo {
228228
/// and all varargs at the callsite will be passed to any calls to
229229
/// ForwardVarArgsTo. The caller of InlineFunction has to make sure any varargs
230230
/// are only used by ForwardVarArgsTo.
231-
InlineResult InlineFunction(CallBase *CB, InlineFunctionInfo &IFI,
232-
AAResults *CalleeAAR = nullptr,
233-
bool InsertLifetime = true);
234-
InlineResult InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
231+
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
235232
AAResults *CalleeAAR = nullptr,
236233
bool InsertLifetime = true,
237234
Function *ForwardVarArgsTo = nullptr);

llvm/lib/CodeGen/SafeStack.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3434
#include "llvm/IR/Argument.h"
3535
#include "llvm/IR/Attributes.h"
36-
#include "llvm/IR/CallSite.h"
3736
#include "llvm/IR/ConstantRange.h"
3837
#include "llvm/IR/Constants.h"
3938
#include "llvm/IR/DIBuilder.h"
@@ -200,7 +199,7 @@ class SafeStack {
200199
bool IsAccessSafe(Value *Addr, uint64_t Size, const Value *AllocaPtr,
201200
uint64_t AllocaSize);
202201

203-
bool ShouldInlinePointerAddress(CallSite &CS);
202+
bool ShouldInlinePointerAddress(CallInst &CI);
204203
void TryInlinePointerAddress();
205204

206205
public:
@@ -322,7 +321,7 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
322321

323322
case Instruction::Call:
324323
case Instruction::Invoke: {
325-
ImmutableCallSite CS(I);
324+
const CallBase &CS = *cast<CallBase>(I);
326325

327326
if (I->isLifetimeStartOrEnd())
328327
continue;
@@ -344,8 +343,8 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
344343
// FIXME: a more precise solution would require an interprocedural
345344
// analysis here, which would look at all uses of an argument inside
346345
// the function being called.
347-
ImmutableCallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end();
348-
for (ImmutableCallSite::arg_iterator A = B; A != E; ++A)
346+
auto B = CS.arg_begin(), E = CS.arg_end();
347+
for (auto A = B; A != E; ++A)
349348
if (A->get() == V)
350349
if (!(CS.doesNotCapture(A - B) && (CS.doesNotAccessMemory(A - B) ||
351350
CS.doesNotAccessMemory()))) {
@@ -705,34 +704,34 @@ void SafeStack::moveDynamicAllocasToUnsafeStack(
705704
}
706705
}
707706

708-
bool SafeStack::ShouldInlinePointerAddress(CallSite &CS) {
709-
Function *Callee = CS.getCalledFunction();
710-
if (CS.hasFnAttr(Attribute::AlwaysInline) &&
707+
bool SafeStack::ShouldInlinePointerAddress(CallInst &CI) {
708+
Function *Callee = CI.getCalledFunction();
709+
if (CI.hasFnAttr(Attribute::AlwaysInline) &&
711710
isInlineViable(*Callee).isSuccess())
712711
return true;
713712
if (Callee->isInterposable() || Callee->hasFnAttribute(Attribute::NoInline) ||
714-
CS.isNoInline())
713+
CI.isNoInline())
715714
return false;
716715
return true;
717716
}
718717

719718
void SafeStack::TryInlinePointerAddress() {
720-
if (!isa<CallInst>(UnsafeStackPtr))
719+
auto *CI = dyn_cast<CallInst>(UnsafeStackPtr);
720+
if (!CI)
721721
return;
722722

723723
if(F.hasOptNone())
724724
return;
725725

726-
CallSite CS(UnsafeStackPtr);
727-
Function *Callee = CS.getCalledFunction();
726+
Function *Callee = CI->getCalledFunction();
728727
if (!Callee || Callee->isDeclaration())
729728
return;
730729

731-
if (!ShouldInlinePointerAddress(CS))
730+
if (!ShouldInlinePointerAddress(*CI))
732731
return;
733732

734733
InlineFunctionInfo IFI;
735-
InlineFunction(CS, IFI);
734+
InlineFunction(*CI, IFI);
736735
}
737736

738737
bool SafeStack::run() {

llvm/lib/Target/AMDGPU/AMDGPUInline.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "llvm/Analysis/InlineCost.h"
2424
#include "llvm/Analysis/TargetTransformInfo.h"
2525
#include "llvm/Analysis/ValueTracking.h"
26-
#include "llvm/IR/CallSite.h"
2726
#include "llvm/IR/DataLayout.h"
2827
#include "llvm/IR/Instructions.h"
2928
#include "llvm/IR/Module.h"
@@ -67,9 +66,9 @@ class AMDGPUInliner : public LegacyInlinerBase {
6766

6867
static char ID; // Pass identification, replacement for typeid
6968

70-
unsigned getInlineThreshold(CallSite CS) const;
69+
unsigned getInlineThreshold(CallBase &CB) const;
7170

72-
InlineCost getInlineCost(CallSite CS) override;
71+
InlineCost getInlineCost(CallBase &CB) override;
7372

7473
bool runOnSCC(CallGraphSCC &SCC) override;
7574

@@ -106,13 +105,13 @@ void AMDGPUInliner::getAnalysisUsage(AnalysisUsage &AU) const {
106105
LegacyInlinerBase::getAnalysisUsage(AU);
107106
}
108107

109-
unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {
108+
unsigned AMDGPUInliner::getInlineThreshold(CallBase &CB) const {
110109
int Thres = Params.DefaultThreshold;
111110

112-
Function *Caller = CS.getCaller();
111+
Function *Caller = CB.getCaller();
113112
// Listen to the inlinehint attribute when it would increase the threshold
114113
// and the caller does not need to minimize its size.
115-
Function *Callee = CS.getCalledFunction();
114+
Function *Callee = CB.getCalledFunction();
116115
bool InlineHint = Callee && !Callee->isDeclaration() &&
117116
Callee->hasFnAttribute(Attribute::InlineHint);
118117
if (InlineHint && Params.HintThreshold && Params.HintThreshold > Thres
@@ -129,7 +128,7 @@ unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {
129128
// Increase the inline threshold to allow inliniting in this case.
130129
uint64_t AllocaSize = 0;
131130
SmallPtrSet<const AllocaInst *, 8> AIVisited;
132-
for (Value *PtrArg : CS.args()) {
131+
for (Value *PtrArg : CB.args()) {
133132
PointerType *Ty = dyn_cast<PointerType>(PtrArg->getType());
134133
if (!Ty || (Ty->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS &&
135134
Ty->getAddressSpace() != AMDGPUAS::FLAT_ADDRESS))
@@ -156,8 +155,8 @@ unsigned AMDGPUInliner::getInlineThreshold(CallSite CS) const {
156155

157156
// Check if call is just a wrapper around another call.
158157
// In this case we only have call and ret instructions.
159-
static bool isWrapperOnlyCall(CallSite CS) {
160-
Function *Callee = CS.getCalledFunction();
158+
static bool isWrapperOnlyCall(CallBase &CB) {
159+
Function *Callee = CB.getCalledFunction();
161160
if (!Callee || Callee->size() != 1)
162161
return false;
163162
const BasicBlock &BB = Callee->getEntryBlock();
@@ -174,32 +173,32 @@ static bool isWrapperOnlyCall(CallSite CS) {
174173
return false;
175174
}
176175

177-
InlineCost AMDGPUInliner::getInlineCost(CallSite CS) {
178-
Function *Callee = CS.getCalledFunction();
179-
Function *Caller = CS.getCaller();
176+
InlineCost AMDGPUInliner::getInlineCost(CallBase &CB) {
177+
Function *Callee = CB.getCalledFunction();
178+
Function *Caller = CB.getCaller();
180179

181180
if (!Callee || Callee->isDeclaration())
182181
return llvm::InlineCost::getNever("undefined callee");
183182

184-
if (CS.isNoInline())
183+
if (CB.isNoInline())
185184
return llvm::InlineCost::getNever("noinline");
186185

187186
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
188187
if (!TTI.areInlineCompatible(Caller, Callee))
189188
return llvm::InlineCost::getNever("incompatible");
190189

191-
if (CS.hasFnAttr(Attribute::AlwaysInline)) {
190+
if (CB.hasFnAttr(Attribute::AlwaysInline)) {
192191
auto IsViable = isInlineViable(*Callee);
193192
if (IsViable.isSuccess())
194193
return llvm::InlineCost::getAlways("alwaysinline viable");
195194
return llvm::InlineCost::getNever(IsViable.getFailureReason());
196195
}
197196

198-
if (isWrapperOnlyCall(CS))
197+
if (isWrapperOnlyCall(CB))
199198
return llvm::InlineCost::getAlways("wrapper-only call");
200199

201200
InlineParams LocalParams = Params;
202-
LocalParams.DefaultThreshold = (int)getInlineThreshold(CS);
201+
LocalParams.DefaultThreshold = (int)getInlineThreshold(CB);
203202
bool RemarksEnabled = false;
204203
const auto &BBs = Caller->getBasicBlockList();
205204
if (!BBs.empty()) {
@@ -214,9 +213,9 @@ InlineCost AMDGPUInliner::getInlineCost(CallSite CS) {
214213
return ACT->getAssumptionCache(F);
215214
};
216215

217-
auto IC = llvm::getInlineCost(cast<CallBase>(*CS.getInstruction()), Callee,
218-
LocalParams, TTI, GetAssumptionCache, None,
219-
GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
216+
auto IC =
217+
llvm::getInlineCost(CB, Callee, LocalParams, TTI, GetAssumptionCache,
218+
None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
220219

221220
if (IC && !IC.isAlways() && !Callee->hasFnAttribute(Attribute::InlineHint)) {
222221
// Single BB does not increase total BB amount, thus subtract 1

llvm/lib/Transforms/IPO/AlwaysInliner.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/Analysis/AssumptionCache.h"
1717
#include "llvm/Analysis/InlineCost.h"
1818
#include "llvm/Analysis/TargetLibraryInfo.h"
19-
#include "llvm/IR/CallSite.h"
2019
#include "llvm/IR/CallingConv.h"
2120
#include "llvm/IR/DataLayout.h"
2221
#include "llvm/IR/Instructions.h"
@@ -43,7 +42,7 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
4342
};
4443
InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);
4544

46-
SmallSetVector<CallSite, 16> Calls;
45+
SmallSetVector<CallBase *, 16> Calls;
4746
bool Changed = false;
4847
SmallVector<Function *, 16> InlinedFunctions;
4948
for (Function &F : M)
@@ -52,15 +51,15 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
5251
Calls.clear();
5352

5453
for (User *U : F.users())
55-
if (auto CS = CallSite(U))
56-
if (CS.getCalledFunction() == &F)
57-
Calls.insert(CS);
54+
if (auto *CB = dyn_cast<CallBase>(U))
55+
if (CB->getCalledFunction() == &F)
56+
Calls.insert(CB);
5857

59-
for (CallSite CS : Calls)
58+
for (CallBase *CB : Calls)
6059
// FIXME: We really shouldn't be able to fail to inline at this point!
6160
// We should do something to log or check the inline failures here.
6261
Changed |=
63-
InlineFunction(CS, IFI, /*CalleeAAR=*/nullptr, InsertLifetime)
62+
InlineFunction(*CB, IFI, /*CalleeAAR=*/nullptr, InsertLifetime)
6463
.isSuccess();
6564

6665
// Remember to try and delete this function afterward. This both avoids
@@ -117,7 +116,7 @@ class AlwaysInlinerLegacyPass : public LegacyInlinerBase {
117116

118117
static char ID; // Pass identification, replacement for typeid
119118

120-
InlineCost getInlineCost(CallSite CS) override;
119+
InlineCost getInlineCost(CallBase &CB) override;
121120

122121
using llvm::Pass::doFinalization;
123122
bool doFinalization(CallGraph &CG) override {
@@ -152,8 +151,8 @@ Pass *llvm::createAlwaysInlinerLegacyPass(bool InsertLifetime) {
152151
/// computed here, but as we only expect to do this for relatively few and
153152
/// small functions which have the explicit attribute to force inlining, it is
154153
/// likely not worth it in practice.
155-
InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallSite CS) {
156-
Function *Callee = CS.getCalledFunction();
154+
InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallBase &CB) {
155+
Function *Callee = CB.getCalledFunction();
157156

158157
// Only inline direct calls to functions with always-inline attributes
159158
// that are viable for inlining.
@@ -164,7 +163,7 @@ InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallSite CS) {
164163
if (Callee->isDeclaration())
165164
return InlineCost::getNever("no definition");
166165

167-
if (!CS.hasFnAttr(Attribute::AlwaysInline))
166+
if (!CB.hasFnAttr(Attribute::AlwaysInline))
168167
return InlineCost::getNever("no alwaysinline attribute");
169168

170169
auto IsViable = isInlineViable(*Callee);

llvm/lib/Transforms/IPO/InlineSimple.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "llvm/Analysis/ProfileSummaryInfo.h"
1616
#include "llvm/Analysis/TargetLibraryInfo.h"
1717
#include "llvm/Analysis/TargetTransformInfo.h"
18-
#include "llvm/IR/CallSite.h"
1918
#include "llvm/IR/CallingConv.h"
2019
#include "llvm/IR/DataLayout.h"
2120
#include "llvm/IR/Instructions.h"
@@ -52,26 +51,26 @@ class SimpleInliner : public LegacyInlinerBase {
5251

5352
static char ID; // Pass identification, replacement for typeid
5453

55-
InlineCost getInlineCost(CallSite CS) override {
56-
Function *Callee = CS.getCalledFunction();
54+
InlineCost getInlineCost(CallBase &CB) override {
55+
Function *Callee = CB.getCalledFunction();
5756
TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
5857

5958
bool RemarksEnabled = false;
60-
const auto &BBs = CS.getCaller()->getBasicBlockList();
59+
const auto &BBs = CB.getCaller()->getBasicBlockList();
6160
if (!BBs.empty()) {
6261
auto DI = OptimizationRemark(DEBUG_TYPE, "", DebugLoc(), &BBs.front());
6362
if (DI.isEnabled())
6463
RemarksEnabled = true;
6564
}
66-
OptimizationRemarkEmitter ORE(CS.getCaller());
65+
OptimizationRemarkEmitter ORE(CB.getCaller());
6766

6867
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
6968
[&](Function &F) -> AssumptionCache & {
7069
return ACT->getAssumptionCache(F);
7170
};
72-
return llvm::getInlineCost(
73-
cast<CallBase>(*CS.getInstruction()), Params, TTI, GetAssumptionCache,
74-
/*GetBFI=*/None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
71+
return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache,
72+
/*GetBFI=*/None, GetTLI, PSI,
73+
RemarksEnabled ? &ORE : nullptr);
7574
}
7675

7776
bool runOnSCC(CallGraphSCC &SCC) override;

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static InlineResult inlineCallIfPossible(
283283

284284
// Try to inline the function. Get the list of static allocas that were
285285
// inlined.
286-
InlineResult IR = InlineFunction(&CS, IFI, &AAR, InsertLifetime);
286+
InlineResult IR = InlineFunction(CS, IFI, &AAR, InsertLifetime);
287287
if (!IR.isSuccess())
288288
return IR;
289289

@@ -1087,7 +1087,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
10871087

10881088
using namespace ore;
10891089

1090-
InlineResult IR = InlineFunction(CS, IFI);
1090+
InlineResult IR = InlineFunction(*CS, IFI);
10911091
if (!IR.isSuccess()) {
10921092
setInlineRemark(*CS, std::string(IR.getFailureReason()) + "; " +
10931093
inlineCostStr(*OIC));

0 commit comments

Comments
 (0)