[llvm] 53ee8fb - [CallSite removal][SCCP] Use CallBase instead of CallSite. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 20 00:16:31 PDT 2020
Author: Craig Topper
Date: 2020-04-20T00:16:09-07:00
New Revision: 53ee8fbc23f6973598b8dfe531612d76750ddcd0
URL: https://github.com/llvm/llvm-project/commit/53ee8fbc23f6973598b8dfe531612d76750ddcd0
DIFF: https://github.com/llvm/llvm-project/commit/53ee8fbc23f6973598b8dfe531612d76750ddcd0.diff
LOG: [CallSite removal][SCCP] Use CallBase instead of CallSite. NFC
Differential Revision: https://reviews.llvm.org/D78470
Added:
Modified:
llvm/lib/Transforms/Scalar/SCCP.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 18431d0b70ff..6d640fe8f9f4 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -33,7 +33,6 @@
#include "llvm/Analysis/ValueLattice.h"
#include "llvm/Analysis/ValueLatticeUtils.h"
#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
@@ -516,8 +515,8 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
// propagate the call arguments.
if (isa<Function>(I)) {
for (User *U : I->users()) {
- if (auto CS = CallSite(U))
- handleCallResult(CS);
+ if (auto *CB = dyn_cast<CallBase>(U))
+ handleCallResult(*CB);
}
} else {
for (User *U : I->users())
@@ -532,9 +531,9 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
OperandChangedState(UI);
}
}
- void handleCallOverdefined(CallSite CS);
- void handleCallResult(CallSite CS);
- void handleCallArguments(CallSite CS);
+ void handleCallOverdefined(CallBase &CB);
+ void handleCallResult(CallBase &CB);
+ void handleCallArguments(CallBase &CB);
private:
friend class InstVisitor<SCCPSolver>;
@@ -569,20 +568,20 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
void visitGetElementPtrInst(GetElementPtrInst &I);
void visitCallInst (CallInst &I) {
- visitCallSite(&I);
+ visitCallBase(I);
}
void visitInvokeInst (InvokeInst &II) {
- visitCallSite(&II);
+ visitCallBase(II);
visitTerminator(II);
}
void visitCallBrInst (CallBrInst &CBI) {
- visitCallSite(&CBI);
+ visitCallBase(CBI);
visitTerminator(CBI);
}
- void visitCallSite (CallSite CS);
+ void visitCallBase (CallBase &CB);
void visitResumeInst (ResumeInst &I) { /*returns void*/ }
void visitUnreachableInst(UnreachableInst &I) { /*returns void*/ }
void visitFenceInst (FenceInst &I) { /*returns void*/ }
@@ -1132,58 +1131,55 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
markOverdefined(IV, &I);
}
-void SCCPSolver::visitCallSite(CallSite CS) {
- handleCallResult(CS);
- handleCallArguments(CS);
+void SCCPSolver::visitCallBase(CallBase &CB) {
+ handleCallResult(CB);
+ handleCallArguments(CB);
}
-void SCCPSolver::handleCallOverdefined(CallSite CS) {
- Function *F = CS.getCalledFunction();
- Instruction *I = CS.getInstruction();
+void SCCPSolver::handleCallOverdefined(CallBase &CB) {
+ Function *F = CB.getCalledFunction();
// Void return and not tracking callee, just bail.
- if (I->getType()->isVoidTy())
+ if (CB.getType()->isVoidTy())
return;
// Otherwise, if we have a single return value case, and if the function is
// a declaration, maybe we can constant fold it.
- if (F && F->isDeclaration() && !I->getType()->isStructTy() &&
- canConstantFoldCallTo(cast<CallBase>(CS.getInstruction()), F)) {
+ if (F && F->isDeclaration() && !CB.getType()->isStructTy() &&
+ canConstantFoldCallTo(&CB, F)) {
SmallVector<Constant *, 8> Operands;
- for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end(); AI != E;
- ++AI) {
+ for (auto AI = CB.arg_begin(), E = CB.arg_end(); AI != E; ++AI) {
if (AI->get()->getType()->isStructTy())
- return markOverdefined(I); // Can't handle struct args.
+ return markOverdefined(&CB); // Can't handle struct args.
ValueLatticeElement State = getValueState(*AI);
if (State.isUnknownOrUndef())
return; // Operands are not resolved yet.
if (isOverdefined(State))
- return (void)markOverdefined(I);
+ return (void)markOverdefined(&CB);
assert(isConstant(State) && "Unknown state!");
Operands.push_back(getConstant(State));
}
- if (isOverdefined(getValueState(I)))
- return (void)markOverdefined(I);
+ if (isOverdefined(getValueState(&CB)))
+ return (void)markOverdefined(&CB);
// If we can constant fold this, mark the result of the call as a
// constant.
- if (Constant *C = ConstantFoldCall(cast<CallBase>(CS.getInstruction()), F,
- Operands, &GetTLI(*F))) {
+ if (Constant *C = ConstantFoldCall(&CB, F, Operands, &GetTLI(*F))) {
// call -> undef.
if (isa<UndefValue>(C))
return;
- return (void)markConstant(I, C);
+ return (void)markConstant(&CB, C);
}
}
// Otherwise, we don't know anything about this call, mark it overdefined.
- return (void)markOverdefined(I);
+ return (void)markOverdefined(&CB);
}
-void SCCPSolver::handleCallArguments(CallSite CS) {
- Function *F = CS.getCalledFunction();
+void SCCPSolver::handleCallArguments(CallBase &CB) {
+ Function *F = CB.getCalledFunction();
// If this is a local function that doesn't have its address taken, mark its
// entry block executable and merge in the actual arguments to the call into
// the formal arguments of the function.
@@ -1192,7 +1188,7 @@ void SCCPSolver::handleCallArguments(CallSite CS) {
MarkBlockExecutable(&F->front());
// Propagate information from this call site into the callee.
- CallSite::arg_iterator CAI = CS.arg_begin();
+ auto CAI = CB.arg_begin();
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); AI != E;
++AI, ++CAI) {
// If this argument is byval, and if the function is not readonly, there
@@ -1214,34 +1210,33 @@ void SCCPSolver::handleCallArguments(CallSite CS) {
}
}
-void SCCPSolver::handleCallResult(CallSite CS) {
- Function *F = CS.getCalledFunction();
- Instruction *I = CS.getInstruction();
+void SCCPSolver::handleCallResult(CallBase &CB) {
+ Function *F = CB.getCalledFunction();
- if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+ if (auto *II = dyn_cast<IntrinsicInst>(&CB)) {
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
- if (ValueState[I].isOverdefined())
+ if (ValueState[&CB].isOverdefined())
return;
- Value *CopyOf = I->getOperand(0);
- auto *PI = getPredicateInfoFor(I);
+ Value *CopyOf = CB.getOperand(0);
+ auto *PI = getPredicateInfoFor(&CB);
auto *PBranch = dyn_cast_or_null<PredicateBranch>(PI);
if (!PI || !PBranch) {
- mergeInValue(ValueState[I], I, getValueState(CopyOf));
+ mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf));
return;
}
// Everything below relies on the condition being a comparison.
auto *Cmp = dyn_cast<CmpInst>(PBranch->Condition);
if (!Cmp) {
- mergeInValue(ValueState[I], I, getValueState(CopyOf));
+ mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf));
return;
}
Value *CmpOp0 = Cmp->getOperand(0);
Value *CmpOp1 = Cmp->getOperand(1);
if (CopyOf != CmpOp0 && CopyOf != CmpOp1) {
- mergeInValue(ValueState[I], I, getValueState(CopyOf));
+ mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf));
return;
}
@@ -1253,7 +1248,7 @@ void SCCPSolver::handleCallResult(CallSite CS) {
// Wait until CmpOp1 is resolved.
if (getValueState(CmpOp1).isUnknown()) {
- addAdditionalUser(CmpOp1, I);
+ addAdditionalUser(CmpOp1, &CB);
return;
}
@@ -1261,7 +1256,7 @@ void SCCPSolver::handleCallResult(CallSite CS) {
Pred = CmpInst::getInversePredicate(Pred);
ValueLatticeElement CondVal = getValueState(CmpOp1);
- ValueLatticeElement &IV = ValueState[I];
+ ValueLatticeElement &IV = ValueState[&CB];
ValueLatticeElement OriginalVal = getValueState(CopyOf);
if (CondVal.isConstantRange() || OriginalVal.isConstantRange()) {
auto NewCR =
@@ -1280,7 +1275,7 @@ void SCCPSolver::handleCallResult(CallSite CS) {
DL.getTypeSizeInBits(CopyOf->getType()));
NewCR = NewCR.intersectWith(OriginalCR);
- addAdditionalUser(CmpOp1, I);
+ addAdditionalUser(CmpOp1, &CB);
// TODO: Actually filp MayIncludeUndef for the created range to false,
// once most places in the optimizer respect the branches on
// undef/poison are UB rule. The reason why the new range cannot be
@@ -1291,18 +1286,18 @@ void SCCPSolver::handleCallResult(CallSite CS) {
// i32, %a, i32_max). For the latter overdefined/empty range will be
// inferred, but the branch will get folded accordingly anyways.
mergeInValue(
- IV, I,
+ IV, &CB,
ValueLatticeElement::getRange(NewCR, /*MayIncludeUndef=*/true));
return;
} else if (Pred == CmpInst::ICMP_EQ && CondVal.isConstant()) {
// For non-integer values or integer constant expressions, only
// propagate equal constants.
- addAdditionalUser(CmpOp1, I);
- mergeInValue(IV, I, CondVal);
+ addAdditionalUser(CmpOp1, &CB);
+ mergeInValue(IV, &CB, CondVal);
return;
}
- return (void)mergeInValue(IV, I, getValueState(CopyOf));
+ return (void)mergeInValue(IV, &CB, getValueState(CopyOf));
}
}
@@ -1310,25 +1305,25 @@ void SCCPSolver::handleCallResult(CallSite CS) {
// are not doing interprocedural analysis or the callee is indirect, or is
// external. Handle these cases first.
if (!F || F->isDeclaration())
- return handleCallOverdefined(CS);
+ return handleCallOverdefined(CB);
// If this is a single/zero retval case, see if we're tracking the function.
if (auto *STy = dyn_cast<StructType>(F->getReturnType())) {
if (!MRVFunctionsTracked.count(F))
- return handleCallOverdefined(CS); // Not tracking this callee.
+ return handleCallOverdefined(CB); // Not tracking this callee.
// If we are tracking this callee, propagate the result of the function
// into this call site.
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
- mergeInValue(getStructValueState(I, i), I,
+ mergeInValue(getStructValueState(&CB, i), &CB,
TrackedMultipleRetVals[std::make_pair(F, i)]);
} else {
auto TFRVI = TrackedRetVals.find(F);
if (TFRVI == TrackedRetVals.end())
- return handleCallOverdefined(CS); // Not tracking this callee.
+ return handleCallOverdefined(CB); // Not tracking this callee.
// If so, propagate the return value of the callee into this call result.
- mergeInValue(I, TFRVI->second);
+ mergeInValue(&CB, TFRVI->second);
}
}
@@ -1413,8 +1408,8 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// Only a few things that can be structs matter for undef.
// Tracked calls must never be marked overdefined in ResolvedUndefsIn.
- if (CallSite CS = CallSite(&I))
- if (Function *F = CS.getCalledFunction())
+ if (auto *CB = dyn_cast<CallBase>(&I))
+ if (Function *F = CB->getCalledFunction())
if (MRVFunctionsTracked.count(F))
continue;
@@ -1441,8 +1436,8 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
// 2. It could be constant-foldable.
// Because of the way we solve return values, tracked calls must
// never be marked overdefined in ResolvedUndefsIn.
- if (CallSite CS = CallSite(&I))
- if (Function *F = CS.getCalledFunction())
+ if (auto *CB = dyn_cast<CallBase>(&I))
+ if (Function *F = CB->getCalledFunction())
if (TrackedRetVals.count(F))
continue;
@@ -1572,8 +1567,7 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
// unless the call itself can be removed
CallInst *CI = dyn_cast<CallInst>(V);
if (CI && CI->isMustTailCall() && !CI->isSafeToRemove()) {
- CallSite CS(CI);
- Function *F = CS.getCalledFunction();
+ Function *F = CI->getCalledFunction();
// Don't zap returns of the callee
if (F)
@@ -1736,7 +1730,7 @@ static void findReturnsToZap(Function &F,
// uses (like blockaddresses) could stuck around, without being
// used in the underlying IR, meaning we do not have lattice
// values for them.
- if (!CallSite(U))
+ if (!isa<CallBase>(U))
return true;
if (U->getType()->isStructTy()) {
return all_of(Solver.getStructLatticeValueFor(U),
More information about the llvm-commits
mailing list