14#ifndef CLANG_LIB_CIR_ADDRESS_H
15#define CLANG_LIB_CIR_ADDRESS_H
17#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
18#include "mlir/IR/Value.h"
25#include "llvm/ADT/PointerIntPair.h"
26#include "llvm/Support/Casting.h"
36 llvm::PointerIntPair<mlir::Value, 1, bool> pointerAndKnownNonNull;
41 mlir::Type elementType;
49 Address(mlir::Value pointer, mlir::Type elementType,
53 Address(mlir::Value pointer, mlir::Type elementType,
56 elementType(elementType), alignment(alignment) {
57 assert(pointer &&
"Pointer cannot be null");
58 assert(elementType &&
"Element type cannot be null");
59 assert(!alignment.isZero() &&
"Alignment cannot be zero");
61 assert(mlir::isa<cir::PointerType>(pointer.getType()) &&
62 "Expected cir.ptr type");
64 assert(mlir::cast<cir::PointerType>(pointer.getType()).getPointee() ==
72 assert((!alignment.isZero() || pointer ==
nullptr) &&
73 "creating valid address with invalid alignment");
78 return pointerAndKnownNonNull.getPointer() !=
nullptr;
100 return pointerAndKnownNonNull.getPointer();
106 assert(
isValid() &&
"pointer isn't valid");
118 assert(mlir::cast<cir::PointerType>(
119 pointerAndKnownNonNull.getPointer().getType())
120 .getPointee() == elementType);
127 assert(mlir::cast<cir::PointerType>(
128 pointerAndKnownNonNull.getPointer().getType())
129 .getPointee() == elementType);
134 auto ptrTy = mlir::dyn_cast<cir::PointerType>(
getType());
135 return ptrTy.getAddrSpace();
159 while (cir::CastOp castOp = ptr.getDefiningOp<cir::CastOp>()) {
160 if (!castOp.isAllocaPreservingCast())
162 ptr = castOp.getSrc();
164 return ptr.getDefiningOp<cir::AllocaOp>();
169 assert(
isValid() &&
"Invalid address");
170 return static_cast<bool>(pointerAndKnownNonNull.getInt());
175 assert(
isValid() &&
"Invalid address");
176 pointerAndKnownNonNull.setInt(
true);
bool isKnownNonNull() const
Whether the pointer is known not to be null.
Address withPointer(mlir::Value newPtr) const
Return address with different pointer, but same element type and alignment.
mlir::ptr::MemorySpaceAttrInterface getAddressSpace() const
mlir::Value getPointer() const
Address(mlir::Value pointer, clang::CharUnits alignment)
mlir::Type getElementType() const
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const
Return address with different element type, a bitcast pointer, and the same alignment.
Address setKnownNonNull()
Set the non-null bit.
clang::CharUnits getAlignment() const
Address withAlignment(clang::CharUnits newAlignment) const
Return address with different alignment, but same pointer and element type.
mlir::Value getBasePointer() const
mlir::Type getType() const
Address(mlir::Value pointer, mlir::Type elementType, clang::CharUnits alignment, bool isKnownNonNull)
Address(mlir::Value pointer, mlir::Type elementType, clang::CharUnits alignment)
OpTy getDefiningOp() const
cir::AllocaOp getUnderlyingAllocaOp() const
Return the underlying alloca for this address, if any.
mlir::Operation * getDefiningOp() const
Get the operation which defines this address.
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits - This is an opaque type for sizes expressed in character units.
PointerType - C99 6.7.5.1 - Pointer Declarators.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
U cast(CodeGen::Address addr)
static bool addressPointerAuthInfo()