Go to the documentation of this file.
14 #ifndef LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
15 #define LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
18 #include "llvm/ADT/PointerIntPair.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/Support/MathExtras.h"
28 template <
typename T,
bool = alignof(llvm::Value *) >= 8>
class AddressImpl {};
30 template <
typename T>
class AddressImpl<T,
false> {
32 llvm::Type *ElementType;
38 : Pointer(Pointer), ElementType(ElementType), Alignment(Alignment) {}
44 template <
typename T>
class AddressImpl<T,
true> {
46 llvm::PointerIntPair<llvm::Value *, 3, unsigned> Pointer;
48 llvm::PointerIntPair<llvm::Type *, 3, unsigned> ElementType;
53 : Pointer(Pointer), ElementType(ElementType) {
59 assert(Alignment.
isPowerOfTwo() &&
"Alignment cannot be zero");
60 auto AlignLog = llvm::Log2_64(Alignment.
getQuantity());
61 assert(AlignLog < (1 << 6) &&
"cannot fit alignment into 6 bits");
62 this->Pointer.setInt(AlignLog >> 3);
63 this->ElementType.setInt(AlignLog & 7);
65 llvm::Value *
getPointer()
const {
return Pointer.getPointer(); }
68 unsigned AlignLog = (Pointer.getInt() << 3) | ElementType.getInt();
82 : A(Pointer, ElementType, Alignment) {
83 assert(Pointer !=
nullptr &&
"Pointer cannot be null");
84 assert(ElementType !=
nullptr &&
"Element type cannot be null");
85 assert(llvm::cast<llvm::PointerType>(Pointer->getType())
86 ->isOpaqueOrPointeeTypeMatches(ElementType) &&
87 "Incorrect pointer element type");
91 bool isValid()
const {
return A.getPointer() !=
nullptr; }
95 return A.getPointer();
106 return A.getElementType();
111 return getType()->getAddressSpace();
122 return A.getAlignment();
146 :
Address(pointer, elementType, alignment) {}
157 llvm::Constant *BitCast = llvm::ConstantExpr::getBitCast(
163 return llvm::isa<llvm::Constant>(addr.
getPointer());
175 return U::castImpl(addr);
178 return U::isaImpl(addr);
CharUnits getAlignment() const
ConstantAddress getElementBitCast(llvm::Type *ElemTy) const
A specialization of Address that requires the address to be an LLVM Constant.
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
U cast(CodeGen::Address addr)
AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment)
static bool isaImpl(Address addr)
ConstantAddress(llvm::Constant *pointer, llvm::Type *elementType, CharUnits alignment)
llvm::StringRef getName() const
Return the IR name of the pointer value.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment)
llvm::PointerType * getType() const
Return the type of the pointer value.
bool isPowerOfTwo() const
isPowerOfTwo - Test whether the quantity is a power of two.
bool isa(CodeGen::Address addr)
bool Zero(InterpState &S, CodePtr OpPC)
Address(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment)
unsigned getAddressSpace() const
Return the address space that this address resides in.
CharUnits getAlignment() const
Address withAlignment(CharUnits NewAlignment) const
Return address with different alignment, but same pointer and element type.
static ConstantAddress castImpl(Address addr)
llvm::Value * getPointer() const
llvm::Value * getPointer() const
bool isZero() const
isZero - Test whether the quantity equals zero.
Address withPointer(llvm::Value *NewPointer) const
Return address with different pointer, but same element type and alignment.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::Constant * getPointer() const
static ConstantAddress invalid()
llvm::Value * getPointer() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
llvm::Type * getElementType() const