9#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
10#define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
14#include "llvm/IR/DataLayout.h"
15#include "llvm/IR/IRBuilder.h"
16#include "llvm/IR/Type.h"
32 void InsertHelper(llvm::Instruction *I,
const llvm::Twine &Name,
34 llvm::BasicBlock::iterator InsertPt)
const override;
42typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
54 const llvm::ConstantFolder &F,
66 return llvm::ConstantInt::get(TypeCache.
SizeTy, N);
82 const llvm::Twine &Name =
"") {
88 using CGBuilderBaseTy::CreateAlignedLoad;
91 const llvm::Twine &Name =
"") {
92 assert(llvm::cast<llvm::PointerType>(Addr->getType())
93 ->isOpaqueOrPointeeTypeMatches(Ty));
100 bool IsVolatile =
false) {
105 using CGBuilderBaseTy::CreateAlignedStore;
108 bool IsVolatile =
false) {
116 bool IsVolatile =
false) {
117 return CGBuilderBaseTy::CreateStore(Val, Addr, IsVolatile);
122 const llvm::Twine &Name =
"") {
123 assert(llvm::cast<llvm::PointerType>(Addr->getType())
124 ->isOpaqueOrPointeeTypeMatches(getInt1Ty()));
130 assert(llvm::cast<llvm::PointerType>(Addr->getType())
131 ->isOpaqueOrPointeeTypeMatches(getInt1Ty()));
137 llvm::AtomicCmpXchgInst *
139 llvm::AtomicOrdering SuccessOrdering,
140 llvm::AtomicOrdering FailureOrdering,
141 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
142 return CGBuilderBaseTy::CreateAtomicCmpXchg(
143 Ptr, Cmp, New, llvm::MaybeAlign(), SuccessOrdering, FailureOrdering,
149 llvm::AtomicRMWInst *
151 llvm::Value *Val, llvm::AtomicOrdering Ordering,
152 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
153 return CGBuilderBaseTy::CreateAtomicRMW(Op, Ptr, Val, llvm::MaybeAlign(),
157 using CGBuilderBaseTy::CreateAddrSpaceCast;
159 const llvm::Twine &Name =
"") {
160 assert(cast<llvm::PointerType>(Ty)->isOpaqueOrPointeeTypeMatches(
162 "Should not change the element type");
170 const llvm::Twine &Name =
"") {
176 using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
178 llvm::Type *ElementTy,
179 const llvm::Twine &Name =
"") {
192 using CGBuilderBaseTy::CreateStructGEP;
194 const llvm::Twine &Name =
"") {
195 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
196 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
197 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
215 const llvm::Twine &Name =
"") {
216 llvm::ArrayType *ElTy = cast<llvm::ArrayType>(Addr.
getElementType());
217 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
223 {getSize(CharUnits::Zero()), getSize(Index)}, Name),
224 ElTy->getElementType(),
235 const llvm::Twine &Name =
"") {
237 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
252 const llvm::Twine &Name =
"") {
253 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
266 using CGBuilderBaseTy::CreateGEP;
268 const llvm::Twine &Name =
"") {
269 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
281 const llvm::Twine &Name =
"") {
290 const llvm::Twine &Name =
"") {
299 using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
301 const llvm::Twine &Name =
"") {
302 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
307 DL.getIndexSizeInBits(Addr.
getType()->getPointerAddressSpace()), 0,
309 if (!GEP->accumulateConstantOffset(DL,
Offset))
310 llvm_unreachable(
"offset of GEP with constants is always computable");
311 return Address(GEP, GEP->getResultElementType(),
317 using CGBuilderBaseTy::CreateMemCpy;
319 bool IsVolatile =
false) {
325 bool IsVolatile =
false) {
331 using CGBuilderBaseTy::CreateMemCpyInline;
338 using CGBuilderBaseTy::CreateMemMove;
340 bool IsVolatile =
false) {
346 using CGBuilderBaseTy::CreateMemSet;
348 llvm::Value *Size,
bool IsVolatile =
false) {
353 using CGBuilderBaseTy::CreateMemSetInline;
361 using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
364 llvm::MDNode *DbgInfo) {
365 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
366 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
367 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
371 Index, FieldIndex, DbgInfo),
376 using CGBuilderBaseTy::CreateLaunderInvariantGroup;
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.
CharUnits getAlignment() const
Return the alignment of this pointer.
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.
unsigned getAddressSpace() const
Return the address space that this address resides in.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
llvm::Value * getPointer() 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
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const override
This forwards to CodeGenFunction::InsertHelper.
CGBuilderInserter(CodeGenFunction *CGF)
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="")
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 CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
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, llvm::Value *Ptr, llvm::Value *Val, llvm::AtomicOrdering Ordering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
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::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 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 CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
llvm::ConstantInt * getSize(uint64_t N)
llvm::AtomicCmpXchgInst * CreateAtomicCmpXchg(llvm::Value *Ptr, llvm::Value *Cmp, llvm::Value *New, llvm::AtomicOrdering SuccessOrdering, llvm::AtomicOrdering FailureOrdering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
Address CreateGEP(Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::IRBuilder< llvm::ConstantFolder, CGBuilderInserterTy > CGBuilderBaseTy
CGBuilderInserter CGBuilderInserterTy
@ C
Languages that the frontend can parse and compile.
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