1//===- IRBuilder.cpp - Builder for LLVM Instrs ----------------------------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file implements the IRBuilder class, which is used as a convenient way 10// to create LLVM instructions with a consistent and simplified interface. 12//===----------------------------------------------------------------------===// 40/// CreateGlobalString - Make a new global variable with an initializer that 41/// has array of i8 type filled in with the nul terminated string value 42/// specified. If Name is specified, it is the name of the global variable 55 GV->setAlignment(
Align(1));
65for (
auto &KV : MetadataToCopy)
66if (KV.first == LLVMContext::MD_dbg)
67return {cast<DILocation>(KV.second)};
72for (
constauto &KV : MetadataToCopy)
73if (KV.first == LLVMContext::MD_dbg) {
84if (isa<FPMathOperator>(CI))
90assert(isa<ConstantInt>(Scaling) &&
"Expected constant integer");
91if (cast<ConstantInt>(Scaling)->
isZero())
95return cast<ConstantInt>(Scaling)->isOne() ? CI :
CreateMul(CI, Scaling);
99Constant *MinEC = ConstantInt::get(DstType, EC.getKnownMinValue());
104Constant *MinSize = ConstantInt::get(DstType,
Size.getKnownMinValue());
110if (isa<ScalableVectorType>(DstType)) {
111Type *StepVecType = DstType;
112// TODO: We expect this special case (element type < 8 bits) to be 113// temporary - once the intrinsic properly supports < 8 bits this code 120if (StepVecType != DstType)
125unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
127// Create a vector of consecutive numbers from zero to VF. 129for (
unsigned i = 0; i < NumEls; ++i)
130 Indices.
push_back(ConstantInt::get(STy, i));
132// Add the consecutive indices to the vector value. 146 cast<MemSetInst>(CI)->setDestAlignment(*
Align);
148// Set the TBAA info if present. 153 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
156 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
163bool IsVolatile,
MDNode *TBAATag,
167Type *Tys[] = {Dst->getType(),
Size->getType()};
172 cast<MemSetInlineInst>(CI)->setDestAlignment(*DstAlign);
174// Set the TBAA info if present. 179 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
182 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
197 cast<AtomicMemSetInst>(CI)->setDestAlignment(Alignment);
199// Set the TBAA info if present. 204 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
207 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
216assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
217 IntrID == Intrinsic::memmove) &&
218"Unexpected intrinsic ID");
220Type *Tys[] = {Dst->getType(), Src->getType(),
Size->getType()};
224auto* MCI = cast<MemTransferInst>(CI);
226 MCI->setDestAlignment(*DstAlign);
228 MCI->setSourceAlignment(*SrcAlign);
230// Set the TBAA info if present. 234// Set the TBAA Struct info if present. 236 CI->
setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
239 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
242 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
251assert(DstAlign >= ElementSize &&
252"Pointer alignment must be at least element size");
253assert(SrcAlign >= ElementSize &&
254"Pointer alignment must be at least element size");
256Type *Tys[] = {Dst->getType(), Src->getType(),
Size->getType()};
261// Set the alignment of the pointer args. 262auto *AMCI = cast<AtomicMemCpyInst>(CI);
263 AMCI->setDestAlignment(DstAlign);
264 AMCI->setSourceAlignment(SrcAlign);
266// Set the TBAA info if present. 270// Set the TBAA Struct info if present. 272 CI->
setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
275 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
278 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
283/// isConstantOne - Return true only if val is constant int 1 285assert(Val &&
"isConstantOne does not work with nullptr Val");
286constConstantInt *CVal = dyn_cast<ConstantInt>(Val);
287return CVal && CVal->
isOne();
294// malloc(type) becomes: 295// i8* malloc(typeSize) 296// malloc(type, arraySize) becomes: 297// i8* malloc(typeSize*arraySize) 299 ArraySize = ConstantInt::get(IntPtrTy, 1);
300elseif (ArraySize->
getType() != IntPtrTy)
305 AllocSize = ArraySize;
// Operand * 1 = Operand 307// Multiply type size by the array size... 308 AllocSize =
CreateMul(ArraySize, AllocSize,
"mallocsize");
312assert(AllocSize->
getType() == IntPtrTy &&
"malloc arg is wrong size");
313// Create the call to Malloc. 318// prototype malloc as "void *malloc(size_t)" 319 MallocFunc = M->getOrInsertFunction(
"malloc", BPTy, IntPtrTy);
325F->setReturnDoesNotAlias();
337returnCreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
341/// CreateFree - Generate the IR for a call to the builtin free function. 344assert(Source->getType()->isPointerTy() &&
345"Can not free something of nonpointer type!");
351// prototype free as "void free(void*)" 352FunctionCallee FreeFunc = M->getOrInsertFunction(
"free", VoidTy, VoidPtrTy);
354 Result->setTailCall();
356 Result->setCallingConv(
F->getCallingConv());
365assert(DstAlign >= ElementSize &&
366"Pointer alignment must be at least element size");
367assert(SrcAlign >= ElementSize &&
368"Pointer alignment must be at least element size");
370Type *Tys[] = {Dst->getType(), Src->getType(),
Size->getType()};
375// Set the alignment of the pointer args. 379// Set the TBAA info if present. 383// Set the TBAA Struct info if present. 385 CI->
setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
388 CI->
setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
391 CI->
setMetadata(LLVMContext::MD_noalias, NoAliasTag);
398Type *Tys[] = { Src->getType() };
403Value *Ops[] = {Acc, Src};
404returnCreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
408Value *Ops[] = {Acc, Src};
409returnCreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
413return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
417return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
421return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
425return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
429return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
434 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
435return getReductionIntrinsic(
ID, Src);
440 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
441return getReductionIntrinsic(
ID, Src);
445return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
449return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
453return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
457return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
461assert(isa<PointerType>(
Ptr->getType()) &&
462"lifetime.start only applies to pointers.");
467"lifetime.start requires the size to be an i64");
473assert(isa<PointerType>(
Ptr->getType()) &&
474"lifetime.end only applies to pointers.");
479"lifetime.end requires the size to be an i64");
486assert(isa<PointerType>(
Ptr->getType()) &&
487"invariant.start only applies to pointers.");
492"invariant.start requires the size to be an i64");
495// Fill in the single overloaded type: memory object type. 496Type *ObjectPtr[1] = {
Ptr->getType()};
501if (
auto *O = dyn_cast<GlobalObject>(
Ptr))
503if (
auto *
A = dyn_cast<GlobalAlias>(
Ptr))
504returnA->getAliaseeObject()->getAlign();
509assert(isa<GlobalValue>(
Ptr) && cast<GlobalValue>(
Ptr)->isThreadLocal() &&
510"threadlocal_address only applies to thread local variables.");
524"an assumption condition must be of type i1");
537/// Create a call to a Masked Load intrinsic. 538/// \p Ty - vector type to load 539/// \p Ptr - base pointer for the load 540/// \p Alignment - alignment of the source location 541/// \p Mask - vector of booleans which indicates what vector lanes should 542/// be accessed in memory 543/// \p PassThru - pass-through value that is used to fill the masked-off lanes 545/// \p Name - name of the result variable 549auto *PtrTy = cast<PointerType>(
Ptr->getType());
551assert(Mask &&
"Mask should not be all-ones (null)");
554Type *OverloadedTypes[] = { Ty, PtrTy };
556return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
557 OverloadedTypes,
Name);
560/// Create a call to a Masked Store intrinsic. 561/// \p Val - data to be stored, 562/// \p Ptr - base pointer for the store 563/// \p Alignment - alignment of the destination location 564/// \p Mask - vector of booleans which indicates what vector lanes should 565/// be accessed in memory 568auto *PtrTy = cast<PointerType>(
Ptr->getType());
571assert(Mask &&
"Mask should not be all-ones (null)");
572Type *OverloadedTypes[] = { DataTy, PtrTy };
574return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
577/// Create a call to a Masked intrinsic, with given intrinsic Id, 578/// an array of operands - Ops, and an array of overloaded types - 587/// Create a call to a Masked Gather intrinsic. 588/// \p Ty - vector type to gather 589/// \p Ptrs - vector of pointers for loading 590/// \p Align - alignment for one element 591/// \p Mask - vector of booleans which indicates what vector lanes should 592/// be accessed in memory 593/// \p PassThru - pass-through value that is used to fill the masked-off lanes 595/// \p Name - name of the result variable 600auto *VecTy = cast<VectorType>(Ty);
602auto *PtrsTy = cast<VectorType>(Ptrs->
getType());
603assert(NumElts == PtrsTy->getElementCount() &&
"Element count mismatch");
611Type *OverloadedTypes[] = {Ty, PtrsTy};
614// We specify only one type when we create this intrinsic. Types of other 615// arguments are derived from this type. 616return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
620/// Create a call to a Masked Scatter intrinsic. 621/// \p Data - data to be stored, 622/// \p Ptrs - the vector of pointers, where the \p Data elements should be 624/// \p Align - alignment for one element 625/// \p Mask - vector of booleans which indicates what vector lanes should 626/// be accessed in memory 629auto *PtrsTy = cast<VectorType>(Ptrs->
getType());
630auto *DataTy = cast<VectorType>(
Data->getType());
636Type *OverloadedTypes[] = {DataTy, PtrsTy};
639// We specify only one type when we create this intrinsic. Types of other 640// arguments are derived from this type. 641return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
644/// Create a call to Masked Expand Load intrinsic 645/// \p Ty - vector type to load 646/// \p Ptr - base pointer for the load 647/// \p Align - alignment of \p Ptr 648/// \p Mask - vector of booleans which indicates what vector lanes should 649/// be accessed in memory 650/// \p PassThru - pass-through value that is used to fill the masked-off lanes 652/// \p Name - name of the result variable 658assert(Mask &&
"Mask should not be all-ones (null)");
661Type *OverloadedTypes[] = {Ty};
662Value *Ops[] = {
Ptr, Mask, PassThru};
663CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
664 OverloadedTypes,
Name);
670/// Create a call to Masked Compress Store intrinsic 671/// \p Val - data to be stored, 672/// \p Ptr - base pointer for the store 673/// \p Align - alignment of \p Ptr 674/// \p Mask - vector of booleans which indicates what vector lanes should 675/// be accessed in memory 681assert(Mask &&
"Mask should not be all-ones (null)");
682Type *OverloadedTypes[] = {DataTy};
684CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
691template <
typename T0>
692static std::vector<Value *>
695 std::vector<Value *> Args;
696 Args.push_back(
B.getInt64(
ID));
697 Args.push_back(
B.getInt32(NumPatchBytes));
698 Args.push_back(ActualCallee);
699 Args.push_back(
B.getInt32(CallArgs.
size()));
700 Args.push_back(
B.getInt32(Flags));
702// GC Transition and Deopt args are now always handled via operand bundle. 703// They will be removed from the signature of gc.statepoint shortly. 704 Args.push_back(
B.getInt32(0));
705 Args.push_back(
B.getInt32(0));
706// GC args are now encoded in the gc-live operand bundle 710template<
typename T1,
typename T2,
typename T3>
711static std::vector<OperandBundleDef>
715 std::vector<OperandBundleDef> Rval;
719 Rval.emplace_back(
"deopt", DeoptValues);
724 Rval.emplace_back(
"gc-transition", TransitionValues);
729 Rval.emplace_back(
"gc-live", LiveValues);
734template <
typename T0,
typename T1,
typename T2,
typename T3>
742// Fill in the one generic type'd argument (the function is also vararg) 744 M, Intrinsic::experimental_gc_statepoint,
748 *Builder,
ID, NumPatchBytes, ActualCallee.
getCallee(), Flags, CallArgs);
763return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
765 CallArgs, std::nullopt
/* No Transition Args */, DeoptArgs, GCArgs,
Name);
774return CreateGCStatepointCallCommon<Value *, Use, Use, Value *>(
775this,
ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
776 DeoptArgs, GCArgs,
Name);
783return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
785 CallArgs, std::nullopt, DeoptArgs, GCArgs,
Name);
788template <
typename T0,
typename T1,
typename T2,
typename T3>
797// Fill in the one generic type'd argument (the function is also vararg) 799 M, Intrinsic::experimental_gc_statepoint,
802 std::vector<Value *> Args =
807 FnStatepoint, NormalDest, UnwindDest, Args,
820return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
821this,
ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
823 std::nullopt
/* No Transition Args*/, DeoptArgs, GCArgs,
Name);
832return CreateGCStatepointInvokeCommon<Value *, Use, Use, Value *>(
833this,
ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
834 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs,
Name);
842return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
843this,
ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
851Type *Types[] = {ResultType};
853Value *Args[] = {Statepoint};
858int BaseOffset,
int DerivedOffset,
860Type *Types[] = {ResultType};
863returnCreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
871 {PtrTy, PtrTy}, {DerivedPtr}, {},
Name);
877returnCreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
878 {DerivedPtr}, {},
Name);
895/*FMFSource=*/nullptr))
927 matchIntrinsicSignature(FTy,
TableRef, OverloadTys);
930"Wrong types for intrinsic!");
931// TODO: Handle varargs intrinsics. 939constTwine &
Name,
MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
940 std::optional<fp::ExceptionBehavior> Except) {
941Value *RoundingV = getConstrainedFPRounding(Rounding);
942Value *ExceptV = getConstrainedFPExcept(Except);
947 {L, R, RoundingV, ExceptV},
nullptr,
Name);
949 setFPAttrs(
C, FPMathTag, UseFMF);
956 std::optional<fp::ExceptionBehavior> Except) {
957Value *ExceptV = getConstrainedFPExcept(Except);
964 setFPAttrs(
C, FPMathTag, UseFMF);
971assert(Ops.
size() == 2 &&
"Invalid number of operands!");
973 Ops[0], Ops[1],
Name, FPMathTag);
976assert(Ops.
size() == 1 &&
"Invalid number of operands!");
978 Ops[0],
Name, FPMathTag);
985constTwine &
Name,
MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
986 std::optional<fp::ExceptionBehavior> Except) {
987Value *ExceptV = getConstrainedFPExcept(Except);
993Value *RoundingV = getConstrainedFPRounding(Rounding);
1002if (isa<FPMathOperator>(
C))
1003 setFPAttrs(
C, FPMathTag, UseFMF);
1012autoID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1013 : Intrinsic::experimental_constrained_fcmp;
1026constTwine &
Name, std::optional<fp::ExceptionBehavior> Except) {
1027Value *PredicateV = getConstrainedFPPredicate(
P);
1028Value *ExceptV = getConstrainedFPExcept(Except);
1031 {L, R, PredicateV, ExceptV},
nullptr,
Name);
1038 std::optional<RoundingMode> Rounding,
1039 std::optional<fp::ExceptionBehavior> Except) {
1045 UseArgs.
push_back(getConstrainedFPRounding(Rounding));
1046 UseArgs.
push_back(getConstrainedFPExcept(Except));
1068 Sel = addBranchMetadata(Sel, Prof, Unpred);
1070if (isa<FPMathOperator>(Sel))
1078"Pointer subtraction operand types must match!");
1087assert(isa<PointerType>(
Ptr->getType()) &&
1088"launder.invariant.group only applies to pointers.");
1089auto *PtrType =
Ptr->getType();
1092 M, Intrinsic::launder_invariant_group, {PtrType});
1097"LaunderInvariantGroup should take and return the same type");
1103assert(isa<PointerType>(
Ptr->getType()) &&
1104"strip.invariant.group only applies to pointers.");
1106auto *PtrType =
Ptr->getType();
1109 M, Intrinsic::strip_invariant_group, {PtrType});
1114"StripInvariantGroup should take and return the same type");
1120auto *Ty = cast<VectorType>(V->getType());
1121if (isa<ScalableVectorType>(Ty)) {
1127// Keep the original behaviour for fixed vector 1129int NumElts = Ty->getElementCount().getKnownMinValue();
1130for (
int i = 0; i < NumElts; ++i)
1139"Splice expects matching operand types!");
1141if (
auto *VTy = dyn_cast<ScalableVectorType>(V1->
getType())) {
1150unsigned NumElts = cast<FixedVectorType>(V1->
getType())->getNumElements();
1151assert(((-Imm <= NumElts) || (Imm < NumElts)) &&
1152"Invalid immediate for vector splice!");
1154// Keep the original behaviour for fixed vector 1155unsignedIdx = (NumElts + Imm) % NumElts;
1157for (
unsignedI = 0;
I < NumElts; ++
I)
1158 Mask.push_back(
Idx +
I);
1171assert(EC.isNonZero() &&
"Cannot splat to an empty vector!");
1173// First insert it into a poison vector so we can shuffle it. 1177// Shuffle the value across the desired number of elements. 1179 Zeros.
resize(EC.getKnownMinValue());
1184Type *ElTy,
Value *
Base,
unsigned Dimension,
unsigned LastIndex,
1188"Invalid Base ptr type for preserve.array.access.index.");
1204 Fn->
setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1212"Invalid Base ptr type for preserve.union.access.index.");
1219 Fn->
setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1229"Invalid Base ptr type for preserve.struct.access.index.");
1243 Fn->
setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1257Value *OffsetValue) {
1268Value *OffsetValue) {
1270"trying to create an alignment assumption on a non-pointer?");
1271assert(Alignment != 0 &&
"Invalid Alignment");
1272auto *PtrTy = cast<PointerType>(PtrValue->
getType());
1274Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1275return CreateAlignmentAssumptionHelper(
DL, PtrValue, AlignValue, OffsetValue);
1281Value *OffsetValue) {
1283"trying to create an alignment assumption on a non-pointer?");
1284return CreateAlignmentAssumptionHelper(
DL, PtrValue, Alignment, OffsetValue);
1290void ConstantFolder::anchor() {}
1291void NoFolder::anchor() {}
ArrayRef< TableEntry > TableRef
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static bool isConstantOne(const Value *Val)
isConstantOne - Return true only if val is constant int 1
static InvokeInst * CreateGCStatepointInvokeCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, ArrayRef< T0 > InvokeArgs, std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
static CallInst * CreateGCStatepointCallCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs, std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
static std::vector< OperandBundleDef > getStatepointBundles(std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs)
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs)
Module.h This file contains the declarations for the Module class.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
void setCallingConv(CallingConv::ID CC)
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
This is the shared class of boolean and integer constants.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
static ConstantInt * getTrue(LLVMContext &Context)
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getFixed(ScalarTy MinVal)
This instruction compares its operands according to the predicate given to the constructor.
This provides a helper for copying FMF from an instruction or setting specified flags.
FastMathFlags get(FastMathFlags Default) const
Convenience struct for specifying and reasoning about fast-math flags.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionType * getFunctionType()
Class to represent function types.
Type * getParamType(unsigned i) const
Parameter type accessors.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Type * getReturnType() const
Returns the type of the ret val.
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
Module * getParent()
Get the module that this global value is contained inside of...
@ PrivateLinkage
Like Internal, but omit from symbol table.
Common base class shared among various IRBuilders.
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memcpy between the specified pointers.
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Value * CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS, const Twine &Name="")
Return the i64 difference between two pointer values, dividing out the size of the pointed-to objects...
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
Value * CreateVScale(Constant *Scaling, const Twine &Name="")
Create a call to llvm.vscale, multiplied by Scaling.
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
CallInst * CreateConstrainedFPUnroundedBinOp(Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
CallInst * CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.pointer.base intrinsic to get the base pointer for the specified...
CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef< Value * > CallArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create a call to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
CallInst * CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, const Twine &Name="", std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Value * CreateVectorSplice(Value *V1, Value *V2, int64_t Imm, const Twine &Name="")
Return a vector splice intrinsic if using scalable vectors, otherwise return a shufflevector.
CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles={})
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
CallInst * CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.get.pointer.offset intrinsic to get the offset of the specified ...
Value * CreateTypeSize(Type *DstType, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
CallInst * CreateConstrainedFPBinOp(Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type of an integer with size at least as big as that of a pointer in the given address spac...
BasicBlock * GetInsertBlock() const
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
Value * createIsFPClass(Value *FPNum, unsigned Test)
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles={})
Generate the IR for a call to the builtin free function.
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
Value * CreateNAryOp(unsigned Opc, ArrayRef< Value * > Ops, const Twine &Name="", MDNode *FPMathTag=nullptr)
Create either a UnaryOperator or BinaryOperator depending on Opc.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
LLVMContext & getContext() const
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateGCResult(Instruction *Statepoint, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.result intrinsic to extract the result from a call wrapped in a ...
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memmove between the specified pointers.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
void setConstrainedFPCallAttr(CallBase *I)
InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
const IRBuilderFolder & Folder
CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
CallInst * CreateGCRelocate(Instruction *Statepoint, int BaseOffset, int DerivedOffset, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.relocate intrinsics to project the relocated value of one pointe...
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr, bool AddNull=true)
Make a new global variable with initializer type i8*.
CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
CallInst * CreateConstrainedFPCast(Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
~IRBuilderCallbackInserter() override
virtual ~IRBuilderDefaultInserter()
virtual Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
virtual Value * FoldSelect(Value *C, Value *True, Value *False) const =0
virtual ~IRBuilderFolder()
virtual Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, Instruction *FMFSource=nullptr) const =0
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
A Module instance is used to store all the information related to an LLVM module.
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents the LLVM 'select' instruction.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, Instruction *MDFrom=nullptr)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVMContext & getContext() const
All values hold a context through their type.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
MatchIntrinsicTypesResult
@ MatchIntrinsicTypes_Match
bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
MaybeAlign getAlign(const Function &F, unsigned Index)
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.