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 Function *getCalleeWithFormalArgs(CallBase &CB,
130 SmallVectorImpl<Constant *> &Formals);
134 bool getFormalParams(CallBase &CB, Function *
F,
135 SmallVectorImpl<Constant *> &Formals);
137 Constant *ComputeLoadResult(Constant *
P, Type *Ty);
138 Constant *ComputeLoadResult(GlobalVariable *GV, Type *Ty,
144 std::deque<DenseMap<Value*, Constant*>> ValueStack;
148 SmallVector<Function*, 4> CallStack;
153 DenseMap<GlobalVariable *, MutableValue> MutatedMemory;
158 SmallVector<std::unique_ptr<GlobalVariable>, 32> AllocaTmps;
162 SmallPtrSet<GlobalVariable*, 8> Invariants;
166 SmallPtrSet<Constant*, 8> SimpleConstants;
168 const DataLayout &DL;
169 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)