10 #ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 11 #define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 13 #include "llvm/IR/DataLayout.h" 14 #include "llvm/IR/IRBuilder.h" 21 class CodeGenFunction;
33 void InsertHelper(llvm::Instruction *I,
const llvm::Twine &Name,
35 llvm::BasicBlock::iterator InsertPt)
const;
42 typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
53 llvm::LLVMContext &C,
const llvm::ConstantFolder &F,
54 const CGBuilderInserterTy &Inserter)
65 return llvm::ConstantInt::get(TypeCache.
SizeTy, N);
83 const llvm::Twine &Name =
"") {
90 using CGBuilderBaseTy::CreateAlignedLoad;
92 const llvm::Twine &Name =
"") {
93 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
97 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
101 const llvm::Twine &Name =
"") {
102 assert(Addr->getType()->getPointerElementType() == Ty);
103 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
109 bool IsVolatile =
false) {
110 return CreateAlignedStore(Val, Addr.
getPointer(),
114 using CGBuilderBaseTy::CreateAlignedStore;
116 CharUnits Align,
bool IsVolatile =
false) {
117 return CreateAlignedStore(Val, Addr, Align.
getQuantity(), IsVolatile);
124 bool IsVolatile =
false) {
125 return CGBuilderBaseTy::CreateStore(Val, Addr, IsVolatile);
130 const llvm::Twine &Name =
"") {
131 assert(Addr->getType()->getPointerElementType() == getInt1Ty());
132 return CreateAlignedLoad(getInt1Ty(), Addr,
CharUnits::One(), Name);
137 assert(Addr->getType()->getPointerElementType() == getInt1Ty());
138 return CreateAlignedStore(getInt1(Value), Addr,
CharUnits::One());
141 using CGBuilderBaseTy::CreateBitCast;
143 const llvm::Twine &Name =
"") {
148 using CGBuilderBaseTy::CreateAddrSpaceCast;
150 const llvm::Twine &Name =
"") {
158 const llvm::Twine &Name =
"") {
160 return CreateBitCast(Addr, PtrTy, Name);
163 using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
165 const llvm::Twine &Name =
"") {
167 CreatePointerBitCastOrAddrSpaceCast(Addr.
getPointer(), Ty, Name);
171 using CGBuilderBaseTy::CreateStructGEP;
173 const llvm::Twine &Name =
"") {
179 const llvm::StructLayout *Layout,
180 const llvm::Twine &Name =
"") {
182 return CreateStructGEP(Addr, Index,
Offset, Name);
196 const llvm::Twine &Name =
"") {
213 const llvm::Twine &Name =
"") {
215 getSize(Index), Name),
227 const llvm::Twine &Name =
"") {
229 getSize(Index), Name),
235 const llvm::Twine &Name =
"") {
241 const llvm::Twine &Name =
"") {
247 using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
249 unsigned Idx1,
const llvm::DataLayout &DL,
250 const llvm::Twine &Name =
"") {
251 auto *GEP = cast<llvm::GetElementPtrInst>(CreateConstInBoundsGEP2_32(
254 DL.getIndexSizeInBits(Addr.
getType()->getPointerAddressSpace()), 0,
256 if (!GEP->accumulateConstantOffset(DL, Offset))
257 llvm_unreachable(
"offset of GEP with constants is always computable");
263 const llvm::Twine &Name =
"") {
264 assert(Ptr->getType()->getPointerElementType() == TypeCache.
Int8Ty);
265 return CreateInBoundsGEP(Ptr, getSize(Offset), Name);
268 const llvm::Twine &Name =
"") {
269 assert(Ptr->getType()->getPointerElementType() == TypeCache.
Int8Ty);
270 return CreateGEP(Ptr, getSize(Offset), Name);
273 using CGBuilderBaseTy::CreateMemCpy;
275 bool IsVolatile =
false) {
281 bool IsVolatile =
false) {
287 using CGBuilderBaseTy::CreateMemMove;
289 bool IsVolatile =
false) {
295 using CGBuilderBaseTy::CreateMemSet;
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::Instruction *I)
llvm::StoreInst * CreateDefaultAlignedStore(llvm::Value *Val, llvm::Value *Addr, bool IsVolatile=false)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::BasicBlock *BB)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::StructLayout *Layout, const llvm::Twine &Name="")
Address CreateConstGEP(Address Addr, uint64_t Index, CharUnits EltSize, const llvm::Twine &Name="")
Given addr = T* ...
llvm::ConstantInt * getSize(CharUnits N)
llvm::ConstantInt * getSize(uint64_t N)
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C, const llvm::ConstantFolder &F, const CGBuilderInserterTy &Inserter)
CGBuilderInserter CGBuilderInserterTy
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::Value * getPointer() const
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const char *Name)
unsigned getAddressSpace() const
Return the address space that this address resides in.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CGBuilderInserter(CodeGenFunction *CGF)
llvm::IntegerType * SizeTy
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::CallInst * CreateMemMove(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
CGBuilderInserter()=default
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...
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, uint64_t Size, bool IsVolatile=false)
CharUnits getAlignment() const
Return the alignment of this pointer.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
static CharUnits One()
One - Construct a CharUnits quantity of one.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
llvm::PointerType * getType() const
Return the type of the pointer value.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
llvm::StoreInst * CreateFlagStore(bool Value, llvm::Value *Addr)
Emit a store to an i1 flag variable.
The l-value was considered opaque, so the alignment was determined from a type.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
This forwards to CodeGenFunction::InsertHelper.
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::DataLayout &DL, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const char *Name)
This is an IRBuilder insertion helper that forwards to CodeGenFunction::InsertHelper, which adds necessary metadata to instructions.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset...
Dataflow Directional Tag Classes.
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, CharUnits EltSize, const llvm::Twine &Name="")
Given addr = T* ...
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateConstArrayGEP(Address Addr, uint64_t Index, CharUnits EltSize, const llvm::Twine &Name="")
Given addr = [n x T]* ...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::Value * CreateConstInBoundsByteGEP(llvm::Value *Ptr, CharUnits Offset, const llvm::Twine &Name="")
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
Address CreateConstByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, bool IsVolatile, const llvm::Twine &Name="")
llvm::Value * CreateConstByteGEP(llvm::Value *Ptr, CharUnits Offset, const llvm::Twine &Name="")
This structure provides a set of types that are commonly used during IR emission. ...
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::LLVMContext &C)
llvm::IRBuilder< llvm::ConstantFolder, CGBuilderInserterTy > CGBuilderBaseTy