14#ifndef CLANG_LIB_CIR_ADDRESS_H
15#define CLANG_LIB_CIR_ADDRESS_H
17#include "mlir/IR/Value.h"
22#include "llvm/ADT/PointerIntPair.h"
23#include "llvm/Support/Casting.h"
33 llvm::PointerIntPair<mlir::Value, 1, bool> pointerAndKnownNonNull;
38 mlir::Type elementType;
46 Address(mlir::Value pointer, mlir::Type elementType,
50 Address(mlir::Value pointer, mlir::Type elementType,
53 elementType(elementType), alignment(alignment) {
54 assert(pointer &&
"Pointer cannot be null");
55 assert(elementType &&
"Element type cannot be null");
56 assert(!alignment.isZero() &&
"Alignment cannot be zero");
58 assert(mlir::isa<cir::PointerType>(pointer.getType()) &&
59 "Expected cir.ptr type");
61 assert(mlir::cast<cir::PointerType>(pointer.getType()).getPointee() ==
69 assert((!alignment.isZero() || pointer ==
nullptr) &&
70 "creating valid address with invalid alignment");
75 return pointerAndKnownNonNull.getPointer() !=
nullptr;
97 return pointerAndKnownNonNull.getPointer();
103 assert(
isValid() &&
"pointer isn't valid");
115 assert(mlir::cast<cir::PointerType>(
116 pointerAndKnownNonNull.getPointer().getType())
117 .getPointee() == elementType);
124 assert(mlir::cast<cir::PointerType>(
125 pointerAndKnownNonNull.getPointer().getType())
126 .getPointee() == elementType);
131 auto ptrTy = mlir::dyn_cast<cir::PointerType>(
getType());
132 return ptrTy.getAddrSpace();
150 assert(
isValid() &&
"Invalid address");
151 return static_cast<bool>(pointerAndKnownNonNull.getInt());
156 assert(
isValid() &&
"Invalid address");
157 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::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.
cir::TargetAddressSpaceAttr getAddressSpace() const
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
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()