class Evaluator

Declaration

class Evaluator { /* full declaration omitted */ };

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.

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:37

Member Variables

private std::deque<DenseMap<Value*, Constant*>> ValueStack
As we compute SSA register values, we store their contents here. The back of the deque contains the current function and the stack contains the values in the calling frames.
private SmallVector<llvm::Function*, 4> CallStack
This is used to detect recursion. In pathological situations we could hit exponential behavior, but at least there is nothing unbounded.
private DenseMap<llvm::GlobalVariable*, llvm::Evaluator::MutableValue> MutatedMemory
For each store we execute, we update this map. Loads check this to get the most up-to-date value. If evaluation is successful, this state is committed to the process.
private SmallVector<std::unique_ptr<GlobalVariable>, 32> AllocaTmps
To 'execute' an alloca, we create a temporary global variable to represent its body. This vector is needed so we can delete the temporary globals when we are done.
private SmallPtrSet<llvm::GlobalVariable*, 8> Invariants
These global variables have been marked invariant by the static constructor.
private SmallPtrSet<llvm::Constant*, 8> SimpleConstants
These are constants we have checked and know to be simple enough to live in a static initializer of a global.
private const llvm::DataLayout& DL
private const llvm::TargetLibraryInfo* TLI

Method Overview

  • private llvm::Constant * ComputeLoadResult(llvm::Constant * P, llvm::Type * Ty)
  • private llvm::Constant * ComputeLoadResult(llvm::GlobalVariable * GV, llvm::Type * Ty, const llvm::APInt & Offset)
  • private bool EvaluateBlock(BasicBlock::iterator CurInst, llvm::BasicBlock *& NextBB, bool & StrippedPointerCastsForAliasAnalysis)
  • public bool EvaluateFunction(llvm::Function * F, llvm::Constant *& RetVal, const SmallVectorImpl<llvm::Constant *> & ActualArgs)
  • public Evaluator(const llvm::DataLayout & DL, const llvm::TargetLibraryInfo * TLI)
  • private llvm::Constant * castCallResultIfNeeded(llvm::Type * ReturnType, llvm::Constant * RV)
  • private llvm::Function * getCalleeWithFormalArgs(llvm::CallBase & CB, SmallVectorImpl<llvm::Constant *> & Formals)
  • private bool getFormalParams(llvm::CallBase & CB, llvm::Function * F, SmallVectorImpl<llvm::Constant *> & Formals)
  • public const SmallPtrSetImpl<llvm::GlobalVariable *> & getInvariants() const
  • public DenseMap<llvm::GlobalVariable *, llvm::Constant *> getMutatedInitializers() const
  • private llvm::Constant * getVal(llvm::Value * V)
  • private void setVal(llvm::Value * V, llvm::Constant * C)
  • public ~Evaluator()

Methods

llvm::Constant* ComputeLoadResult(
    llvm::Constant* P,
    llvm::Type* Ty)

Description

Return the value that would be computed by a load from P after the stores reflected by 'memory' have been performed. If we can't decide, return null.

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:140

Parameters

llvm::Constant* P
llvm::Type* Ty

llvm::Constant* ComputeLoadResult(
    llvm::GlobalVariable* GV,
    llvm::Type* Ty,
    const llvm::APInt& Offset)

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:141

Parameters

llvm::GlobalVariable* GV
llvm::Type* Ty
const llvm::APInt& Offset

bool EvaluateBlock(
    BasicBlock::iterator CurInst,
    llvm::BasicBlock*& NextBB,
    bool& StrippedPointerCastsForAliasAnalysis)

Description

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. StrippedPointerCastsForAliasAnalysis is set to true if we looked through pointer casts to evaluate something.

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:114

Parameters

BasicBlock::iterator CurInst
llvm::BasicBlock*& NextBB
bool& StrippedPointerCastsForAliasAnalysis

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

Description

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.

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:99

Parameters

llvm::Function* F
llvm::Constant*& RetVal
const SmallVectorImpl<llvm::Constant*>& ActualArgs

Evaluator(const llvm::DataLayout& DL,
          const llvm::TargetLibraryInfo* TLI)

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:82

Parameters

const llvm::DataLayout& DL
const llvm::TargetLibraryInfo* TLI

llvm::Constant* castCallResultIfNeeded(
    llvm::Type* ReturnType,
    llvm::Constant* RV)

Description

Casts call result to a type of bitcast call expression

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:129

Parameters

llvm::Type* ReturnType
llvm::Constant* RV

llvm::Function* getCalleeWithFormalArgs(
    llvm::CallBase& CB,
    SmallVectorImpl<llvm::Constant*>& Formals)

Description

Given call site return callee and list of its formal arguments

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:132

Parameters

llvm::CallBase& CB
SmallVectorImpl<llvm::Constant*>& Formals

bool getFormalParams(
    llvm::CallBase& CB,
    llvm::Function* F,
    SmallVectorImpl<llvm::Constant*>& Formals)

Description

Given call site and callee returns list of callee formal argument values converting them when necessary

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:137

Parameters

llvm::CallBase& CB
llvm::Function* F
SmallVectorImpl<llvm::Constant*>& Formals

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

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:109

DenseMap<llvm::GlobalVariable*, llvm::Constant*>
getMutatedInitializers() const

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:102

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

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:117

Parameters

llvm::Value* V

void setVal(llvm::Value* V, llvm::Constant* C)

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:124

Parameters

llvm::Value* V
llvm::Constant* C

~Evaluator()

Declared at: llvm/include/llvm/Transforms/Utils/Evaluator.h:87