|
LLVM 24.0.0git
|
A helper to analyze a load from a constant global. More...
#include "llvm/Analysis/Loads.h"
Public Member Functions | |
| LLVM_ABI Constant * | getElementAt (uint64_t Idx) const |
| Get the element of the global that the load instruction reads for the given canonical index. | |
| uint64_t | getElementCount () const |
| Number of elements that can be read from the global. | |
| LLVM_ABI Value * | buildCanonicalIndex (IRBuilderBase &Builder) const |
| Build the canonicalized index that will index the global without wrapping. | |
| Value * | getIndex () const |
| Returns the index value of the linear expression that indexes the global. | |
Static Public Member Functions | |
| static LLVM_ABI std::optional< ConstGlobalLoad > | fromLoadInst (LoadInst *LI) |
| Analyze a load instruction to a linear expression that loads from a constant global. | |
A helper to analyze a load from a constant global.
Provides an API that allows canonicalizing the indices in generated code to allow comparing indexes with known indices, and to access the global elements with canonical index values at compile time.
Currently the analysis requires constant offsets to the global to be less than the stride, so the global is always accessed with 0 as the first valid index.
Canonicalization masks the index values to handle wrapping. getElementAt takes canonical indices, instead of index values that may wrap around to access the global.
| Value * ConstGlobalLoad::buildCanonicalIndex | ( | IRBuilderBase & | Builder | ) | const |
Build the canonicalized index that will index the global without wrapping.
When the offset calculations do not wrap, this returns the original index value as-is.
Otherwise this masks the index value as necessary to convert it into the canonical index.
After canonicalization, the index values can be compared against known index values of global elements.
When you don't need to compare canonical indices and just want to index the table, getIndex can be used to get original index value.
Definition at line 1138 of file Loads.cpp.
References llvm::BitWidth, and llvm::APInt::getLowBitsSet().
|
static |
Analyze a load instruction to a linear expression that loads from a constant global.
Definition at line 1073 of file Loads.cpp.
References llvm::decomposeLinearExpression(), llvm::divideCeil(), DL, llvm::dyn_cast(), llvm::Instruction::getDataLayout(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::LoadInst::getPointerOperand(), llvm::Value::getType(), llvm::getUnderlyingObject(), llvm::APInt::getZExtValue(), llvm::APInt::isNegative(), llvm::APInt::isPowerOf2(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable(), llvm::LoadInst::isVolatile(), llvm::APInt::uge(), and llvm::APInt::ult().
Referenced by llvm::InstCombinerImpl::foldCmpLoadFromIndexedGlobal(), and parseJumpTable().
Get the element of the global that the load instruction reads for the given canonical index.
This uses ConstantFoldLoadFromConst and returns null under the same circumstances that ConstantFoldLoadFromConst returns null. (e.g. when the value being loaded cannot be reinterpreted as the load type)
Definition at line 1130 of file Loads.cpp.
References assert(), llvm::cast(), llvm::ConstantFoldLoadFromConst(), llvm::GlobalValue::getDataLayout(), llvm::GlobalVariable::getInitializer(), and llvm::Offset.
|
inline |
|
inline |