9 #ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 10 #define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 12 #include "llvm/IR/DataLayout.h" 13 #include "llvm/IR/IRBuilder.h" 20 class CodeGenFunction;
32 void InsertHelper(llvm::Instruction *I,
const llvm::Twine &Name,
34 llvm::BasicBlock::iterator InsertPt)
const;
41 typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
52 llvm::LLVMContext &C,
const llvm::ConstantFolder &F,
53 const CGBuilderInserterTy &Inserter)
64 return llvm::ConstantInt::get(TypeCache.
SizeTy, N);
82 const llvm::Twine &Name =
"") {
89 using CGBuilderBaseTy::CreateAlignedLoad;
91 const llvm::Twine &Name =
"") {
92 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
96 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
100 const llvm::Twine &Name =
"") {
101 assert(Addr->getType()->getPointerElementType() == Ty);
102 return CreateAlignedLoad(Addr, Align.
getQuantity(), Name);
108 bool IsVolatile =
false) {
109 return CreateAlignedStore(Val, Addr.
getPointer(),
113 using CGBuilderBaseTy::CreateAlignedStore;
115 CharUnits Align,
bool IsVolatile =
false) {
116 return CreateAlignedStore(Val, Addr, Align.
getQuantity(), IsVolatile);
123 bool IsVolatile =
false) {
124 return CGBuilderBaseTy::CreateStore(Val, Addr, IsVolatile);
129 const llvm::Twine &Name =
"") {
130 assert(Addr->getType()->getPointerElementType() == getInt1Ty());
131 return CreateAlignedLoad(getInt1Ty(), Addr,
CharUnits::One(), Name);
136 assert(Addr->getType()->getPointerElementType() == getInt1Ty());
137 return CreateAlignedStore(getInt1(Value), Addr,
CharUnits::One());
140 using CGBuilderBaseTy::CreateBitCast;
142 const llvm::Twine &Name =
"") {
147 using CGBuilderBaseTy::CreateAddrSpaceCast;
149 const llvm::Twine &Name =
"") {
157 const llvm::Twine &Name =
"") {
159 return CreateBitCast(Addr, PtrTy, Name);
162 using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
164 const llvm::Twine &Name =
"") {
166 CreatePointerBitCastOrAddrSpaceCast(Addr.
getPointer(), Ty, Name);
177 using CGBuilderBaseTy::CreateStructGEP;
179 const llvm::Twine &Name =
"") {
180 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
181 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
182 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
199 const llvm::Twine &Name =
"") {
200 llvm::ArrayType *ElTy = cast<llvm::ArrayType>(Addr.
getElementType());
201 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
217 const llvm::Twine &Name =
"") {
219 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
223 getSize(Index), Name),
233 const llvm::Twine &Name =
"") {
234 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
239 getSize(Index), Name),
245 const llvm::Twine &Name =
"") {
251 const llvm::Twine &Name =
"") {
257 using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
259 const llvm::Twine &Name =
"") {
260 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
262 auto *GEP = cast<llvm::GetElementPtrInst>(CreateConstInBoundsGEP2_32(
265 DL.getIndexSizeInBits(Addr.
getType()->getPointerAddressSpace()), 0,
267 if (!GEP->accumulateConstantOffset(DL, Offset))
268 llvm_unreachable(
"offset of GEP with constants is always computable");
273 using CGBuilderBaseTy::CreateMemCpy;
275 bool IsVolatile =
false) {
281 bool IsVolatile =
false) {
287 using CGBuilderBaseTy::CreateMemMove;
289 bool IsVolatile =
false) {
295 using CGBuilderBaseTy::CreateMemSet;
302 using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
306 llvm::MDNode *DbgInfo) {
307 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
308 const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
309 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
313 Index, FieldIndex, DbgInfo),
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::Instruction *I)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ...
llvm::StoreInst * CreateDefaultAlignedStore(llvm::Value *Val, llvm::Value *Addr, bool IsVolatile=false)
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Address CreatePreserveStructAccessIndex(Address Addr, unsigned Index, unsigned FieldIndex, llvm::MDNode *DbgInfo)
CGBuilderTy(const CodeGenTypeCache &TypeCache, llvm::BasicBlock *BB)
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 CreateConstGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ...
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP2_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]* ...
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
This forwards to CodeGenFunction::InsertHelper.
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.
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
llvm::Type * getElementType() const
Return the type of the values stored in this address.
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="")
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