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

26

31

32

34

35

36

37

38

39

40

41

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

44 llvm::Type *ElementType;

46

47protected:

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

75

76

79 return ElementType;

80 }

81

82

84 return getType()->getAddressSpace();

85 }

86

87

91

92

95 return Alignment;

96 }

97

98

99

103

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:

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

175

177 bool isValid() const { return Pointer.getPointer() != nullptr; }

178

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

181 return isSigned() ? Pointer.getPointer() : nullptr;

182 }

183

184

185

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

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

189 "Pointer's type changed");

190 Pointer.setPointer(P);

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

192 }

193

195

197

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

200 return Pointer.getPointer();

201 }

202

203

205 return llvm::castllvm::PointerType(Pointer.getPointer()->getType());

206 }

207

208

211 return ElementType;

212 }

213

214

216

217

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

219

222

223

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

227 ElementType = Ty;

228 }

229

230 bool isSigned() const { return PtrAuthInfo.isSigned(); }

231

232

237

243

245

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

247

250

251

252

256 return emitRawPointerSlow(CGF);

257 }

258

259

260

264 IsKnownNonNull);

265 }

266

267

268

273

274

275

282 A.ElementType = ElemTy;

283 return A;

284 }

285};

286

293

294

295

297 ConstantAddress(std::nullptr_t) : RawAddress(nullptr) {}

298

299public:

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

303

305 return ConstantAddress(nullptr);

306 }

307

311

315

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

318 }

320 return ConstantAddress(llvm::castllvm::Constant(addr.getPointer()),

322 }

323};

324}

325

326

328 return U::castImpl(addr);

329}

331 return U::isaImpl(addr);

332}

333

334}

335

336#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 ...

Definition Address.h:128

llvm::Value * getBasePointer() const

Definition Address.h:198

Address(std::nullptr_t)

Definition Address.h:151

static Address invalid()

Definition Address.h:176

bool isSigned() const

Definition Address.h:230

llvm::Value * getPointerIfNotSigned() const

Definition Address.h:179

llvm::Value * emitRawPointer(CodeGenFunction &CGF) const

Return the pointer contained in this class after authenticating it and adding offset to it if necessa...

Definition Address.h:253

CharUnits getAlignment() const

Definition Address.h:194

llvm::Type * getElementType() const

Return the type of the values stored in this address.

Definition Address.h:209

void setPointerAuthInfo(const CGPointerAuthInfo &Info)

Definition Address.h:221

Address withPointer(llvm::Value *NewPointer, KnownNonNull_t IsKnownNonNull) const

Return address with different pointer, but same element type and alignment.

Definition Address.h:261

Address withElementType(llvm::Type *ElemTy) const

Return address with different element type, but same pointer and alignment.

Definition Address.h:276

unsigned getAddressSpace() const

Return the address space that this address resides in.

Definition Address.h:215

Address(llvm::Value *pointer, llvm::Type *elementType, CharUnits alignment, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)

Definition Address.h:154

bool hasOffset() const

Definition Address.h:244

KnownNonNull_t isKnownNonNull() const

Whether the pointer is known not to be null.

Definition Address.h:233

Address setKnownNonNull()

Definition Address.h:238

void setAlignment(CharUnits Value)

Definition Address.h:196

Address withAlignment(CharUnits NewAlignment) const

Return address with different alignment, but same pointer and element type.

Definition Address.h:269

llvm::Value * getOffset() const

Definition Address.h:246

void replaceBasePointer(llvm::Value *P)

This function is used in situations where the caller is doing some sort of opaque "laundering" of the...

Definition Address.h:186

Address(RawAddress RawAddr)

Definition Address.h:169

llvm::StringRef getName() const

Return the IR name of the pointer value.

Definition Address.h:218

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

const CGPointerAuthInfo & getPointerAuthInfo() const

Definition Address.h:220

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

Definition Address.h:163

friend class CGBuilderTy

Definition Address.h:129

void setElementType(llvm::Type *Ty)

Definition Address.h:224

bool isValid() const

Definition Address.h:177

llvm::PointerType * getType() const

Return the type of the pointer value.

Definition Address.h:204

CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...

This class organizes the cross-function state that is used while generating LLVM code.

static ConstantAddress castImpl(RawAddress addr)

Definition Address.h:319

ConstantAddress withElementType(llvm::Type *ElemTy) const

Definition Address.h:312

static bool isaImpl(RawAddress addr)

Definition Address.h:316

static ConstantAddress invalid()

Definition Address.h:304

ConstantAddress(llvm::Constant *pointer, llvm::Type *elementType, CharUnits alignment)

Definition Address.h:300

llvm::Constant * getPointer() const

Definition Address.h:308

An abstract representation of an aligned address.

Definition Address.h:42

RawAddress withElementType(llvm::Type *ElemTy) const

Return address with different element type, but same pointer and alignment.

Definition Address.h:100

llvm::StringRef getName() const

Return the IR name of the pointer value.

Definition Address.h:88

llvm::PointerType * getType() const

Return the type of the pointer value.

Definition Address.h:72

CharUnits getAlignment() const

Return the alignment of this pointer.

Definition Address.h:93

llvm::Type * getElementType() const

Return the type of the values stored in this address.

Definition Address.h:77

KnownNonNull_t isKnownNonNull() const

Definition Address.h:104

RawAddress(llvm::Value *Pointer, llvm::Type *ElementType, CharUnits Alignment, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)

Definition Address.h:51

llvm::Value * getPointer() const

Definition Address.h:66

unsigned getAddressSpace() const

Return the address space that this address resides in.

Definition Address.h:83

static RawAddress invalid()

Definition Address.h:61

RawAddress(std::nullptr_t)

Definition Address.h:48

bool isValid() const

Definition Address.h:62

KnownNonNull_t

Definition Address.h:33

@ KnownNonNull

Definition Address.h:33

@ NotKnownNonNull

Definition Address.h:33

The JSON file list parser is used to communicate input to InstallAPI.

bool isa(CodeGen::Address addr)

Definition Address.h:330

nullptr

This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...

U cast(CodeGen::Address addr)

Definition Address.h:327