llvm::getPointersDiff

Returns the distance between compatible pointers PtrA and PtrB.

Synopsis

Declared in <llvm/Analysis/LoopAccessAnalysis.h>

std::optional<int64_t>
getPointersDiff(
    Type* ElemTyA,
    Value* PtrA,
    Type* ElemTyB,
    Value* PtrB,
    DataLayout const& DL,
    ScalarEvolution& SE,
    bool StrictCheck = false,
    bool CheckType = true);

Description

Returns the distance iff they are compatible and it is possible to calculate the distance between them. This is a simple API that does not depend on the analysis pass.

Return Value

The distance between the pointers, or std::nullopt if not computable.

Parameters

NameDescription
ElemTyAElement type of the access through PtrA.
PtrAFirst pointer value.
ElemTyBElement type of the access through PtrB.
PtrBSecond pointer value.
DLData layout used to compute type sizes and offsets.
SEScalarEvolution used to analyze the pointers.
StrictCheckEnsure that the calculated distance matches the type-based one after all the bitcasts removal in the provided pointers.
CheckTypeWhen true, require the element types to match.