LLVM  9.0.0svn
Public Member Functions | List of all members
llvm::Evaluator Class Reference

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...
 
ConstantgetVal (Value *V)
 
void setVal (Value *V, Constant *C)
 
FunctiongetCalleeWithFormalArgs (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...
 
ConstantcastCallResultIfNeeded (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
 

Detailed Description

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 38 of file Evaluator.h.

Constructor & Destructor Documentation

◆ Evaluator()

llvm::Evaluator::Evaluator ( const DataLayout DL,
const TargetLibraryInfo TLI 
)
inline

Definition at line 40 of file Evaluator.h.

◆ ~Evaluator()

llvm::Evaluator::~Evaluator ( )
inline

Definition at line 45 of file Evaluator.h.

References EvaluateBlock(), EvaluateFunction(), F(), and llvm::Constant::getNullValue().

Member Function Documentation

◆ castCallResultIfNeeded()

Constant * Evaluator::castCallResultIfNeeded ( Value CallExpr,
Constant RV 
)

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 311 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().

◆ EvaluateBlock()

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 328 of file Evaluator.cpp.

References C, Callee, castCallResultIfNeeded(), llvm::ConstantFoldCall(), llvm::ConstantFoldConstant(), llvm::ConstantFoldLoadThroughBitcast(), llvm::dbgs(), evaluateBitcastFromPtr(), EvaluateFunction(), GEP, llvm::ConstantExpr::get(), llvm::UndefValue::get(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getCalledValue(), getCalleeWithFormalArgs(), llvm::ConstantExpr::getCast(), llvm::ConstantExpr::getCompare(), llvm::ConstantExpr::getExtractValue(), llvm::Function::getFunctionType(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getInsertValue(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getInstruction(), llvm::APInt::getLimitedValue(), llvm::Value::getName(), llvm::ConstantExpr::getSelect(), llvm::Value::getType(), llvm::DataLayout::getTypeStoreSize(), getVal(), llvm::ConstantInt::getValue(), llvm::GlobalValue::InternalLinkage, 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(), SI, Size, and llvm::Constant::stripPointerCasts().

Referenced by EvaluateFunction(), and ~Evaluator().

◆ EvaluateFunction()

bool Evaluator::EvaluateFunction ( Function F,
Constant *&  RetVal,
const SmallVectorImpl< Constant *> &  ActualArgs 
)

◆ getCalleeWithFormalArgs()

Function * Evaluator::getCalleeWithFormalArgs ( CallSite CS,
SmallVector< Constant *, 8 > &  Formals 
)

◆ getFormalParams()

bool Evaluator::getFormalParams ( CallSite CS,
Function F,
SmallVector< Constant *, 8 > &  Formals 
)

◆ getInvariants()

const SmallPtrSetImpl<GlobalVariable*>& llvm::Evaluator::getInvariants ( ) const
inline

Definition at line 92 of file Evaluator.h.

References P.

Referenced by EvaluateStaticConstructor().

◆ getMutatedMemory()

const DenseMap<Constant*, Constant*>& llvm::Evaluator::getMutatedMemory ( ) const
inline

Definition at line 88 of file Evaluator.h.

Referenced by EvaluateStaticConstructor().

◆ getVal()

Constant* llvm::Evaluator::getVal ( Value V)
inline

Definition at line 65 of file Evaluator.h.

References assert().

Referenced by EvaluateBlock(), EvaluateFunction(), getCalleeWithFormalArgs(), and getFormalParams().

◆ setVal()

void llvm::Evaluator::setVal ( Value V,
Constant C 
)
inline

Definition at line 72 of file Evaluator.h.

References C, castCallResultIfNeeded(), getCalleeWithFormalArgs(), and getFormalParams().

Referenced by EvaluateFunction().


The documentation for this class was generated from the following files: