LLVM 24.0.0git
Context.h
Go to the documentation of this file.
1//===--- Context.h - State Tracking for llubi -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_TOOLS_LLUBI_CONTEXT_H
10#define LLVM_TOOLS_LLUBI_CONTEXT_H
11
12#include "Value.h"
13#include "llvm/ADT/DenseMap.h"
16#include "llvm/IR/FPEnv.h"
17#include "llvm/IR/Module.h"
18#include "llvm/IR/Operator.h"
20#include <map>
21#include <optional>
22#include <random>
23
24namespace llvm::ubi {
25
31
40
42 // This memory object is accessible.
43 // Valid transitions:
44 // -> Dead (after the end of lifetime of an alloca)
45 // -> Freed (after free is called on a heap object)
47 // This memory object is out of lifetime. Its contents are poison. Loads and
48 // memory transfers from it are allowed and propagate poison, stores to it
49 // cause immediate UB, and non-accessing operations such as getelementptr are
50 // allowed.
51 // Valid transition:
52 // -> Alive (after the start of lifetime of an alloca)
54 // This heap memory object has been freed. Any access to it
55 // causes immediate UB. Like dead objects, it is still possible to
56 // perform operations that do not access its content.
58};
59
61 NonDeterministic, // Each use of the undef value can yield different results.
62 Zero, // All uses of the undef value yield zero.
63};
64
66 NonDeterministic, // Non-deterministically choose from valid NaN results
67 PreferredNaN, // The quiet bit is set and the payload is all-zero
68 QuietingNaN, // The quiet bit is set and the payload is copied from any input
69 // operand that is a NaN
70 UnchangedNaN, // The quiet bit and payload are copied from any input operand
71 // that is a NaN
72 TargetSpecificNaN // The quiet bit is set and the payload is picked from a
73 // known target-specific set of "extra" possible NaN
74 // payloads
75};
76
78 enum class ProgramExitKind {
79 // Program exited via a normal return
81 // Program exited with an interpreter error (UB/Unsupported
82 // instruction/etc.)
84 // Program exited via a call to exit()
86 // Program exited via a call to abort()
88 // Program exited via a call to terminate()
90 };
91
94
97
103};
104
105class MemoryObject : public RefCountedBase<MemoryObject> {
106 uint64_t Address;
107 uint64_t Size;
109 StringRef Name;
110 unsigned AS;
111
112 MemoryObjectState State;
113 MemAllocKind AllocKind;
114 bool IsConstant = false;
115 bool IsIRGlobalValue = false;
116 bool IsInaccessible = false;
117
118 // Tagged provenances related to this memory object.
119 // It is used to erasing the tags after the memory object is freed.
120 SmallVector<APInt> AssociatedTags;
121
122 friend class Context;
123
124public:
126 unsigned AS, MemInitKind InitKind,
127 MemAllocKind AllocKind, bool IsIRGlobalValue = false);
128 MemoryObject(const MemoryObject &) = delete;
133
134 uint64_t getAddress() const { return Address; }
135 uint64_t getSize() const { return Size; }
136 StringRef getName() const { return Name; }
137 unsigned getAddressSpace() const { return AS; }
138 MemoryObjectState getState() const { return State; }
139 void setState(MemoryObjectState S) { State = S; }
140 MemAllocKind getAllocKind() const { return AllocKind; }
141 bool isIRGlobalValue() const { return IsIRGlobalValue; }
142 bool isConstant() const { return IsConstant; }
143 void setIsConstant(bool C) { IsConstant = C; }
144 bool isInaccessible() const { return IsInaccessible; }
145 void setIsInaccessible(bool V) { IsInaccessible = V; }
146
147 bool inBounds(const APInt &NewAddr) const {
148 return NewAddr.uge(Address) && NewAddr.ule(Address + Size);
149 }
150
152 assert(Offset < Size && "Offset out of bounds");
153 return Bytes[Offset];
154 }
155 ArrayRef<Byte> getBytes() const { return Bytes; }
156 MutableArrayRef<Byte> getBytes() { return Bytes; }
157
158 LLVM_ABI bool isGlobal() const;
159 LLVM_ABI bool isStackAllocated() const;
160 LLVM_ABI bool isHeapAllocated() const;
161};
162
163/// An interface for handling events and managing outputs during interpretation.
164/// If the handler returns false from any of the methods, the interpreter will
165/// stop execution immediately.
167public:
168 virtual ~EventHandler() = default;
169
170 virtual bool onInstructionExecuted(Instruction &I, const AnyValue &Result) {
171 return true;
172 }
173 virtual void onError(StringRef Msg) {}
175 virtual void onImmediateUB(StringRef Msg) {}
176 virtual bool onBBJump(Instruction &I, BasicBlock &To) { return true; }
178 CallBase *CallSite) {
179 return true;
180 }
181 virtual bool onFunctionExit(Function &F, const AnyValue &RetVal) {
182 return true;
183 }
184 virtual void onProgramExit(const ProgramExitInfo &ExitInfo) {}
185 virtual bool onPrint(StringRef Msg) {
186 outs() << Msg;
187 outs().flush();
188 return true;
189 }
190};
191
192/// Endianness aware accessor for bytes.
193template <typename ArrayRefT> class BytesView {
194 ArrayRefT Bytes;
195 bool IsLittleEndian;
196
197public:
198 explicit BytesView(ArrayRefT Ref, bool IsLittleEndian)
199 : Bytes(Ref), IsLittleEndian(IsLittleEndian) {}
200 explicit BytesView(ArrayRefT Ref, const DataLayout &DL)
201 : BytesView(Ref, DL.isLittleEndian()) {}
202
203 auto &operator[](uint32_t Index) {
204 return Bytes[IsLittleEndian ? Index : Bytes.size() - 1 - Index];
205 }
206
207 size_t size() const { return Bytes.size(); }
208};
209
212
214 bool Cacheable;
215
216public:
217 MaterializedConstant(std::nullopt_t) : Cacheable(false) {}
219 : AnyValue(std::move(V)), Cacheable(Cacheable) {}
220
221 bool isCacheable() const { return Cacheable; }
222};
223
224/// The global context for the interpreter.
225/// It tracks global state such as heap memory objects and floating point
226/// environment.
227class Context {
228 // Module
229 LLVMContext &Ctx;
230 Module &M;
231 const AsmParserContext *ParserContext;
232 const DataLayout &DL;
233 const TargetLibraryInfoImpl TLIImpl;
234
235 // Configuration
236 uint64_t MaxMem = 0;
237 uint32_t VScale = 4;
238 uint32_t MaxSteps = 0;
239 uint32_t MaxStackDepth = 256;
240 bool Deterministic = false;
243 bool FusedMultiplyAdd = false;
244
245 std::mt19937_64 Rng;
246 /// Always returns a random APInt value. It is not controlled by
247 /// Deterministic.
248 APInt generateRandomAPInt(uint32_t BitWidth);
249
250 // Memory
251 uint64_t UsedMem = 0;
252 // The addresses of memory objects are monotonically increasing.
253 // For now we don't model the behavior of address reuse, which is common
254 // with stack coloring.
255 uint64_t AllocationBase = 8;
256 // All live memory objects.
258 // Mapping from tags to provenances. Tags are lazily generated when a
259 // pointer is captured by memory.
261 // Maintains a global list of 'exposed' provenances. This is used to convert
262 // an address back to a pointer with a previously exposed provenance. In
263 // theory the provenance is picked from all previously exposed provenances
264 // using angelic non-determinism. Since llubi is just an interpreter, we make
265 // two approximations:
266 // 1. Each address maps to at most one memory object during the execution of
267 // the program, as AllocationBase increases monotonically.
268 // 2. We maintain the set of exposed provenances. When ptrtoint executes,
269 // the provenance is inserted to the set. When inttoptr executes, it yields
270 // a pointer with a wildcard provenance. That is, each later use will check
271 // whether there is an exposed provenance in the snapshot allowing the
272 // operation. The invalid provenance will be masked out after the operation.
273 // If we cannot pick one, it is UB.
274
275 /// Exposed provenances are grouped by associated memory objects for efficient
276 /// invalidation.
277 struct ExposedProvenance {
279 uint64_t Generation;
280
281 bool operator<(const ExposedProvenance &RHS) const {
282 return Generation < RHS.Generation;
283 }
284 };
285 struct ExposedProvenanceSet {
286 // (Provenance, Generation)
288 // FIXME: Implement a partial order comparator for provenance instead of
289 // deduplicating by pointers.
291 };
292 std::map<uint64_t, ExposedProvenanceSet> ExposedProvenances;
293 // Global version number for the set of exposed provenances.
294 uint64_t ExposedProvenanceSetGeneration = 0;
295
296 /// Get the tag for the given pointer provenance.
297 APInt getTag(uint32_t BitWidth, Provenance &Prov);
298 AnyValue fromBytes(ConstBytesView Bytes, Type *Ty, uint32_t OffsetInBits,
299 bool CheckPaddingBits, bool *ContainsUndefinedBits);
300 void toBytes(const AnyValue &Val, Type *Ty, uint32_t OffsetInBits,
301 MutableBytesView Bytes, bool PaddingBits);
302
303 AnyValue computePtrAdd(const Pointer &Ptr, const APInt &Offset,
304 GEPNoWrapFlags Flags, AnyValue &AccumulatedOffset);
305
306 // Constants
307 // Use std::map to avoid iterator/reference invalidation.
308 std::map<Constant *, MaterializedConstant> ConstCache;
309 // Temporary buffer for non-cacheable constants (e.g.,
310 // undef/ptrtoint/inttoptr).
312 size_t NoncacheableConstCount = 0;
316 ValidFuncTargets;
318 ValidBlockTargets;
320 MaterializedConstant getConstantValueImpl(Constant *C);
321 MaterializedConstant evaluateConstantExpression(ConstantExpr *CE);
322
323 // Floating-point environment
324 RoundingMode CurrentRoundingMode = RoundingMode::NearestTiesToEven;
325 fp::ExceptionBehavior CurrentExceptionBehavior =
327
328 // TODO: errno
329
330public:
331 LLVM_ABI explicit Context(Module &M, const AsmParserContext *ParserContext);
332 Context(const Context &) = delete;
333 Context(Context &&) = delete;
334 Context &operator=(const Context &) = delete;
335 Context &operator=(Context &&) = delete;
337
338 void setMemoryLimit(uint64_t Max) { MaxMem = Max; }
339 void setVScale(uint32_t VS) { VScale = VS; }
340 void setMaxSteps(uint32_t MS) { MaxSteps = MS; }
341 void setMaxStackDepth(uint32_t Depth) { MaxStackDepth = Depth; }
342 void setFusedMultiplyAdd(bool F) { FusedMultiplyAdd = F; }
343 uint64_t getMemoryLimit() const { return MaxMem; }
344 uint32_t getVScale() const { return VScale; }
345 uint32_t getMaxSteps() const { return MaxSteps; }
346 uint32_t getMaxStackDepth() const { return MaxStackDepth; }
347 void setDeterministic(bool D) { Deterministic = D; }
348 bool isDeterministic() const { return Deterministic; }
349 bool mayUseNonDeterminism() const { return !Deterministic; }
352 bool fuseMultiplyAdd() const { return FusedMultiplyAdd; }
353 void setUndefValueBehavior(UndefValueBehavior UB) { UndefBehavior = UB; }
355 NaNBehavior = NaNBehav;
356 }
357 void reseed(uint32_t Seed) { Rng.seed(Seed); }
358
359 LLVMContext &getContext() const { return Ctx; }
360 Module &getModule() const { return M; }
361 const AsmParserContext *getParserContext() const { return ParserContext; }
362 const DataLayout &getDataLayout() const { return DL; }
363 const Triple &getTargetTriple() const { return M.getTargetTriple(); }
364 const TargetLibraryInfoImpl &getTLIImpl() const { return TLIImpl; }
365 /// Get the effective vector length for a vector type.
367 if (EC.isScalable())
368 return VScale * EC.getKnownMinValue();
369 return EC.getFixedValue();
370 }
371 /// The result is multiplied by VScale for scalable type sizes.
373 if (Size.isScalable())
374 return VScale * Size.getKnownMinValue();
375 return Size.getFixedValue();
376 }
377 /// Returns DL.getTypeAllocSize/getTypeStoreSize for the given type.
378 /// An exception to this is that for scalable vector types, the size is
379 /// computed as if the vector has getEVL(ElementCount) elements.
382
383 /// Returns a pointer to an evaluated constant \p C. If it cannot be
384 /// evaluated, returns nullptr. Note that it returns a pointer to a temporary
385 /// buffer when \p C is not context-free. The caller is responsible for
386 /// calling resetNoncacheableConstantBuffer after all references are dropped.
389 /// Returns true if an object of \p Size bytes in address space \p AS is
390 /// larger than the largest signed integer that fits into the index type.
391 /// Creating such an object is undefined behavior.
392 bool exceedsMaxObjectSize(uint64_t Size, unsigned AS) const {
393 return !isUIntN(DL.getIndexSizeInBits(AS) - 1, Size);
394 }
396 allocate(uint64_t Size, uint64_t Align, StringRef Name, unsigned AS,
397 MemInitKind InitKind, MemAllocKind AllocKind,
398 bool IsIRGlobalValue = false);
399 LLVM_ABI bool free(const MemoryObject &Obj);
400 /// Derive a pointer from a memory object with offset 0.
401 /// Please use Pointer's interface for further manipulations.
403 /// Mark this provenance as exposed. It is no-op if it is not associated with
404 /// a memory object or a wildcard provenance.
406 /// A helper to check both concrete and wildcard provenance. Please don't
407 /// report UB inside the \p Check callback due to the existence of wildcard
408 /// provenance.
409 /// Returns the resolved memory object if success. \p Ptr is guaranteed to be
410 /// within the bounds of the returned memory object. But the state is not
411 /// checked, for better diagnostic messages. If \p HasSideEffect is true, some
412 /// invalid provenances will be masked out. Note that in this case the caller
413 /// must report UB when the result is nullptr.
415 checkProvenance(const Pointer &Ptr,
416 function_ref<bool(const Provenance &)> Check,
417 bool HasSideEffect = true);
418 /// Returns the snapshot of currently exposed provenances.
420 /// Convert byte sequence to a value of the given type. Uninitialized bits are
421 /// flushed according to the options.
422 /// If \p ContainsUndefinedBits is provided, it will be set to true when there
423 /// are poison or undef bits in the value or in the padding bits that poison
424 /// value bits.
425 LLVM_ABI AnyValue fromBytes(ArrayRef<Byte> Bytes, Type *Ty,
426 bool *ContainsUndefinedBits = nullptr);
427 /// Convert a value to byte sequence. If every non-padding bit in the padding
428 /// byte is poison, the padding bits are poison; otherwise, they are zero.
429 LLVM_ABI void toBytes(const AnyValue &Val, Type *Ty,
431 /// Read the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of \p Src as a
432 /// value of type \p Ty. The bit range must be within \p Src.
433 LLVM_ABI AnyValue extractBits(const ByteValue &Src, uint32_t OffsetInBits,
434 Type *Ty);
435 /// Overwrite the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of \p Base
436 /// with \p Val. The bit range must be within \p Base.
437 LLVM_ABI void insertBits(ByteValue &Base, uint32_t OffsetInBits,
438 const AnyValue &Val, Type *Ty);
439 /// Direct memory load without checks.
441 bool *ContainsUndefinedBits = nullptr);
442 /// Direct memory store without checks.
443 LLVM_ABI void store(MemoryObject &MO, uint64_t Offset, const AnyValue &Val,
444 Type *ValTy);
446 const void *Data, uint64_t Size);
447
448 /// Freeze the value in-place.
449 LLVM_ABI void freeze(AnyValue &Val, Type *Ty);
450
452 GEPOperator &GEP, function_ref<const AnyValue &(Value *V)> GetValue);
453 LLVM_ABI AnyValue computePtrAdd(const AnyValue &Ptr, const APInt &Offset,
454 GEPNoWrapFlags Flags,
455 AnyValue &AccumulatedOffset);
457 const AnyValue &Index,
458 const APInt &Scale,
459 GEPNoWrapFlags Flags,
460 AnyValue &AccumulatedOffset);
461 /// Sign extends or truncates the GEP index \p Idx to \p IndexBitWidth bits.
462 /// Returns poison if truncating it would violate \p Flags.
464 unsigned IndexBitWidth,
465 GEPNoWrapFlags Flags);
466
469
470 /// Initialize global variables and function/block objects. This function
471 /// should be called before executing any function. Returns false if the
472 /// initialization fails (e.g., the memory limit is exceeded during
473 /// initialization).
475 /// Execute the function \p F with arguments \p Args, and store the return
476 /// value in \p RetVal if the function is not void.
477 /// Returns a `ProgramExitInfo` indicating how the program finished:
478 /// Kind = Returned: The program executed successfully and returned normally.
479 /// Kind = Failed: The interpreter encountered an error and could not execute
480 /// the program.
481 /// Kind = Exited/Aborted/Terminated: The program ended via an
482 /// explicit call to `exit()`, `abort()`, or `terminate()`.
484 AnyValue &RetVal, EventHandler &Handler);
485
490 LLVM_ABI bool isDefaultFPEnv() const;
491
492 LLVM_ABI bool getRandomBool();
494};
495
496} // namespace llvm::ubi
497
498#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
AMDGPU Mark last scratch load
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
This file contains the declarations of entities that describe floating point environment and related ...
Hexagon Common GEP
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
const char * Msg
Value * RHS
Class for arbitrary precision integers.
Definition APInt.h:78
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Definition APInt.h:1154
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition APInt.h:1225
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Registry of file location information for LLVM IR constructs.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1316
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Represents flags for the getelementptr instruction/expression.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition Allocator.h:398
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Implementation of the target library information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
Represents a scalar byte value.
Definition Value.h:257
Endianness aware accessor for bytes.
Definition Context.h:193
BytesView(ArrayRefT Ref, bool IsLittleEndian)
Definition Context.h:198
BytesView(ArrayRefT Ref, const DataLayout &DL)
Definition Context.h:200
size_t size() const
Definition Context.h:207
auto & operator[](uint32_t Index)
Definition Context.h:203
Context & operator=(const Context &)=delete
LLVM_ABI ProgramExitInfo runFunction(Function &F, ArrayRef< AnyValue > Args, AnyValue &RetVal, EventHandler &Handler)
Execute the function F with arguments Args, and store the return value in RetVal if the function is n...
LLVM_ABI bool isDefaultFPEnv() const
Definition Context.cpp:1336
uint64_t getMemoryLimit() const
Definition Context.h:343
uint32_t getEVL(ElementCount EC) const
Get the effective vector length for a vector type.
Definition Context.h:366
LLVM_ABI Pointer deriveFromMemoryObject(IntrusiveRefCntPtr< MemoryObject > Obj)
Derive a pointer from a memory object with offset 0.
Definition Context.cpp:1189
uint32_t getMaxStackDepth() const
Definition Context.h:346
LLVM_ABI UndefValueBehavior getEffectiveUndefValueBehavior() const
Definition Context.cpp:1340
void setUndefValueBehavior(UndefValueBehavior UB)
Definition Context.h:353
Context(const Context &)=delete
bool exceedsMaxObjectSize(uint64_t Size, unsigned AS) const
Returns true if an object of Size bytes in address space AS is larger than the largest signed integer...
Definition Context.h:392
LLVM_ABI void resetNoncacheableConstantBuffer()
Definition Context.cpp:422
LLVM_ABI void setCurrentRoundingMode(RoundingMode RM)
Definition Context.cpp:1328
LLVM_ABI void setCurrentExceptionBehavior(fp::ExceptionBehavior EB)
Definition Context.cpp:1332
const AsmParserContext * getParserContext() const
Definition Context.h:361
Context(Context &&)=delete
bool fuseMultiplyAdd() const
Definition Context.h:352
LLVM_ABI bool initGlobalValues()
Initialize global variables and function/block objects.
Definition Context.cpp:27
void setMaxStackDepth(uint32_t Depth)
Definition Context.h:341
void setNaNPropagationBehavior(NaNPropagationBehavior NaNBehav)
Definition Context.h:354
LLVM_ABI IntrusiveRefCntPtr< MemoryObject > allocate(uint64_t Size, uint64_t Align, StringRef Name, unsigned AS, MemInitKind InitKind, MemAllocKind AllocKind, bool IsIRGlobalValue=false)
Definition Context.cpp:1144
uint64_t getEffectiveTypeSize(TypeSize Size) const
The result is multiplied by VScale for scalable type sizes.
Definition Context.h:372
LLVM_ABI IntrusiveRefCntPtr< Provenance > getWildcardProvenance()
Returns the snapshot of currently exposed provenances.
Definition Context.cpp:1283
LLVM_ABI Function * getTargetFunction(const Pointer &Ptr)
Definition Context.cpp:1293
LLVM_ABI uint64_t getEffectiveTypeAllocSize(Type *Ty)
Returns DL.getTypeAllocSize/getTypeStoreSize for the given type.
Definition Context.cpp:1312
void setFusedMultiplyAdd(bool F)
Definition Context.h:342
LLVM_ABI uint64_t getEffectiveTypeStoreSize(Type *Ty)
Definition Context.cpp:1316
LLVM_ABI AnyValue extractBits(const ByteValue &Src, uint32_t OffsetInBits, Type *Ty)
Read the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Src as a value of type Ty.
Definition Context.cpp:848
LLVM_ABI AnyValue computeGEP(GEPOperator &GEP, function_ref< const AnyValue &(Value *V)> GetValue)
Definition Context.cpp:1043
const DataLayout & getDataLayout() const
Definition Context.h:362
const Triple & getTargetTriple() const
Definition Context.h:363
LLVM_ABI bool getRandomBool()
Definition Context.cpp:1352
LLVM_ABI NaNPropagationBehavior getEffectiveNaNPropagationBehavior() const
Definition Context.cpp:1346
LLVM_ABI fp::ExceptionBehavior getCurrentExceptionBehavior() const
Definition Context.cpp:1324
bool mayUseNonDeterminism() const
Definition Context.h:349
static LLVM_ABI AnyValue canonicalizeIndex(const AnyValue &Idx, unsigned IndexBitWidth, GEPNoWrapFlags Flags)
Sign extends or truncates the GEP index Idx to IndexBitWidth bits.
Definition Context.cpp:1023
void reseed(uint32_t Seed)
Definition Context.h:357
LLVMContext & getContext() const
Definition Context.h:359
LLVM_ABI Context(Module &M, const AsmParserContext *ParserContext)
Definition Context.cpp:21
LLVM_ABI ~Context()
LLVM_ABI const MaterializedConstant * getConstantValue(Constant *C)
Returns a pointer to an evaluated constant C.
Definition Context.cpp:404
LLVM_ABI bool free(const MemoryObject &Obj)
Definition Context.cpp:1169
LLVM_ABI void insertBits(ByteValue &Base, uint32_t OffsetInBits, const AnyValue &Val, Type *Ty)
Overwrite the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Base with Val.
Definition Context.cpp:858
LLVM_ABI void store(MemoryObject &MO, uint64_t Offset, const AnyValue &Val, Type *ValTy)
Direct memory store without checks.
Definition Context.cpp:875
LLVM_ABI BasicBlock * getTargetBlock(const Pointer &Ptr)
Definition Context.cpp:1302
void setMaxSteps(uint32_t MS)
Definition Context.h:340
uint32_t getMaxSteps() const
Definition Context.h:345
void setDeterministic(bool D)
Definition Context.h:347
LLVM_ABI void storeRawBytes(MemoryObject &MO, uint64_t Offset, const void *Data, uint64_t Size)
Definition Context.cpp:881
LLVM_ABI AnyValue computeScaledPtrAdd(const AnyValue &Ptr, const AnyValue &Index, const APInt &Scale, GEPNoWrapFlags Flags, AnyValue &AccumulatedOffset)
Definition Context.cpp:1006
void setMemoryLimit(uint64_t Max)
Definition Context.h:338
LLVM_ABI void exposeProvenance(Provenance &Prov)
Mark this provenance as exposed.
Definition Context.cpp:1196
const TargetLibraryInfoImpl & getTLIImpl() const
Definition Context.h:364
LLVM_ABI RoundingMode getCurrentRoundingMode() const
Definition Context.cpp:1320
bool isDeterministic() const
Definition Context.h:348
LLVM_ABI MemoryObject * checkProvenance(const Pointer &Ptr, function_ref< bool(const Provenance &)> Check, bool HasSideEffect=true)
A helper to check both concrete and wildcard provenance.
Definition Context.cpp:1209
Context & operator=(Context &&)=delete
LLVM_ABI uint64_t getRandomUInt64()
Definition Context.cpp:1359
void setVScale(uint32_t VS)
Definition Context.h:339
uint32_t getVScale() const
Definition Context.h:344
Module & getModule() const
Definition Context.h:360
An interface for handling events and managing outputs during interpretation.
Definition Context.h:166
virtual bool onFunctionEntry(Function &F, ArrayRef< AnyValue > Args, CallBase *CallSite)
Definition Context.h:177
virtual bool onFunctionExit(Function &F, const AnyValue &RetVal)
Definition Context.h:181
virtual void onProgramExit(const ProgramExitInfo &ExitInfo)
Definition Context.h:184
virtual bool onBBJump(Instruction &I, BasicBlock &To)
Definition Context.h:176
virtual void onError(StringRef Msg)
Definition Context.h:173
virtual ~EventHandler()=default
virtual bool onInstructionExecuted(Instruction &I, const AnyValue &Result)
Definition Context.h:170
virtual bool onPrint(StringRef Msg)
Definition Context.h:185
virtual void onImmediateUB(StringRef Msg)
Definition Context.h:175
virtual void onUnrecognizedInstruction(Instruction &I)
Definition Context.h:174
MaterializedConstant(AnyValue V, bool Cacheable)
Definition Context.h:218
MaterializedConstant(std::nullopt_t)
Definition Context.h:217
MemoryObject & operator=(MemoryObject &&)=delete
LLVM_ABI MemoryObject(uint64_t Addr, uint64_t Size, StringRef Name, unsigned AS, MemInitKind InitKind, MemAllocKind AllocKind, bool IsIRGlobalValue=false)
Definition Context.cpp:1123
bool isInaccessible() const
Definition Context.h:144
void setIsInaccessible(bool V)
Definition Context.h:145
bool isConstant() const
Definition Context.h:142
unsigned getAddressSpace() const
Definition Context.h:137
ArrayRef< Byte > getBytes() const
Definition Context.h:155
MemoryObject(const MemoryObject &)=delete
MemoryObjectState getState() const
Definition Context.h:138
LLVM_ABI bool isHeapAllocated() const
Definition Context.cpp:1373
Byte & operator[](uint64_t Offset)
Definition Context.h:151
void setState(MemoryObjectState S)
Definition Context.h:139
MemoryObject(MemoryObject &&)=delete
MutableArrayRef< Byte > getBytes()
Definition Context.h:156
LLVM_ABI bool isGlobal() const
Definition Context.cpp:1365
bool inBounds(const APInt &NewAddr) const
Definition Context.h:147
void setIsConstant(bool C)
Definition Context.h:143
MemoryObject & operator=(const MemoryObject &)=delete
friend class Context
Definition Context.h:122
uint64_t getAddress() const
Definition Context.h:134
MemAllocKind getAllocKind() const
Definition Context.h:140
StringRef getName() const
Definition Context.h:136
uint64_t getSize() const
Definition Context.h:135
bool isIRGlobalValue() const
Definition Context.h:141
LLVM_ABI bool isStackAllocated() const
Definition Context.cpp:1369
Components of a pointer excluding address.
Definition Value.h:188
ExceptionBehavior
Exception behavior used for floating point operations.
Definition FPEnv.h:39
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition FPEnv.h:40
UndefValueBehavior
Definition Context.h:60
MemoryObjectState
Definition Context.h:41
NaNPropagationBehavior
Definition Context.h:65
BytesView< ArrayRef< Byte > > ConstBytesView
Definition Context.h:210
BytesView< MutableArrayRef< Byte > > MutableBytesView
Definition Context.h:211
@ Offset
Definition DWP.cpp:577
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:244
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Representation of a byte in memory.
Definition Value.h:43
ProgramExitKind Kind
Definition Context.h:92
bool isExitedByLibcall() const
Definition Context.h:98
ProgramExitInfo(ProgramExitKind Kind, uint64_t ExitCode)
Definition Context.h:95