Skip to content

Commit

Permalink
[llvm][NFC][CallSite] Remove Implementation uses of CallSite
Browse files Browse the repository at this point in the history
Reviewers: dblaikie, davidxl, craig.topper

Subscribers: arsenm, dschuff, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, kerbowa, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78142
  • Loading branch information
mtrofin committed Apr 14, 2020
1 parent cc220d4 commit 447e2c3
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 55 deletions.
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/CGSCCPassManager.cpp
Expand Up @@ -15,7 +15,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
Expand Down Expand Up @@ -456,8 +455,8 @@ static LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass(
// because if there is a single call edge, whether there are ref edges is
// irrelevant.
for (Instruction &I : instructions(F))
if (auto CS = CallSite(&I))
if (Function *Callee = CS.getCalledFunction())
if (auto *CB = dyn_cast<CallBase>(&I))
if (Function *Callee = CB->getCalledFunction())
if (Visited.insert(Callee).second && !Callee->isDeclaration()) {
Node &CalleeN = *G.lookup(*Callee);
Edge *E = N->lookup(CalleeN);
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Analysis/LazyCallGraph.cpp
Expand Up @@ -17,7 +17,6 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
Expand Down Expand Up @@ -100,8 +99,8 @@ LazyCallGraph::EdgeSequence &LazyCallGraph::Node::populateSlow() {
// safety of optimizing a direct call edge.
for (BasicBlock &BB : *F)
for (Instruction &I : BB) {
if (auto CS = CallSite(&I))
if (Function *Callee = CS.getCalledFunction())
if (auto *CB = dyn_cast<CallBase>(&I))
if (Function *Callee = CB->getCalledFunction())
if (!Callee->isDeclaration())
if (Callees.insert(Callee).second) {
Visited.insert(Callee);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/LoopInfo.cpp
Expand Up @@ -480,8 +480,8 @@ bool Loop::isSafeToClone() const {
return false;

for (Instruction &I : *BB)
if (auto CS = CallSite(&I))
if (CS.cannotDuplicate())
if (auto *CB = dyn_cast<CallBase>(&I))
if (CB->cannotDuplicate())
return false;
}
return true;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -86,7 +86,6 @@
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
Expand Down Expand Up @@ -6579,7 +6578,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {

case Instruction::Call:
case Instruction::Invoke:
if (Value *RV = CallSite(U).getReturnedArgOperand())
if (Value *RV = cast<CallBase>(U)->getReturnedArgOperand())
return getSCEV(RV);
break;
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Expand Up @@ -27,7 +27,6 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
Expand Down Expand Up @@ -5312,7 +5311,7 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
for (auto UI = I.first->materialized_user_begin(), UE = I.first->user_end();
UI != UE;)
// Don't expect any other users than call sites
CallSite(*UI++).setCalledFunction(I.second);
cast<CallBase>(*UI++)->setCalledFunction(I.second);

// Finish fn->subprogram upgrade for materialized functions.
if (DISubprogram *SP = MDLoader->lookupSubprogramForFunction(F))
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/AMDGPU/AMDGPUAnnotateKernelFeatures.cpp
Expand Up @@ -21,7 +21,6 @@
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
Expand Down Expand Up @@ -287,14 +286,13 @@ bool AMDGPUAnnotateKernelFeatures::addFeatureAttributes(Function &F) {

for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
CallSite CS(&I);
if (CS) {
const Function *Callee
= dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
if (auto *CB = dyn_cast<CallBase>(&I)) {
const Function *Callee =
dyn_cast<Function>(CB->getCalledValue()->stripPointerCasts());

// TODO: Do something with indirect calls.
if (!Callee) {
if (!CS.isInlineAsm())
if (!CB->isInlineAsm())
HaveCall = true;
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp
Expand Up @@ -220,9 +220,8 @@ AMDGPUPerfHintAnalysis::FuncInfo *AMDGPUPerfHint::visit(const Function &F) {
++FI.InstCount;
continue;
}
CallSite CS(const_cast<Instruction *>(&I));
if (CS) {
Function *Callee = CS.getCalledFunction();
if (auto *CB = dyn_cast<CallBase>(&I)) {
Function *Callee = CB->getCalledFunction();
if (!Callee || Callee->isDeclaration()) {
++FI.InstCount;
continue;
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp
Expand Up @@ -109,7 +109,6 @@ bool PPCLowerMASSVEntries::lowerMASSVCall(CallInst *CI, Function &Func,
FunctionCallee FCache = M.getOrInsertFunction(
MASSVEntryName, Func.getFunctionType(), Func.getAttributes());

CallSite CS(CI);
CI->setCalledFunction(FCache);

return true;
Expand Down
Expand Up @@ -23,7 +23,6 @@
//===----------------------------------------------------------------------===//

#include "WebAssembly.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -73,11 +72,11 @@ static void findUses(Value *V, Function &F,
else if (auto *A = dyn_cast<GlobalAlias>(U.getUser()))
findUses(A, F, Uses, ConstantBCs);
else if (U.get()->getType() != F.getType()) {
CallSite CS(U.getUser());
if (!CS)
CallBase *CB = dyn_cast<CallBase>(U.getUser());
if (!CB)
// Skip uses that aren't immediately called
continue;
Value *Callee = CS.getCalledValue();
Value *Callee = CB->getCalledValue();
if (Callee != V)
// Skip calls where the function isn't the callee
continue;
Expand Down
21 changes: 9 additions & 12 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Expand Up @@ -32,7 +32,6 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
Expand Down Expand Up @@ -1094,7 +1093,7 @@ static bool hasCallsInBlockBetween(Instruction *From, Instruction *To) {
if (isa<IntrinsicInst>(I))
continue;

if (CallSite(I))
if (isa<CallBase>(I))
return true;
}
return false;
Expand Down Expand Up @@ -1164,13 +1163,11 @@ static bool simplifySuspendPoint(CoroSuspendInst *Suspend,
Prev = Pred->getTerminator();
}

CallSite CS{Prev};
if (!CS)
CallBase *CB = dyn_cast<CallBase>(Prev);
if (!CB)
return false;

auto *CallInstr = CS.getInstruction();

auto *Callee = CS.getCalledValue()->stripPointerCasts();
auto *Callee = CB->getCalledValue()->stripPointerCasts();

// See if the callsite is for resumption or destruction of the coroutine.
auto *SubFn = dyn_cast<CoroSubFnInst>(Callee);
Expand All @@ -1185,7 +1182,7 @@ static bool simplifySuspendPoint(CoroSuspendInst *Suspend,
// calls in between Save and CallInstr. They can potenitally resume the
// coroutine rendering this optimization unsafe.
auto *Save = Suspend->getCoroSave();
if (hasCallsBetween(Save, CallInstr))
if (hasCallsBetween(Save, CB))
return false;

// Replace llvm.coro.suspend with the value that results in resumption over
Expand All @@ -1195,13 +1192,13 @@ static bool simplifySuspendPoint(CoroSuspendInst *Suspend,
Save->eraseFromParent();

// No longer need a call to coro.resume or coro.destroy.
if (auto *Invoke = dyn_cast<InvokeInst>(CallInstr)) {
if (auto *Invoke = dyn_cast<InvokeInst>(CB)) {
BranchInst::Create(Invoke->getNormalDest(), Invoke);
}

// Grab the CalledValue from CS before erasing the CallInstr.
auto *CalledValue = CS.getCalledValue();
CallInstr->eraseFromParent();
// Grab the CalledValue from CB before erasing the CallInstr.
auto *CalledValue = CB->getCalledValue();
CB->eraseFromParent();

// If no more users remove it. Usually it is a bitcast of SubFn.
if (CalledValue != SubFn && CalledValue->user_empty())
Expand Down
22 changes: 10 additions & 12 deletions llvm/lib/Transforms/IPO/GlobalOpt.cpp
Expand Up @@ -720,17 +720,17 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) {
Changed = true;
}
} else if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
CallSite CS(I);
if (CS.getCalledValue() == V) {
CallBase *CB = cast<CallBase>(I);
if (CB->getCalledValue() == V) {
// Calling through the pointer! Turn into a direct call, but be careful
// that the pointer is not also being passed as an argument.
CS.setCalledFunction(NewV);
CB->setCalledOperand(NewV);
Changed = true;
bool PassedAsArg = false;
for (unsigned i = 0, e = CS.arg_size(); i != e; ++i)
if (CS.getArgument(i) == V) {
for (unsigned i = 0, e = CB->arg_size(); i != e; ++i)
if (CB->getArgOperand(i) == V) {
PassedAsArg = true;
CS.setArgument(i, NewV);
CB->setArgOperand(i, NewV);
}

if (PassedAsArg) {
Expand Down Expand Up @@ -2131,8 +2131,7 @@ static void ChangeCalleesToFastCall(Function *F) {
for (User *U : F->users()) {
if (isa<BlockAddress>(U))
continue;
CallSite CS(cast<Instruction>(U));
CS.setCallingConv(CallingConv::Fast);
cast<CallBase>(U)->setCallingConv(CallingConv::Fast);
}
}

Expand All @@ -2149,8 +2148,8 @@ static void RemoveAttribute(Function *F, Attribute::AttrKind A) {
for (User *U : F->users()) {
if (isa<BlockAddress>(U))
continue;
CallSite CS(cast<Instruction>(U));
CS.setAttributes(StripAttr(F->getContext(), CS.getAttributes(), A));
CallBase *CB = cast<CallBase>(U);
CB->setAttributes(StripAttr(F->getContext(), CB->getAttributes(), A));
}
}

Expand Down Expand Up @@ -2230,8 +2229,7 @@ static void changeCallSitesToColdCC(Function *F) {
for (User *U : F->users()) {
if (isa<BlockAddress>(U))
continue;
CallSite CS(cast<Instruction>(U));
CS.setCallingConv(CallingConv::Cold);
cast<CallBase>(U)->setCallingConv(CallingConv::Cold);
}
}

Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/Transforms/IPO/HotColdSplitting.cpp
Expand Up @@ -39,7 +39,6 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
Expand Down Expand Up @@ -110,8 +109,8 @@ bool unlikelyExecuted(BasicBlock &BB) {
// The block is cold if it calls/invokes a cold function. However, do not
// mark sanitizer traps as cold.
for (Instruction &I : BB)
if (auto CS = CallSite(&I))
if (CS.hasFnAttr(Attribute::Cold) && !CS->getMetadata("nosanitize"))
if (auto *CB = dyn_cast<CallBase>(&I))
if (CB->hasFnAttr(Attribute::Cold) && !CB->getMetadata("nosanitize"))
return true;

// The block is cold if it has an unreachable terminator, unless it's
Expand Down Expand Up @@ -325,11 +324,10 @@ Function *HotColdSplitting::extractColdRegion(
if (Function *OutF = CE.extractCodeRegion(CEAC)) {
User *U = *OutF->user_begin();
CallInst *CI = cast<CallInst>(U);
CallSite CS(CI);
NumColdRegionsOutlined++;
if (TTI.useColdCCForColdCall(*OutF)) {
OutF->setCallingConv(CallingConv::Cold);
CS.setCallingConv(CallingConv::Cold);
CI->setCallingConv(CallingConv::Cold);
}
CI->setIsNoInline();

Expand Down

0 comments on commit 447e2c3

Please sign in to comment.