LLVM 24.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"
17#include "llvm/IR/Constant.h"
18#include "llvm/IR/Constants.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/GlobalValue.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/Module.h"
27#include "llvm/IR/NoFolder.h"
28#include "llvm/IR/Operator.h"
30#include "llvm/IR/Statepoint.h"
31#include "llvm/IR/Type.h"
32#include "llvm/IR/Value.h"
34#include <cassert>
35#include <cstdint>
36#include <optional>
37#include <vector>
38
39using namespace llvm;
40
41/// CreateGlobalString - Make a new global variable with an initializer that
42/// has array of i8 type filled in with the nul terminated string value
43/// specified. If Name is specified, it is the name of the global variable
44/// created.
46 const Twine &Name,
47 unsigned AddressSpace,
48 Module *M, bool AddNull) {
49 Constant *StrConstant = ConstantDataArray::getString(Context, Str, AddNull);
50 if (!M)
51 M = BB->getParent()->getParent();
52 auto *GV = new GlobalVariable(
53 *M, StrConstant->getType(), true, GlobalValue::PrivateLinkage,
54 StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace);
55 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
56 GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty()));
57 return GV;
58}
59
61 assert(BB && BB->getParent() && "No current function!");
62 return BB->getParent()->getReturnType();
63}
64
67 // We prefer to set our current debug location if any has been set, but if
68 // our debug location is empty and I has a valid location, we shouldn't
69 // overwrite it.
70 I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
71}
72
74 Type *SrcTy = V->getType();
75 if (SrcTy == DestTy)
76 return V;
77
78 if (SrcTy->isAggregateType()) {
79 unsigned NumElements;
80 if (SrcTy->isStructTy()) {
81 assert(DestTy->isStructTy() && "Expected StructType");
82 assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements() &&
83 "Expected StructTypes with equal number of elements");
84 NumElements = SrcTy->getStructNumElements();
85 } else {
86 assert(SrcTy->isArrayTy() && DestTy->isArrayTy() && "Expected ArrayType");
87 assert(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements() &&
88 "Expected ArrayTypes with equal number of elements");
89 NumElements = SrcTy->getArrayNumElements();
90 }
91
92 Value *Result = PoisonValue::get(DestTy);
93 for (unsigned I = 0; I < NumElements; ++I) {
94 Type *ElementTy = SrcTy->isStructTy() ? DestTy->getStructElementType(I)
95 : DestTy->getArrayElementType();
96 Value *Element =
98
99 Result = CreateInsertValue(Result, Element, ArrayRef(I));
100 }
101 return Result;
102 }
103
104 return CreateBitOrPointerCast(V, DestTy);
105}
106
108 Value *V, Type *NewTy) {
109 Type *OldTy = V->getType();
110
111 if (OldTy == NewTy)
112 return V;
113
114 assert(!(isa<IntegerType>(OldTy) && isa<IntegerType>(NewTy)) &&
115 "Integer types must be the exact same to convert.");
116
117 // A variant of bitcast that supports a mixture of fixed and scalable types
118 // that are know to have the same size.
119 auto CreateBitCastLike = [this](Value *In, Type *Ty) -> Value * {
120 Type *InTy = In->getType();
121 if (InTy == Ty)
122 return In;
123
125 // For vscale_range(2) expand <4 x i32> to <vscale x 4 x i16> -->
126 // <4 x i32> to <vscale x 2 x i32> to <vscale x 4 x i16>
128 return CreateBitCast(
129 CreateInsertVector(VTy, PoisonValue::get(VTy), In, getInt64(0)), Ty);
130 }
131
133 // For vscale_range(2) expand <vscale x 4 x i16> to <4 x i32> -->
134 // <vscale x 4 x i16> to <vscale x 2 x i32> to <4 x i32>
136 return CreateExtractVector(Ty, CreateBitCast(In, VTy), getInt64(0));
137 }
138
139 return CreateBitCast(In, Ty);
140 };
141
142 // See if we need inttoptr for this type pair. May require additional bitcast.
143 if (OldTy->isIntOrIntVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
144 // Expand <2 x i32> to i8* --> <2 x i32> to i64 to i8*
145 // Expand i128 to <2 x i8*> --> i128 to <2 x i64> to <2 x i8*>
146 // Expand <4 x i32> to <2 x i8*> --> <4 x i32> to <2 x i64> to <2 x i8*>
147 // Directly handle i64 to i8*
148 return CreateIntToPtr(CreateBitCastLike(V, DL.getIntPtrType(NewTy)), NewTy);
149 }
150
151 // See if we need ptrtoint for this type pair. May require additional bitcast.
152 if (OldTy->isPtrOrPtrVectorTy() && NewTy->isIntOrIntVectorTy()) {
153 // Expand <2 x i8*> to i128 --> <2 x i8*> to <2 x i64> to i128
154 // Expand i8* to <2 x i32> --> i8* to i64 to <2 x i32>
155 // Expand <2 x i8*> to <4 x i32> --> <2 x i8*> to <2 x i64> to <4 x i32>
156 // Expand i8* to i64 --> i8* to i64 to i64
157 return CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)), NewTy);
158 }
159
160 if (OldTy->isPtrOrPtrVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
161 unsigned OldAS = OldTy->getPointerAddressSpace();
162 unsigned NewAS = NewTy->getPointerAddressSpace();
163 // To convert pointers with different address spaces (they are already
164 // checked convertible, i.e. they have the same pointer size), so far we
165 // cannot use `bitcast` (which has restrict on the same address space) or
166 // `addrspacecast` (which is not always no-op casting). Instead, use a pair
167 // of no-op `ptrtoint`/`inttoptr` casts through an integer with the same bit
168 // size.
169 if (OldAS != NewAS) {
170 return CreateIntToPtr(
171 CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
172 DL.getIntPtrType(NewTy)),
173 NewTy);
174 }
175 }
176
177 return CreateBitCastLike(V, NewTy);
178}
179
180CallInst *
181IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
182 const Twine &Name, FMFSource FMFSource,
183 ArrayRef<OperandBundleDef> OpBundles) {
184 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
185 if (isa<FPMathOperator>(CI))
187 return CI;
188}
189
191 Value *VScale = B.CreateVScale(Ty);
192 if (Scale == 1)
193 return VScale;
194
195 return B.CreateNUWMul(VScale, ConstantInt::get(Ty, Scale));
196}
197
199 if (EC.isFixed() || EC.isZero())
200 return ConstantInt::get(Ty, EC.getKnownMinValue());
201
202 return CreateVScaleMultiple(*this, Ty, EC.getKnownMinValue());
203}
204
206 if (Size.isFixed() || Size.isZero())
207 return ConstantInt::get(Ty, Size.getKnownMinValue());
208
209 return CreateVScaleMultiple(*this, Ty, Size.getKnownMinValue());
210}
211
213 const DataLayout &DL = BB->getDataLayout();
214 TypeSize ElemSize = DL.getTypeAllocSize(AI->getAllocatedType());
215 Value *Size = CreateTypeSize(DestTy, ElemSize);
216 if (AI->isArrayAllocation())
218 return Size;
219}
220
222 Type *STy = DstType->getScalarType();
223 if (isa<ScalableVectorType>(DstType)) {
224 Type *StepVecType = DstType;
225 // TODO: We expect this special case (element type < 8 bits) to be
226 // temporary - once the intrinsic properly supports < 8 bits this code
227 // can be removed.
228 if (STy->getScalarSizeInBits() < 8)
229 StepVecType =
231 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
232 nullptr, Name);
233 if (StepVecType != DstType)
234 Res = CreateTrunc(Res, DstType);
235 return Res;
236 }
237
238 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
239
240 // Create a vector of consecutive numbers from zero to VF.
241 // It's okay if the values wrap around.
243 for (unsigned i = 0; i < NumEls; ++i)
244 Indices.push_back(
245 ConstantInt::get(STy, i, /*IsSigned=*/false, /*ImplicitTrunc=*/true));
246
247 // Add the consecutive indices to the vector value.
248 return ConstantVector::get(Indices);
249}
250
252 MaybeAlign Align, bool isVolatile,
253 const AAMDNodes &AAInfo) {
254 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
255 Type *Tys[] = {Ptr->getType(), Size->getType()};
256
257 auto *CI = cast<MemSetInst>(
258 CreateIntrinsicWithoutFolding(Intrinsic::memset, Tys, Ops));
259
260 if (Align)
261 CI->setDestAlignment(*Align);
262 CI->setAAMetadata(AAInfo);
263 return CI;
264}
265
267 Value *Val, Value *Size,
268 bool IsVolatile,
269 const AAMDNodes &AAInfo) {
270 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
271 Type *Tys[] = {Dst->getType(), Size->getType()};
272
273 auto *CI = cast<MemSetInst>(
274 CreateIntrinsicWithoutFolding(Intrinsic::memset_inline, Tys, Ops));
275
276 if (DstAlign)
277 CI->setDestAlignment(*DstAlign);
278 CI->setAAMetadata(AAInfo);
279 return CI;
280}
281
283 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
284 const AAMDNodes &AAInfo) {
285
286 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
287 Type *Tys[] = {Ptr->getType(), Size->getType()};
288
290 Intrinsic::memset_element_unordered_atomic, Tys, Ops));
291 CI->setDestAlignment(Alignment);
292 CI->setAAMetadata(AAInfo);
293 return CI;
294}
295
297 MaybeAlign DstAlign, Value *Src,
298 MaybeAlign SrcAlign, Value *Size,
299 bool isVolatile,
300 const AAMDNodes &AAInfo) {
301 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
302 IntrID == Intrinsic::memmove) &&
303 "Unexpected intrinsic ID");
304 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
305 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
306
307 auto *MCI =
309
310 if (DstAlign)
311 MCI->setDestAlignment(*DstAlign);
312 if (SrcAlign)
313 MCI->setSourceAlignment(*SrcAlign);
314 MCI->setAAMetadata(AAInfo);
315 return MCI;
316}
317
319 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
320 uint32_t ElementSize, const AAMDNodes &AAInfo) {
321 assert(DstAlign >= ElementSize &&
322 "Pointer alignment must be at least element size");
323 assert(SrcAlign >= ElementSize &&
324 "Pointer alignment must be at least element size");
325 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
326 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
327
329 Intrinsic::memcpy_element_unordered_atomic, Tys, Ops));
330
331 // Set the alignment of the pointer args.
332 AMCI->setDestAlignment(DstAlign);
333 AMCI->setSourceAlignment(SrcAlign);
334 AMCI->setAAMetadata(AAInfo);
335 return AMCI;
336}
337
338/// isConstantOne - Return true only if val is constant int 1
339static bool isConstantOne(const Value *Val) {
340 assert(Val && "isConstantOne does not work with nullptr Val");
341 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
342 return CVal && CVal->isOne();
343}
344
346 Value *AllocSize, Value *ArraySize,
348 Function *MallocF, const Twine &Name) {
349 // malloc(type) becomes:
350 // i8* malloc(typeSize)
351 // malloc(type, arraySize) becomes:
352 // i8* malloc(typeSize*arraySize)
353 if (!ArraySize)
354 ArraySize = ConstantInt::get(IntPtrTy, 1);
355 else if (ArraySize->getType() != IntPtrTy)
356 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
357
358 if (!isConstantOne(ArraySize)) {
359 if (isConstantOne(AllocSize)) {
360 AllocSize = ArraySize; // Operand * 1 = Operand
361 } else {
362 // Multiply type size by the array size...
363 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
364 }
365 }
366
367 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
368 // Create the call to Malloc.
369 Module *M = BB->getParent()->getParent();
371 FunctionCallee MallocFunc = MallocF;
372 if (!MallocFunc)
373 // prototype malloc as "void *malloc(size_t)"
374 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
375 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
376
377 MCall->setTailCall();
378 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
379 MCall->setCallingConv(F->getCallingConv());
380 F->setReturnDoesNotAlias();
381 }
382
383 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
384
385 return MCall;
386}
387
389 Value *AllocSize, Value *ArraySize,
390 Function *MallocF, const Twine &Name) {
391
392 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
393 Name);
394}
395
396/// CreateFree - Generate the IR for a call to the builtin free function.
399 assert(Source->getType()->isPointerTy() &&
400 "Can not free something of nonpointer type!");
401
402 Module *M = BB->getParent()->getParent();
403
404 Type *VoidTy = Type::getVoidTy(M->getContext());
405 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
406 // prototype free as "void free(void*)"
407 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
408 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
409 Result->setTailCall();
410 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
411 Result->setCallingConv(F->getCallingConv());
412
413 return Result;
414}
415
417 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
418 uint32_t ElementSize, const AAMDNodes &AAInfo) {
419 assert(DstAlign >= ElementSize &&
420 "Pointer alignment must be at least element size");
421 assert(SrcAlign >= ElementSize &&
422 "Pointer alignment must be at least element size");
423 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
424 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
425
427 Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
428
429 // Set the alignment of the pointer args.
430 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
431 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
432 CI->setAAMetadata(AAInfo);
433 return CI;
434}
435
436Value *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
437 Value *Ops[] = {Src};
438 Type *Tys[] = { Src->getType() };
439 return CreateIntrinsic(ID, Tys, Ops);
440}
441
443 Value *Ops[] = {Acc, Src};
444 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
445}
446
448 Value *Ops[] = {Acc, Src};
449 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
450}
451
453 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
454}
455
457 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
458}
459
461 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
462}
463
465 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
466}
467
469 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
470}
471
473 auto ID =
474 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
475 return getReductionIntrinsic(ID, Src);
476}
477
479 auto ID =
480 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
481 return getReductionIntrinsic(ID, Src);
482}
483
485 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
486}
487
489 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
490}
491
493 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
494}
495
497 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
498}
499
501 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximumnum, Src);
502}
503
505 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimumnum, Src);
506}
507
510 "lifetime.start only applies to pointers.");
511 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_start,
512 {Ptr->getType()}, {Ptr});
513}
514
517 "lifetime.end only applies to pointers.");
518 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_end,
519 {Ptr->getType()}, {Ptr});
520}
521
523
525 "invariant.start only applies to pointers.");
526 if (!Size)
527 Size = getInt64(-1);
528 else
529 assert(Size->getType() == getInt64Ty() &&
530 "invariant.start requires the size to be an i64");
531
532 Value *Ops[] = {Size, Ptr};
533 // Fill in the single overloaded type: memory object type.
534 Type *ObjectPtr[1] = {Ptr->getType()};
535 return CreateIntrinsicWithoutFolding(Intrinsic::invariant_start, ObjectPtr,
536 Ops);
537}
538
540 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
541 return V->getAlign();
542 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
543 return getAlign(A->getAliaseeObject());
544 return {};
545}
546
548 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
549 "threadlocal_address only applies to thread local variables.");
551 llvm::Intrinsic::threadlocal_address, {Ptr->getType()}, {Ptr});
552 if (MaybeAlign A = getAlign(Ptr)) {
555 }
556 return CI;
557}
558
560 assert(Cond->getType() == getInt1Ty() &&
561 "an assumption condition must be of type i1");
562 return CreateIntrinsicWithoutFolding(Intrinsic::assume, /*OverloadTypes=*/{},
563 {Cond});
564}
565
566CallInst *
570 Intrinsic::assume, /*OverloadTypes=*/{}, Args,
571 /*FMFSource=*/nullptr, /*Name=*/"", OpBundles);
572}
573
576 Intrinsic::experimental_noalias_scope_decl, {}, {Scope});
577}
578
579/// Create a call to a Masked Load intrinsic.
580/// \p Ty - vector type to load
581/// \p Ptr - base pointer for the load
582/// \p Alignment - alignment of the source location
583/// \p Mask - vector of booleans which indicates what vector lanes should
584/// be accessed in memory
585/// \p PassThru - pass-through value that is used to fill the masked-off lanes
586/// of the result
587/// \p Name - name of the result variable
589 Value *Mask, Value *PassThru,
590 const Twine &Name) {
591 auto *PtrTy = cast<PointerType>(Ptr->getType());
592 assert(Ty->isVectorTy() && "Type should be vector");
593 assert(Mask && "Mask should not be all-ones (null)");
594 if (!PassThru)
595 PassThru = PoisonValue::get(Ty);
596 Type *OverloadedTypes[] = { Ty, PtrTy };
597 Value *Ops[] = {Ptr, Mask, PassThru};
598 CallInst *CI =
599 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
600 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
601 return CI;
602}
603
604/// Create a call to a Masked Store intrinsic.
605/// \p Val - data to be stored,
606/// \p Ptr - base pointer for the store
607/// \p Alignment - alignment of the destination location
608/// \p Mask - vector of booleans which indicates what vector lanes should
609/// be accessed in memory
611 Align Alignment, Value *Mask) {
612 auto *PtrTy = cast<PointerType>(Ptr->getType());
613 Type *DataTy = Val->getType();
614 assert(DataTy->isVectorTy() && "Val should be a vector");
615 assert(Mask && "Mask should not be all-ones (null)");
616 Type *OverloadedTypes[] = { DataTy, PtrTy };
617 Value *Ops[] = {Val, Ptr, Mask};
618 CallInst *CI =
619 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
620 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
621 return CI;
622}
623
624/// Create a call to a Masked intrinsic, with given intrinsic Id,
625/// an array of operands - Ops, and an array of overloaded types -
626/// OverloadedTypes.
627CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
629 ArrayRef<Type *> OverloadedTypes,
630 const Twine &Name) {
631 return CreateIntrinsicWithoutFolding(Id, OverloadedTypes, Ops, {}, Name);
632}
633
634/// Create a call to a Masked Gather intrinsic.
635/// \p Ty - vector type to gather
636/// \p Ptrs - vector of pointers for loading
637/// \p Align - alignment for one element
638/// \p Mask - vector of booleans which indicates what vector lanes should
639/// be accessed in memory
640/// \p PassThru - pass-through value that is used to fill the masked-off lanes
641/// of the result
642/// \p Name - name of the result variable
644 Align Alignment, Value *Mask,
645 Value *PassThru,
646 const Twine &Name) {
647 auto *VecTy = cast<VectorType>(Ty);
648 ElementCount NumElts = VecTy->getElementCount();
649 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
650 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
651
652 if (!Mask)
653 Mask = getAllOnesMask(NumElts);
654
655 if (!PassThru)
656 PassThru = PoisonValue::get(Ty);
657
658 Type *OverloadedTypes[] = {Ty, PtrsTy};
659 Value *Ops[] = {Ptrs, Mask, PassThru};
660
661 // We specify only one type when we create this intrinsic. Types of other
662 // arguments are derived from this type.
663 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
664 OverloadedTypes, Name);
665 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
666 return CI;
667}
668
669/// Create a call to a Masked Scatter intrinsic.
670/// \p Data - data to be stored,
671/// \p Ptrs - the vector of pointers, where the \p Data elements should be
672/// stored
673/// \p Align - alignment for one element
674/// \p Mask - vector of booleans which indicates what vector lanes should
675/// be accessed in memory
677 Align Alignment, Value *Mask) {
678 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
679 auto *DataTy = cast<VectorType>(Data->getType());
680 ElementCount NumElts = PtrsTy->getElementCount();
681
682 if (!Mask)
683 Mask = getAllOnesMask(NumElts);
684
685 Type *OverloadedTypes[] = {DataTy, PtrsTy};
686 Value *Ops[] = {Data, Ptrs, Mask};
687
688 // We specify only one type when we create this intrinsic. Types of other
689 // arguments are derived from this type.
690 CallInst *CI =
691 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
692 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
693 return CI;
694}
695
696/// Create a call to Masked Expand Load intrinsic
697/// \p Ty - vector type to load
698/// \p Ptr - base pointer for the load
699/// \p Align - alignment of \p Ptr
700/// \p Mask - vector of booleans which indicates what vector lanes should
701/// be accessed in memory
702/// \p PassThru - pass-through value that is used to fill the masked-off lanes
703/// of the result
704/// \p Name - name of the result variable
706 MaybeAlign Align, Value *Mask,
707 Value *PassThru,
708 const Twine &Name) {
709 assert(Ty->isVectorTy() && "Type should be vector");
710 assert(Mask && "Mask should not be all-ones (null)");
711 if (!PassThru)
712 PassThru = PoisonValue::get(Ty);
713 Type *PtrTy = Ptr->getType();
714 Type *OverloadedTypes[] = {Ty, PtrTy};
715 Value *Ops[] = {Ptr, Mask, PassThru};
716 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
717 OverloadedTypes, Name);
718 if (Align)
720 return CI;
721}
722
723/// Create a call to Masked Compress Store intrinsic
724/// \p Val - data to be stored,
725/// \p Ptr - base pointer for the store
726/// \p Align - alignment of \p Ptr
727/// \p Mask - vector of booleans which indicates what vector lanes should
728/// be accessed in memory
731 Value *Mask) {
732 Type *DataTy = Val->getType();
733 assert(DataTy->isVectorTy() && "Val should be a vector");
734 assert(Mask && "Mask should not be all-ones (null)");
735 Type *PtrTy = Ptr->getType();
736 Type *OverloadedTypes[] = {DataTy, PtrTy};
737 Value *Ops[] = {Val, Ptr, Mask};
738 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
739 OverloadedTypes);
740 if (Align)
742 return CI;
743}
744
745template <typename T0>
746static std::vector<Value *>
748 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
749 std::vector<Value *> Args;
750 Args.push_back(B.getInt64(ID));
751 Args.push_back(B.getInt32(NumPatchBytes));
752 Args.push_back(ActualCallee);
753 Args.push_back(B.getInt32(CallArgs.size()));
754 Args.push_back(B.getInt32(Flags));
755 llvm::append_range(Args, CallArgs);
756 // GC Transition and Deopt args are now always handled via operand bundle.
757 // They will be removed from the signature of gc.statepoint shortly.
758 Args.push_back(B.getInt32(0));
759 Args.push_back(B.getInt32(0));
760 // GC args are now encoded in the gc-live operand bundle
761 return Args;
762}
763
764template<typename T1, typename T2, typename T3>
765static std::vector<OperandBundleDef>
766getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
767 std::optional<ArrayRef<T2>> DeoptArgs,
768 ArrayRef<T3> GCArgs) {
769 std::vector<OperandBundleDef> Rval;
770 if (DeoptArgs)
771 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
772 if (TransitionArgs)
773 Rval.emplace_back("gc-transition",
774 SmallVector<Value *, 16>(*TransitionArgs));
775 if (GCArgs.size())
776 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
777 return Rval;
778}
779
780template <typename T0, typename T1, typename T2, typename T3>
782 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
783 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
784 std::optional<ArrayRef<T1>> TransitionArgs,
785 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
786 const Twine &Name) {
787 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
788 // Fill in the one generic type'd argument (the function is also vararg)
790 M, Intrinsic::experimental_gc_statepoint,
791 {ActualCallee.getCallee()->getType()});
792
793 std::vector<Value *> Args = getStatepointArgs(
794 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
795
796 CallInst *CI = Builder->CreateCall(
797 FnStatepoint, Args,
798 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
799 CI->addParamAttr(2,
800 Attribute::get(Builder->getContext(), Attribute::ElementType,
801 ActualCallee.getFunctionType()));
802 return CI;
803}
804
806 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
807 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
808 ArrayRef<Value *> GCArgs, const Twine &Name) {
810 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
811 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
812}
813
815 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
816 uint32_t Flags, ArrayRef<Value *> CallArgs,
817 std::optional<ArrayRef<Use>> TransitionArgs,
818 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
819 const Twine &Name) {
821 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
822 DeoptArgs, GCArgs, Name);
823}
824
826 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
827 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
828 ArrayRef<Value *> GCArgs, const Twine &Name) {
830 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
831 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
832}
833
834template <typename T0, typename T1, typename T2, typename T3>
836 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
837 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
838 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
839 std::optional<ArrayRef<T1>> TransitionArgs,
840 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
841 const Twine &Name) {
842 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
843 // Fill in the one generic type'd argument (the function is also vararg)
845 M, Intrinsic::experimental_gc_statepoint,
846 {ActualInvokee.getCallee()->getType()});
847
848 std::vector<Value *> Args =
849 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
850 Flags, InvokeArgs);
851
852 InvokeInst *II = Builder->CreateInvoke(
853 FnStatepoint, NormalDest, UnwindDest, Args,
854 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
855 II->addParamAttr(2,
856 Attribute::get(Builder->getContext(), Attribute::ElementType,
857 ActualInvokee.getFunctionType()));
858 return II;
859}
860
862 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
863 BasicBlock *NormalDest, BasicBlock *UnwindDest,
864 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
865 ArrayRef<Value *> GCArgs, const Twine &Name) {
867 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
868 uint32_t(StatepointFlags::None), InvokeArgs,
869 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
870}
871
873 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
874 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
875 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
876 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
877 const Twine &Name) {
879 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
880 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
881}
882
884 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
885 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
886 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
887 const Twine &Name) {
889 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
890 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
891 GCArgs, Name);
892}
893
895 Type *ResultType, const Twine &Name) {
896 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
897 Type *Types[] = {ResultType};
898
899 Value *Args[] = {Statepoint};
900 return CreateIntrinsicWithoutFolding(ID, Types, Args, {}, Name);
901}
902
904 int BaseOffset, int DerivedOffset,
905 Type *ResultType, const Twine &Name) {
906 Type *Types[] = {ResultType};
907
908 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
909 return CreateIntrinsicWithoutFolding(Intrinsic::experimental_gc_relocate,
910 Types, Args, {}, Name);
911}
912
914 const Twine &Name) {
915 Type *PtrTy = DerivedPtr->getType();
917 Intrinsic::experimental_gc_get_pointer_base, PtrTy, DerivedPtr, {}, Name);
918}
919
921 const Twine &Name) {
922 Type *PtrTy = DerivedPtr->getType();
924 Intrinsic::experimental_gc_get_pointer_offset, {PtrTy}, {DerivedPtr}, {},
925 Name);
926}
927
930 const Twine &Name) {
931 Module *M = BB->getModule();
932 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, Op->getType());
933 if (Value *V =
934 Folder.FoldIntrinsic(ID, Op, Fn->getReturnType(), FMFSource.get(FMF),
936 return V;
937 return createCallHelper(Fn, Op, Name, FMFSource);
938}
939
942 const Twine &Name) {
943 Module *M = BB->getModule();
944 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
945 if (Value *V = Folder.FoldIntrinsic(ID, {LHS, RHS}, Fn->getReturnType(),
948 return V;
949 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
950}
951
953 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
954 FMFSource FMFSource, const Twine &Name,
955 ArrayRef<OperandBundleDef> OpBundles) {
956 Module *M = BB->getModule();
957 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTypes);
958 return createCallHelper(Fn, Args, Name, FMFSource, OpBundles);
959}
960
962 Intrinsic::ID ID,
965 const Twine &Name) {
966 Module *M = BB->getModule();
968 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, RetTy, ArgTys);
969 return createCallHelper(Fn, Args, Name, FMFSource);
970}
971
973 ArrayRef<Type *> OverloadTypes,
975 FMFSource FMFSource, const Twine &Name,
977 function_ref<void(CallInst *)> SetFn) {
978 Type *RetTy = Intrinsic::getType(Context, ID, OverloadTypes)->getReturnType();
979 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
981 return V;
982 CallInst *CI = CreateIntrinsicWithoutFolding(ID, OverloadTypes, Args,
983 FMFSource, Name, OpBundles);
984 SetFn(CI);
985 return CI;
986}
987
990 FMFSource FMFSource, const Twine &Name,
991 function_ref<void(CallInst *)> SetFn) {
992 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
994 return V;
995 CallInst *CI =
996 CreateIntrinsicWithoutFolding(RetTy, ID, Args, FMFSource, Name);
997 SetFn(CI);
998 return CI;
999}
1000
1003 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1004 std::optional<fp::ExceptionBehavior> Except) {
1005 Value *RoundingV = getConstrainedFPRounding(Rounding);
1006 Value *ExceptV = getConstrainedFPExcept(Except);
1007
1008 FastMathFlags UseFMF = FMFSource.get(FMF);
1010 ID, {L->getType()}, {L, R, RoundingV, ExceptV}, nullptr, Name, {});
1012 setFPAttrs(C, FPMathTag, UseFMF);
1013 return C;
1014}
1015
1018 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
1019 std::optional<RoundingMode> Rounding,
1020 std::optional<fp::ExceptionBehavior> Except) {
1021 Value *RoundingV = getConstrainedFPRounding(Rounding);
1022 Value *ExceptV = getConstrainedFPExcept(Except);
1023
1024 FastMathFlags UseFMF = FMFSource.get(FMF);
1025
1026 llvm::SmallVector<Value *, 5> ExtArgs(Args);
1027 ExtArgs.push_back(RoundingV);
1028 ExtArgs.push_back(ExceptV);
1029 CallInst *C =
1030 CreateIntrinsicWithoutFolding(ID, Types, ExtArgs, nullptr, Name, {});
1032 setFPAttrs(C, FPMathTag, UseFMF);
1033 return C;
1034}
1035
1038 const Twine &Name, MDNode *FPMathTag,
1039 std::optional<fp::ExceptionBehavior> Except) {
1040 Value *ExceptV = getConstrainedFPExcept(Except);
1041
1042 FastMathFlags UseFMF = FMFSource.get(FMF);
1044 ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name, {});
1046 setFPAttrs(C, FPMathTag, UseFMF);
1047 return C;
1048}
1049
1051 const Twine &Name, MDNode *FPMathTag) {
1053 assert(Ops.size() == 2 && "Invalid number of operands!");
1054 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
1055 Ops[0], Ops[1], Name, FPMathTag);
1056 }
1058 assert(Ops.size() == 1 && "Invalid number of operands!");
1059 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
1060 Ops[0], Name, FPMathTag);
1061 }
1062 llvm_unreachable("Unexpected opcode!");
1063}
1064
1066 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource,
1067 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1068 std::optional<fp::ExceptionBehavior> Except) {
1069 Value *ExceptV = getConstrainedFPExcept(Except);
1070
1071 FastMathFlags UseFMF = FMFSource.get(FMF);
1072
1073 CallInst *C;
1075 Value *RoundingV = getConstrainedFPRounding(Rounding);
1077 ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV}, nullptr, Name, {});
1078 } else
1079 C = CreateIntrinsicWithoutFolding(ID, {DestTy, V->getType()}, {V, ExceptV},
1080 nullptr, Name, {});
1082
1084 setFPAttrs(C, FPMathTag, UseFMF);
1085 return C;
1086}
1087
1088Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
1089 Value *RHS, const Twine &Name,
1090 MDNode *FPMathTag, FMFSource FMFSource,
1091 bool IsSignaling) {
1092 if (IsFPConstrained) {
1093 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1094 : Intrinsic::experimental_constrained_fcmp;
1095 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1096 }
1097
1098 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1099 return V;
1100 return Insert(
1101 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1102 Name);
1103}
1104
1107 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1108 Value *PredicateV = getConstrainedFPPredicate(P);
1109 Value *ExceptV = getConstrainedFPExcept(Except);
1110
1112 ID, {L->getType()}, {L, R, PredicateV, ExceptV}, nullptr, Name, {});
1114 return C;
1115}
1116
1118 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1119 std::optional<RoundingMode> Rounding,
1120 std::optional<fp::ExceptionBehavior> Except) {
1121 llvm::SmallVector<Value *, 6> UseArgs(Args);
1122
1123 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1124 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1125 UseArgs.push_back(getConstrainedFPExcept(Except));
1126
1127 CallInst *C = CreateCall(Callee, UseArgs, Name);
1129 return C;
1130}
1131
1133 Value *False,
1135 const Twine &Name) {
1136 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1137 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1139 }
1140 return Ret;
1141}
1142
1144 Value *False,
1147 const Twine &Name) {
1148 Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
1149 if (auto *SI = dyn_cast<SelectInst>(Ret))
1151 return Ret;
1152}
1153
1155 const Twine &Name, Instruction *MDFrom) {
1156 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1157}
1158
1160 FMFSource FMFSource, const Twine &Name,
1161 Instruction *MDFrom) {
1162 if (auto *V = Folder.FoldSelect(C, True, False, FMFSource.get(FMF)))
1163 return V;
1164
1165 SelectInst *Sel = SelectInst::Create(C, True, False);
1166 if (MDFrom) {
1167 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1168 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1169 Sel = addBranchMetadata(Sel, Prof, Unpred);
1170 }
1171 if (isa<FPMathOperator>(Sel))
1172 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1173 return Insert(Sel, Name);
1174}
1175
1177 bool IsNUW) {
1178 assert(LHS->getType() == RHS->getType() &&
1179 "Pointer subtraction operand types must match!");
1180 Value *LHSAddr = CreatePtrToAddr(LHS);
1181 Value *RHSAddr = CreatePtrToAddr(RHS);
1182 return CreateSub(LHSAddr, RHSAddr, Name, IsNUW);
1183}
1185 const Twine &Name) {
1186 const DataLayout &DL = BB->getDataLayout();
1187 TypeSize ElemSize = DL.getTypeAllocSize(ElemTy);
1188 if (ElemSize == TypeSize::getFixed(1))
1189 return CreatePtrDiff(LHS, RHS, Name);
1190
1191 Value *Diff = CreatePtrDiff(LHS, RHS);
1192 return CreateExactSDiv(Diff, CreateTypeSize(Diff->getType(), ElemSize), Name);
1193}
1194
1197 "launder.invariant.group only applies to pointers.");
1198 auto *PtrType = Ptr->getType();
1199 Module *M = BB->getParent()->getParent();
1200 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1201 M, Intrinsic::launder_invariant_group, {PtrType});
1202
1203 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1204 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1205 PtrType &&
1206 "LaunderInvariantGroup should take and return the same type");
1207
1208 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1209}
1210
1213 "strip.invariant.group only applies to pointers.");
1214
1215 auto *PtrType = Ptr->getType();
1216 Module *M = BB->getParent()->getParent();
1217 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1218 M, Intrinsic::strip_invariant_group, {PtrType});
1219
1220 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1221 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1222 PtrType &&
1223 "StripInvariantGroup should take and return the same type");
1224
1225 return CreateCall(FnStripInvariantGroup, {Ptr});
1226}
1227
1229 auto *Ty = cast<VectorType>(V->getType());
1230 if (isa<ScalableVectorType>(Ty)) {
1231 Module *M = BB->getParent()->getParent();
1232 Function *F =
1233 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1234 return Insert(CallInst::Create(F, V), Name);
1235 }
1236 // Keep the original behaviour for fixed vector
1237 SmallVector<int, 8> ShuffleMask;
1238 int NumElts = Ty->getElementCount().getKnownMinValue();
1239 for (int i = 0; i < NumElts; ++i)
1240 ShuffleMask.push_back(NumElts - i - 1);
1241 return CreateShuffleVector(V, ShuffleMask, Name);
1242}
1243
1244static SmallVector<int, 8> getSpliceMask(int64_t Imm, unsigned NumElts) {
1245 unsigned Idx = (NumElts + Imm) % NumElts;
1247 for (unsigned I = 0; I < NumElts; ++I)
1248 Mask.push_back(Idx + I);
1249 return Mask;
1250}
1251
1253 Value *Offset, const Twine &Name) {
1254 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1255 assert(V1->getType() == V2->getType() &&
1256 "Splice expects matching operand types!");
1257
1258 // Emit a shufflevector for fixed vectors with a constant offset
1259 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1260 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1261 return CreateShuffleVector(
1262 V1, V2,
1263 getSpliceMask(COffset->getZExtValue(), FVTy->getNumElements()));
1264
1265 return CreateIntrinsic(Intrinsic::vector_splice_left, V1->getType(),
1266 {V1, V2, Offset}, {}, Name);
1267}
1268
1270 Value *Offset,
1271 const Twine &Name) {
1272 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1273 assert(V1->getType() == V2->getType() &&
1274 "Splice expects matching operand types!");
1275
1276 // Emit a shufflevector for fixed vectors with a constant offset
1277 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1278 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1279 return CreateShuffleVector(
1280 V1, V2,
1281 getSpliceMask(-COffset->getZExtValue(), FVTy->getNumElements()));
1282
1283 return CreateIntrinsic(Intrinsic::vector_splice_right, V1->getType(),
1284 {V1, V2, Offset}, {}, Name);
1285}
1286
1288 const Twine &Name) {
1289 auto EC = ElementCount::getFixed(NumElts);
1290 return CreateVectorSplat(EC, V, Name);
1291}
1292
1294 const Twine &Name) {
1295 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1296
1297 // First insert it into a poison vector so we can shuffle it.
1298 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1299 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1300
1301 // Shuffle the value across the desired number of elements.
1303 Zeros.resize(EC.getKnownMinValue());
1304 return CreateShuffleVector(V, Zeros, Name + ".splat");
1305}
1306
1308 const Twine &Name) {
1309 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1310 "Unexpected number of operands to interleave");
1311
1312 // Make sure all operands are the same type.
1313 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1314
1315#ifndef NDEBUG
1316 for (unsigned I = 1; I < Ops.size(); I++) {
1317 assert(Ops[I]->getType() == Ops[0]->getType() &&
1318 "Vector interleave expects matching operand types!");
1319 }
1320#endif
1321
1322 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1323 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1324 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1325 SubvecTy->getElementCount() * Ops.size());
1326 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1327}
1328
1330 unsigned Dimension,
1331 unsigned LastIndex,
1332 MDNode *DbgInfo) {
1333 auto *BaseType = Base->getType();
1335 "Invalid Base ptr type for preserve.array.access.index.");
1336
1337 Value *LastIndexV = getInt32(LastIndex);
1338 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1339 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1340 IdxList.push_back(LastIndexV);
1341
1342 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1343
1344 Value *DimV = getInt32(Dimension);
1346 Intrinsic::preserve_array_access_index, {ResultType, BaseType},
1347 {Base, DimV, LastIndexV});
1348 Fn->addParamAttr(
1349 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1350 if (DbgInfo)
1351 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1352
1353 return Fn;
1354}
1355
1357 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1358 assert(isa<PointerType>(Base->getType()) &&
1359 "Invalid Base ptr type for preserve.union.access.index.");
1360 auto *BaseType = Base->getType();
1361
1362 Value *DIIndex = getInt32(FieldIndex);
1363 CallInst *Fn =
1364 CreateIntrinsicWithoutFolding(Intrinsic::preserve_union_access_index,
1365 {BaseType, BaseType}, {Base, DIIndex});
1366 if (DbgInfo)
1367 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1368
1369 return Fn;
1370}
1371
1373 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1374 MDNode *DbgInfo) {
1375 auto *BaseType = Base->getType();
1377 "Invalid Base ptr type for preserve.struct.access.index.");
1378
1379 Value *GEPIndex = getInt32(Index);
1380 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1381 Type *ResultType =
1382 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1383
1384 Value *DIIndex = getInt32(FieldIndex);
1386 Intrinsic::preserve_struct_access_index, {ResultType, BaseType},
1387 {Base, GEPIndex, DIIndex});
1388 Fn->addParamAttr(
1389 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1390 if (DbgInfo)
1391 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1392
1393 return Fn;
1394}
1395
1397 ConstantInt *TestV = getInt32(Test);
1398 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1399 {FPNum, TestV});
1400}
1401
1402CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1403 Value *PtrValue,
1404 Value *AlignValue,
1405 Value *OffsetValue) {
1406 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1407 if (OffsetValue)
1408 Vals.push_back(OffsetValue);
1409 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1410 return CreateAssumption({AlignOpB});
1411}
1412
1414 Value *PtrValue,
1415 uint64_t Alignment,
1416 Value *OffsetValue) {
1417 assert(isa<PointerType>(PtrValue->getType()) &&
1418 "trying to create an alignment assumption on a non-pointer?");
1419 assert(Alignment != 0 && "Invalid Alignment");
1420 Value *AlignValue = ConstantInt::get(getInt64Ty(), Alignment);
1421 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1422}
1423
1425 Value *PtrValue,
1426 Value *Alignment,
1427 Value *OffsetValue) {
1428 assert(isa<PointerType>(PtrValue->getType()) &&
1429 "trying to create an alignment assumption on a non-pointer?");
1430 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1431}
1432
1434 Value *SizeValue) {
1435 assert(isa<PointerType>(PtrValue->getType()) &&
1436 "trying to create a deferenceable assumption on a non-pointer?");
1437 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1438 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1439 return CreateAssumption({DereferenceableOpB});
1440}
1441
1443 assert(isa<PointerType>(PtrValue->getType()) &&
1444 "trying to create a nonnull assumption on a non-pointer?");
1445 return CreateAssumption(OperandBundleDef("nonnull", PtrValue));
1446}
1447
1451void ConstantFolder::anchor() {}
1452void NoFolder::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
unsigned uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 MaybeAlign getAlign(Value *Ptr)
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
This file defines less commonly used SmallVector utilities.
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
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:740
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, bool ByteString=false)
This method constructs a CDS and initializes it with a text string.
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:126
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:23
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.
Type * getReturnType() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:211
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:216
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:1505
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition IRBuilder.h:452
BasicBlock * BB
Definition IRBuilder.h:120
LLVM_ABI CallInst * CreateIntrinsicWithoutFolding(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={})
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
LLVM_ABI Value * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
LLVM_ABI Value * CreateXorReduce(Value *Src)
Create a vector int XOR 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 Value * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
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:2672
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:519
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:2726
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:60
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 CallInst * CreateNonnullAssumption(Value *PtrValue)
Create an assume intrinsic call that represents a nonnull assumption on the provided pointer.
LLVM_ABI Value * CreateFPMaximumNumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
LLVM_ABI Value * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
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:2149
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 Value * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Value * CreatePtrToAddr(Value *V, const Twine &Name="")
Definition IRBuilder.h:2239
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:2719
LLVM_ABI Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
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)
LLVM_ABI Value * CreateFPMinimumNumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
LLVMContext & Context
Definition IRBuilder.h:122
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI Value * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
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 ...
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2248
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)
Value * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1122
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:73
LLVM_ABI CallInst * CreateAssumption(Value *Cond)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
BasicBlock * GetInsertBlock() const
Definition IRBuilder.h:175
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:539
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.
FastMathFlags FMF
Definition IRBuilder.h:127
LLVM_ABI Value * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
LLVM_ABI Value * CreateBitPreservingCastChain(const DataLayout &DL, Value *V, Type *NewTy)
Create a chain of casts to convert V to NewTy, preserving the bit pattern of V.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition IRBuilder.h:482
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:850
LLVM_ABI Value * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1868
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
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 Value * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:477
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:2335
LLVM_ABI Value * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition IRBuilder.h:146
LLVM_ABI Value * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
LLVM_ABI DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition IRBuilder.cpp:65
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1449
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2253
LLVM_ABI Value * CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name="", bool IsNUW=false)
Return the difference between two pointer values.
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:629
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:608
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:2694
LLVMContext & getContext() const
Definition IRBuilder.h:177
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
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:2243
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2564
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:2117
LLVM_ABI CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, uint64_t Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1741
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 a dereferencable assumption on the provided pointer.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2326
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:350
LLVM_ABI Value * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
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:123
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 Value * 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:66
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:524
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)
Value * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition IRBuilder.h:1136
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:1466
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 Value * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *Op, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
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:45
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 * 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:1069
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(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
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 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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI Type * getStructElementType(unsigned N) const
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:288
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition Type.h:279
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:309
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:263
Type * getArrayElementType() const
Definition Type.h:425
LLVM_ABI unsigned getStructNumElements() const
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM_ABI uint64_t getArrayNumElements() const
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:282
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:368
bool isStructTy() const
True if this is an instance of StructType.
Definition Type.h:276
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:232
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:285
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:141
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static VectorType * getWithSizeAndScalar(VectorType *SizeTy, Type *EltTy)
This static method attempts to construct a VectorType with the same size-in-bits as SizeTy but with a...
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI Intrinsic::ID getInterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > OverloadTys={})
Return the function type for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
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
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
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
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:34
IntPtrTy
Definition InstrProf.h:82
DWARFExpression::Operation Op
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