LLVM 24.0.0git
llvm::ubi::Context Class Reference

The global context for the interpreter. More...

#include "llvm/UBAwareInterpreter/Context.h"

Public Member Functions

LLVM_ABI Context (Module &M, const AsmParserContext *ParserContext)
 Context (const Context &)=delete
 Context (Context &&)=delete
Context & operator= (const Context &)=delete
Context & operator= (Context &&)=delete
LLVM_ABI ~Context ()
void setMemoryLimit (uint64_t Max)
void setVScale (uint32_t VS)
void setMaxSteps (uint32_t MS)
void setMaxStackDepth (uint32_t Depth)
void setFusedMultiplyAdd (bool F)
uint64_t getMemoryLimit () const
uint32_t getVScale () const
uint32_t getMaxSteps () const
uint32_t getMaxStackDepth () const
void setDeterministic (bool D)
bool isDeterministic () const
bool mayUseNonDeterminism () const
LLVM_ABI UndefValueBehavior getEffectiveUndefValueBehavior () const
LLVM_ABI NaNPropagationBehavior getEffectiveNaNPropagationBehavior () const
bool fuseMultiplyAdd () const
void setUndefValueBehavior (UndefValueBehavior UB)
void setNaNPropagationBehavior (NaNPropagationBehavior NaNBehav)
void reseed (uint32_t Seed)
LLVMContext & getContext () const
Module & getModule () const
const AsmParserContext * getParserContext () const
const DataLayout & getDataLayout () const
const Triple & getTargetTriple () const
const TargetLibraryInfoImpl & getTLIImpl () const
uint32_t getEVL (ElementCount EC) const
 Get the effective vector length for a vector type.
uint64_t getEffectiveTypeSize (TypeSize Size) const
 The result is multiplied by VScale for scalable type sizes.
LLVM_ABI uint64_t getEffectiveTypeAllocSize (Type *Ty)
 Returns DL.getTypeAllocSize/getTypeStoreSize for the given type.
LLVM_ABI uint64_t getEffectiveTypeStoreSize (Type *Ty)
LLVM_ABI const MaterializedConstant * getConstantValue (Constant *C)
 Returns a pointer to an evaluated constant C.
LLVM_ABI void resetNoncacheableConstantBuffer ()
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 that fits into the index type.
LLVM_ABI IntrusiveRefCntPtr< MemoryObject > allocate (uint64_t Size, uint64_t Align, StringRef Name, unsigned AS, MemInitKind InitKind, MemAllocKind AllocKind, bool IsIRGlobalValue=false)
LLVM_ABI bool free (const MemoryObject &Obj)
LLVM_ABI Pointer deriveFromMemoryObject (IntrusiveRefCntPtr< MemoryObject > Obj)
 Derive a pointer from a memory object with offset 0.
LLVM_ABI void exposeProvenance (Provenance &Prov)
 Mark this provenance as exposed.
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.
LLVM_ABI IntrusiveRefCntPtr< Provenance > getWildcardProvenance ()
 Returns the snapshot of currently exposed provenances.
LLVM_ABI AnyValue fromBytes (ArrayRef< Byte > Bytes, Type *Ty, bool *ContainsUndefinedBits=nullptr)
 Convert byte sequence to a value of the given type.
LLVM_ABI void toBytes (const AnyValue &Val, Type *Ty, MutableArrayRef< Byte > Bytes)
 Convert a value to byte sequence.
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.
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.
LLVM_ABI AnyValue load (MemoryObject &MO, uint64_t Offset, Type *ValTy, bool *ContainsUndefinedBits=nullptr)
 Direct memory load without checks.
LLVM_ABI void store (MemoryObject &MO, uint64_t Offset, const AnyValue &Val, Type *ValTy)
 Direct memory store without checks.
LLVM_ABI void storeRawBytes (MemoryObject &MO, uint64_t Offset, const void *Data, uint64_t Size)
LLVM_ABI void freeze (AnyValue &Val, Type *Ty)
 Freeze the value in-place.
LLVM_ABI AnyValue computeGEP (GEPOperator &GEP, function_ref< const AnyValue &(Value *V)> GetValue)
LLVM_ABI AnyValue computePtrAdd (const AnyValue &Ptr, const APInt &Offset, GEPNoWrapFlags Flags, AnyValue &AccumulatedOffset)
LLVM_ABI AnyValue computeScaledPtrAdd (const AnyValue &Ptr, const AnyValue &Index, const APInt &Scale, GEPNoWrapFlags Flags, AnyValue &AccumulatedOffset)
LLVM_ABI Function * getTargetFunction (const Pointer &Ptr)
LLVM_ABI BasicBlock * getTargetBlock (const Pointer &Ptr)
LLVM_ABI bool initGlobalValues ()
 Initialize global variables and function/block objects.
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 not void.
LLVM_ABI RoundingMode getCurrentRoundingMode () const
LLVM_ABI fp::ExceptionBehavior getCurrentExceptionBehavior () const
LLVM_ABI void setCurrentRoundingMode (RoundingMode RM)
LLVM_ABI void setCurrentExceptionBehavior (fp::ExceptionBehavior EB)
LLVM_ABI bool isDefaultFPEnv () const
LLVM_ABI bool getRandomBool ()
LLVM_ABI uint64_t getRandomUInt64 ()

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.

Detailed Description

The global context for the interpreter.

It tracks global state such as heap memory objects and floating point environment.

Definition at line 227 of file Context.h.

Constructor & Destructor Documentation

◆ Context() [1/3]

llvm::ubi::Context::Context ( Module & M,
const AsmParserContext * ParserContext )
explicit

Definition at line 21 of file Context.cpp.

References getContext(), getDataLayout(), and getTargetTriple().

Referenced by Context(), Context(), operator=(), and operator=().

◆ Context() [2/3]

llvm::ubi::Context::Context ( const Context & )
delete

References Context().

◆ Context() [3/3]

llvm::ubi::Context::Context ( Context && )
delete

References Context().

◆ ~Context()

llvm::ubi::Context::~Context ( )
default

References LLVM_ABI.

Member Function Documentation

◆ allocate()

IntrusiveRefCntPtr< MemoryObject > llvm::ubi::Context::allocate ( uint64_t Size,
uint64_t Align,
StringRef Name,
unsigned AS,
MemInitKind InitKind,
MemAllocKind AllocKind,
bool IsIRGlobalValue = false )

◆ canonicalizeIndex()

AnyValue llvm::ubi::Context::canonicalizeIndex ( const AnyValue & Idx,
unsigned IndexBitWidth,
GEPNoWrapFlags Flags )
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().

◆ checkProvenance()

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().

◆ computeGEP()

◆ computePtrAdd()

AnyValue llvm::ubi::Context::computePtrAdd ( const AnyValue & Ptr,
const APInt & Offset,
GEPNoWrapFlags Flags,
AnyValue & AccumulatedOffset )

◆ computeScaledPtrAdd()

AnyValue llvm::ubi::Context::computeScaledPtrAdd ( const AnyValue & Ptr,
const AnyValue & Index,
const APInt & Scale,
GEPNoWrapFlags Flags,
AnyValue & AccumulatedOffset )

◆ deriveFromMemoryObject()

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().

◆ exceedsMaxObjectSize()

bool llvm::ubi::Context::exceedsMaxObjectSize ( uint64_t Size,
unsigned AS ) const
inline

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().

◆ exposeProvenance()

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.

◆ extractBits()

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().

◆ free()

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()

◆ fromBytes()

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.

◆ fuseMultiplyAdd()

bool llvm::ubi::Context::fuseMultiplyAdd ( ) const
inline

Definition at line 352 of file Context.h.

◆ getConstantValue()

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().

◆ getContext()

LLVMContext & llvm::ubi::Context::getContext ( ) const
inline

Definition at line 359 of file Context.h.

Referenced by Context().

◆ getCurrentExceptionBehavior()

fp::ExceptionBehavior llvm::ubi::Context::getCurrentExceptionBehavior ( ) const

Definition at line 1324 of file Context.cpp.

◆ getCurrentRoundingMode()

RoundingMode llvm::ubi::Context::getCurrentRoundingMode ( ) const

Definition at line 1320 of file Context.cpp.

◆ getDataLayout()

const DataLayout & llvm::ubi::Context::getDataLayout ( ) const
inline

Definition at line 362 of file Context.h.

Referenced by Context().

◆ getEffectiveNaNPropagationBehavior()

NaNPropagationBehavior llvm::ubi::Context::getEffectiveNaNPropagationBehavior ( ) const

Definition at line 1346 of file Context.cpp.

References isDeterministic(), and llvm::ubi::PreferredNaN.

◆ getEffectiveTypeAllocSize()

uint64_t llvm::ubi::Context::getEffectiveTypeAllocSize ( Type * Ty)

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().

◆ getEffectiveTypeSize()

uint64_t llvm::ubi::Context::getEffectiveTypeSize ( TypeSize Size) const
inline

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().

◆ getEffectiveTypeStoreSize()

uint64_t llvm::ubi::Context::getEffectiveTypeStoreSize ( Type * Ty)

Definition at line 1316 of file Context.cpp.

References getEffectiveTypeSize(), and uint64_t.

Referenced by fromBytes(), load(), store(), and toBytes().

◆ getEffectiveUndefValueBehavior()

UndefValueBehavior llvm::ubi::Context::getEffectiveUndefValueBehavior ( ) const

Definition at line 1340 of file Context.cpp.

References isDeterministic(), and llvm::ubi::Zero.

◆ getEVL()

uint32_t llvm::ubi::Context::getEVL ( ElementCount EC) const
inline

Get the effective vector length for a vector type.

Definition at line 366 of file Context.h.

Referenced by computeGEP(), fromBytes(), and toBytes().

◆ getMaxStackDepth()

uint32_t llvm::ubi::Context::getMaxStackDepth ( ) const
inline

Definition at line 346 of file Context.h.

◆ getMaxSteps()

uint32_t llvm::ubi::Context::getMaxSteps ( ) const
inline

Definition at line 345 of file Context.h.

◆ getMemoryLimit()

uint64_t llvm::ubi::Context::getMemoryLimit ( ) const
inline

Definition at line 343 of file Context.h.

References uint64_t.

◆ getModule()

Module & llvm::ubi::Context::getModule ( ) const
inline

Definition at line 360 of file Context.h.

◆ getParserContext()

const AsmParserContext * llvm::ubi::Context::getParserContext ( ) const
inline

Definition at line 361 of file Context.h.

◆ getRandomBool()

bool llvm::ubi::Context::getRandomBool ( )

Definition at line 1352 of file Context.cpp.

References mayUseNonDeterminism().

◆ getRandomUInt64()

uint64_t llvm::ubi::Context::getRandomUInt64 ( )

Definition at line 1359 of file Context.cpp.

References mayUseNonDeterminism(), and uint64_t.

◆ getTargetBlock()

BasicBlock * llvm::ubi::Context::getTargetBlock ( const Pointer & Ptr)

◆ getTargetFunction()

Function * llvm::ubi::Context::getTargetFunction ( const Pointer & Ptr)

◆ getTargetTriple()

const Triple & llvm::ubi::Context::getTargetTriple ( ) const
inline

Definition at line 363 of file Context.h.

Referenced by Context().

◆ getTLIImpl()

const TargetLibraryInfoImpl & llvm::ubi::Context::getTLIImpl ( ) const
inline

Definition at line 364 of file Context.h.

◆ getVScale()

uint32_t llvm::ubi::Context::getVScale ( ) const
inline

Definition at line 344 of file Context.h.

◆ getWildcardProvenance()

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().

◆ initGlobalValues()

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.

◆ insertBits()

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.

◆ isDefaultFPEnv()

bool llvm::ubi::Context::isDefaultFPEnv ( ) const

Definition at line 1336 of file Context.cpp.

References llvm::isDefaultFPEnvironment().

◆ isDeterministic()

bool llvm::ubi::Context::isDeterministic ( ) const
inline

◆ load()

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.

◆ mayUseNonDeterminism()

bool llvm::ubi::Context::mayUseNonDeterminism ( ) const
inline

Definition at line 349 of file Context.h.

Referenced by freeze(), getRandomBool(), and getRandomUInt64().

◆ operator=() [1/2]

Context & llvm::ubi::Context::operator= ( const Context & )
delete

References Context().

◆ operator=() [2/2]

Context & llvm::ubi::Context::operator= ( Context && )
delete

References Context().

◆ reseed()

void llvm::ubi::Context::reseed ( uint32_t Seed)
inline

Definition at line 357 of file Context.h.

References Seed.

◆ resetNoncacheableConstantBuffer()

void llvm::ubi::Context::resetNoncacheableConstantBuffer ( )

Definition at line 422 of file Context.cpp.

Referenced by initGlobalValues().

◆ runFunction()

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().

◆ setCurrentExceptionBehavior()

void llvm::ubi::Context::setCurrentExceptionBehavior ( fp::ExceptionBehavior EB)

Definition at line 1332 of file Context.cpp.

◆ setCurrentRoundingMode()

void llvm::ubi::Context::setCurrentRoundingMode ( RoundingMode RM)

Definition at line 1328 of file Context.cpp.

◆ setDeterministic()

void llvm::ubi::Context::setDeterministic ( bool D)
inline

Definition at line 347 of file Context.h.

References D().

◆ setFusedMultiplyAdd()

void llvm::ubi::Context::setFusedMultiplyAdd ( bool F)
inline

Definition at line 342 of file Context.h.

References F.

◆ setMaxStackDepth()

void llvm::ubi::Context::setMaxStackDepth ( uint32_t Depth)
inline

Definition at line 341 of file Context.h.

References llvm::Depth.

◆ setMaxSteps()

void llvm::ubi::Context::setMaxSteps ( uint32_t MS)
inline

Definition at line 340 of file Context.h.

◆ setMemoryLimit()

void llvm::ubi::Context::setMemoryLimit ( uint64_t Max)
inline

Definition at line 338 of file Context.h.

References uint64_t.

◆ setNaNPropagationBehavior()

void llvm::ubi::Context::setNaNPropagationBehavior ( NaNPropagationBehavior NaNBehav)
inline

Definition at line 354 of file Context.h.

◆ setUndefValueBehavior()

void llvm::ubi::Context::setUndefValueBehavior ( UndefValueBehavior UB)
inline

Definition at line 353 of file Context.h.

◆ setVScale()

void llvm::ubi::Context::setVScale ( uint32_t VS)
inline

Definition at line 339 of file Context.h.

◆ store()

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().

◆ storeRawBytes()

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.

◆ toBytes()


The documentation for this class was generated from the following files: