LLVM 24.0.0git
llvm::ConstGlobalLoad Class Reference

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.

Detailed Description

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.

Definition at line 256 of file Loads.h.

Member Function Documentation

◆ buildCanonicalIndex()

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

◆ fromLoadInst()

◆ getElementAt()

Constant * ConstGlobalLoad::getElementAt ( uint64_t Idx) const

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.

◆ getElementCount()

uint64_t llvm::ConstGlobalLoad::getElementCount ( ) const
inline

Number of elements that can be read from the global.

Definition at line 279 of file Loads.h.

References uint64_t.

◆ getIndex()

Value * llvm::ConstGlobalLoad::getIndex ( ) const
inline

Returns the index value of the linear expression that indexes the global.

This can't be used to compare known canonical index values with runtime values of the index, use buildCanonicalIndex for that.

Definition at line 301 of file Loads.h.


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