diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -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 @@ /// 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 @@ if (isa(U)) continue; - CallSite CS(cast(U)); - Function *CallerFunc = CS.getInstruction()->getParent()->getParent(); + CallBase &CB = cast(*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 @@ for (BasicBlock &BB : F) { for (Instruction &I : BB) { if (CallInst *CI = dyn_cast(&I)) { - CallSite CS(cast(CI)); // Skip over isline asm instructions since they aren't function calls. if (CI->isInlineAsm()) continue; @@ -2259,7 +2257,7 @@ CalledFn->hasAddressTaken()) return false; BlockFrequencyInfo &CallerBFI = GetBFI(F); - if (!isColdCallSite(CS, CallerBFI)) + if (!isColdCallSite(*CI, CallerBFI)) return false; } } diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp --- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -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 @@ // constant. bool MadeChange = false; for (Use &U : F.uses()) { - CallSite CS(U.getUser()); - Instruction* Call = CS.getInstruction(); + CallBase *CB = dyn_cast(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 @@ if (Argument *A = dyn_cast(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(*I); // Increment now, so we can remove the use @@ -266,7 +264,7 @@ if (Argument *A = dyn_cast(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(); } diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1712,8 +1712,8 @@ static bool isDirectCall(Use& U) { auto *Usr = dyn_cast(U.getUser()); if (Usr) { - CallSite CS(Usr); - if (CS.isCallee(&U)) + auto *CB = dyn_cast(Usr); + if (CB && CB->isCallee(&U)) return true; } return false; diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -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 @@ 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(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); } } diff --git a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp --- a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp +++ b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp @@ -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 @@ if (!Edge.first) return Res; assert(isa(Edge.first)); - CallSite CS(cast(Edge.first)); - Function *Caller = CS.getCaller(); + CallBase &CB = cast(*Edge.first); + Function *Caller = CB.getCaller(); auto &BFI = FAM.getResult(*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; diff --git a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp --- a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp +++ b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp @@ -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 @@ if (!BBCount) continue; for (auto &I : BB) { - CallSite CS(&I); - if (!CS) + CallBase *CB = dyn_cast(&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(ValueData, ActualNumValueData)) { @@ -66,7 +64,7 @@ } continue; } - UpdateCounts(TTI, &F, CS.getCalledFunction(), *BBCount); + UpdateCounts(TTI, &F, CB->getCalledFunction(), *BBCount); } } } diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -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 @@ BlocksToInstrument.push_back(&BB); for (auto &Inst : BB) { if (Options.IndirectCalls) { - CallSite CS(&Inst); - if (CS && !CS.getCalledFunction()) + CallBase *CB = dyn_cast(&Inst); + if (CB && !CB->getCalledFunction()) IndirCalls.push_back(&Inst); } if (Options.TraceCmp) { @@ -786,8 +785,8 @@ Options.Inline8bitCounters || Options.InlineBoolFlag); for (auto I : IndirCalls) { IRBuilder<> IRB(I); - CallSite CS(I); - Value *Callee = CS.getCalledValue(); + CallBase &CB = cast(*I); + Value *Callee = CB.getCalledValue(); if (isa(Callee)) continue; IRB.CreateCall(SanCovTracePCIndir, IRB.CreatePointerCast(Callee, IntptrTy)); diff --git a/llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc b/llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc --- a/llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc +++ b/llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc @@ -59,7 +59,7 @@ void run(std::vector &Candidates) { std::vector Result = findIndirectCalls(F); for (Instruction *I : Result) { - Value *Callee = CallSite(I).getCalledValue(); + Value *Callee = cast(I)->getCalledValue(); Instruction *InsertPt = I; Instruction *AnnotatedInst = I; Candidates.emplace_back(CandidateInfo{Callee, InsertPt, AnnotatedInst}); diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -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 @@ for (const auto BB : CurrentLoop->blocks()) { for (auto &I : *BB) { - auto CS = CallSite(&I); - if (!CS) continue; - if (CS.isConvergent()) + auto *CB = dyn_cast(&I); + if (!CB) + continue; + if (CB->isConvergent()) return false; if (auto *II = dyn_cast(&I)) if (!II->getUnwindDest()->canSplitPredecessors()) diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -1612,8 +1612,7 @@ if (auto *CI = dyn_cast(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(Expr)) { // Special case bitcasts, which are used to materialize matrixes from // non-matrix ops. diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -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 @@ 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(cpySrc); if (!srcAlloca) @@ -831,8 +826,8 @@ // 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 @@ 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)