Skip to content

Commit 9ee02ae

Browse files
committed
[llvm][NFC][CallSite] Remove CallSite from FunctionAttrs
Reviewers: dblaikie, craig.topper Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78584
1 parent d892eec commit 9ee02ae

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "llvm/IR/Argument.h"
3434
#include "llvm/IR/Attributes.h"
3535
#include "llvm/IR/BasicBlock.h"
36-
#include "llvm/IR/CallSite.h"
3736
#include "llvm/IR/Constant.h"
3837
#include "llvm/IR/Constants.h"
3938
#include "llvm/IR/Function.h"
@@ -160,8 +159,7 @@ static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody,
160159

161160
// Check whether all pointer arguments point to local memory, and
162161
// ignore calls that only access local memory.
163-
for (CallSite::arg_iterator CI = Call->arg_begin(), CE = Call->arg_end();
164-
CI != CE; ++CI) {
162+
for (auto CI = Call->arg_begin(), CE = Call->arg_end(); CI != CE; ++CI) {
165163
Value *Arg = *CI;
166164
if (!Arg->getType()->isPtrOrPtrVectorTy())
167165
continue;
@@ -362,13 +360,13 @@ struct ArgumentUsesTracker : public CaptureTracker {
362360
void tooManyUses() override { Captured = true; }
363361

364362
bool captured(const Use *U) override {
365-
CallSite CS(U->getUser());
366-
if (!CS.getInstruction()) {
363+
CallBase *CB = dyn_cast<CallBase>(U->getUser());
364+
if (!CB) {
367365
Captured = true;
368366
return true;
369367
}
370368

371-
Function *F = CS.getCalledFunction();
369+
Function *F = CB->getCalledFunction();
372370
if (!F || !F->hasExactDefinition() || !SCCNodes.count(F)) {
373371
Captured = true;
374372
return true;
@@ -379,14 +377,14 @@ struct ArgumentUsesTracker : public CaptureTracker {
379377
// these.
380378

381379
unsigned UseIndex =
382-
std::distance(const_cast<const Use *>(CS.arg_begin()), U);
380+
std::distance(const_cast<const Use *>(CB->arg_begin()), U);
383381

384-
assert(UseIndex < CS.data_operands_size() &&
382+
assert(UseIndex < CB->data_operands_size() &&
385383
"Indirect function calls should have been filtered above!");
386384

387-
if (UseIndex >= CS.getNumArgOperands()) {
385+
if (UseIndex >= CB->getNumArgOperands()) {
388386
// Data operand, but not a argument operand -- must be a bundle operand
389-
assert(CS.hasOperandBundles() && "Must be!");
387+
assert(CB->hasOperandBundles() && "Must be!");
390388

391389
// CaptureTracking told us that we're being captured by an operand bundle
392390
// use. In this case it does not matter if the callee is within our SCC
@@ -490,15 +488,15 @@ determinePointerReadAttrs(Argument *A,
490488
Worklist.push_back(&UU);
491489
};
492490

493-
CallSite CS(I);
494-
if (CS.doesNotAccessMemory()) {
491+
CallBase &CB = cast<CallBase>(*I);
492+
if (CB.doesNotAccessMemory()) {
495493
AddUsersToWorklistIfCapturing();
496494
continue;
497495
}
498496

499-
Function *F = CS.getCalledFunction();
497+
Function *F = CB.getCalledFunction();
500498
if (!F) {
501-
if (CS.onlyReadsMemory()) {
499+
if (CB.onlyReadsMemory()) {
502500
IsRead = true;
503501
AddUsersToWorklistIfCapturing();
504502
continue;
@@ -510,23 +508,23 @@ determinePointerReadAttrs(Argument *A,
510508
// operands. This means there is no need to adjust UseIndex to account
511509
// for these.
512510

513-
unsigned UseIndex = std::distance(CS.arg_begin(), U);
511+
unsigned UseIndex = std::distance(CB.arg_begin(), U);
514512

515513
// U cannot be the callee operand use: since we're exploring the
516514
// transitive uses of an Argument, having such a use be a callee would
517-
// imply the CallSite is an indirect call or invoke; and we'd take the
515+
// imply the call site is an indirect call or invoke; and we'd take the
518516
// early exit above.
519-
assert(UseIndex < CS.data_operands_size() &&
517+
assert(UseIndex < CB.data_operands_size() &&
520518
"Data operand use expected!");
521519

522-
bool IsOperandBundleUse = UseIndex >= CS.getNumArgOperands();
520+
bool IsOperandBundleUse = UseIndex >= CB.getNumArgOperands();
523521

524522
if (UseIndex >= F->arg_size() && !IsOperandBundleUse) {
525523
assert(F->isVarArg() && "More params than args in non-varargs call");
526524
return Attribute::None;
527525
}
528526

529-
Captures &= !CS.doesNotCapture(UseIndex);
527+
Captures &= !CB.doesNotCapture(UseIndex);
530528

531529
// Since the optimizer (by design) cannot see the data flow corresponding
532530
// to a operand bundle use, these cannot participate in the optimistic SCC
@@ -535,12 +533,12 @@ determinePointerReadAttrs(Argument *A,
535533
if (IsOperandBundleUse ||
536534
!SCCNodes.count(&*std::next(F->arg_begin(), UseIndex))) {
537535

538-
// The accessors used on CallSite here do the right thing for calls and
536+
// The accessors used on call site here do the right thing for calls and
539537
// invokes with operand bundles.
540538

541-
if (!CS.onlyReadsMemory() && !CS.onlyReadsMemory(UseIndex))
539+
if (!CB.onlyReadsMemory() && !CB.onlyReadsMemory(UseIndex))
542540
return Attribute::None;
543-
if (!CS.doesNotAccessMemory(UseIndex))
541+
if (!CB.doesNotAccessMemory(UseIndex))
544542
IsRead = true;
545543
}
546544

@@ -638,16 +636,16 @@ static bool addArgumentAttrsFromCallsites(Function &F) {
638636
// callsite.
639637
BasicBlock &Entry = F.getEntryBlock();
640638
for (Instruction &I : Entry) {
641-
if (auto CS = CallSite(&I)) {
642-
if (auto *CalledFunc = CS.getCalledFunction()) {
639+
if (auto *CB = dyn_cast<CallBase>(&I)) {
640+
if (auto *CalledFunc = CB->getCalledFunction()) {
643641
for (auto &CSArg : CalledFunc->args()) {
644642
if (!CSArg.hasNonNullAttr())
645643
continue;
646644

647645
// If the non-null callsite argument operand is an argument to 'F'
648646
// (the caller) and the call is guaranteed to execute, then the value
649647
// must be non-null throughout 'F'.
650-
auto *FArg = dyn_cast<Argument>(CS.getArgOperand(CSArg.getArgNo()));
648+
auto *FArg = dyn_cast<Argument>(CB->getArgOperand(CSArg.getArgNo()));
651649
if (FArg && !FArg->hasNonNullAttr()) {
652650
FArg->addAttr(Attribute::NonNull);
653651
Changed = true;
@@ -904,10 +902,10 @@ static bool isFunctionMallocLike(Function *F, const SCCNodeSet &SCCNodes) {
904902
break;
905903
case Instruction::Call:
906904
case Instruction::Invoke: {
907-
CallSite CS(RVI);
908-
if (CS.hasRetAttr(Attribute::NoAlias))
905+
CallBase &CB = cast<CallBase>(*RVI);
906+
if (CB.hasRetAttr(Attribute::NoAlias))
909907
break;
910-
if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
908+
if (CB.getCalledFunction() && SCCNodes.count(CB.getCalledFunction()))
911909
break;
912910
LLVM_FALLTHROUGH;
913911
}
@@ -1013,8 +1011,8 @@ static bool isReturnNonNull(Function *F, const SCCNodeSet &SCCNodes,
10131011
}
10141012
case Instruction::Call:
10151013
case Instruction::Invoke: {
1016-
CallSite CS(RVI);
1017-
Function *Callee = CS.getCalledFunction();
1014+
CallBase &CB = cast<CallBase>(*RVI);
1015+
Function *Callee = CB.getCalledFunction();
10181016
// A call to a node within the SCC is assumed to return null until
10191017
// proven otherwise
10201018
if (Callee && SCCNodes.count(Callee)) {
@@ -1223,10 +1221,11 @@ bool AttributeInferer::run(const SCCNodeSet &SCCNodes) {
12231221
/// Helper for non-Convergent inference predicate InstrBreaksAttribute.
12241222
static bool InstrBreaksNonConvergent(Instruction &I,
12251223
const SCCNodeSet &SCCNodes) {
1226-
const CallSite CS(&I);
1224+
const CallBase *CB = dyn_cast<CallBase>(&I);
12271225
// Breaks non-convergent assumption if CS is a convergent call to a function
12281226
// not in the SCC.
1229-
return CS && CS.isConvergent() && SCCNodes.count(CS.getCalledFunction()) == 0;
1227+
return CB && CB->isConvergent() &&
1228+
SCCNodes.count(CB->getCalledFunction()) == 0;
12301229
}
12311230

12321231
/// Helper for NoUnwind inference predicate InstrBreaksAttribute.
@@ -1247,11 +1246,11 @@ static bool InstrBreaksNonThrowing(Instruction &I, const SCCNodeSet &SCCNodes) {
12471246

12481247
/// Helper for NoFree inference predicate InstrBreaksAttribute.
12491248
static bool InstrBreaksNoFree(Instruction &I, const SCCNodeSet &SCCNodes) {
1250-
CallSite CS(&I);
1251-
if (!CS)
1249+
CallBase *CB = dyn_cast<CallBase>(&I);
1250+
if (!CB)
12521251
return false;
12531252

1254-
Function *Callee = CS.getCalledFunction();
1253+
Function *Callee = CB->getCalledFunction();
12551254
if (!Callee)
12561255
return true;
12571256

@@ -1368,8 +1367,8 @@ static bool addNoRecurseAttrs(const SCCNodeSet &SCCNodes) {
13681367
// marked norecurse, so any called from F to F will not be marked norecurse.
13691368
for (auto &BB : *F)
13701369
for (auto &I : BB.instructionsWithoutDebug())
1371-
if (auto CS = CallSite(&I)) {
1372-
Function *Callee = CS.getCalledFunction();
1370+
if (auto *CB = dyn_cast<CallBase>(&I)) {
1371+
Function *Callee = CB->getCalledFunction();
13731372
if (!Callee || Callee == F || !Callee->doesNotRecurse())
13741373
// Function calls a potentially recursive function.
13751374
return false;
@@ -1439,8 +1438,8 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
14391438
// function.
14401439
if (!HasUnknownCall)
14411440
for (Instruction &I : instructions(F))
1442-
if (auto CS = CallSite(&I))
1443-
if (!CS.getCalledFunction()) {
1441+
if (auto *CB = dyn_cast<CallBase>(&I))
1442+
if (!CB->getCalledFunction()) {
14441443
HasUnknownCall = true;
14451444
break;
14461445
}
@@ -1575,8 +1574,8 @@ static bool addNoRecurseAttrsTopDown(Function &F) {
15751574
auto *I = dyn_cast<Instruction>(U);
15761575
if (!I)
15771576
return false;
1578-
CallSite CS(I);
1579-
if (!CS || !CS.getParent()->getParent()->doesNotRecurse())
1577+
CallBase *CB = dyn_cast<CallBase>(I);
1578+
if (!CB || !CB->getParent()->getParent()->doesNotRecurse())
15801579
return false;
15811580
}
15821581
return setDoesNotRecurse(F);

0 commit comments

Comments
 (0)