|
LLVM 24.0.0git
|
The global context for the interpreter. More...
#include "llvm/UBAwareInterpreter/Context.h"
Static Public Member Functions | |
| static LLVM_ABI AnyValue | canonicalizeIndex (const AnyValue &Idx, unsigned IndexBitWidth, GEPNoWrapFlags Flags) |
Sign extends or truncates the GEP index Idx to IndexBitWidth bits. | |
The global context for the interpreter.
It tracks global state such as heap memory objects and floating point environment.
|
explicit |
Definition at line 21 of file Context.cpp.
References getContext(), getDataLayout(), and getTargetTriple().
Referenced by Context(), Context(), operator=(), and operator=().
|
default |
References LLVM_ABI.
| IntrusiveRefCntPtr< MemoryObject > llvm::ubi::Context::allocate | ( | uint64_t | Size, |
| uint64_t | Align, | ||
| StringRef | Name, | ||
| unsigned | AS, | ||
| MemInitKind | InitKind, | ||
| MemAllocKind | AllocKind, | ||
| bool | IsIRGlobalValue = false ) |
Definition at line 1144 of file Context.cpp.
References llvm::alignTo(), exceedsMaxObjectSize(), llvm::isUIntN(), llvm::makeIntrusiveRefCnt(), llvm::SaturatingAdd(), llvm::Size, and uint64_t.
Referenced by initGlobalValues().
|
static |
Sign extends or truncates the GEP index Idx to IndexBitWidth bits.
Returns poison if truncating it would violate Flags.
Definition at line 1023 of file Context.cpp.
References llvm::ubi::AnyValue::poison().
Referenced by computeGEP().
| MemoryObject * llvm::ubi::Context::checkProvenance | ( | const Pointer & | Ptr, |
| function_ref< bool(const Provenance &)> | Check, | ||
| bool | HasSideEffect = true ) |
A helper to check both concrete and wildcard provenance.
Please don't report UB inside the Check callback due to the existence of wildcard provenance. Returns the resolved memory object if success. Ptr is guaranteed to be within the bounds of the returned memory object. But the state is not checked, for better diagnostic messages. If HasSideEffect is true, some invalid provenances will be masked out. Note that in this case the caller must report UB when the result is nullptr.
Definition at line 1209 of file Context.cpp.
References llvm::ubi::Pointer::address(), assert(), llvm::APInt::getAllOnes(), llvm::APInt::getLimitedValue(), I, llvm::ubi::MemoryObject::inBounds(), llvm::List, llvm::ubi::Pointer::provenance(), uint64_t, and llvm::upper_bound().
| AnyValue llvm::ubi::Context::computeGEP | ( | GEPOperator & | GEP, |
| function_ref< const AnyValue &(Value *V)> | GetValue ) |
Definition at line 1043 of file Context.cpp.
References llvm::ubi::AnyValue::asAggregate(), assert(), canonicalizeIndex(), llvm::cast(), computeScaledPtrAdd(), llvm::dyn_cast(), GEP, llvm::gep_type_begin(), llvm::gep_type_end(), getEffectiveTypeSize(), llvm::StructLayout::getElementOffset(), getEVL(), llvm::ubi::AnyValue::getVectorSplat(), llvm::isa(), llvm::ubi::AnyValue::isAggregate(), llvm::APInt::isZero(), llvm::Offset, V, and llvm::zip().
| AnyValue llvm::ubi::Context::computePtrAdd | ( | const AnyValue & | Ptr, |
| const APInt & | Offset, | ||
| GEPNoWrapFlags | Flags, | ||
| AnyValue & | AccumulatedOffset ) |
Definition at line 998 of file Context.cpp.
References llvm::ubi::AnyValue::asPointer(), llvm::ubi::AnyValue::isPoison(), llvm::Offset, and llvm::ubi::AnyValue::poison().
| AnyValue llvm::ubi::Context::computeScaledPtrAdd | ( | const AnyValue & | Ptr, |
| const AnyValue & | Index, | ||
| const APInt & | Scale, | ||
| GEPNoWrapFlags | Flags, | ||
| AnyValue & | AccumulatedOffset ) |
Definition at line 1006 of file Context.cpp.
References llvm::ubi::AnyValue::asInteger(), assert(), llvm::APInt::isOne(), llvm::ubi::AnyValue::isPointer(), llvm::ubi::AnyValue::isPoison(), llvm::ubi::mulNoWrap(), and llvm::ubi::AnyValue::poison().
Referenced by computeGEP().
| Pointer llvm::ubi::Context::deriveFromMemoryObject | ( | IntrusiveRefCntPtr< MemoryObject > | Obj | ) |
Derive a pointer from a memory object with offset 0.
Please use Pointer's interface for further manipulations.
Definition at line 1189 of file Context.cpp.
References assert(), llvm::makeIntrusiveRefCnt(), and llvm::ubi::Pointer.
Referenced by initGlobalValues().
Returns true if an object of Size bytes in address space AS is larger than the largest signed integer that fits into the index type.
Creating such an object is undefined behavior.
Definition at line 392 of file Context.h.
References llvm::isUIntN(), llvm::Size, and uint64_t.
Referenced by allocate().
| void llvm::ubi::Context::exposeProvenance | ( | Provenance & | Prov | ) |
Mark this provenance as exposed.
It is no-op if it is not associated with a memory object or a wildcard provenance.
Definition at line 1196 of file Context.cpp.
References llvm::Address, llvm::ubi::Alive, llvm::ubi::Provenance::getMemoryObject(), and uint64_t.
| AnyValue llvm::ubi::Context::extractBits | ( | const ByteValue & | Src, |
| uint32_t | OffsetInBits, | ||
| Type * | Ty ) |
Read the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Src as a value of type Ty.
The bit range must be within Src.
Definition at line 848 of file Context.cpp.
References assert().
| bool llvm::ubi::Context::free | ( | const MemoryObject & | Obj | ) |
Definition at line 1169 of file Context.cpp.
References llvm::Address, llvm::ubi::Freed, llvm::Tag, and uint64_t.
Freeze the value in-place.
Definition at line 899 of file Context.cpp.
References llvm::ubi::AnyValue::asAggregate(), llvm::ubi::AnyValue::asMutableByte(), llvm::ubi::ByteValue::canonicalize(), llvm::dyn_cast(), E(), freeze, llvm::APInt::getZero(), I, llvm::ubi::AnyValue::isAggregate(), llvm::ubi::AnyValue::isByte(), llvm::ubi::AnyValue::isPoison(), llvm_unreachable, mayUseNonDeterminism(), llvm::ubi::ByteValue::mutableBytes(), llvm::ubi::ByteValue::PaddingFromValue, llvm::ubi::Pointer, and V.
| AnyValue llvm::ubi::Context::fromBytes | ( | ArrayRef< Byte > | Bytes, |
| Type * | Ty, | ||
| bool * | ContainsUndefinedBits = nullptr ) |
Convert byte sequence to a value of the given type.
Uninitialized bits are flushed according to the options. If ContainsUndefinedBits is provided, it will be set to true when there are poison or undef bits in the value or in the padding bits that poison value bits.
Definition at line 579 of file Context.cpp.
References llvm::alignTo(), assert(), llvm::BitWidth, llvm::Data, llvm::ArrayRef< T >::data(), llvm::dyn_cast(), llvm::ubi::ByteValue::FlushNonCanonicalToPoison, getEffectiveTypeAllocSize(), getEffectiveTypeSize(), getEffectiveTypeStoreSize(), llvm::StructLayout::getElementOffset(), getEVL(), I, llvm::ubi::Byte::isCanonicalPaddingByte(), llvm_unreachable, llvm::ubi::ByteValue::mutableBytes(), llvm::ubi::Byte::poison(), llvm::ArrayRef< T >::size(), llvm::ArrayRef< T >::slice(), uint64_t, and V.
| const MaterializedConstant * llvm::ubi::Context::getConstantValue | ( | Constant * | C | ) |
Returns a pointer to an evaluated constant C.
If it cannot be evaluated, returns nullptr. Note that it returns a pointer to a temporary buffer when C is not context-free. The caller is responsible for calling resetNoncacheableConstantBuffer after all references are dropped.
Definition at line 404 of file Context.cpp.
References assert(), C(), llvm::ubi::MaterializedConstant::isCacheable(), and llvm::ubi::AnyValue::isNone().
Referenced by initGlobalValues().
|
inline |
| fp::ExceptionBehavior llvm::ubi::Context::getCurrentExceptionBehavior | ( | ) | const |
Definition at line 1324 of file Context.cpp.
| RoundingMode llvm::ubi::Context::getCurrentRoundingMode | ( | ) | const |
Definition at line 1320 of file Context.cpp.
|
inline |
| NaNPropagationBehavior llvm::ubi::Context::getEffectiveNaNPropagationBehavior | ( | ) | const |
Definition at line 1346 of file Context.cpp.
References isDeterministic(), and llvm::ubi::PreferredNaN.
Returns DL.getTypeAllocSize/getTypeStoreSize for the given type.
An exception to this is that for scalable vector types, the size is computed as if the vector has getEVL(ElementCount) elements.
Definition at line 1312 of file Context.cpp.
References getEffectiveTypeSize(), and uint64_t.
Referenced by fromBytes(), initGlobalValues(), and toBytes().
The result is multiplied by VScale for scalable type sizes.
Definition at line 372 of file Context.h.
References llvm::Size, and uint64_t.
Referenced by computeGEP(), fromBytes(), getEffectiveTypeAllocSize(), getEffectiveTypeStoreSize(), and toBytes().
Definition at line 1316 of file Context.cpp.
References getEffectiveTypeSize(), and uint64_t.
Referenced by fromBytes(), load(), store(), and toBytes().
| UndefValueBehavior llvm::ubi::Context::getEffectiveUndefValueBehavior | ( | ) | const |
Definition at line 1340 of file Context.cpp.
References isDeterministic(), and llvm::ubi::Zero.
|
inline |
Get the effective vector length for a vector type.
Definition at line 366 of file Context.h.
Referenced by computeGEP(), fromBytes(), and toBytes().
|
inline |
|
inline |
|
inline |
| bool llvm::ubi::Context::getRandomBool | ( | ) |
Definition at line 1352 of file Context.cpp.
References mayUseNonDeterminism().
| uint64_t llvm::ubi::Context::getRandomUInt64 | ( | ) |
Definition at line 1359 of file Context.cpp.
References mayUseNonDeterminism(), and uint64_t.
| BasicBlock * llvm::ubi::Context::getTargetBlock | ( | const Pointer & | Ptr | ) |
Definition at line 1302 of file Context.cpp.
References llvm::ubi::Pointer::address(), llvm::APInt::getActiveBits(), and llvm::APInt::getZExtValue().
Definition at line 1293 of file Context.cpp.
References llvm::ubi::Pointer::address(), llvm::APInt::getActiveBits(), and llvm::APInt::getZExtValue().
|
inline |
| IntrusiveRefCntPtr< Provenance > llvm::ubi::Context::getWildcardProvenance | ( | ) |
Returns the snapshot of currently exposed provenances.
Definition at line 1283 of file Context.cpp.
References llvm::makeIntrusiveRefCnt(), and llvm::ubi::Provenance::nullary().
| bool llvm::ubi::Context::initGlobalValues | ( | ) |
Initialize global variables and function/block objects.
This function should be called before executing any function. Returns false if the initialization fails (e.g., the memory limit is exceeded during initialization).
Definition at line 27 of file Context.cpp.
References allocate(), assert(), llvm::ubi::BlockAddress, deriveFromMemoryObject(), F, getConstantValue(), getEffectiveTypeAllocSize(), llvm::ubi::Global, resetNoncacheableConstantBuffer(), llvm::Size, store(), uint64_t, llvm::ubi::Uninitialized, and llvm::ubi::Zeroed.
| void llvm::ubi::Context::insertBits | ( | ByteValue & | Base, |
| uint32_t | OffsetInBits, | ||
| const AnyValue & | Val, | ||
| Type * | Ty ) |
Overwrite the bits [OffsetInBits, OffsetInBits + bitwidth(Ty)) of Base with Val.
The bit range must be within Base.
Definition at line 858 of file Context.cpp.
References assert(), llvm::sampleprof::Base, and llvm::ubi::ByteValue::PaddingFromValue.
| bool llvm::ubi::Context::isDefaultFPEnv | ( | ) | const |
Definition at line 1336 of file Context.cpp.
References llvm::isDefaultFPEnvironment().
|
inline |
Definition at line 348 of file Context.h.
Referenced by getEffectiveNaNPropagationBehavior(), and getEffectiveUndefValueBehavior().
| AnyValue llvm::ubi::Context::load | ( | MemoryObject & | MO, |
| uint64_t | Offset, | ||
| Type * | ValTy, | ||
| bool * | ContainsUndefinedBits = nullptr ) |
Direct memory load without checks.
Definition at line 868 of file Context.cpp.
References llvm::ubi::MemoryObject::getBytes(), getEffectiveTypeStoreSize(), llvm::Offset, and uint64_t.
|
inline |
Definition at line 349 of file Context.h.
Referenced by freeze(), getRandomBool(), and getRandomUInt64().
|
inline |
| void llvm::ubi::Context::resetNoncacheableConstantBuffer | ( | ) |
Definition at line 422 of file Context.cpp.
Referenced by initGlobalValues().
| ProgramExitInfo llvm::ubi::Context::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 not void.
Returns a ProgramExitInfo indicating how the program finished: Kind = Returned: The program executed successfully and returned normally. Kind = Failed: The interpreter encountered an error and could not execute the program. Kind = Exited/Aborted/Terminated: The program ended via an explicit call to exit(), abort(), or terminate().
Definition at line 3288 of file Interpreter.cpp.
References F, and llvm::ubi::InstExecutor::runMainLoop().
| void llvm::ubi::Context::setCurrentExceptionBehavior | ( | fp::ExceptionBehavior | EB | ) |
Definition at line 1332 of file Context.cpp.
| void llvm::ubi::Context::setCurrentRoundingMode | ( | RoundingMode | RM | ) |
Definition at line 1328 of file Context.cpp.
|
inline |
|
inline |
|
inline |
Definition at line 341 of file Context.h.
References llvm::Depth.
|
inline |
|
inline |
|
inline |
|
inline |
| void llvm::ubi::Context::store | ( | MemoryObject & | MO, |
| uint64_t | Offset, | ||
| const AnyValue & | Val, | ||
| Type * | ValTy ) |
Direct memory store without checks.
Definition at line 875 of file Context.cpp.
References llvm::ubi::MemoryObject::getBytes(), getEffectiveTypeStoreSize(), llvm::Offset, and uint64_t.
Referenced by initGlobalValues().
| void llvm::ubi::Context::storeRawBytes | ( | MemoryObject & | MO, |
| uint64_t | Offset, | ||
| const void * | Data, | ||
| uint64_t | Size ) |
Definition at line 881 of file Context.cpp.
References llvm::ubi::Byte::concrete(), llvm::Data, I, llvm::Offset, llvm::Size, and uint64_t.
| void llvm::ubi::Context::toBytes | ( | const AnyValue & | Val, |
| Type * | Ty, | ||
| MutableArrayRef< Byte > | Bytes ) |
Convert a value to byte sequence.
If every non-padding bit in the padding byte is poison, the padding bits are poison; otherwise, they are zero.
Definition at line 766 of file Context.cpp.
References llvm::alignTo(), llvm::ubi::AnyValue::asAggregate(), llvm::ubi::AnyValue::asByte(), assert(), llvm::MutableArrayRef< T >::begin(), llvm::ubi::Byte::ConcreteMask, llvm::copy(), llvm::dyn_cast(), E(), llvm::End, llvm::enumerate(), llvm::fill(), getEffectiveTypeAllocSize(), getEffectiveTypeSize(), getEffectiveTypeStoreSize(), llvm::StructLayout::getElementOffset(), getEVL(), I, llvm_unreachable, llvm::Offset, llvm::ubi::Byte::poisonBits(), llvm::reverse(), llvm::ArrayRef< T >::size(), llvm::MutableArrayRef< T >::slice(), uint64_t, llvm::ubi::Byte::undef(), and llvm::ubi::Byte::zeroBits().