[llvm][NFC][CallSite] Remove CallSite from a few trivial locations

Summary: Implementation details and internal (to module) APIs.

Reviewers: craig.topper, dblaikie

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78610
This commit is contained in:
Mircea Trofin 2020-04-21 21:56:04 -07:00
parent 188f5cde96
commit 1b6b05a250
11 changed files with 50 additions and 64 deletions

View File

@ -28,7 +28,6 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
@ -2188,12 +2187,12 @@ static bool hasChangeableCC(Function *F) {
/// Return true if the block containing the call site has a BlockFrequency of
/// less than ColdCCRelFreq% of the entry block.
static bool isColdCallSite(CallSite CS, BlockFrequencyInfo &CallerBFI) {
static bool isColdCallSite(CallBase &CB, BlockFrequencyInfo &CallerBFI) {
const BranchProbability ColdProb(ColdCCRelFreq, 100);
auto CallSiteBB = CS.getInstruction()->getParent();
auto *CallSiteBB = CB.getParent();
auto CallSiteFreq = CallerBFI.getBlockFreq(CallSiteBB);
auto CallerEntryFreq =
CallerBFI.getBlockFreq(&(CS.getCaller()->getEntryBlock()));
CallerBFI.getBlockFreq(&(CB.getCaller()->getEntryBlock()));
return CallSiteFreq < CallerEntryFreq * ColdProb;
}
@ -2213,10 +2212,10 @@ isValidCandidateForColdCC(Function &F,
if (isa<BlockAddress>(U))
continue;
CallSite CS(cast<Instruction>(U));
Function *CallerFunc = CS.getInstruction()->getParent()->getParent();
CallBase &CB = cast<CallBase>(*U);
Function *CallerFunc = CB.getParent()->getParent();
BlockFrequencyInfo &CallerBFI = GetBFI(*CallerFunc);
if (!isColdCallSite(CS, CallerBFI))
if (!isColdCallSite(CB, CallerBFI))
return false;
auto It = std::find(AllCallsCold.begin(), AllCallsCold.end(), CallerFunc);
if (It == AllCallsCold.end())
@ -2242,7 +2241,6 @@ hasOnlyColdCalls(Function &F,
for (BasicBlock &BB : F) {
for (Instruction &I : BB) {
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
CallSite CS(cast<Instruction>(CI));
// Skip over isline asm instructions since they aren't function calls.
if (CI->isInlineAsm())
continue;
@ -2259,7 +2257,7 @@ hasOnlyColdCalls(Function &F,
CalledFn->hasAddressTaken())
return false;
BlockFrequencyInfo &CallerBFI = GetBFI(F);
if (!isColdCallSite(CS, CallerBFI))
if (!isColdCallSite(*CI, CallerBFI))
return false;
}
}

View File

@ -17,7 +17,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
@ -222,16 +221,15 @@ static bool PropagateConstantReturn(Function &F) {
// constant.
bool MadeChange = false;
for (Use &U : F.uses()) {
CallSite CS(U.getUser());
Instruction* Call = CS.getInstruction();
CallBase *CB = dyn_cast<CallBase>(U.getUser());
// Not a call instruction or a call instruction that's not calling F
// directly?
if (!Call || !CS.isCallee(&U))
if (!CB || !CB->isCallee(&U))
continue;
// Call result not used?
if (Call->use_empty())
if (CB->use_empty())
continue;
MadeChange = true;
@ -241,12 +239,12 @@ static bool PropagateConstantReturn(Function &F) {
if (Argument *A = dyn_cast<Argument>(New))
// Was an argument returned? Then find the corresponding argument in
// the call instruction and use that.
New = CS.getArgument(A->getArgNo());
Call->replaceAllUsesWith(New);
New = CB->getArgOperand(A->getArgNo());
CB->replaceAllUsesWith(New);
continue;
}
for (auto I = Call->user_begin(), E = Call->user_end(); I != E;) {
for (auto I = CB->user_begin(), E = CB->user_end(); I != E;) {
Instruction *Ins = cast<Instruction>(*I);
// Increment now, so we can remove the use
@ -266,7 +264,7 @@ static bool PropagateConstantReturn(Function &F) {
if (Argument *A = dyn_cast<Argument>(New))
// Was an argument returned? Then find the corresponding argument in
// the call instruction and use that.
New = CS.getArgument(A->getArgNo());
New = CB->getArgOperand(A->getArgNo());
Ins->replaceAllUsesWith(New);
Ins->eraseFromParent();
}

View File

@ -1712,8 +1712,8 @@ bool LowerTypeTestsModule::runForTesting(Module &M) {
static bool isDirectCall(Use& U) {
auto *Usr = dyn_cast<CallInst>(U.getUser());
if (Usr) {
CallSite CS(Usr);
if (CS.isCallee(&U))
auto *CB = dyn_cast<CallBase>(Usr);
if (CB && CB->isCallee(&U))
return true;
}
return false;

View File

@ -95,7 +95,6 @@
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
@ -467,13 +466,13 @@ void MergeFunctions::replaceDirectCallers(Function *Old, Function *New) {
for (auto UI = Old->use_begin(), UE = Old->use_end(); UI != UE;) {
Use *U = &*UI;
++UI;
CallSite CS(U->getUser());
if (CS && CS.isCallee(U)) {
CallBase *CB = dyn_cast<CallBase>(U->getUser());
if (CB && CB->isCallee(U)) {
// Do not copy attributes from the called function to the call-site.
// Function comparison ensures that the attributes are the same up to
// type congruences in byval(), in which case we need to keep the byval
// type of the call-site, not the callee function.
remove(CS.getInstruction()->getFunction());
remove(CB->getFunction());
U->set(BitcastNew);
}
}

View File

@ -31,7 +31,6 @@
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/SyntheticCountsUtils.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
@ -111,13 +110,13 @@ PreservedAnalyses SyntheticCountsPropagation::run(Module &M,
if (!Edge.first)
return Res;
assert(isa<Instruction>(Edge.first));
CallSite CS(cast<Instruction>(Edge.first));
Function *Caller = CS.getCaller();
CallBase &CB = cast<CallBase>(*Edge.first);
Function *Caller = CB.getCaller();
auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(*Caller);
// Now compute the callsite count from relative frequency and
// entry count:
BasicBlock *CSBB = CS.getInstruction()->getParent();
BasicBlock *CSBB = CB.getParent();
Scaled64 EntryFreq(BFI.getEntryFreq(), 0);
Scaled64 BBCount(BFI.getBlockFreq(CSBB).getFrequency(), 0);
BBCount /= EntryFreq;

View File

@ -11,7 +11,6 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/MDBuilder.h"
@ -49,16 +48,15 @@ PreservedAnalyses CGProfilePass::run(Module &M, ModuleAnalysisManager &MAM) {
if (!BBCount)
continue;
for (auto &I : BB) {
CallSite CS(&I);
if (!CS)
CallBase *CB = dyn_cast<CallBase>(&I);
if (!CB)
continue;
if (CS.isIndirectCall()) {
if (CB->isIndirectCall()) {
InstrProfValueData ValueData[8];
uint32_t ActualNumValueData;
uint64_t TotalC;
if (!getValueProfDataFromInst(*CS.getInstruction(),
IPVK_IndirectCallTarget, 8, ValueData,
ActualNumValueData, TotalC))
if (!getValueProfDataFromInst(*CB, IPVK_IndirectCallTarget, 8,
ValueData, ActualNumValueData, TotalC))
continue;
for (const auto &VD :
ArrayRef<InstrProfValueData>(ValueData, ActualNumValueData)) {
@ -66,7 +64,7 @@ PreservedAnalyses CGProfilePass::run(Module &M, ModuleAnalysisManager &MAM) {
}
continue;
}
UpdateCounts(TTI, &F, CS.getCalledFunction(), *BBCount);
UpdateCounts(TTI, &F, CB->getCalledFunction(), *BBCount);
}
}
}

View File

@ -16,7 +16,6 @@
#include "llvm/Analysis/EHPersonalities.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
@ -661,8 +660,8 @@ void ModuleSanitizerCoverage::instrumentFunction(
BlocksToInstrument.push_back(&BB);
for (auto &Inst : BB) {
if (Options.IndirectCalls) {
CallSite CS(&Inst);
if (CS && !CS.getCalledFunction())
CallBase *CB = dyn_cast<CallBase>(&Inst);
if (CB && !CB->getCalledFunction())
IndirCalls.push_back(&Inst);
}
if (Options.TraceCmp) {
@ -786,8 +785,8 @@ void ModuleSanitizerCoverage::InjectCoverageForIndirectCalls(
Options.Inline8bitCounters || Options.InlineBoolFlag);
for (auto I : IndirCalls) {
IRBuilder<> IRB(I);
CallSite CS(I);
Value *Callee = CS.getCalledValue();
CallBase &CB = cast<CallBase>(*I);
Value *Callee = CB.getCalledValue();
if (isa<InlineAsm>(Callee))
continue;
IRB.CreateCall(SanCovTracePCIndir, IRB.CreatePointerCast(Callee, IntptrTy));

View File

@ -59,7 +59,7 @@ public:
void run(std::vector<CandidateInfo> &Candidates) {
std::vector<Instruction *> Result = findIndirectCalls(F);
for (Instruction *I : Result) {
Value *Callee = CallSite(I).getCalledValue();
Value *Callee = cast<CallBase>(I)->getCalledValue();
Instruction *InsertPt = I;
Instruction *AnnotatedInst = I;
Candidates.emplace_back(CandidateInfo{Callee, InsertPt, AnnotatedInst});

View File

@ -43,7 +43,6 @@
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
@ -682,9 +681,10 @@ bool LoopUnswitch::processCurrentLoop() {
for (const auto BB : CurrentLoop->blocks()) {
for (auto &I : *BB) {
auto CS = CallSite(&I);
if (!CS) continue;
if (CS.isConvergent())
auto *CB = dyn_cast<CallBase>(&I);
if (!CB)
continue;
if (CB->isConvergent())
return false;
if (auto *II = dyn_cast<InvokeInst>(&I))
if (!II->getUnwindDest()->canSplitPredecessors())

View File

@ -1612,8 +1612,7 @@ public:
if (auto *CI = dyn_cast<CallInst>(I)) {
writeFnName(CI);
Ops.append(CallSite(CI).arg_begin(),
CallSite(CI).arg_end() - getNumShapeArgs(CI));
Ops.append(CI->arg_begin(), CI->arg_end() - getNumShapeArgs(CI));
} else if (isa<BitCastInst>(Expr)) {
// Special case bitcasts, which are used to materialize matrixes from
// non-matrix ops.

View File

@ -27,7 +27,6 @@
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
@ -728,10 +727,6 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpy, Value *cpyDest,
if (F->isIntrinsic() && F->getIntrinsicID() == Intrinsic::lifetime_start)
return false;
// Deliberately get the source and destination with bitcasts stripped away,
// because we'll need to do type comparisons based on the underlying type.
CallSite CS(C);
// Require that src be an alloca. This simplifies the reasoning considerably.
AllocaInst *srcAlloca = dyn_cast<AllocaInst>(cpySrc);
if (!srcAlloca)
@ -831,8 +826,8 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpy, Value *cpyDest,
// Check that src isn't captured by the called function since the
// transformation can cause aliasing issues in that case.
for (unsigned i = 0, e = CS.arg_size(); i != e; ++i)
if (CS.getArgument(i) == cpySrc && !CS.doesNotCapture(i))
for (unsigned ArgI = 0, E = C->arg_size(); ArgI != E; ++ArgI)
if (C->getArgOperand(ArgI) == cpySrc && !C->doesNotCapture(ArgI))
return false;
// Since we're changing the parameter to the callsite, we need to make sure
@ -859,25 +854,26 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpy, Value *cpyDest,
if (cpySrc->getType()->getPointerAddressSpace() !=
cpyDest->getType()->getPointerAddressSpace())
return false;
for (unsigned i = 0; i < CS.arg_size(); ++i)
if (CS.getArgument(i)->stripPointerCasts() == cpySrc &&
for (unsigned ArgI = 0; ArgI < C->arg_size(); ++ArgI)
if (C->getArgOperand(ArgI)->stripPointerCasts() == cpySrc &&
cpySrc->getType()->getPointerAddressSpace() !=
CS.getArgument(i)->getType()->getPointerAddressSpace())
C->getArgOperand(ArgI)->getType()->getPointerAddressSpace())
return false;
// All the checks have passed, so do the transformation.
bool changedArgument = false;
for (unsigned i = 0; i < CS.arg_size(); ++i)
if (CS.getArgument(i)->stripPointerCasts() == cpySrc) {
for (unsigned ArgI = 0; ArgI < C->arg_size(); ++ArgI)
if (C->getArgOperand(ArgI)->stripPointerCasts() == cpySrc) {
Value *Dest = cpySrc->getType() == cpyDest->getType() ? cpyDest
: CastInst::CreatePointerCast(cpyDest, cpySrc->getType(),
cpyDest->getName(), C);
changedArgument = true;
if (CS.getArgument(i)->getType() == Dest->getType())
CS.setArgument(i, Dest);
if (C->getArgOperand(ArgI)->getType() == Dest->getType())
C->setArgOperand(ArgI, Dest);
else
CS.setArgument(i, CastInst::CreatePointerCast(Dest,
CS.getArgument(i)->getType(), Dest->getName(), C));
C->setArgOperand(ArgI, CastInst::CreatePointerCast(
Dest, C->getArgOperand(ArgI)->getType(),
Dest->getName(), C));
}
if (!changedArgument)