14#ifndef LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
15#define LLVM_CLANG_LIB_CODEGEN_ADDRESS_H
19#include "llvm/ADT/PointerIntPair.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/Support/MathExtras.h"
42 llvm::PointerIntPair<llvm::Value *, 1, bool> PointerAndKnownNonNull;
43 llvm::Type *ElementType;
52 : PointerAndKnownNonNull(
Pointer, IsKnownNonNull),
53 ElementType(ElementType), Alignment(Alignment) {
54 assert(
Pointer !=
nullptr &&
"Pointer cannot be null");
55 assert(ElementType !=
nullptr &&
"Element type cannot be null");
62 return PointerAndKnownNonNull.getPointer() !=
nullptr;
67 return PointerAndKnownNonNull.getPointer();
83 return getType()->getAddressSpace();
115 llvm::PointerIntPair<llvm::Value *, 1, bool>
Pointer;
120 llvm::Type *ElementType =
nullptr;
125 llvm::Value *Offset =
nullptr;
130 Address(std::nullptr_t) : ElementType(nullptr) {}
135 :
Pointer(pointer, IsKnownNonNull), ElementType(elementType),
136 Alignment(alignment) {
137 assert(pointer !=
nullptr &&
"Pointer cannot be null");
138 assert(elementType !=
nullptr &&
"Element type cannot be null");
139 assert(!alignment.
isZero() &&
"Alignment cannot be zero");
144 :
Pointer(BasePtr, IsKnownNonNull), ElementType(ElementType),
145 Alignment(Alignment), Offset(Offset) {}
159 assert(
isValid() &&
"pointer isn't valid");
160 assert(
P->getType() ==
Pointer.getPointer()->getType() &&
161 "Pointer's type changed");
163 assert(
isValid() &&
"pointer is invalid after replacement");
171 assert(
isValid() &&
"pointer isn't valid");
177 return llvm::PointerType::get(
179 llvm::cast<llvm::PointerType>(
Pointer.getPointer()->getType())
180 ->getAddressSpace());
198 "this funcion shouldn't be called when there is no offset");
246 A.ElementType = ElemTy;
252 : PointerAndKnownNonNull(Addr.isValid() ? Addr.getBasePointer() : nullptr,
253 Addr.isValid() ? Addr.isKnownNonNull()
255 ElementType(Addr.isValid() ? Addr.getElementType() : nullptr),
256 Alignment(Addr.isValid() ? Addr.getAlignment() :
CharUnits::Zero()) {}
266 :
RawAddress(pointer, elementType, alignment) {}
281 return llvm::isa<llvm::Constant>(addr.
getPointer());
292 return U::castImpl(addr);
295 return U::isaImpl(addr);
C Language Family Type Representation.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withPointer(llvm::Value *NewPointer, KnownNonNull_t IsKnownNonNull) const
Return address with different pointer, but same element type and alignment.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
unsigned getAddressSpace() const
Return the address space that this address resides in.
Address(llvm::Value *pointer, llvm::Type *elementType, CharUnits alignment, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
Address setKnownNonNull()
void setAlignment(CharUnits Value)
Address withAlignment(CharUnits NewAlignment) const
Return address with different alignment, but same pointer and element type.
llvm::Value * getOffset() const
Address(llvm::Value *BasePtr, llvm::Type *ElementType, CharUnits Alignment, llvm::Value *Offset, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
void replaceBasePointer(llvm::Value *P)
This function is used in situations where the caller is doing some sort of opaque "laundering" of the...
Address(RawAddress RawAddr)
llvm::StringRef getName() const
Return the IR name of the pointer value.
void setElementType(llvm::Type *Ty)
llvm::PointerType * getType() const
Return the type of the pointer value.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
A specialization of Address that requires the address to be an LLVM Constant.
static ConstantAddress castImpl(RawAddress addr)
ConstantAddress withElementType(llvm::Type *ElemTy) const
static bool isaImpl(RawAddress addr)
static ConstantAddress invalid()
ConstantAddress(llvm::Constant *pointer, llvm::Type *elementType, CharUnits alignment)
llvm::Constant * getPointer() const
An abstract representation of an aligned address.
RawAddress withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::StringRef getName() const
Return the IR name of the pointer value.
llvm::PointerType * getType() const
Return the type of the pointer value.
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
KnownNonNull_t isKnownNonNull() const
RawAddress(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
llvm::Value * getPointer() const
unsigned getAddressSpace() const
Return the address space that this address resides in.
static RawAddress invalid()
RawAddress(std::nullptr_t)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)