clang 24.0.0git
CIRBasicAliasAnalysis.cpp File Reference
#include "clang/CIR/Dialect/Analysis/CIRBasicAliasAnalysis.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/MathExtras.h"
#include <limits>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "cir-basic-alias-analysis"

Functions

static std::optional< int64_t > getTypeSizeInBytes (mlir::Type type, const mlir::DataLayout &dataLayout)
 Return the size in bytes of type, or std::nullopt when that size isn't statically known (void, function types, incomplete records, ...).
static std::optional< int64_t > getConstantIndex (mlir::Value val)
 If val is a constant integer that fits in an int64_t, return its value.
static std::optional< int64_t > scaleOffset (std::optional< int64_t > count, std::optional< int64_t > size)
 Return count * size, or std::nullopt if either input is unknown or the product overflows.
static void addToOffset (std::optional< int64_t > &offset, std::optional< int64_t > delta)
 Add delta bytes to offset, making the offset unknown if delta is unknown or if the sum overflows.
static PointerOffset decomposePointer (mlir::Value val, const mlir::DataLayout &dataLayout)
 Trace val back to the object it points into, accumulating the byte offset of val from the start of that object.
static bool areDistinctObjects (mlir::Value lhs, mlir::Value rhs)
 Return true if lhs and rhs are provably different objects.

Variables

static constexpr unsigned MaxLookupDepth = 6

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "cir-basic-alias-analysis"

Definition at line 18 of file CIRBasicAliasAnalysis.cpp.

Function Documentation

◆ addToOffset()

void addToOffset ( std::optional< int64_t > & offset,
std::optional< int64_t > delta )
static

Add delta bytes to offset, making the offset unknown if delta is unknown or if the sum overflows.

Definition at line 74 of file CIRBasicAliasAnalysis.cpp.

Referenced by decomposePointer().

◆ areDistinctObjects()

bool areDistinctObjects ( mlir::Value lhs,
mlir::Value rhs )
static

Return true if lhs and rhs are provably different objects.

TODO: Extend to cover global addresses, function arguments with noalias, and heap allocations.

Definition at line 230 of file CIRBasicAliasAnalysis.cpp.

Referenced by cir::CIRBasicAliasAnalysis::alias().

◆ decomposePointer()

PointerOffset decomposePointer ( mlir::Value val,
const mlir::DataLayout & dataLayout )
static

Trace val back to the object it points into, accumulating the byte offset of val from the start of that object.

The walk stops at a block argument, at an allocation, or at any operation whose result cannot be described as an offset from one of its operands. The returned base and offset always describe val, even when the walk stops early because the depth limit was reached.

Operations contributing an offset that isn't a compile-time constant (a dynamic cir.ptr_stride index, for example) are still traced through, leaving the offset unknown. Knowing which object a pointer points into is useful even when the offset within that object is not known.

Definition at line 115 of file CIRBasicAliasAnalysis.cpp.

References addToOffset(), getConstantIndex(), getTypeSizeInBytes(), MaxLookupDepth, and scaleOffset().

Referenced by cir::CIRBasicAliasAnalysis::alias().

◆ getConstantIndex()

std::optional< int64_t > getConstantIndex ( mlir::Value val)
static

If val is a constant integer that fits in an int64_t, return its value.

The constant is interpreted according to the signedness of its type.

Definition at line 44 of file CIRBasicAliasAnalysis.cpp.

Referenced by decomposePointer().

◆ getTypeSizeInBytes()

std::optional< int64_t > getTypeSizeInBytes ( mlir::Type type,
const mlir::DataLayout & dataLayout )
static

Return the size in bytes of type, or std::nullopt when that size isn't statically known (void, function types, incomplete records, ...).

Definition at line 32 of file CIRBasicAliasAnalysis.cpp.

References cir::isSized().

Referenced by decomposePointer().

◆ scaleOffset()

std::optional< int64_t > scaleOffset ( std::optional< int64_t > count,
std::optional< int64_t > size )
static

Return count * size, or std::nullopt if either input is unknown or the product overflows.

Definition at line 62 of file CIRBasicAliasAnalysis.cpp.

Referenced by decomposePointer().

Variable Documentation

◆ MaxLookupDepth

unsigned MaxLookupDepth = 6
staticconstexpr

Definition at line 27 of file CIRBasicAliasAnalysis.cpp.

Referenced by decomposePointer().