diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp --- 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 @@ // propagate the call arguments. if (isa(I)) { for (User *U : I->users()) { - if (auto CS = CallSite(U)) - handleCallResult(CS); + if (auto *CB = dyn_cast(U)) + handleCallResult(*CB); } } else { for (User *U : I->users()) @@ -532,9 +531,9 @@ OperandChangedState(UI); } } - void handleCallOverdefined(CallSite CS); - void handleCallResult(CallSite CS); - void handleCallArguments(CallSite CS); + void handleCallOverdefined(CallBase &I); + void handleCallResult(CallBase &I); + void handleCallArguments(CallBase &I); private: friend class InstVisitor; @@ -569,20 +568,20 @@ 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 &I); void visitResumeInst (ResumeInst &I) { /*returns void*/ } void visitUnreachableInst(UnreachableInst &I) { /*returns void*/ } void visitFenceInst (FenceInst &I) { /*returns void*/ } @@ -1132,58 +1131,55 @@ markOverdefined(IV, &I); } -void SCCPSolver::visitCallSite(CallSite CS) { - handleCallResult(CS); - handleCallArguments(CS); +void SCCPSolver::visitCallBase(CallBase &I) { + handleCallResult(I); + handleCallArguments(I); } -void SCCPSolver::handleCallOverdefined(CallSite CS) { - Function *F = CS.getCalledFunction(); - Instruction *I = CS.getInstruction(); +void SCCPSolver::handleCallOverdefined(CallBase &I) { + Function *F = I.getCalledFunction(); // Void return and not tracking callee, just bail. - if (I->getType()->isVoidTy()) + if (I.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(CS.getInstruction()), F)) { + if (F && F->isDeclaration() && !I.getType()->isStructTy() && + canConstantFoldCallTo(&I, F)) { SmallVector Operands; - for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end(); AI != E; - ++AI) { + for (auto AI = I.arg_begin(), E = I.arg_end(); AI != E; ++AI) { if (AI->get()->getType()->isStructTy()) - return markOverdefined(I); // Can't handle struct args. + return markOverdefined(&I); // 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(&I); assert(isConstant(State) && "Unknown state!"); Operands.push_back(getConstant(State)); } - if (isOverdefined(getValueState(I))) - return (void)markOverdefined(I); + if (isOverdefined(getValueState(&I))) + return (void)markOverdefined(&I); // If we can constant fold this, mark the result of the call as a // constant. - if (Constant *C = ConstantFoldCall(cast(CS.getInstruction()), F, - Operands, &GetTLI(*F))) { + if (Constant *C = ConstantFoldCall(&I, F, Operands, &GetTLI(*F))) { // call -> undef. if (isa(C)) return; - return (void)markConstant(I, C); + return (void)markConstant(&I, C); } } // Otherwise, we don't know anything about this call, mark it overdefined. - return (void)markOverdefined(I); + return (void)markOverdefined(&I); } -void SCCPSolver::handleCallArguments(CallSite CS) { - Function *F = CS.getCalledFunction(); +void SCCPSolver::handleCallArguments(CallBase &I) { + Function *F = I.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 @@ MarkBlockExecutable(&F->front()); // Propagate information from this call site into the callee. - CallSite::arg_iterator CAI = CS.arg_begin(); + auto CAI = I.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::handleCallResult(CallSite CS) { - Function *F = CS.getCalledFunction(); - Instruction *I = CS.getInstruction(); +void SCCPSolver::handleCallResult(CallBase &I) { + Function *F = I.getCalledFunction(); - if (auto *II = dyn_cast(I)) { + if (auto *II = dyn_cast(&I)) { if (II->getIntrinsicID() == Intrinsic::ssa_copy) { - if (ValueState[I].isOverdefined()) + if (ValueState[&I].isOverdefined()) return; - Value *CopyOf = I->getOperand(0); - auto *PI = getPredicateInfoFor(I); + Value *CopyOf = I.getOperand(0); + auto *PI = getPredicateInfoFor(&I); auto *PBranch = dyn_cast_or_null(PI); if (!PI || !PBranch) { - mergeInValue(ValueState[I], I, getValueState(CopyOf)); + mergeInValue(ValueState[&I], &I, getValueState(CopyOf)); return; } // Everything below relies on the condition being a comparison. auto *Cmp = dyn_cast(PBranch->Condition); if (!Cmp) { - mergeInValue(ValueState[I], I, getValueState(CopyOf)); + mergeInValue(ValueState[&I], &I, 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[&I], &I, getValueState(CopyOf)); return; } @@ -1253,7 +1248,7 @@ // Wait until CmpOp1 is resolved. if (getValueState(CmpOp1).isUnknown()) { - addAdditionalUser(CmpOp1, I); + addAdditionalUser(CmpOp1, &I); return; } @@ -1261,7 +1256,7 @@ Pred = CmpInst::getInversePredicate(Pred); ValueLatticeElement CondVal = getValueState(CmpOp1); - ValueLatticeElement &IV = ValueState[I]; + ValueLatticeElement &IV = ValueState[&I]; ValueLatticeElement OriginalVal = getValueState(CopyOf); if (CondVal.isConstantRange() || OriginalVal.isConstantRange()) { auto NewCR = @@ -1280,7 +1275,7 @@ DL.getTypeSizeInBits(CopyOf->getType())); NewCR = NewCR.intersectWith(OriginalCR); - addAdditionalUser(CmpOp1, I); + addAdditionalUser(CmpOp1, &I); // 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 @@ // 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, &I, 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, &I); + mergeInValue(IV, &I, CondVal); return; } - return (void)mergeInValue(IV, I, getValueState(CopyOf)); + return (void)mergeInValue(IV, &I, getValueState(CopyOf)); } } @@ -1310,25 +1305,25 @@ // 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(I); // If this is a single/zero retval case, see if we're tracking the function. if (auto *STy = dyn_cast(F->getReturnType())) { if (!MRVFunctionsTracked.count(F)) - return handleCallOverdefined(CS); // Not tracking this callee. + return handleCallOverdefined(I); // 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(&I, i), &I, 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(I); // Not tracking this callee. // If so, propagate the return value of the callee into this call result. - mergeInValue(I, TFRVI->second); + mergeInValue(&I, TFRVI->second); } } @@ -1413,8 +1408,8 @@ // 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(&I)) + if (Function *F = CB->getCalledFunction()) if (MRVFunctionsTracked.count(F)) continue; @@ -1441,8 +1436,8 @@ // 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(&I)) + if (Function *F = CB->getCalledFunction()) if (TrackedRetVals.count(F)) continue; @@ -1572,8 +1567,7 @@ // unless the call itself can be removed CallInst *CI = dyn_cast(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 @@ // 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(U)) return true; if (U->getType()->isStructTy()) { return all_of(Solver.getStructLatticeValueFor(U),