#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 <cassert>
ValueStack.back()[V] = C;
}
- /// Given call site return callee and list of its formal arguments
- Function *getCalleeWithFormalArgs(CallSite &CS,
- SmallVector<Constant *, 8> &Formals);
-
- /// Given call site and callee returns list of callee formal argument
- /// values converting them when necessary
- bool getFormalParams(CallSite &CS, Function *F,
- SmallVector<Constant *, 8> &Formals);
-
/// Casts call result to a type of bitcast call expression
Constant *castCallResultIfNeeded(Value *CallExpr, Constant *RV);
}
private:
+ /// Given call site return callee and list of its formal arguments
+ Function *getCalleeWithFormalArgs(CallBase &CB,
+ SmallVectorImpl<Constant *> &Formals);
+
+ /// Given call site and callee returns list of callee formal argument
+ /// values converting them when necessary
+ bool getFormalParams(CallBase &CB, Function *F,
+ SmallVectorImpl<Constant *> &Formals);
+
Constant *ComputeLoadResult(Constant *P);
/// As we compute SSA register values, we store their contents here. The back
#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"
}
Function *
-Evaluator::getCalleeWithFormalArgs(CallSite &CS,
- SmallVector<Constant *, 8> &Formals) {
- auto *V = CS.getCalledValue();
+Evaluator::getCalleeWithFormalArgs(CallBase &CB,
+ SmallVectorImpl<Constant *> &Formals) {
+ 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<ConstantExpr>(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<Function>(
ConstantFoldLoadThroughBitcast(CE, CE->getOperand(0)->getType(), DL));
}
-bool Evaluator::getFormalParams(CallSite &CS, Function *F,
- SmallVector<Constant *, 8> &Formals) {
+bool Evaluator::getFormalParams(CallBase &CB, Function *F,
+ SmallVectorImpl<Constant *> &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);
InstResult = AllocaTmps.back().get();
LLVM_DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n");
} else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
- CallSite CS(&*CurInst);
+ CallBase &CB = *cast<CallBase>(&*CurInst);
// Debug info can safely be ignored here.
- if (isa<DbgInfoIntrinsic>(CS.getInstruction())) {
+ if (isa<DbgInfoIntrinsic>(CB)) {
LLVM_DEBUG(dbgs() << "Ignoring debug info.\n");
++CurInst;
continue;
}
// Cannot handle inline asm.
- if (isa<InlineAsm>(CS.getCalledValue())) {
+ if (isa<InlineAsm>(CB.getCalledValue())) {
LLVM_DEBUG(dbgs() << "Found inline asm, can not evaluate.\n");
return false;
}
- if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
+ if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&CB)) {
if (MemSetInst *MSI = dyn_cast<MemSetInst>(II)) {
if (MSI->isVolatile()) {
LLVM_DEBUG(dbgs() << "Can not optimize a volatile memset "
// Resolve function pointers.
SmallVector<Constant *, 8> 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.
if (Callee->isDeclaration()) {
// If this is a function we can constant fold, do it.
- if (Constant *C = ConstantFoldCall(cast<CallBase>(CS.getInstruction()),
- Callee, Formals, TLI)) {
- InstResult = castCallResultIfNeeded(CS.getCalledValue(), C);
+ if (Constant *C = ConstantFoldCall(&CB, Callee, Formals, TLI)) {
+ InstResult = castCallResultIfNeeded(CB.getCalledValue(), C);
if (!InstResult)
return false;
LLVM_DEBUG(dbgs() << "Constant folded function call. Result: "
return false;
}
ValueStack.pop_back();
- InstResult = castCallResultIfNeeded(CS.getCalledValue(), RetVal);
+ InstResult = castCallResultIfNeeded(CB.getCalledValue(), RetVal);
if (RetVal && !InstResult)
return false;