LLVM 23.0.0git
IRBuilder.cpp
Go to the documentation of this file.
1//===- IRBuilder.cpp - Builder for LLVM Instrs ----------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/IRBuilder.h"
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/IR/Constant.h"
17#include "llvm/IR/Constants.h"
19#include "llvm/IR/Function.h"
20#include "llvm/IR/GlobalValue.h"
23#include "llvm/IR/Intrinsics.h"
24#include "llvm/IR/LLVMContext.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/NoFolder.h"
27#include "llvm/IR/Operator.h"
29#include "llvm/IR/Statepoint.h"
30#include "llvm/IR/Type.h"
31#include "llvm/IR/Value.h"
33#include <cassert>
34#include <cstdint>
35#include <optional>
36#include <vector>
37
38using namespace llvm;
39
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
43/// created.
45 const Twine &Name,
46 unsigned AddressSpace,
47 Module *M, bool AddNull) {
48 Constant *StrConstant = ConstantDataArray::getString(Context, Str, AddNull);
49 if (!M)
50 M = BB->getParent()->getParent();
51 auto *GV = new GlobalVariable(
52 *M, StrConstant->getType(), true, GlobalValue::PrivateLinkage,
53 StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace);
54 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
55 GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty()));
56 return GV;
57}
58
60 assert(BB && BB->getParent() && "No current function!");
61 return BB->getParent()->getReturnType();
62}
63
66 // We prefer to set our current debug location if any has been set, but if
67 // our debug location is empty and I has a valid location, we shouldn't
68 // overwrite it.
69 I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
70}
71
73 Type *SrcTy = V->getType();
74 if (SrcTy == DestTy)
75 return V;
76
77 if (SrcTy->isAggregateType()) {
78 unsigned NumElements;
79 if (SrcTy->isStructTy()) {
80 assert(DestTy->isStructTy() && "Expected StructType");
81 assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements() &&
82 "Expected StructTypes with equal number of elements");
83 NumElements = SrcTy->getStructNumElements();
84 } else {
85 assert(SrcTy->isArrayTy() && DestTy->isArrayTy() && "Expected ArrayType");
86 assert(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements() &&
87 "Expected ArrayTypes with equal number of elements");
88 NumElements = SrcTy->getArrayNumElements();
89 }
90
91 Value *Result = PoisonValue::get(DestTy);
92 for (unsigned I = 0; I < NumElements; ++I) {
93 Type *ElementTy = SrcTy->isStructTy() ? DestTy->getStructElementType(I)
94 : DestTy->getArrayElementType();
95 Value *Element =
97
98 Result = CreateInsertValue(Result, Element, ArrayRef(I));
99 }
100 return Result;
101 }
102
103 return CreateBitOrPointerCast(V, DestTy);
104}
105
106CallInst *
107IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
108 const Twine &Name, FMFSource FMFSource,
109 ArrayRef<OperandBundleDef> OpBundles) {
110 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
111 if (isa<FPMathOperator>(CI))
113 return CI;
114}
115
117 Value *VScale = B.CreateVScale(Ty);
118 if (Scale == 1)
119 return VScale;
120
121 return B.CreateNUWMul(VScale, ConstantInt::get(Ty, Scale));
122}
123
125 if (EC.isFixed() || EC.isZero())
126 return ConstantInt::get(Ty, EC.getKnownMinValue());
127
128 return CreateVScaleMultiple(*this, Ty, EC.getKnownMinValue());
129}
130
132 if (Size.isFixed() || Size.isZero())
133 return ConstantInt::get(Ty, Size.getKnownMinValue());
134
135 return CreateVScaleMultiple(*this, Ty, Size.getKnownMinValue());
136}
137
139 const DataLayout &DL = BB->getDataLayout();
140 TypeSize ElemSize = DL.getTypeAllocSize(AI->getAllocatedType());
141 Value *Size = CreateTypeSize(DestTy, ElemSize);
142 if (AI->isArrayAllocation())
144 return Size;
145}
146
148 Type *STy = DstType->getScalarType();
149 if (isa<ScalableVectorType>(DstType)) {
150 Type *StepVecType = DstType;
151 // TODO: We expect this special case (element type < 8 bits) to be
152 // temporary - once the intrinsic properly supports < 8 bits this code
153 // can be removed.
154 if (STy->getScalarSizeInBits() < 8)
155 StepVecType =
157 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
158 nullptr, Name);
159 if (StepVecType != DstType)
160 Res = CreateTrunc(Res, DstType);
161 return Res;
162 }
163
164 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
165
166 // Create a vector of consecutive numbers from zero to VF.
167 // It's okay if the values wrap around.
169 for (unsigned i = 0; i < NumEls; ++i)
170 Indices.push_back(
171 ConstantInt::get(STy, i, /*IsSigned=*/false, /*ImplicitTrunc=*/true));
172
173 // Add the consecutive indices to the vector value.
174 return ConstantVector::get(Indices);
175}
176
178 MaybeAlign Align, bool isVolatile,
179 const AAMDNodes &AAInfo) {
180 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
181 Type *Tys[] = {Ptr->getType(), Size->getType()};
182
183 CallInst *CI = CreateIntrinsic(Intrinsic::memset, Tys, Ops);
184
185 if (Align)
186 cast<MemSetInst>(CI)->setDestAlignment(*Align);
187 CI->setAAMetadata(AAInfo);
188 return CI;
189}
190
192 Value *Val, Value *Size,
193 bool IsVolatile,
194 const AAMDNodes &AAInfo) {
195 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
196 Type *Tys[] = {Dst->getType(), Size->getType()};
197
198 CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);
199
200 if (DstAlign)
201 cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);
202 CI->setAAMetadata(AAInfo);
203 return CI;
204}
205
207 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
208 const AAMDNodes &AAInfo) {
209
210 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
211 Type *Tys[] = {Ptr->getType(), Size->getType()};
212
213 CallInst *CI =
214 CreateIntrinsic(Intrinsic::memset_element_unordered_atomic, Tys, Ops);
215
216 cast<AnyMemSetInst>(CI)->setDestAlignment(Alignment);
217 CI->setAAMetadata(AAInfo);
218 return CI;
219}
220
222 MaybeAlign DstAlign, Value *Src,
223 MaybeAlign SrcAlign, Value *Size,
224 bool isVolatile,
225 const AAMDNodes &AAInfo) {
226 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
227 IntrID == Intrinsic::memmove) &&
228 "Unexpected intrinsic ID");
229 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
230 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
231
232 CallInst *CI = CreateIntrinsic(IntrID, Tys, Ops);
233
234 auto* MCI = cast<MemTransferInst>(CI);
235 if (DstAlign)
236 MCI->setDestAlignment(*DstAlign);
237 if (SrcAlign)
238 MCI->setSourceAlignment(*SrcAlign);
239 MCI->setAAMetadata(AAInfo);
240 return CI;
241}
242
244 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
245 uint32_t ElementSize, const AAMDNodes &AAInfo) {
246 assert(DstAlign >= ElementSize &&
247 "Pointer alignment must be at least element size");
248 assert(SrcAlign >= ElementSize &&
249 "Pointer alignment must be at least element size");
250 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
251 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
252
253 CallInst *CI =
254 CreateIntrinsic(Intrinsic::memcpy_element_unordered_atomic, Tys, Ops);
255
256 // Set the alignment of the pointer args.
257 auto *AMCI = cast<AnyMemCpyInst>(CI);
258 AMCI->setDestAlignment(DstAlign);
259 AMCI->setSourceAlignment(SrcAlign);
260 AMCI->setAAMetadata(AAInfo);
261 return CI;
262}
263
264/// isConstantOne - Return true only if val is constant int 1
265static bool isConstantOne(const Value *Val) {
266 assert(Val && "isConstantOne does not work with nullptr Val");
267 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
268 return CVal && CVal->isOne();
269}
270
272 Value *AllocSize, Value *ArraySize,
274 Function *MallocF, const Twine &Name) {
275 // malloc(type) becomes:
276 // i8* malloc(typeSize)
277 // malloc(type, arraySize) becomes:
278 // i8* malloc(typeSize*arraySize)
279 if (!ArraySize)
280 ArraySize = ConstantInt::get(IntPtrTy, 1);
281 else if (ArraySize->getType() != IntPtrTy)
282 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
283
284 if (!isConstantOne(ArraySize)) {
285 if (isConstantOne(AllocSize)) {
286 AllocSize = ArraySize; // Operand * 1 = Operand
287 } else {
288 // Multiply type size by the array size...
289 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
290 }
291 }
292
293 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
294 // Create the call to Malloc.
295 Module *M = BB->getParent()->getParent();
297 FunctionCallee MallocFunc = MallocF;
298 if (!MallocFunc)
299 // prototype malloc as "void *malloc(size_t)"
300 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
301 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
302
303 MCall->setTailCall();
304 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
305 MCall->setCallingConv(F->getCallingConv());
306 F->setReturnDoesNotAlias();
307 }
308
309 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
310
311 return MCall;
312}
313
315 Value *AllocSize, Value *ArraySize,
316 Function *MallocF, const Twine &Name) {
317
318 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
319 Name);
320}
321
322/// CreateFree - Generate the IR for a call to the builtin free function.
325 assert(Source->getType()->isPointerTy() &&
326 "Can not free something of nonpointer type!");
327
328 Module *M = BB->getParent()->getParent();
329
330 Type *VoidTy = Type::getVoidTy(M->getContext());
331 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
332 // prototype free as "void free(void*)"
333 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
334 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
335 Result->setTailCall();
336 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
337 Result->setCallingConv(F->getCallingConv());
338
339 return Result;
340}
341
343 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
344 uint32_t ElementSize, const AAMDNodes &AAInfo) {
345 assert(DstAlign >= ElementSize &&
346 "Pointer alignment must be at least element size");
347 assert(SrcAlign >= ElementSize &&
348 "Pointer alignment must be at least element size");
349 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
350 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
351
352 CallInst *CI =
353 CreateIntrinsic(Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
354
355 // Set the alignment of the pointer args.
356 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
357 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
358 CI->setAAMetadata(AAInfo);
359 return CI;
360}
361
362CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
363 Value *Ops[] = {Src};
364 Type *Tys[] = { Src->getType() };
365 return CreateIntrinsic(ID, Tys, Ops);
366}
367
369 Value *Ops[] = {Acc, Src};
370 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
371}
372
374 Value *Ops[] = {Acc, Src};
375 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
376}
377
379 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
380}
381
383 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
384}
385
387 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
388}
389
391 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
392}
393
395 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
396}
397
399 auto ID =
400 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
401 return getReductionIntrinsic(ID, Src);
402}
403
405 auto ID =
406 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
407 return getReductionIntrinsic(ID, Src);
408}
409
411 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
412}
413
415 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
416}
417
419 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
420}
421
423 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
424}
425
428 "lifetime.start only applies to pointers.");
429 return CreateIntrinsic(Intrinsic::lifetime_start, {Ptr->getType()}, {Ptr});
430}
431
434 "lifetime.end only applies to pointers.");
435 return CreateIntrinsic(Intrinsic::lifetime_end, {Ptr->getType()}, {Ptr});
436}
437
439
441 "invariant.start only applies to pointers.");
442 if (!Size)
443 Size = getInt64(-1);
444 else
445 assert(Size->getType() == getInt64Ty() &&
446 "invariant.start requires the size to be an i64");
447
448 Value *Ops[] = {Size, Ptr};
449 // Fill in the single overloaded type: memory object type.
450 Type *ObjectPtr[1] = {Ptr->getType()};
451 return CreateIntrinsic(Intrinsic::invariant_start, ObjectPtr, Ops);
452}
453
455 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
456 return V->getAlign();
457 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
458 return getAlign(A->getAliaseeObject());
459 return {};
460}
461
463 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
464 "threadlocal_address only applies to thread local variables.");
465 CallInst *CI = CreateIntrinsic(llvm::Intrinsic::threadlocal_address,
466 {Ptr->getType()}, {Ptr});
467 if (MaybeAlign A = getAlign(Ptr)) {
470 }
471 return CI;
472}
473
474CallInst *
476 ArrayRef<OperandBundleDef> OpBundles) {
477 assert(Cond->getType() == getInt1Ty() &&
478 "an assumption condition must be of type i1");
479
480 Value *Ops[] = { Cond };
481 Module *M = BB->getParent()->getParent();
482 Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
483 return CreateCall(FnAssume, Ops, OpBundles);
484}
485
487 return CreateIntrinsic(Intrinsic::experimental_noalias_scope_decl, {},
488 {Scope});
489}
490
491/// Create a call to a Masked Load intrinsic.
492/// \p Ty - vector type to load
493/// \p Ptr - base pointer for the load
494/// \p Alignment - alignment of the source location
495/// \p Mask - vector of booleans which indicates what vector lanes should
496/// be accessed in memory
497/// \p PassThru - pass-through value that is used to fill the masked-off lanes
498/// of the result
499/// \p Name - name of the result variable
501 Value *Mask, Value *PassThru,
502 const Twine &Name) {
503 auto *PtrTy = cast<PointerType>(Ptr->getType());
504 assert(Ty->isVectorTy() && "Type should be vector");
505 assert(Mask && "Mask should not be all-ones (null)");
506 if (!PassThru)
507 PassThru = PoisonValue::get(Ty);
508 Type *OverloadedTypes[] = { Ty, PtrTy };
509 Value *Ops[] = {Ptr, Mask, PassThru};
510 CallInst *CI =
511 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
512 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
513 return CI;
514}
515
516/// Create a call to a Masked Store intrinsic.
517/// \p Val - data to be stored,
518/// \p Ptr - base pointer for the store
519/// \p Alignment - alignment of the destination location
520/// \p Mask - vector of booleans which indicates what vector lanes should
521/// be accessed in memory
523 Align Alignment, Value *Mask) {
524 auto *PtrTy = cast<PointerType>(Ptr->getType());
525 Type *DataTy = Val->getType();
526 assert(DataTy->isVectorTy() && "Val should be a vector");
527 assert(Mask && "Mask should not be all-ones (null)");
528 Type *OverloadedTypes[] = { DataTy, PtrTy };
529 Value *Ops[] = {Val, Ptr, Mask};
530 CallInst *CI =
531 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
532 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
533 return CI;
534}
535
536/// Create a call to a Masked intrinsic, with given intrinsic Id,
537/// an array of operands - Ops, and an array of overloaded types -
538/// OverloadedTypes.
539CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
541 ArrayRef<Type *> OverloadedTypes,
542 const Twine &Name) {
543 return CreateIntrinsic(Id, OverloadedTypes, Ops, {}, Name);
544}
545
546/// Create a call to a Masked Gather intrinsic.
547/// \p Ty - vector type to gather
548/// \p Ptrs - vector of pointers for loading
549/// \p Align - alignment for one element
550/// \p Mask - vector of booleans which indicates what vector lanes should
551/// be accessed in memory
552/// \p PassThru - pass-through value that is used to fill the masked-off lanes
553/// of the result
554/// \p Name - name of the result variable
556 Align Alignment, Value *Mask,
557 Value *PassThru,
558 const Twine &Name) {
559 auto *VecTy = cast<VectorType>(Ty);
560 ElementCount NumElts = VecTy->getElementCount();
561 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
562 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
563
564 if (!Mask)
565 Mask = getAllOnesMask(NumElts);
566
567 if (!PassThru)
568 PassThru = PoisonValue::get(Ty);
569
570 Type *OverloadedTypes[] = {Ty, PtrsTy};
571 Value *Ops[] = {Ptrs, Mask, PassThru};
572
573 // We specify only one type when we create this intrinsic. Types of other
574 // arguments are derived from this type.
575 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
576 OverloadedTypes, Name);
577 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
578 return CI;
579}
580
581/// Create a call to a Masked Scatter intrinsic.
582/// \p Data - data to be stored,
583/// \p Ptrs - the vector of pointers, where the \p Data elements should be
584/// stored
585/// \p Align - alignment for one element
586/// \p Mask - vector of booleans which indicates what vector lanes should
587/// be accessed in memory
589 Align Alignment, Value *Mask) {
590 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
591 auto *DataTy = cast<VectorType>(Data->getType());
592 ElementCount NumElts = PtrsTy->getElementCount();
593
594 if (!Mask)
595 Mask = getAllOnesMask(NumElts);
596
597 Type *OverloadedTypes[] = {DataTy, PtrsTy};
598 Value *Ops[] = {Data, Ptrs, Mask};
599
600 // We specify only one type when we create this intrinsic. Types of other
601 // arguments are derived from this type.
602 CallInst *CI =
603 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
604 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
605 return CI;
606}
607
608/// Create a call to Masked Expand Load intrinsic
609/// \p Ty - vector type to load
610/// \p Ptr - base pointer for the load
611/// \p Align - alignment of \p Ptr
612/// \p Mask - vector of booleans which indicates what vector lanes should
613/// be accessed in memory
614/// \p PassThru - pass-through value that is used to fill the masked-off lanes
615/// of the result
616/// \p Name - name of the result variable
618 MaybeAlign Align, Value *Mask,
619 Value *PassThru,
620 const Twine &Name) {
621 assert(Ty->isVectorTy() && "Type should be vector");
622 assert(Mask && "Mask should not be all-ones (null)");
623 if (!PassThru)
624 PassThru = PoisonValue::get(Ty);
625 Type *OverloadedTypes[] = {Ty};
626 Value *Ops[] = {Ptr, Mask, PassThru};
627 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
628 OverloadedTypes, Name);
629 if (Align)
631 return CI;
632}
633
634/// Create a call to Masked Compress Store intrinsic
635/// \p Val - data to be stored,
636/// \p Ptr - base pointer for the store
637/// \p Align - alignment of \p Ptr
638/// \p Mask - vector of booleans which indicates what vector lanes should
639/// be accessed in memory
642 Value *Mask) {
643 Type *DataTy = Val->getType();
644 assert(DataTy->isVectorTy() && "Val should be a vector");
645 assert(Mask && "Mask should not be all-ones (null)");
646 Type *OverloadedTypes[] = {DataTy};
647 Value *Ops[] = {Val, Ptr, Mask};
648 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
649 OverloadedTypes);
650 if (Align)
652 return CI;
653}
654
655template <typename T0>
656static std::vector<Value *>
658 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
659 std::vector<Value *> Args;
660 Args.push_back(B.getInt64(ID));
661 Args.push_back(B.getInt32(NumPatchBytes));
662 Args.push_back(ActualCallee);
663 Args.push_back(B.getInt32(CallArgs.size()));
664 Args.push_back(B.getInt32(Flags));
665 llvm::append_range(Args, CallArgs);
666 // GC Transition and Deopt args are now always handled via operand bundle.
667 // They will be removed from the signature of gc.statepoint shortly.
668 Args.push_back(B.getInt32(0));
669 Args.push_back(B.getInt32(0));
670 // GC args are now encoded in the gc-live operand bundle
671 return Args;
672}
673
674template<typename T1, typename T2, typename T3>
675static std::vector<OperandBundleDef>
676getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
677 std::optional<ArrayRef<T2>> DeoptArgs,
678 ArrayRef<T3> GCArgs) {
679 std::vector<OperandBundleDef> Rval;
680 if (DeoptArgs)
681 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
682 if (TransitionArgs)
683 Rval.emplace_back("gc-transition",
684 SmallVector<Value *, 16>(*TransitionArgs));
685 if (GCArgs.size())
686 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
687 return Rval;
688}
689
690template <typename T0, typename T1, typename T2, typename T3>
692 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
693 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
694 std::optional<ArrayRef<T1>> TransitionArgs,
695 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
696 const Twine &Name) {
697 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
698 // Fill in the one generic type'd argument (the function is also vararg)
700 M, Intrinsic::experimental_gc_statepoint,
701 {ActualCallee.getCallee()->getType()});
702
703 std::vector<Value *> Args = getStatepointArgs(
704 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
705
706 CallInst *CI = Builder->CreateCall(
707 FnStatepoint, Args,
708 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
709 CI->addParamAttr(2,
710 Attribute::get(Builder->getContext(), Attribute::ElementType,
711 ActualCallee.getFunctionType()));
712 return CI;
713}
714
716 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
717 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
718 ArrayRef<Value *> GCArgs, const Twine &Name) {
720 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
721 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
722}
723
725 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
726 uint32_t Flags, ArrayRef<Value *> CallArgs,
727 std::optional<ArrayRef<Use>> TransitionArgs,
728 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
729 const Twine &Name) {
731 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
732 DeoptArgs, GCArgs, Name);
733}
734
736 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
737 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
738 ArrayRef<Value *> GCArgs, const Twine &Name) {
740 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
741 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
742}
743
744template <typename T0, typename T1, typename T2, typename T3>
746 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
747 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
748 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
749 std::optional<ArrayRef<T1>> TransitionArgs,
750 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
751 const Twine &Name) {
752 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
753 // Fill in the one generic type'd argument (the function is also vararg)
755 M, Intrinsic::experimental_gc_statepoint,
756 {ActualInvokee.getCallee()->getType()});
757
758 std::vector<Value *> Args =
759 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
760 Flags, InvokeArgs);
761
762 InvokeInst *II = Builder->CreateInvoke(
763 FnStatepoint, NormalDest, UnwindDest, Args,
764 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
765 II->addParamAttr(2,
766 Attribute::get(Builder->getContext(), Attribute::ElementType,
767 ActualInvokee.getFunctionType()));
768 return II;
769}
770
772 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
773 BasicBlock *NormalDest, BasicBlock *UnwindDest,
774 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
775 ArrayRef<Value *> GCArgs, const Twine &Name) {
777 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
778 uint32_t(StatepointFlags::None), InvokeArgs,
779 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
780}
781
783 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
784 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
785 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
786 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
787 const Twine &Name) {
789 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
790 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
791}
792
794 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
795 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
796 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
797 const Twine &Name) {
799 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
800 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
801 GCArgs, Name);
802}
803
805 Type *ResultType, const Twine &Name) {
806 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
807 Type *Types[] = {ResultType};
808
809 Value *Args[] = {Statepoint};
810 return CreateIntrinsic(ID, Types, Args, {}, Name);
811}
812
814 int BaseOffset, int DerivedOffset,
815 Type *ResultType, const Twine &Name) {
816 Type *Types[] = {ResultType};
817
818 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
819 return CreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
820 Name);
821}
822
824 const Twine &Name) {
825 Type *PtrTy = DerivedPtr->getType();
826 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_base,
827 {PtrTy, PtrTy}, {DerivedPtr}, {}, Name);
828}
829
831 const Twine &Name) {
832 Type *PtrTy = DerivedPtr->getType();
833 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
834 {DerivedPtr}, {}, Name);
835}
836
839 const Twine &Name) {
840 Module *M = BB->getModule();
841 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
842 return createCallHelper(Fn, {V}, Name, FMFSource);
843}
844
847 const Twine &Name) {
848 Module *M = BB->getModule();
849 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
850 if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(),
851 /*FMFSource=*/nullptr))
852 return V;
853 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
854}
855
857 ArrayRef<Type *> Types,
860 const Twine &Name) {
861 Module *M = BB->getModule();
863 return createCallHelper(Fn, Args, Name, FMFSource);
864}
865
869 const Twine &Name) {
870 Module *M = BB->getModule();
871
872 SmallVector<Type *> ArgTys;
873 ArgTys.reserve(Args.size());
874 for (auto &I : Args)
875 ArgTys.push_back(I->getType());
876
877 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, RetTy, ArgTys);
878 return createCallHelper(Fn, Args, Name, FMFSource);
879}
880
883 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
884 std::optional<fp::ExceptionBehavior> Except) {
885 Value *RoundingV = getConstrainedFPRounding(Rounding);
886 Value *ExceptV = getConstrainedFPExcept(Except);
887
888 FastMathFlags UseFMF = FMFSource.get(FMF);
889
890 CallInst *C = CreateIntrinsic(ID, {L->getType()},
891 {L, R, RoundingV, ExceptV}, nullptr, Name);
893 setFPAttrs(C, FPMathTag, UseFMF);
894 return C;
895}
896
899 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
900 std::optional<RoundingMode> Rounding,
901 std::optional<fp::ExceptionBehavior> Except) {
902 Value *RoundingV = getConstrainedFPRounding(Rounding);
903 Value *ExceptV = getConstrainedFPExcept(Except);
904
905 FastMathFlags UseFMF = FMFSource.get(FMF);
906
907 llvm::SmallVector<Value *, 5> ExtArgs(Args);
908 ExtArgs.push_back(RoundingV);
909 ExtArgs.push_back(ExceptV);
910
911 CallInst *C = CreateIntrinsic(ID, Types, ExtArgs, nullptr, Name);
913 setFPAttrs(C, FPMathTag, UseFMF);
914 return C;
915}
916
919 const Twine &Name, MDNode *FPMathTag,
920 std::optional<fp::ExceptionBehavior> Except) {
921 Value *ExceptV = getConstrainedFPExcept(Except);
922
923 FastMathFlags UseFMF = FMFSource.get(FMF);
924
925 CallInst *C =
926 CreateIntrinsic(ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name);
928 setFPAttrs(C, FPMathTag, UseFMF);
929 return C;
930}
931
933 const Twine &Name, MDNode *FPMathTag) {
935 assert(Ops.size() == 2 && "Invalid number of operands!");
936 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
937 Ops[0], Ops[1], Name, FPMathTag);
938 }
940 assert(Ops.size() == 1 && "Invalid number of operands!");
941 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
942 Ops[0], Name, FPMathTag);
943 }
944 llvm_unreachable("Unexpected opcode!");
945}
946
949 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
950 std::optional<fp::ExceptionBehavior> Except) {
951 Value *ExceptV = getConstrainedFPExcept(Except);
952
953 FastMathFlags UseFMF = FMFSource.get(FMF);
954
955 CallInst *C;
957 Value *RoundingV = getConstrainedFPRounding(Rounding);
958 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
959 nullptr, Name);
960 } else
961 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
962 Name);
963
965
967 setFPAttrs(C, FPMathTag, UseFMF);
968 return C;
969}
970
971Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
972 Value *RHS, const Twine &Name,
973 MDNode *FPMathTag, FMFSource FMFSource,
974 bool IsSignaling) {
975 if (IsFPConstrained) {
976 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
977 : Intrinsic::experimental_constrained_fcmp;
978 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
979 }
980
981 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
982 return V;
983 return Insert(
984 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
985 Name);
986}
987
990 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
991 Value *PredicateV = getConstrainedFPPredicate(P);
992 Value *ExceptV = getConstrainedFPExcept(Except);
993
994 CallInst *C = CreateIntrinsic(ID, {L->getType()},
995 {L, R, PredicateV, ExceptV}, nullptr, Name);
997 return C;
998}
999
1001 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1002 std::optional<RoundingMode> Rounding,
1003 std::optional<fp::ExceptionBehavior> Except) {
1004 llvm::SmallVector<Value *, 6> UseArgs(Args);
1005
1006 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1007 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1008 UseArgs.push_back(getConstrainedFPExcept(Except));
1009
1010 CallInst *C = CreateCall(Callee, UseArgs, Name);
1012 return C;
1013}
1014
1016 Value *False,
1018 const Twine &Name) {
1019 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1020 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1022 }
1023 return Ret;
1024}
1025
1027 Value *False,
1030 const Twine &Name) {
1031 Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
1032 if (auto *SI = dyn_cast<SelectInst>(Ret))
1034 return Ret;
1035}
1036
1038 const Twine &Name, Instruction *MDFrom) {
1039 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1040}
1041
1043 FMFSource FMFSource, const Twine &Name,
1044 Instruction *MDFrom) {
1045 if (auto *V = Folder.FoldSelect(C, True, False))
1046 return V;
1047
1048 SelectInst *Sel = SelectInst::Create(C, True, False);
1049 if (MDFrom) {
1050 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1051 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1052 Sel = addBranchMetadata(Sel, Prof, Unpred);
1053 }
1054 if (isa<FPMathOperator>(Sel))
1055 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1056 return Insert(Sel, Name);
1057}
1058
1060 const Twine &Name) {
1061 assert(LHS->getType() == RHS->getType() &&
1062 "Pointer subtraction operand types must match!");
1063 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1064 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1065 Value *Difference = CreateSub(LHS_int, RHS_int);
1066 return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ElemTy),
1067 Name);
1068}
1069
1072 "launder.invariant.group only applies to pointers.");
1073 auto *PtrType = Ptr->getType();
1074 Module *M = BB->getParent()->getParent();
1075 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1076 M, Intrinsic::launder_invariant_group, {PtrType});
1077
1078 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1079 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1080 PtrType &&
1081 "LaunderInvariantGroup should take and return the same type");
1082
1083 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1084}
1085
1088 "strip.invariant.group only applies to pointers.");
1089
1090 auto *PtrType = Ptr->getType();
1091 Module *M = BB->getParent()->getParent();
1092 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1093 M, Intrinsic::strip_invariant_group, {PtrType});
1094
1095 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1096 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1097 PtrType &&
1098 "StripInvariantGroup should take and return the same type");
1099
1100 return CreateCall(FnStripInvariantGroup, {Ptr});
1101}
1102
1104 auto *Ty = cast<VectorType>(V->getType());
1105 if (isa<ScalableVectorType>(Ty)) {
1106 Module *M = BB->getParent()->getParent();
1107 Function *F =
1108 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1109 return Insert(CallInst::Create(F, V), Name);
1110 }
1111 // Keep the original behaviour for fixed vector
1112 SmallVector<int, 8> ShuffleMask;
1113 int NumElts = Ty->getElementCount().getKnownMinValue();
1114 for (int i = 0; i < NumElts; ++i)
1115 ShuffleMask.push_back(NumElts - i - 1);
1116 return CreateShuffleVector(V, ShuffleMask, Name);
1117}
1118
1119static SmallVector<int, 8> getSpliceMask(int64_t Imm, unsigned NumElts) {
1120 unsigned Idx = (NumElts + Imm) % NumElts;
1122 for (unsigned I = 0; I < NumElts; ++I)
1123 Mask.push_back(Idx + I);
1124 return Mask;
1125}
1126
1128 Value *Offset, const Twine &Name) {
1129 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1130 assert(V1->getType() == V2->getType() &&
1131 "Splice expects matching operand types!");
1132
1133 // Emit a shufflevector for fixed vectors with a constant offset
1134 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1135 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1136 return CreateShuffleVector(
1137 V1, V2,
1138 getSpliceMask(COffset->getZExtValue(), FVTy->getNumElements()));
1139
1140 return CreateIntrinsic(Intrinsic::vector_splice_left, V1->getType(),
1141 {V1, V2, Offset}, {}, Name);
1142}
1143
1145 Value *Offset,
1146 const Twine &Name) {
1147 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1148 assert(V1->getType() == V2->getType() &&
1149 "Splice expects matching operand types!");
1150
1151 // Emit a shufflevector for fixed vectors with a constant offset
1152 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1153 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1154 return CreateShuffleVector(
1155 V1, V2,
1156 getSpliceMask(-COffset->getZExtValue(), FVTy->getNumElements()));
1157
1158 return CreateIntrinsic(Intrinsic::vector_splice_right, V1->getType(),
1159 {V1, V2, Offset}, {}, Name);
1160}
1161
1163 const Twine &Name) {
1164 auto EC = ElementCount::getFixed(NumElts);
1165 return CreateVectorSplat(EC, V, Name);
1166}
1167
1169 const Twine &Name) {
1170 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1171
1172 // First insert it into a poison vector so we can shuffle it.
1173 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1174 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1175
1176 // Shuffle the value across the desired number of elements.
1178 Zeros.resize(EC.getKnownMinValue());
1179 return CreateShuffleVector(V, Zeros, Name + ".splat");
1180}
1181
1183 const Twine &Name) {
1184 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1185 "Unexpected number of operands to interleave");
1186
1187 // Make sure all operands are the same type.
1188 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1189
1190#ifndef NDEBUG
1191 for (unsigned I = 1; I < Ops.size(); I++) {
1192 assert(Ops[I]->getType() == Ops[0]->getType() &&
1193 "Vector interleave expects matching operand types!");
1194 }
1195#endif
1196
1197 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1198 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1199 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1200 SubvecTy->getElementCount() * Ops.size());
1201 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1202}
1203
1205 unsigned Dimension,
1206 unsigned LastIndex,
1207 MDNode *DbgInfo) {
1208 auto *BaseType = Base->getType();
1210 "Invalid Base ptr type for preserve.array.access.index.");
1211
1212 Value *LastIndexV = getInt32(LastIndex);
1213 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1214 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1215 IdxList.push_back(LastIndexV);
1216
1217 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1218
1219 Value *DimV = getInt32(Dimension);
1220 CallInst *Fn =
1221 CreateIntrinsic(Intrinsic::preserve_array_access_index,
1222 {ResultType, BaseType}, {Base, DimV, LastIndexV});
1223 Fn->addParamAttr(
1224 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1225 if (DbgInfo)
1226 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1227
1228 return Fn;
1229}
1230
1232 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1233 assert(isa<PointerType>(Base->getType()) &&
1234 "Invalid Base ptr type for preserve.union.access.index.");
1235 auto *BaseType = Base->getType();
1236
1237 Value *DIIndex = getInt32(FieldIndex);
1238 CallInst *Fn = CreateIntrinsic(Intrinsic::preserve_union_access_index,
1239 {BaseType, BaseType}, {Base, DIIndex});
1240 if (DbgInfo)
1241 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1242
1243 return Fn;
1244}
1245
1247 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1248 MDNode *DbgInfo) {
1249 auto *BaseType = Base->getType();
1251 "Invalid Base ptr type for preserve.struct.access.index.");
1252
1253 Value *GEPIndex = getInt32(Index);
1254 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1255 Type *ResultType =
1256 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1257
1258 Value *DIIndex = getInt32(FieldIndex);
1259 CallInst *Fn =
1260 CreateIntrinsic(Intrinsic::preserve_struct_access_index,
1261 {ResultType, BaseType}, {Base, GEPIndex, DIIndex});
1262 Fn->addParamAttr(
1263 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1264 if (DbgInfo)
1265 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1266
1267 return Fn;
1268}
1269
1271 ConstantInt *TestV = getInt32(Test);
1272 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1273 {FPNum, TestV});
1274}
1275
1276CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1277 Value *PtrValue,
1278 Value *AlignValue,
1279 Value *OffsetValue) {
1280 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1281 if (OffsetValue)
1282 Vals.push_back(OffsetValue);
1283 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1284 return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1285}
1286
1288 Value *PtrValue,
1289 unsigned Alignment,
1290 Value *OffsetValue) {
1291 assert(isa<PointerType>(PtrValue->getType()) &&
1292 "trying to create an alignment assumption on a non-pointer?");
1293 assert(Alignment != 0 && "Invalid Alignment");
1294 auto *PtrTy = cast<PointerType>(PtrValue->getType());
1295 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1296 Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1297 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1298}
1299
1301 Value *PtrValue,
1302 Value *Alignment,
1303 Value *OffsetValue) {
1304 assert(isa<PointerType>(PtrValue->getType()) &&
1305 "trying to create an alignment assumption on a non-pointer?");
1306 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1307}
1308
1310 Value *SizeValue) {
1311 assert(isa<PointerType>(PtrValue->getType()) &&
1312 "trying to create an deferenceable assumption on a non-pointer?");
1313 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1314 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1316 {DereferenceableOpB});
1317}
1318
1322void ConstantFolder::anchor() {}
1323void NoFolder::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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 Value * CreateVScaleMultiple(IRBuilderBase &B, Type *Ty, uint64_t Scale)
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)
static SmallVector< int, 8 > getSpliceMask(int64_t Imm, unsigned NumElts)
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static const char PassName[]
Value * RHS
Value * LHS
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
const Value * getArraySize() const
Get the number of elements allocated.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
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.
Definition InstrTypes.h:676
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static LLVM_ABI 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.
Definition Constants.h:87
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition Constants.h:225
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:123
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
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.
Definition IRBuilder.h:93
FastMathFlags get(FastMathFlags Default) const
Definition IRBuilder.h:103
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:22
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
FunctionType * getFunctionType()
Type * getParamType(unsigned i) const
Parameter type accessors.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:209
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:214
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1480
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition IRBuilder.h:497
BasicBlock * BB
Definition IRBuilder.h:146
LLVM_ABI 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...
LLVM_ABI CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
LLVM_ABI Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
LLVM_ABI Value * CreateSelectFMFWithUnknownProfile(Value *C, Value *True, Value *False, FMFSource FMFSource, StringRef PassName, const Twine &Name="")
LLVM_ABI 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="")
Definition IRBuilder.h:2555
LLVM_ABI CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:547
LLVM_ABI CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2609
LLVM_ABI Value * CreateAllocationSize(Type *DestTy, AllocaInst *AI)
Get allocation size of an alloca as a runtime Value* (handles both static and dynamic allocas and vsc...
LLVM_ABI Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition IRBuilder.cpp:59
LLVM_ABI 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...
LLVM_ABI CallInst * CreateLifetimeStart(Value *Ptr)
Create a lifetime.start intrinsic.
LLVM_ABI 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.
LLVM_ABI Value * CreateVectorSpliceRight(Value *V1, Value *V2, Value *Offset, const Twine &Name="")
Create a vector.splice.right intrinsic call, or a shufflevector that produces the same result if the ...
LLVM_ABI CallInst * CreateLifetimeEnd(Value *Ptr)
Create a lifetime.end intrinsic.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2073
LLVM_ABI CallInst * CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, const Twine &Name="", std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVM_ABI Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles={})
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2602
LLVM_ABI Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
LLVM_ABI 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.
LLVM_ABI CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
LLVM_ABI CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVMContext & Context
Definition IRBuilder.h:148
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI 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 ...
LLVM_ABI CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
LLVM_ABI 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...
Definition IRBuilder.h:611
LLVM_ABI Value * CreateAggregateCast(Value *V, Type *DestTy)
Cast between aggregate types that must have identical structure but may differ in their leaf types.
Definition IRBuilder.cpp:72
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:567
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memmove between the specified pointers.
LLVM_ABI Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
LLVM_ABI CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
FastMathFlags FMF
Definition IRBuilder.h:153
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:527
LLVM_ABI Value * CreateVectorSpliceLeft(Value *V1, Value *V2, Value *Offset, const Twine &Name="")
Create a vector.splice.left intrinsic call, or a shufflevector that produces the same result if the r...
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition IRBuilder.h:862
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1817
LLVM_ABI CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
LLVM_ABI CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
LLVM_ABI 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.
LLVM_ABI Value * createIsFPClass(Value *FPNum, unsigned Test)
LLVM_ABI 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.
LLVM_ABI 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.
Definition IRBuilder.h:522
LLVM_ABI CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles={})
Generate the IR for a call to the builtin free function.
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2259
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition IRBuilder.h:172
LLVM_ABI DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition IRBuilder.cpp:64
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1424
LLVM_ABI 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.
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition IRBuilder.h:651
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert a memset to the specified pointer and the specified value.
Definition IRBuilder.h:630
LLVM_ABI Value * CreateNAryOp(unsigned Opc, ArrayRef< Value * > Ops, const Twine &Name="", MDNode *FPMathTag=nullptr)
Create either a UnaryOperator or BinaryOperator depending on Opc.
LLVM_ABI CallInst * CreateConstrainedFPIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
This function is like CreateIntrinsic for constrained fp intrinsics.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition IRBuilder.h:2577
LLVMContext & getContext() const
Definition IRBuilder.h:203
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
LLVM_ABI CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
LLVM_ABI Value * CreateSelectWithUnknownProfile(Value *C, Value *True, Value *False, StringRef PassName, const Twine &Name="")
LLVM_ABI 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="")
Definition IRBuilder.h:2167
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2481
LLVM_ABI 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)
Definition IRBuilder.h:2041
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1712
LLVM_ABI Value * CreateTypeSize(Type *Ty, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
LLVM_ABI CallInst * CreateDereferenceableAssumption(Value *PtrValue, Value *SizeValue)
Create an assume intrinsic call that represents an dereferencable assumption on the provided pointer.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2250
LLVM_ABI CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memcpy between the specified pointers.
void setConstrainedFPCallAttr(CallBase *I)
Definition IRBuilder.h:395
LLVM_ABI 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.
LLVM_ABI 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
Definition IRBuilder.h:149
LLVM_ABI CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI Value * CreateVectorInterleave(ArrayRef< Value * > Ops, const Twine &Name="")
LLVM_ABI CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition IRBuilder.cpp:65
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:552
LLVM_ABI 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...
LLVM_ABI Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
LLVM_ABI Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
LLVM_ABI 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)
Definition IRBuilder.h:1441
LLVM_ABI Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
LLVM_ABI CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
LLVM_ABI 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*.
Definition IRBuilder.cpp:44
LLVM_ABI Value * CreateElementCount(Type *Ty, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
LLVM_ABI CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
LLVM_ABI 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)
LLVM_ABI Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
LLVM_ABI CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
virtual Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
virtual ~IRBuilderFolder()
LLVM_ABI void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
bool isBinaryOp() const
LLVM_ABI 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.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isUnaryOp() const
Invoke instruction.
Metadata node.
Definition Metadata.h:1080
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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 LLVM_ABI 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, const Instruction *MDFrom=nullptr)
void reserve(size_type N)
void resize(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.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:297
LLVM_ABI Type * getStructElementType(unsigned N) const
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:273
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition Type.h:264
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:296
Type * getArrayElementType() const
Definition Type.h:408
LLVM_ABI unsigned getStructNumElements() const
LLVM_ABI uint64_t getArrayNumElements() const
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:280
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:352
bool isStructTy() const
True if this is an instance of StructType.
Definition Type.h:261
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:230
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:139
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:259
static LLVM_ABI 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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI Intrinsic::ID getInterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
MaybeAlign getAlign(const CallInst &I, unsigned Index)
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2198
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:763
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106