LLVM: include/llvm/Transforms/Utils/Evaluator.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_TRANSFORMS_UTILS_EVALUATOR_H
14#define LLVM_TRANSFORMS_UTILS_EVALUATOR_H
15
22#include
23#include
24#include
25
26namespace llvm {
27
32
33
34
35
36
38 struct MutableAggregate;
39
40
41
42
43 class MutableValue {
45 void clear();
46 bool makeMutable();
47
48 public:
49 MutableValue(Constant *C) { Val = C; }
50 MutableValue(const MutableValue &) = delete;
51 MutableValue(MutableValue &&Other) {
53 Other.Val = nullptr;
54 }
55 ~MutableValue() { clear(); }
56
59 return C->getType();
61 }
62
63 Constant *toConstant() const {
65 return C;
67 }
68
71 };
72
73 struct MutableAggregate {
76
77 MutableAggregate(Type *Ty) : Ty(Ty) {}
79 };
80
81public:
83 : DL(DL), TLI(TLI) {
84 ValueStack.emplace_back();
85 }
86
88 for (auto &Tmp : AllocaTmps)
89
90
91
92 if (!Tmp->use_empty())
94 }
95
96
97
98
101
104 for (const auto &Pair : MutatedMemory)
105 Result[Pair.first] = Pair.second.toConstant();
106 return Result;
107 }
108
110 return Invariants;
111 }
112
113private:
115 bool &StrippedPointerCastsForAliasAnalysis);
116
119 Constant *R = ValueStack.back().lookup(V);
120 assert(R && "Reference to an uncomputed value!");
121 return R;
122 }
123
124 void setVal(Value *V, Constant *C) {
125 ValueStack.back()[V] = C;
126 }
127
128
129 Function *getCalleeWithFormalArgs(CallBase &CB,
130 SmallVectorImpl<Constant *> &Formals);
131
132
133
134 bool getFormalParams(CallBase &CB, Function *F,
135 SmallVectorImpl<Constant *> &Formals);
136
137 Constant *ComputeLoadResult(Constant *P, Type *Ty);
138 Constant *ComputeLoadResult(GlobalVariable *GV, Type *Ty,
139 const APInt &Offset);
140
141
142
143
144 std::deque<DenseMap<Value*, Constant*>> ValueStack;
145
146
147
149
150
151
152
153 DenseMap<GlobalVariable *, MutableValue> MutatedMemory;
154
155
156
157
159
160
161
162 SmallPtrSet<GlobalVariable*, 8> Invariants;
163
164
165
166 SmallPtrSet<Constant*, 8> SimpleConstants;
167
168 const DataLayout &DL;
169 const TargetLibraryInfo *TLI;
170};
171
172}
173
174#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseMap class.
static bool getVal(MDTuple *MD, const char *Key, uint64_t &Val)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
Class for arbitrary precision integers.
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is an important base class in LLVM.
static LLVM_ABI 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.
DenseMap< GlobalVariable *, Constant * > getMutatedInitializers() const
Definition Evaluator.h:102
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
Definition Evaluator.h:109
~Evaluator()
Definition Evaluator.h:87
Evaluator(const DataLayout &DL, const TargetLibraryInfo *TLI)
Definition Evaluator.h:82
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present - Functionally identical to dyn_cast, except that a null (or none in the case ...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.