clang: lib/CodeGen/CGBuilder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
10#define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
11
15#include "llvm/Analysis/Utils/Local.h"
16#include "llvm/IR/DataLayout.h"
17#include "llvm/IR/GEPNoWrapFlags.h"
18#include "llvm/IR/IRBuilder.h"
19#include "llvm/IR/Type.h"
20
22namespace CodeGen {
23
24class CGBuilderTy;
25class CodeGenFunction;
26
27
28
29
32
33public:
36
37
38 void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
39 llvm::BasicBlock::iterator InsertPt) const override;
40
41private:
43};
44
46
47typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
49
52
53
54
56
57 CodeGenFunction *getCGF() const { return getInserter().CGF; }
58
59 llvm::Value *emitRawPointerFromAddress(Address Addr) const {
61 }
62
63 template
64 Address createConstGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1,
65 const llvm::Twine &Name) {
66 const llvm::DataLayout &DL = BB->getDataLayout();
67 llvm::GetElementPtrInst *GEP;
68 if (IsInBounds)
70 Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
71 Name));
72 else
74 Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
75 Name));
76 llvm::APInt Offset(
77 DL.getIndexSizeInBits(Addr.getType()->getPointerAddressSpace()), 0,
78 true);
79 if (!GEP->accumulateConstantOffset(DL, Offset))
80 llvm_unreachable("offset of GEP with constants is always computable");
81 return Address(GEP, GEP->getResultElementType(),
82 Addr.getAlignment().alignmentAtOffset(
85 }
86
87public:
91 const llvm::ConstantFolder &F,
98
100 return llvm::ConstantInt::get(TypeCache.SizeTy, N.getQuantity());
101 }
102 llvm::ConstantInt *getSize(uint64_t N) {
103 return llvm::ConstantInt::get(TypeCache.SizeTy, N);
104 }
105
106
107
110 emitRawPointerFromAddress(Addr),
112 }
114
115
117 emitRawPointerFromAddress(Addr),
119 }
121 const llvm::Twine &Name = "") {
123 Addr.getElementType(), emitRawPointerFromAddress(Addr),
125 }
126
127 using CGBuilderBaseTy::CreateAlignedLoad;
130 const llvm::Twine &Name = "") {
132 }
133
134
135
137 bool IsVolatile = false) {
140 }
141
142 using CGBuilderBaseTy::CreateAlignedStore;
145 bool IsVolatile = false) {
147 }
148
149
150
152 llvm::Value *Addr,
153 bool IsVolatile = false) {
154 return CGBuilderBaseTy::CreateStore(Val, Addr, IsVolatile);
155 }
156
157
159 const llvm::Twine &Name = "") {
161 }
162
163
166 }
167
168 llvm::AtomicCmpXchgInst *
170 llvm::AtomicOrdering SuccessOrdering,
171 llvm::AtomicOrdering FailureOrdering,
172 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
173 return CGBuilderBaseTy::CreateAtomicCmpXchg(
176 SSID);
177 }
178
179 llvm::AtomicRMWInst *
181 llvm::AtomicOrdering Ordering,
182 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
183 return CGBuilderBaseTy::CreateAtomicRMW(
186 }
187
188 using CGBuilderBaseTy::CreateAddrSpaceCast;
190 llvm::Type *ElementTy,
191 const llvm::Twine &Name = "") {
196
200 }
201
202 using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
204 llvm::Type *ElementTy,
205 const llvm::Twine &Name = "") {
206 if (Addr.getType()->getAddressSpace() == Ty->getPointerAddressSpace())
209 }
210
211
212
213
214
215
216
217
218 using CGBuilderBaseTy::CreateStructGEP;
220 const llvm::Twine &Name = "") {
221 llvm::StructType *ElTy = castllvm::StructType(Addr.getElementType());
222 const llvm::DataLayout &DL = BB->getDataLayout();
223 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
225
227 Index, Name),
231 }
232
233
234
235
236
237
238
239
240
242 const llvm::Twine &Name = "") {
243 llvm::ArrayType *ElTy = castllvm::ArrayType(Addr.getElementType());
244 const llvm::DataLayout &DL = BB->getDataLayout();
247
250 {getSize(CharUnits::Zero()), getSize(Index)}, Name),
254 }
255
256
257
258
259
260
262 const llvm::Twine &Name = "") {
264 const llvm::DataLayout &DL = BB->getDataLayout();
266
271 }
272
273
274
275
276
277
279 const llvm::Twine &Name = "") {
281 const llvm::DataLayout &DL = BB->getDataLayout();
283
287 }
288
289
290
291 using CGBuilderBaseTy::CreateGEP;
293 const llvm::Twine &Name = "") {
294 const llvm::DataLayout &DL = BB->getDataLayout();
297
302 }
303
304
306 const llvm::Twine &Name = "") {
313 }
314
316 const llvm::Twine &Name = "") {
322 }
323
324 using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
326 const llvm::Twine &Name = "") {
327 return createConstGEP2_32(Addr, Idx0, Idx1, Name);
328 }
329
330 using CGBuilderBaseTy::CreateConstGEP2_32;
332 const llvm::Twine &Name = "") {
333 return createConstGEP2_32(Addr, Idx0, Idx1, Name);
334 }
335
337 llvm::Type *ElementType, CharUnits Align,
338 const Twine &Name = "",
339 llvm::GEPNoWrapFlags NW = llvm::GEPNoWrapFlags::none()) {
340 llvm::Value *Ptr = emitRawPointerFromAddress(Addr);
342 ElementType, Align);
343 }
344
345 using CGBuilderBaseTy::CreateInBoundsGEP;
347 llvm::Type *ElementType, CharUnits Align,
348 const Twine &Name = "") {
350 emitRawPointerFromAddress(Addr),
351 IdxList, Name),
353 }
354
355 using CGBuilderBaseTy::CreateIsNull;
359
360
361 return llvm::ConstantInt::getFalse(Context);
362 }
363
364 using CGBuilderBaseTy::CreateMemCpy;
366 bool IsVolatile = false) {
367 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
368 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
371 }
373 bool IsVolatile = false) {
374 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
375 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
378 }
379
380 using CGBuilderBaseTy::CreateMemCpyInline;
382 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
383 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
386 }
387
388 using CGBuilderBaseTy::CreateMemMove;
390 bool IsVolatile = false) {
391 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
392 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
395 }
396
397 using CGBuilderBaseTy::CreateMemSet;
399 llvm::Value *Size, bool IsVolatile = false) {
400 return CreateMemSet(emitRawPointerFromAddress(Dest), Value, Size,
402 }
403
404 using CGBuilderBaseTy::CreateMemSetInline;
406 uint64_t Size) {
409 getInt64(Size));
410 }
411
412 using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
414 unsigned FieldIndex,
415 llvm::MDNode *DbgInfo) {
416 llvm::StructType *ElTy = castllvm::StructType(Addr.getElementType());
417 const llvm::DataLayout &DL = BB->getDataLayout();
418 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
420
423 Index, FieldIndex, DbgInfo),
426 }
427
428 using CGBuilderBaseTy::CreatePreserveUnionAccessIndex;
430 llvm::MDNode *DbgInfo) {
433 return Addr;
434 }
435
436 using CGBuilderBaseTy::CreateLaunderInvariantGroup;
439 return Addr;
440 }
441
442 using CGBuilderBaseTy::CreateStripInvariantGroup;
445 return Addr;
446 }
447};
448
449}
450}
451
452#endif
CharUnits - This is an opaque type for sizes expressed in character units.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
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 withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
void replaceBasePointer(llvm::Value *P)
This function is used in situations where the caller is doing some sort of opaque "laundering" of the...
const CGPointerAuthInfo & getPointerAuthInfo() const
llvm::PointerType * getType() const
Return the type of the pointer value.
This is an IRBuilder insertion helper that forwards to CodeGenFunction::InsertHelper,...
CGBuilderInserter()=default
CGBuilderInserter(CodeGenFunction *CGF)
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock::iterator InsertPt) const override
This forwards to CodeGenFunction::InsertHelper.
llvm::LoadInst * CreateLoad(Address Addr, bool IsVolatile, const llvm::Twine &Name="")
llvm::StoreInst * CreateFlagStore(bool Value, llvm::Value *Addr)
Emit a store to an i1 flag variable.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, uint64_t Size, bool IsVolatile=false)
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
llvm::Value * CreateIsNull(Address Addr, const Twine &Name="")
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C, const llvm::ConstantFolder &F, const CGBuilderInserterTy &Inserter)
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
llvm::CallInst * CreateMemMove(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
llvm::CallInst * CreateMemCpyInline(Address Dest, Address Src, uint64_t Size)
llvm::AtomicRMWInst * CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val, llvm::AtomicOrdering Ordering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
Address CreateConstGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = [n x T]* ... produce name = getelementptr inbounds addr, i64 0, i64 index where i64 is a...
llvm::CallInst * CreateMemSetInline(Address Dest, llvm::Value *Value, uint64_t Size)
llvm::StoreInst * CreateDefaultAlignedStore(llvm::Value *Val, llvm::Value *Addr, bool IsVolatile=false)
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C)
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::Instruction *I)
llvm::AtomicCmpXchgInst * CreateAtomicCmpXchg(Address Addr, llvm::Value *Cmp, llvm::Value *New, llvm::AtomicOrdering SuccessOrdering, llvm::AtomicOrdering FailureOrdering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Address CreateConstByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Address CreatePreserveStructAccessIndex(Address Addr, unsigned Index, unsigned FieldIndex, llvm::MDNode *DbgInfo)
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
Address CreateLaunderInvariantGroup(Address Addr)
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::BasicBlock *BB)
Address CreateConstGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
llvm::ConstantInt * getSize(CharUnits N)
llvm::LoadInst * CreateLoad(Address Addr, const char *Name)
Address CreatePreserveUnionAccessIndex(Address Addr, unsigned FieldIndex, llvm::MDNode *DbgInfo)
Address CreateStripInvariantGroup(Address Addr)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
llvm::ConstantInt * getSize(uint64_t N)
Address CreateGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="", llvm::GEPNoWrapFlags NW=llvm::GEPNoWrapFlags::none())
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
An abstract representation of an aligned address.
llvm::IRBuilder< llvm::ConstantFolder, CGBuilderInserterTy > CGBuilderBaseTy
CGBuilderInserter CGBuilderInserterTy
The JSON file list parser is used to communicate input to InstallAPI.
This structure provides a set of types that are commonly used during IR emission.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * SizeTy