9#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
10#define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
15#include "llvm/Analysis/Utils/Local.h"
16#include "llvm/IR/DataLayout.h"
17#include "llvm/IR/IRBuilder.h"
18#include "llvm/IR/Type.h"
37 void InsertHelper(llvm::Instruction *I,
const llvm::Twine &Name,
38 llvm::BasicBlock::iterator InsertPt)
const override;
46typedef llvm::IRBuilder<llvm::ConstantFolder, CGBuilderInserterTy>
58 llvm::Value *emitRawPointerFromAddress(
Address Addr)
const {
62 template <
bool IsInBounds>
63 Address createConstGEP2_32(
Address Addr,
unsigned Idx0,
unsigned Idx1,
64 const llvm::Twine &Name) {
65 const llvm::DataLayout &DL = BB->getDataLayout();
66 llvm::GetElementPtrInst *GEP;
69 Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
73 Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
76 DL.getIndexSizeInBits(Addr.getType()->getPointerAddressSpace()), 0,
78 if (!GEP->accumulateConstantOffset(DL, Offset))
79 llvm_unreachable(
"offset of GEP with constants is always computable");
80 return Address(GEP, GEP->getResultElementType(),
81 Addr.getAlignment().alignmentAtOffset(
90 const llvm::ConstantFolder &F,
102 return llvm::ConstantInt::get(TypeCache.
SizeTy, N);
109 emitRawPointerFromAddress(Addr),
116 emitRawPointerFromAddress(Addr),
120 const llvm::Twine &Name =
"") {
126 using CGBuilderBaseTy::CreateAlignedLoad;
129 const llvm::Twine &Name =
"") {
136 bool IsVolatile =
false) {
141 using CGBuilderBaseTy::CreateAlignedStore;
144 bool IsVolatile =
false) {
152 bool IsVolatile =
false) {
153 return CGBuilderBaseTy::CreateStore(Val, Addr, IsVolatile);
158 const llvm::Twine &Name =
"") {
167 llvm::AtomicCmpXchgInst *
169 llvm::AtomicOrdering SuccessOrdering,
170 llvm::AtomicOrdering FailureOrdering,
171 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
172 return CGBuilderBaseTy::CreateAtomicCmpXchg(
178 llvm::AtomicRMWInst *
180 llvm::AtomicOrdering Ordering,
181 llvm::SyncScope::ID SSID = llvm::SyncScope::System) {
182 return CGBuilderBaseTy::CreateAtomicRMW(
187 using CGBuilderBaseTy::CreateAddrSpaceCast;
189 llvm::Type *ElementTy,
190 const llvm::Twine &Name =
"") {
201 using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast;
203 llvm::Type *ElementTy,
204 const llvm::Twine &Name =
"") {
205 if (Addr.
getType()->getAddressSpace() == Ty->getPointerAddressSpace())
217 using CGBuilderBaseTy::CreateStructGEP;
219 const llvm::Twine &Name =
"") {
220 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
221 const llvm::DataLayout &DL = BB->getDataLayout();
222 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
241 const llvm::Twine &Name =
"") {
242 llvm::ArrayType *ElTy = cast<llvm::ArrayType>(Addr.
getElementType());
243 const llvm::DataLayout &DL = BB->getDataLayout();
249 {getSize(CharUnits::Zero()), getSize(Index)}, Name),
261 const llvm::Twine &Name =
"") {
263 const llvm::DataLayout &DL = BB->getDataLayout();
278 const llvm::Twine &Name =
"") {
280 const llvm::DataLayout &DL = BB->getDataLayout();
290 using CGBuilderBaseTy::CreateGEP;
292 const llvm::Twine &Name =
"") {
293 const llvm::DataLayout &DL = BB->getDataLayout();
305 const llvm::Twine &Name =
"") {
315 const llvm::Twine &Name =
"") {
323 using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
325 const llvm::Twine &Name =
"") {
326 return createConstGEP2_32<true>(Addr, Idx0, Idx1, Name);
329 using CGBuilderBaseTy::CreateConstGEP2_32;
331 const llvm::Twine &Name =
"") {
332 return createConstGEP2_32<false>(Addr, Idx0, Idx1, Name);
336 llvm::Type *ElementType,
CharUnits Align,
337 const Twine &Name =
"") {
338 llvm::Value *Ptr = emitRawPointerFromAddress(Addr);
343 using CGBuilderBaseTy::CreateInBoundsGEP;
345 llvm::Type *ElementType,
CharUnits Align,
346 const Twine &Name =
"") {
348 emitRawPointerFromAddress(Addr),
353 using CGBuilderBaseTy::CreateIsNull;
359 return llvm::ConstantInt::getFalse(Context);
362 using CGBuilderBaseTy::CreateMemCpy;
364 bool IsVolatile =
false) {
365 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
366 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
371 bool IsVolatile =
false) {
372 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
373 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
378 using CGBuilderBaseTy::CreateMemCpyInline;
380 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
381 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
386 using CGBuilderBaseTy::CreateMemMove;
388 bool IsVolatile =
false) {
389 llvm::Value *DestPtr = emitRawPointerFromAddress(Dest);
390 llvm::Value *SrcPtr = emitRawPointerFromAddress(Src);
395 using CGBuilderBaseTy::CreateMemSet;
397 llvm::Value *Size,
bool IsVolatile =
false) {
402 using CGBuilderBaseTy::CreateMemSetInline;
410 using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
413 llvm::MDNode *DbgInfo) {
414 llvm::StructType *ElTy = cast<llvm::StructType>(Addr.
getElementType());
415 const llvm::DataLayout &DL = BB->getDataLayout();
416 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
421 Index, FieldIndex, DbgInfo),
426 using CGBuilderBaseTy::CreatePreserveUnionAccessIndex;
428 llvm::MDNode *DbgInfo) {
434 using CGBuilderBaseTy::CreateLaunderInvariantGroup;
440 using CGBuilderBaseTy::CreateStripInvariantGroup;
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="")
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