clang: lib/CodeGen/Address.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_LIB_CODEGEN_ADDRESS_H

15#define LLVM_CLANG_LIB_CODEGEN_ADDRESS_H

16

20#include "llvm/ADT/PointerIntPair.h"

21#include "llvm/IR/Constants.h"

22#include "llvm/Support/MathExtras.h"

23

25namespace CodeGen {

26

27class Address;

28class CGBuilderTy;

29class CodeGenFunction;

30class CodeGenModule;

31

32

34

35

36

37

38

39

40

41

43 llvm::PointerIntPair<llvm::Value *, 1, bool> PointerAndKnownNonNull;

44 llvm::Type *ElementType;

46

47protected:

48 RawAddress(std::nullptr_t) : ElementType(nullptr) {}

49

50public:

53 : PointerAndKnownNonNull(Pointer, IsKnownNonNull),

54 ElementType(ElementType), Alignment(Alignment) {

55 assert(Pointer != nullptr && "Pointer cannot be null");

56 assert(ElementType != nullptr && "Element type cannot be null");

57 }

58

60

63 return PointerAndKnownNonNull.getPointer() != nullptr;

64 }

65

68 return PointerAndKnownNonNull.getPointer();

69 }

70

71

72 llvm::PointerType *getType() const {

74 }

75

76

79 return ElementType;

80 }

81

82

84 return getType()->getAddressSpace();

85 }

86

87

90 }

91

92

95 return Alignment;

96 }

97

98

99

102 }

103

106 return (KnownNonNull_t)PointerAndKnownNonNull.getInt();

107 }

108};

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

130

131

132 llvm::PointerIntPair<llvm::Value *, 1, bool> Pointer;

133

134

135

136

137 llvm::Type *ElementType = nullptr;

138

140

141

143

144

145

146 llvm::Value *Offset = nullptr;

147

148 llvm::Value *emitRawPointerSlow(CodeGenFunction &CGF) const;

149

150protected:

151 Address(std::nullptr_t) : ElementType(nullptr) {}

152

153public:

154 Address(llvm::Value *pointer, llvm::Type *elementType, CharUnits alignment,

156 : Pointer(pointer, IsKnownNonNull), ElementType(elementType),

157 Alignment(alignment) {

158 assert(pointer != nullptr && "Pointer cannot be null");

159 assert(elementType != nullptr && "Element type cannot be null");

160 assert(!alignment.isZero() && "Alignment cannot be zero");

161 }

162

163 Address(llvm::Value *BasePtr, llvm::Type *ElementType, CharUnits Alignment,

166 : Pointer(BasePtr, IsKnownNonNull), ElementType(ElementType),

167 Alignment(Alignment), PtrAuthInfo(PtrAuthInfo), Offset(Offset) {}

168

170 : Pointer(RawAddr.isValid() ? RawAddr.getPointer() : nullptr,

175

178

179

180

182 assert(isValid() && "pointer isn't valid");

183 assert(P->getType() == Pointer.getPointer()->getType() &&

184 "Pointer's type changed");

186 assert(isValid() && "pointer is invalid after replacement");

187 }

188

190

192

194 assert(isValid() && "pointer isn't valid");

195 return Pointer.getPointer();

196 }

197

198

200 return llvm::PointerType::get(

201 ElementType,

202 llvm::castllvm::PointerType(Pointer.getPointer()->getType())

203 ->getAddressSpace());

204 }

205

206

209 return ElementType;

210 }

211

212

214

215

216 llvm::StringRef getName() const { return Pointer.getPointer()->getName(); }

217

220

221

224 "this funcion shouldn't be called when there is no offset");

225 ElementType = Ty;

226 }

227

229

230

234 }

235

239 return *this;

240 }

241

243

244 llvm::Value *getOffset() const { return Offset; }

245

248

249

250

254 return emitRawPointerSlow(CGF);

255 }

256

257

258

262 IsKnownNonNull);

263 }

264

265

266

270 }

271

272

273

280 A.ElementType = ElemTy;

281 return A;

282 }

283};

284

286 : PointerAndKnownNonNull(Addr.isValid() ? Addr.getBasePointer() : nullptr,

287 Addr.isValid() ? Addr.isKnownNonNull()

289 ElementType(Addr.isValid() ? Addr.getElementType() : nullptr),

290 Alignment(Addr.isValid() ? Addr.getAlignment() : CharUnits::Zero()) {}

291

292

293

296

297public:

300 : RawAddress(pointer, elementType, alignment) {}

301

304 }

305

308 }

309

312 }

313

315 return llvm::isallvm::Constant(addr.getPointer());

316 }

320 }

321};

322}

323

324

326 return U::castImpl(addr);

327}

329 return U::isaImpl(addr);

330}

331

332}

333

334#endif

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.

void setPointerAuthInfo(const CGPointerAuthInfo &Info)

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

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.

Address getResignedAddress(const CGPointerAuthInfo &NewInfo, CodeGenFunction &CGF) const

const CGPointerAuthInfo & getPointerAuthInfo() const

Address(llvm::Value *BasePtr, llvm::Type *ElementType, CharUnits Alignment, CGPointerAuthInfo PtrAuthInfo, llvm::Value *Offset, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)

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)