13#ifndef LLVM_TRANSFORMS_UTILS_EVALUATOR_H
14#define LLVM_TRANSFORMS_UTILS_EVALUATOR_H
31class TargetLibraryInfo;
38 struct MutableAggregate;
50 MutableValue(
const MutableValue &) =
delete;
51 MutableValue(MutableValue &&
Other) {
55 ~MutableValue() { clear(); }
57 Type *getType()
const {
58 if (
auto *
C = dyn_cast_if_present<Constant *>(Val))
60 return cast<MutableAggregate *>(Val)->Ty;
64 if (
auto *
C = dyn_cast_if_present<Constant *>(Val))
66 return cast<MutableAggregate *>(Val)->toConstant();
73 struct MutableAggregate {
77 MutableAggregate(
Type *Ty) : Ty(Ty) {}
84 ValueStack.emplace_back();
88 for (
auto &Tmp : AllocaTmps)
92 if (!Tmp->use_empty())
104 for (
const auto &Pair : MutatedMemory)
105 Result[Pair.first] = Pair.second.toConstant();
115 bool &StrippedPointerCastsForAliasAnalysis);
118 if (
Constant *CV = dyn_cast<Constant>(V))
return CV;
119 Constant *R = ValueStack.back().lookup(V);
120 assert(R &&
"Reference to an uncomputed value!");
124 void setVal(Value *V, Constant *
C) {
125 ValueStack.back()[V] =
C;
129 Constant *castCallResultIfNeeded(Type *ReturnType, Constant *RV);
132 Function *getCalleeWithFormalArgs(CallBase &CB,
133 SmallVectorImpl<Constant *> &Formals);
137 bool getFormalParams(CallBase &CB, Function *
F,
138 SmallVectorImpl<Constant *> &Formals);
140 Constant *ComputeLoadResult(Constant *
P, Type *Ty);
141 Constant *ComputeLoadResult(GlobalVariable *GV, Type *Ty,
147 std::deque<DenseMap<Value*, Constant*>> ValueStack;
151 SmallVector<Function*, 4> CallStack;
156 DenseMap<GlobalVariable *, MutableValue> MutatedMemory;
161 SmallVector<std::unique_ptr<GlobalVariable>, 32> AllocaTmps;
165 SmallPtrSet<GlobalVariable*, 8> Invariants;
169 SmallPtrSet<Constant*, 8> SimpleConstants;
171 const DataLayout &DL;
172 const TargetLibraryInfo *TLI;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
This class evaluates LLVM IR, producing the Constant representing each SSA instruction.
DenseMap< GlobalVariable *, Constant * > getMutatedInitializers() const
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.
const SmallPtrSetImpl< GlobalVariable * > & getInvariants() const
Evaluator(const DataLayout &DL, const TargetLibraryInfo *TLI)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)