diff --git a/llvm/include/llvm/Transforms/Utils/Evaluator.h b/llvm/include/llvm/Transforms/Utils/Evaluator.h --- a/llvm/include/llvm/Transforms/Utils/Evaluator.h +++ b/llvm/include/llvm/Transforms/Utils/Evaluator.h @@ -17,8 +17,8 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CallSite.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/Value.h" #include "llvm/Support/Casting.h" #include @@ -73,15 +73,6 @@ ValueStack.back()[V] = C; } - /// Given call site return callee and list of its formal arguments - Function *getCalleeWithFormalArgs(CallSite &CS, - SmallVector &Formals); - - /// Given call site and callee returns list of callee formal argument - /// values converting them when necessary - bool getFormalParams(CallSite &CS, Function *F, - SmallVector &Formals); - /// Casts call result to a type of bitcast call expression Constant *castCallResultIfNeeded(Value *CallExpr, Constant *RV); @@ -94,6 +85,15 @@ } private: + /// Given call site return callee and list of its formal arguments + Function *getCalleeWithFormalArgs(CallBase &CB, + SmallVector &Formals); + + /// Given call site and callee returns list of callee formal argument + /// values converting them when necessary + bool getFormalParams(CallBase &CB, Function *F, + SmallVector &Formals); + Constant *ComputeLoadResult(Constant *P); /// As we compute SSA register values, we store their contents here. The back diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp --- a/llvm/lib/Transforms/Utils/Evaluator.cpp +++ b/llvm/lib/Transforms/Utils/Evaluator.cpp @@ -17,7 +17,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/ConstantFolding.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" @@ -265,33 +264,33 @@ } Function * -Evaluator::getCalleeWithFormalArgs(CallSite &CS, +Evaluator::getCalleeWithFormalArgs(CallBase &CB, SmallVector &Formals) { - auto *V = CS.getCalledValue(); + auto *V = CB.getCalledValue(); if (auto *Fn = getFunction(getVal(V))) - return getFormalParams(CS, Fn, Formals) ? Fn : nullptr; + return getFormalParams(CB, Fn, Formals) ? Fn : nullptr; auto *CE = dyn_cast(V); if (!CE || CE->getOpcode() != Instruction::BitCast || - !getFormalParams(CS, getFunction(CE->getOperand(0)), Formals)) + !getFormalParams(CB, getFunction(CE->getOperand(0)), Formals)) return nullptr; return dyn_cast( ConstantFoldLoadThroughBitcast(CE, CE->getOperand(0)->getType(), DL)); } -bool Evaluator::getFormalParams(CallSite &CS, Function *F, +bool Evaluator::getFormalParams(CallBase &CB, Function *F, SmallVector &Formals) { if (!F) return false; auto *FTy = F->getFunctionType(); - if (FTy->getNumParams() > CS.getNumArgOperands()) { + if (FTy->getNumParams() > CB.getNumArgOperands()) { LLVM_DEBUG(dbgs() << "Too few arguments for function.\n"); return false; } - auto ArgI = CS.arg_begin(); + auto ArgI = CB.arg_begin(); for (auto ParI = FTy->param_begin(), ParE = FTy->param_end(); ParI != ParE; ++ParI) { auto *ArgC = ConstantFoldLoadThroughBitcast(getVal(*ArgI), *ParI, DL); @@ -477,22 +476,22 @@ InstResult = AllocaTmps.back().get(); LLVM_DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n"); } else if (isa(CurInst) || isa(CurInst)) { - CallSite CS(&*CurInst); + CallBase &CB = *cast(&*CurInst); // Debug info can safely be ignored here. - if (isa(CS.getInstruction())) { + if (isa(CB)) { LLVM_DEBUG(dbgs() << "Ignoring debug info.\n"); ++CurInst; continue; } // Cannot handle inline asm. - if (isa(CS.getCalledValue())) { + if (isa(CB.getCalledValue())) { LLVM_DEBUG(dbgs() << "Found inline asm, can not evaluate.\n"); return false; } - if (IntrinsicInst *II = dyn_cast(CS.getInstruction())) { + if (IntrinsicInst *II = dyn_cast(&CB)) { if (MemSetInst *MSI = dyn_cast(II)) { if (MSI->isVolatile()) { LLVM_DEBUG(dbgs() << "Can not optimize a volatile memset " @@ -560,7 +559,7 @@ // Resolve function pointers. SmallVector Formals; - Function *Callee = getCalleeWithFormalArgs(CS, Formals); + Function *Callee = getCalleeWithFormalArgs(CB, Formals); if (!Callee || Callee->isInterposable()) { LLVM_DEBUG(dbgs() << "Can not resolve function pointer.\n"); return false; // Cannot resolve. @@ -568,9 +567,9 @@ if (Callee->isDeclaration()) { // If this is a function we can constant fold, do it. - if (Constant *C = ConstantFoldCall(cast(CS.getInstruction()), - Callee, Formals, TLI)) { - InstResult = castCallResultIfNeeded(CS.getCalledValue(), C); + if (Constant *C = + ConstantFoldCall(cast(&CB), Callee, Formals, TLI)) { + InstResult = castCallResultIfNeeded(CB.getCalledValue(), C); if (!InstResult) return false; LLVM_DEBUG(dbgs() << "Constant folded function call. Result: " @@ -593,7 +592,7 @@ return false; } ValueStack.pop_back(); - InstResult = castCallResultIfNeeded(CS.getCalledValue(), RetVal); + InstResult = castCallResultIfNeeded(CB.getCalledValue(), RetVal); if (RetVal && !InstResult) return false;