LLVM
8.0.1
|
This class evaluates LLVM IR, producing the Constant representing each SSA instruction. More...
#include "llvm/Transforms/Utils/Evaluator.h"
Public Member Functions | |
Evaluator (const DataLayout &DL, const TargetLibraryInfo *TLI) | |
~Evaluator () | |
bool | EvaluateFunction (Function *F, Constant *&RetVal, const SmallVectorImpl< Constant *> &ActualArgs) |
Evaluate a call to function F, returning true if successful, false if we can't evaluate it. More... | |
bool | EvaluateBlock (BasicBlock::iterator CurInst, BasicBlock *&NextBB) |
Evaluate all instructions in block BB, returning true if successful, false if we can't evaluate it. More... | |
Constant * | getVal (Value *V) |
void | setVal (Value *V, Constant *C) |
Function * | getCalleeWithFormalArgs (CallSite &CS, SmallVector< Constant *, 8 > &Formals) |
Given call site return callee and list of its formal arguments. More... | |
bool | getFormalParams (CallSite &CS, Function *F, SmallVector< Constant *, 8 > &Formals) |
Given call site and callee returns list of callee formal argument values converting them when necessary. More... | |
Constant * | castCallResultIfNeeded (Value *CallExpr, Constant *RV) |
Casts call result to a type of bitcast call expression. More... | |
const DenseMap< Constant *, Constant * > & | getMutatedMemory () const |
const SmallPtrSetImpl< GlobalVariable * > & | getInvariants () const |
This class evaluates LLVM IR, producing the Constant representing each SSA instruction.
Changes to global variables are stored in a mapping that can be iterated over after the evaluation is complete. Once an evaluation call fails, the evaluation object should not be reused.
Definition at line 39 of file Evaluator.h.
|
inline |
Definition at line 41 of file Evaluator.h.
|
inline |
Definition at line 46 of file Evaluator.h.
References EvaluateBlock(), EvaluateFunction(), F(), and llvm::Constant::getNullValue().
Casts call result to a type of bitcast call expression.
If call expression contains bitcast then we may need to cast evaluated return value to a type of the call expression.
Definition at line 274 of file Evaluator.cpp.
References llvm::ConstantFoldLoadThroughBitcast(), llvm::dbgs(), llvm::dyn_cast(), llvm::ConstantExpr::getOpcode(), llvm::Type::getPointerElementType(), llvm::Value::getType(), and LLVM_DEBUG.
Referenced by EvaluateBlock(), and setVal().
bool Evaluator::EvaluateBlock | ( | BasicBlock::iterator | CurInst, |
BasicBlock *& | NextBB | ||
) |
Evaluate all instructions in block BB, returning true if successful, false if we can't evaluate it.
NewBB returns the next BB that control flows into, or null upon return.
Definition at line 291 of file Evaluator.cpp.
References llvm::Intrinsic::assume, C, Callee, castCallResultIfNeeded(), llvm::ConstantFoldCall(), llvm::ConstantFoldConstant(), llvm::ConstantFoldLoadThroughBitcast(), llvm::dbgs(), llvm::dyn_cast(), EvaluateFunction(), GEP, llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::ConstantExpr::get(), llvm::UndefValue::get(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledValue(), getCalleeWithFormalArgs(), llvm::ConstantExpr::getCast(), llvm::ConstantExpr::getCompare(), llvm::Type::getContext(), llvm::ConstantExpr::getExtractValue(), llvm::Function::getFunctionType(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getInsertValue(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::APInt::getLimitedValue(), llvm::Value::getName(), llvm::ConstantExpr::getSelect(), llvm::Value::getType(), llvm::DataLayout::getTypeStoreSize(), getVal(), llvm::ConstantInt::getValue(), llvm::ConstantInt::getZExtValue(), llvm::GlobalValue::InternalLinkage, llvm::Intrinsic::invariant_start, llvm::GlobalValue::isDeclaration(), llvm::GlobalValue::isInterposable(), llvm::ConstantInt::isMinusOne(), isSimpleEnoughPointerToCommit(), isSimpleEnoughValueToCommit(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm::GlobalValue::NotThreadLocal, P, llvm::SmallVectorTemplateBase< T, bool >::push_back(), setVal(), SI, llvm::Intrinsic::sideeffect, Size, and llvm::Value::stripPointerCasts().
Referenced by EvaluateFunction(), and ~Evaluator().
bool Evaluator::EvaluateFunction | ( | Function * | F, |
Constant *& | RetVal, | ||
const SmallVectorImpl< Constant *> & | ActualArgs | ||
) |
Evaluate a call to function F, returning true if successful, false if we can't evaluate it.
ActualArgs contains the formal arguments for the function.
Definition at line 645 of file Evaluator.cpp.
References llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::BasicBlock::begin(), llvm::dbgs(), llvm::dyn_cast(), E, EvaluateBlock(), llvm::Function::front(), llvm::PHINode::getIncomingValueForBlock(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::BasicBlock::getTerminator(), getVal(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::is_contained(), LLVM_DEBUG, and setVal().
Referenced by EvaluateBlock(), EvaluateStaticConstructor(), and ~Evaluator().
Function * Evaluator::getCalleeWithFormalArgs | ( | CallSite & | CS, |
SmallVector< Constant *, 8 > & | Formals | ||
) |
Given call site return callee and list of its formal arguments.
Definition at line 232 of file Evaluator.cpp.
References llvm::ConstantFoldLoadThroughBitcast(), llvm::dyn_cast(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledValue(), getFormalParams(), getFunction(), and getVal().
Referenced by EvaluateBlock(), and setVal().
bool Evaluator::getFormalParams | ( | CallSite & | CS, |
Function * | F, | ||
SmallVector< Constant *, 8 > & | Formals | ||
) |
Given call site and callee returns list of callee formal argument values converting them when necessary.
Definition at line 247 of file Evaluator.cpp.
References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::ConstantFoldLoadThroughBitcast(), llvm::dbgs(), llvm::Function::getFunctionType(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getNumArgOperands(), getVal(), LLVM_DEBUG, and llvm::SmallVectorTemplateBase< T >::push_back().
Referenced by getCalleeWithFormalArgs(), and setVal().
|
inline |
Definition at line 89 of file Evaluator.h.
Referenced by EvaluateStaticConstructor().
Definition at line 66 of file Evaluator.h.
References assert().
Referenced by EvaluateBlock(), EvaluateFunction(), getCalleeWithFormalArgs(), getFormalParams(), and getInitializer().
Definition at line 73 of file Evaluator.h.
References C, castCallResultIfNeeded(), getCalleeWithFormalArgs(), and getFormalParams().
Referenced by EvaluateBlock(), and EvaluateFunction().