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 bool OldIsIntLike =
144 OldTy->isIntOrIntVectorTy() || OldTy->isByteOrByteVectorTy();
145 if (OldIsIntLike && NewTy->isPtrOrPtrVectorTy()) {
146 // Expand <2 x i32> to i8* --> <2 x i32> to i64 to i8*
147 // Expand i128 to <2 x i8*> --> i128 to <2 x i64> to <2 x i8*>
148 // Expand <4 x i32> to <2 x i8*> --> <4 x i32> to <2 x i64> to <2 x i8*>
149 // Directly handle i64 to i8*
150 return CreateIntToPtr(CreateBitCastLike(V, DL.getIntPtrType(NewTy)), NewTy);
151 }
152
153 // See if we need ptrtoint for this type pair. May require additional bitcast.
154 bool NewIsIntLike =
155 NewTy->isIntOrIntVectorTy() || NewTy->isByteOrByteVectorTy();
156 if (OldTy->isPtrOrPtrVectorTy() && NewIsIntLike) {
157 // Expand <2 x i8*> to i128 --> <2 x i8*> to <2 x i64> to i128
158 // Expand i8* to <2 x i32> --> i8* to i64 to <2 x i32>
159 // Expand <2 x i8*> to <4 x i32> --> <2 x i8*> to <2 x i64> to <4 x i32>
160 // Expand i8* to i64 --> i8* to i64 to i64
161 return CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)), NewTy);
162 }
163
164 if (OldTy->isPtrOrPtrVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
165 unsigned OldAS = OldTy->getPointerAddressSpace();
166 unsigned NewAS = NewTy->getPointerAddressSpace();
167 // To convert pointers with different address spaces (they are already
168 // checked convertible, i.e. they have the same pointer size), so far we
169 // cannot use `bitcast` (which has restrict on the same address space) or
170 // `addrspacecast` (which is not always no-op casting). Instead, use a pair
171 // of no-op `ptrtoint`/`inttoptr` casts through an integer with the same bit
172 // size.
173 if (OldAS != NewAS) {
174 return CreateIntToPtr(
175 CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
176 DL.getIntPtrType(NewTy)),
177 NewTy);
178 }
179 }
180
181 return CreateBitCastLike(V, NewTy);
182}
183
184CallInst *
185IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
186 const Twine &Name, FMFSource FMFSource,
187 ArrayRef<OperandBundleDef> OpBundles) {
188 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
189 if (isa<FPMathOperator>(CI))
191 return CI;
192}
193
195 Value *VScale = B.CreateVScale(Ty);
196 if (Scale == 1)
197 return VScale;
198
199 return B.CreateNUWMul(VScale, ConstantInt::get(Ty, Scale));
200}
201
203 if (EC.isFixed() || EC.isZero())
204 return ConstantInt::get(Ty, EC.getKnownMinValue());
205
206 return CreateVScaleMultiple(*this, Ty, EC.getKnownMinValue());
207}
208
210 if (Size.isFixed() || Size.isZero())
211 return ConstantInt::get(Ty, Size.getKnownMinValue());
212
213 return CreateVScaleMultiple(*this, Ty, Size.getKnownMinValue());
214}
215
217 const DataLayout &DL = BB->getDataLayout();
218 TypeSize ElemSize = AI->getAllocationBaseSize(DL);
219 Value *Size = CreateTypeSize(DestTy, ElemSize);
220 if (AI->isArrayAllocation())
222 return Size;
223}
224
226 Type *STy = DstType->getScalarType();
227 if (isa<ScalableVectorType>(DstType)) {
228 Type *StepVecType = DstType;
229 // TODO: We expect this special case (element type < 8 bits) to be
230 // temporary - once the intrinsic properly supports < 8 bits this code
231 // can be removed.
232 if (STy->getScalarSizeInBits() < 8)
233 StepVecType =
235 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
236 nullptr, Name);
237 if (StepVecType != DstType)
238 Res = CreateTrunc(Res, DstType);
239 return Res;
240 }
241
242 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
243
244 // Create a vector of consecutive numbers from zero to VF.
245 // It's okay if the values wrap around.
247 for (unsigned i = 0; i < NumEls; ++i)
248 Indices.push_back(
249 ConstantInt::get(STy, i, /*IsSigned=*/false, /*ImplicitTrunc=*/true));
250
251 // Add the consecutive indices to the vector value.
252 return ConstantVector::get(Indices);
253}
254
256 MaybeAlign Align, bool isVolatile,
257 const AAMDNodes &AAInfo) {
258 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
259 Type *Tys[] = {Ptr->getType(), Size->getType()};
260
261 auto *CI = cast<MemSetInst>(
262 CreateIntrinsicWithoutFolding(Intrinsic::memset, Tys, Ops));
263
264 if (Align)
265 CI->setDestAlignment(*Align);
266 CI->setAAMetadata(AAInfo);
267 return CI;
268}
269
271 Value *Val, Value *Size,
272 bool IsVolatile,
273 const AAMDNodes &AAInfo) {
274 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
275 Type *Tys[] = {Dst->getType(), Size->getType()};
276
277 auto *CI = cast<MemSetInst>(
278 CreateIntrinsicWithoutFolding(Intrinsic::memset_inline, Tys, Ops));
279
280 if (DstAlign)
281 CI->setDestAlignment(*DstAlign);
282 CI->setAAMetadata(AAInfo);
283 return CI;
284}
285
287 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
288 const AAMDNodes &AAInfo) {
289
290 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
291 Type *Tys[] = {Ptr->getType(), Size->getType()};
292
294 Intrinsic::memset_element_unordered_atomic, Tys, Ops));
295 CI->setDestAlignment(Alignment);
296 CI->setAAMetadata(AAInfo);
297 return CI;
298}
299
301 MaybeAlign DstAlign, Value *Src,
302 MaybeAlign SrcAlign, Value *Size,
303 bool isVolatile,
304 const AAMDNodes &AAInfo) {
305 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
306 IntrID == Intrinsic::memmove) &&
307 "Unexpected intrinsic ID");
308 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
309 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
310
311 auto *MCI =
313
314 if (DstAlign)
315 MCI->setDestAlignment(*DstAlign);
316 if (SrcAlign)
317 MCI->setSourceAlignment(*SrcAlign);
318 MCI->setAAMetadata(AAInfo);
319 return MCI;
320}
321
323 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
324 uint32_t ElementSize, const AAMDNodes &AAInfo) {
325 assert(DstAlign >= ElementSize &&
326 "Pointer alignment must be at least element size");
327 assert(SrcAlign >= ElementSize &&
328 "Pointer alignment must be at least element size");
329 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
330 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
331
333 Intrinsic::memcpy_element_unordered_atomic, Tys, Ops));
334
335 // Set the alignment of the pointer args.
336 AMCI->setDestAlignment(DstAlign);
337 AMCI->setSourceAlignment(SrcAlign);
338 AMCI->setAAMetadata(AAInfo);
339 return AMCI;
340}
341
342/// isConstantOne - Return true only if val is constant int 1
343static bool isConstantOne(const Value *Val) {
344 assert(Val && "isConstantOne does not work with nullptr Val");
345 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
346 return CVal && CVal->isOne();
347}
348
350 Value *AllocSize, Value *ArraySize,
352 Function *MallocF, const Twine &Name) {
353 // malloc(type) becomes:
354 // i8* malloc(typeSize)
355 // malloc(type, arraySize) becomes:
356 // i8* malloc(typeSize*arraySize)
357 if (!ArraySize)
358 ArraySize = ConstantInt::get(IntPtrTy, 1);
359 else if (ArraySize->getType() != IntPtrTy)
360 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
361
362 if (!isConstantOne(ArraySize)) {
363 if (isConstantOne(AllocSize)) {
364 AllocSize = ArraySize; // Operand * 1 = Operand
365 } else {
366 // Multiply type size by the array size...
367 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
368 }
369 }
370
371 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
372 // Create the call to Malloc.
373 Module *M = BB->getParent()->getParent();
375 FunctionCallee MallocFunc = MallocF;
376 if (!MallocFunc)
377 // prototype malloc as "void *malloc(size_t)"
378 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
379 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
380
381 MCall->setTailCall();
382 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
383 MCall->setCallingConv(F->getCallingConv());
384 F->setReturnDoesNotAlias();
385 }
386
387 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
388
389 return MCall;
390}
391
393 Value *AllocSize, Value *ArraySize,
394 Function *MallocF, const Twine &Name) {
395
396 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
397 Name);
398}
399
400/// CreateFree - Generate the IR for a call to the builtin free function.
403 assert(Source->getType()->isPointerTy() &&
404 "Can not free something of nonpointer type!");
405
406 Module *M = BB->getParent()->getParent();
407
408 Type *VoidTy = Type::getVoidTy(M->getContext());
409 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
410 // prototype free as "void free(void*)"
411 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
412 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
413 Result->setTailCall();
414 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
415 Result->setCallingConv(F->getCallingConv());
416
417 return Result;
418}
419
421 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
422 uint32_t ElementSize, const AAMDNodes &AAInfo) {
423 assert(DstAlign >= ElementSize &&
424 "Pointer alignment must be at least element size");
425 assert(SrcAlign >= ElementSize &&
426 "Pointer alignment must be at least element size");
427 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
428 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
429
431 Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
432
433 // Set the alignment of the pointer args.
434 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
435 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
436 CI->setAAMetadata(AAInfo);
437 return CI;
438}
439
440Value *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
441 Value *Ops[] = {Src};
442 Type *Tys[] = { Src->getType() };
443 return CreateIntrinsic(ID, Tys, Ops);
444}
445
447 Value *Ops[] = {Acc, Src};
448 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
449}
450
452 Value *Ops[] = {Acc, Src};
453 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
454}
455
457 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
458}
459
461 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
462}
463
465 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
466}
467
469 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
470}
471
473 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
474}
475
477 auto ID =
478 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
479 return getReductionIntrinsic(ID, Src);
480}
481
483 auto ID =
484 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
485 return getReductionIntrinsic(ID, Src);
486}
487
489 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
490}
491
493 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
494}
495
497 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
498}
499
501 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
502}
503
505 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximumnum, Src);
506}
507
509 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimumnum, Src);
510}
511
514 "lifetime.start only applies to pointers.");
515 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_start,
516 {Ptr->getType()}, {Ptr});
517}
518
521 "lifetime.end only applies to pointers.");
522 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_end,
523 {Ptr->getType()}, {Ptr});
524}
525
527
529 "invariant.start only applies to pointers.");
530 if (!Size)
531 Size = getInt64(-1);
532 else
533 assert(Size->getType() == getInt64Ty() &&
534 "invariant.start requires the size to be an i64");
535
536 Value *Ops[] = {Size, Ptr};
537 // Fill in the single overloaded type: memory object type.
538 Type *ObjectPtr[1] = {Ptr->getType()};
539 return CreateIntrinsicWithoutFolding(Intrinsic::invariant_start, ObjectPtr,
540 Ops);
541}
542
544 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
545 return V->getAlign();
546 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
547 return getAlign(A->getAliaseeObject());
548 return {};
549}
550
552 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
553 "threadlocal_address only applies to thread local variables.");
555 llvm::Intrinsic::threadlocal_address, {Ptr->getType()}, {Ptr});
556 if (MaybeAlign A = getAlign(Ptr)) {
559 }
560 return CI;
561}
562
564 assert(Cond->getType() == getInt1Ty() &&
565 "an assumption condition must be of type i1");
566 return CreateIntrinsicWithoutFolding(Intrinsic::assume, /*OverloadTypes=*/{},
567 {Cond});
568}
569
570CallInst *
574 Intrinsic::assume, /*OverloadTypes=*/{}, Args,
575 /*FMFSource=*/nullptr, /*Name=*/"", OpBundles);
576}
577
580 Intrinsic::experimental_noalias_scope_decl, {}, {Scope});
581}
582
583/// Create a call to a Masked Load intrinsic.
584/// \p Ty - vector type to load
585/// \p Ptr - base pointer for the load
586/// \p Alignment - alignment of the source location
587/// \p Mask - vector of booleans which indicates what vector lanes should
588/// be accessed in memory
589/// \p PassThru - pass-through value that is used to fill the masked-off lanes
590/// of the result
591/// \p Name - name of the result variable
593 Value *Mask, Value *PassThru,
594 const Twine &Name) {
595 auto *PtrTy = cast<PointerType>(Ptr->getType());
596 assert(Ty->isVectorTy() && "Type should be vector");
597 assert(Mask && "Mask should not be all-ones (null)");
598 if (!PassThru)
599 PassThru = PoisonValue::get(Ty);
600 Type *OverloadedTypes[] = { Ty, PtrTy };
601 Value *Ops[] = {Ptr, Mask, PassThru};
602 CallInst *CI =
603 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
604 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
605 return CI;
606}
607
608/// Create a call to a Masked Store intrinsic.
609/// \p Val - data to be stored,
610/// \p Ptr - base pointer for the store
611/// \p Alignment - alignment of the destination location
612/// \p Mask - vector of booleans which indicates what vector lanes should
613/// be accessed in memory
615 Align Alignment, Value *Mask) {
616 auto *PtrTy = cast<PointerType>(Ptr->getType());
617 Type *DataTy = Val->getType();
618 assert(DataTy->isVectorTy() && "Val should be a vector");
619 assert(Mask && "Mask should not be all-ones (null)");
620 Type *OverloadedTypes[] = { DataTy, PtrTy };
621 Value *Ops[] = {Val, Ptr, Mask};
622 CallInst *CI =
623 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
624 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
625 return CI;
626}
627
628/// Create a call to a Masked intrinsic, with given intrinsic Id,
629/// an array of operands - Ops, and an array of overloaded types -
630/// OverloadedTypes.
631CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
633 ArrayRef<Type *> OverloadedTypes,
634 const Twine &Name) {
635 return CreateIntrinsicWithoutFolding(Id, OverloadedTypes, Ops, {}, Name);
636}
637
638/// Create a call to a Masked Gather intrinsic.
639/// \p Ty - vector type to gather
640/// \p Ptrs - vector of pointers for loading
641/// \p Align - alignment for one element
642/// \p Mask - vector of booleans which indicates what vector lanes should
643/// be accessed in memory
644/// \p PassThru - pass-through value that is used to fill the masked-off lanes
645/// of the result
646/// \p Name - name of the result variable
648 Align Alignment, Value *Mask,
649 Value *PassThru,
650 const Twine &Name) {
651 auto *VecTy = cast<VectorType>(Ty);
652 ElementCount NumElts = VecTy->getElementCount();
653 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
654 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
655
656 if (!Mask)
657 Mask = getAllOnesMask(NumElts);
658
659 if (!PassThru)
660 PassThru = PoisonValue::get(Ty);
661
662 Type *OverloadedTypes[] = {Ty, PtrsTy};
663 Value *Ops[] = {Ptrs, Mask, PassThru};
664
665 // We specify only one type when we create this intrinsic. Types of other
666 // arguments are derived from this type.
667 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
668 OverloadedTypes, Name);
669 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
670 return CI;
671}
672
673/// Create a call to a Masked Scatter intrinsic.
674/// \p Data - data to be stored,
675/// \p Ptrs - the vector of pointers, where the \p Data elements should be
676/// stored
677/// \p Align - alignment for one element
678/// \p Mask - vector of booleans which indicates what vector lanes should
679/// be accessed in memory
681 Align Alignment, Value *Mask) {
682 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
683 auto *DataTy = cast<VectorType>(Data->getType());
684 ElementCount NumElts = PtrsTy->getElementCount();
685
686 if (!Mask)
687 Mask = getAllOnesMask(NumElts);
688
689 Type *OverloadedTypes[] = {DataTy, PtrsTy};
690 Value *Ops[] = {Data, Ptrs, Mask};
691
692 // We specify only one type when we create this intrinsic. Types of other
693 // arguments are derived from this type.
694 CallInst *CI =
695 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
696 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
697 return CI;
698}
699
700/// Create a call to Masked Expand Load intrinsic
701/// \p Ty - vector type to load
702/// \p Ptr - base pointer for the load
703/// \p Align - alignment of \p Ptr
704/// \p Mask - vector of booleans which indicates what vector lanes should
705/// be accessed in memory
706/// \p PassThru - pass-through value that is used to fill the masked-off lanes
707/// of the result
708/// \p Name - name of the result variable
710 MaybeAlign Align, Value *Mask,
711 Value *PassThru,
712 const Twine &Name) {
713 assert(Ty->isVectorTy() && "Type should be vector");
714 assert(Mask && "Mask should not be all-ones (null)");
715 if (!PassThru)
716 PassThru = PoisonValue::get(Ty);
717 Type *PtrTy = Ptr->getType();
718 Type *OverloadedTypes[] = {Ty, PtrTy};
719 Value *Ops[] = {Ptr, Mask, PassThru};
720 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
721 OverloadedTypes, Name);
722 if (Align)
724 return CI;
725}
726
727/// Create a call to Masked Compress Store intrinsic
728/// \p Val - data to be stored,
729/// \p Ptr - base pointer for the store
730/// \p Align - alignment of \p Ptr
731/// \p Mask - vector of booleans which indicates what vector lanes should
732/// be accessed in memory
735 Value *Mask) {
736 Type *DataTy = Val->getType();
737 assert(DataTy->isVectorTy() && "Val should be a vector");
738 assert(Mask && "Mask should not be all-ones (null)");
739 Type *PtrTy = Ptr->getType();
740 Type *OverloadedTypes[] = {DataTy, PtrTy};
741 Value *Ops[] = {Val, Ptr, Mask};
742 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
743 OverloadedTypes);
744 if (Align)
746 return CI;
747}
748
749template <typename T0>
750static std::vector<Value *>
752 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
753 std::vector<Value *> Args;
754 Args.push_back(B.getInt64(ID));
755 Args.push_back(B.getInt32(NumPatchBytes));
756 Args.push_back(ActualCallee);
757 Args.push_back(B.getInt32(CallArgs.size()));
758 Args.push_back(B.getInt32(Flags));
759 llvm::append_range(Args, CallArgs);
760 // GC Transition and Deopt args are now always handled via operand bundle.
761 // They will be removed from the signature of gc.statepoint shortly.
762 Args.push_back(B.getInt32(0));
763 Args.push_back(B.getInt32(0));
764 // GC args are now encoded in the gc-live operand bundle
765 return Args;
766}
767
768template<typename T1, typename T2, typename T3>
769static std::vector<OperandBundleDef>
770getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
771 std::optional<ArrayRef<T2>> DeoptArgs,
772 ArrayRef<T3> GCArgs) {
773 std::vector<OperandBundleDef> Rval;
774 if (DeoptArgs)
775 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
776 if (TransitionArgs)
777 Rval.emplace_back("gc-transition",
778 SmallVector<Value *, 16>(*TransitionArgs));
779 if (GCArgs.size())
780 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
781 return Rval;
782}
783
784template <typename T0, typename T1, typename T2, typename T3>
786 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
787 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
788 std::optional<ArrayRef<T1>> TransitionArgs,
789 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
790 const Twine &Name) {
791 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
792 // Fill in the one generic type'd argument (the function is also vararg)
794 M, Intrinsic::experimental_gc_statepoint,
795 {ActualCallee.getCallee()->getType()});
796
797 std::vector<Value *> Args = getStatepointArgs(
798 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
799
800 CallInst *CI = Builder->CreateCall(
801 FnStatepoint, Args,
802 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
803 CI->addParamAttr(2,
804 Attribute::get(Builder->getContext(), Attribute::ElementType,
805 ActualCallee.getFunctionType()));
806 return CI;
807}
808
810 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
811 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
812 ArrayRef<Value *> GCArgs, const Twine &Name) {
814 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
815 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
816}
817
819 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
820 uint32_t Flags, ArrayRef<Value *> CallArgs,
821 std::optional<ArrayRef<Use>> TransitionArgs,
822 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
823 const Twine &Name) {
825 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
826 DeoptArgs, GCArgs, Name);
827}
828
830 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
831 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
832 ArrayRef<Value *> GCArgs, const Twine &Name) {
834 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
835 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
836}
837
838template <typename T0, typename T1, typename T2, typename T3>
840 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
841 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
842 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
843 std::optional<ArrayRef<T1>> TransitionArgs,
844 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
845 const Twine &Name) {
846 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
847 // Fill in the one generic type'd argument (the function is also vararg)
849 M, Intrinsic::experimental_gc_statepoint,
850 {ActualInvokee.getCallee()->getType()});
851
852 std::vector<Value *> Args =
853 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
854 Flags, InvokeArgs);
855
856 InvokeInst *II = Builder->CreateInvoke(
857 FnStatepoint, NormalDest, UnwindDest, Args,
858 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
859 II->addParamAttr(2,
860 Attribute::get(Builder->getContext(), Attribute::ElementType,
861 ActualInvokee.getFunctionType()));
862 return II;
863}
864
866 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
867 BasicBlock *NormalDest, BasicBlock *UnwindDest,
868 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
869 ArrayRef<Value *> GCArgs, const Twine &Name) {
871 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
872 uint32_t(StatepointFlags::None), InvokeArgs,
873 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
874}
875
877 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
878 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
879 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
880 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
881 const Twine &Name) {
883 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
884 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
885}
886
888 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
889 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
890 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
891 const Twine &Name) {
893 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
894 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
895 GCArgs, Name);
896}
897
899 Type *ResultType, const Twine &Name) {
900 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
901 Type *Types[] = {ResultType};
902
903 Value *Args[] = {Statepoint};
904 return CreateIntrinsicWithoutFolding(ID, Types, Args, {}, Name);
905}
906
908 int BaseOffset, int DerivedOffset,
909 Type *ResultType, const Twine &Name) {
910 Type *Types[] = {ResultType};
911
912 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
913 return CreateIntrinsicWithoutFolding(Intrinsic::experimental_gc_relocate,
914 Types, Args, {}, Name);
915}
916
918 const Twine &Name) {
919 Type *PtrTy = DerivedPtr->getType();
921 Intrinsic::experimental_gc_get_pointer_base, PtrTy, DerivedPtr, {}, Name);
922}
923
925 const Twine &Name) {
926 Type *PtrTy = DerivedPtr->getType();
928 Intrinsic::experimental_gc_get_pointer_offset, {PtrTy}, {DerivedPtr}, {},
929 Name);
930}
931
934 const Twine &Name) {
935 Module *M = BB->getModule();
936 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, Op->getType());
937 if (Value *V =
938 Folder.FoldIntrinsic(ID, Op, Fn->getReturnType(), FMFSource.get(FMF),
940 return V;
941 return createCallHelper(Fn, Op, Name, FMFSource);
942}
943
946 const Twine &Name) {
947 Module *M = BB->getModule();
948 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
949 if (Value *V = Folder.FoldIntrinsic(ID, {LHS, RHS}, Fn->getReturnType(),
952 return V;
953 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
954}
955
957 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
958 FMFSource FMFSource, const Twine &Name,
959 ArrayRef<OperandBundleDef> OpBundles) {
960 Module *M = BB->getModule();
961 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTypes);
962 return createCallHelper(Fn, Args, Name, FMFSource, OpBundles);
963}
964
966 Intrinsic::ID ID,
969 const Twine &Name) {
970 Module *M = BB->getModule();
972 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, RetTy, ArgTys);
973 return createCallHelper(Fn, Args, Name, FMFSource);
974}
975
977 ArrayRef<Type *> OverloadTypes,
979 FMFSource FMFSource, const Twine &Name,
981 function_ref<void(CallInst *)> SetFn) {
982 Type *RetTy = Intrinsic::getType(Context, ID, OverloadTypes)->getReturnType();
983 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
985 return V;
986 CallInst *CI = CreateIntrinsicWithoutFolding(ID, OverloadTypes, Args,
987 FMFSource, Name, OpBundles);
988 SetFn(CI);
989 return CI;
990}
991
994 FMFSource FMFSource, const Twine &Name,
995 function_ref<void(CallInst *)> SetFn) {
996 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
998 return V;
999 CallInst *CI =
1000 CreateIntrinsicWithoutFolding(RetTy, ID, Args, FMFSource, Name);
1001 SetFn(CI);
1002 return CI;
1003}
1004
1007 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1008 std::optional<fp::ExceptionBehavior> Except) {
1009 Value *RoundingV = getConstrainedFPRounding(Rounding);
1010 Value *ExceptV = getConstrainedFPExcept(Except);
1011
1012 FastMathFlags UseFMF = FMFSource.get(FMF);
1014 ID, {L->getType()}, {L, R, RoundingV, ExceptV}, nullptr, Name, {});
1016 setFPAttrs(C, FPMathTag, UseFMF);
1017 return C;
1018}
1019
1022 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
1023 std::optional<RoundingMode> Rounding,
1024 std::optional<fp::ExceptionBehavior> Except) {
1025 Value *RoundingV = getConstrainedFPRounding(Rounding);
1026 Value *ExceptV = getConstrainedFPExcept(Except);
1027
1028 FastMathFlags UseFMF = FMFSource.get(FMF);
1029
1030 llvm::SmallVector<Value *, 5> ExtArgs(Args);
1031 ExtArgs.push_back(RoundingV);
1032 ExtArgs.push_back(ExceptV);
1033 CallInst *C =
1034 CreateIntrinsicWithoutFolding(ID, Types, ExtArgs, nullptr, Name, {});
1036 setFPAttrs(C, FPMathTag, UseFMF);
1037 return C;
1038}
1039
1042 const Twine &Name, MDNode *FPMathTag,
1043 std::optional<fp::ExceptionBehavior> Except) {
1044 Value *ExceptV = getConstrainedFPExcept(Except);
1045
1046 FastMathFlags UseFMF = FMFSource.get(FMF);
1048 ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name, {});
1050 setFPAttrs(C, FPMathTag, UseFMF);
1051 return C;
1052}
1053
1055 const Twine &Name, MDNode *FPMathTag) {
1057 assert(Ops.size() == 2 && "Invalid number of operands!");
1058 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
1059 Ops[0], Ops[1], Name, FPMathTag);
1060 }
1062 assert(Ops.size() == 1 && "Invalid number of operands!");
1063 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
1064 Ops[0], Name, FPMathTag);
1065 }
1066 llvm_unreachable("Unexpected opcode!");
1067}
1068
1070 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource,
1071 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1072 std::optional<fp::ExceptionBehavior> Except) {
1073 Value *ExceptV = getConstrainedFPExcept(Except);
1074
1075 FastMathFlags UseFMF = FMFSource.get(FMF);
1076
1077 CallInst *C;
1079 Value *RoundingV = getConstrainedFPRounding(Rounding);
1081 ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV}, nullptr, Name, {});
1082 } else
1083 C = CreateIntrinsicWithoutFolding(ID, {DestTy, V->getType()}, {V, ExceptV},
1084 nullptr, Name, {});
1086
1088 setFPAttrs(C, FPMathTag, UseFMF);
1089 return C;
1090}
1091
1092Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
1093 Value *RHS, const Twine &Name,
1094 MDNode *FPMathTag, FMFSource FMFSource,
1095 bool IsSignaling) {
1096 if (IsFPConstrained) {
1097 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1098 : Intrinsic::experimental_constrained_fcmp;
1099 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1100 }
1101
1102 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1103 return V;
1104 return Insert(
1105 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1106 Name);
1107}
1108
1111 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1112 Value *PredicateV = getConstrainedFPPredicate(P);
1113 Value *ExceptV = getConstrainedFPExcept(Except);
1114
1116 ID, {L->getType()}, {L, R, PredicateV, ExceptV}, nullptr, Name, {});
1118 return C;
1119}
1120
1122 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1123 std::optional<RoundingMode> Rounding,
1124 std::optional<fp::ExceptionBehavior> Except) {
1125 llvm::SmallVector<Value *, 6> UseArgs(Args);
1126
1127 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1128 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1129 UseArgs.push_back(getConstrainedFPExcept(Except));
1130
1131 CallInst *C = CreateCall(Callee, UseArgs, Name);
1133 return C;
1134}
1135
1137 Value *False,
1139 const Twine &Name) {
1140 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1141 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1143 }
1144 return Ret;
1145}
1146
1148 Value *False,
1151 const Twine &Name) {
1152 Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
1153 if (auto *SI = dyn_cast<SelectInst>(Ret))
1155 return Ret;
1156}
1157
1159 const Twine &Name, Instruction *MDFrom) {
1160 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1161}
1162
1164 FMFSource FMFSource, const Twine &Name,
1165 Instruction *MDFrom) {
1166 if (auto *V = Folder.FoldSelect(C, True, False, FMFSource.get(FMF)))
1167 return V;
1168
1169 SelectInst *Sel = SelectInst::Create(C, True, False);
1170 if (MDFrom) {
1171 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1172 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1173 Sel = addBranchMetadata(Sel, Prof, Unpred);
1174 }
1175 if (isa<FPMathOperator>(Sel))
1176 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1177 return Insert(Sel, Name);
1178}
1179
1181 bool IsNUW) {
1182 assert(LHS->getType() == RHS->getType() &&
1183 "Pointer subtraction operand types must match!");
1184 Value *LHSAddr = CreatePtrToAddr(LHS);
1185 Value *RHSAddr = CreatePtrToAddr(RHS);
1186 return CreateSub(LHSAddr, RHSAddr, Name, IsNUW);
1187}
1189 const Twine &Name) {
1190 const DataLayout &DL = BB->getDataLayout();
1191 TypeSize ElemSize = DL.getTypeAllocSize(ElemTy);
1192 if (ElemSize == TypeSize::getFixed(1))
1193 return CreatePtrDiff(LHS, RHS, Name);
1194
1195 Value *Diff = CreatePtrDiff(LHS, RHS);
1196 return CreateExactSDiv(Diff, CreateTypeSize(Diff->getType(), ElemSize), Name);
1197}
1198
1201 "launder.invariant.group only applies to pointers.");
1202 auto *PtrType = Ptr->getType();
1203 Module *M = BB->getParent()->getParent();
1204 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1205 M, Intrinsic::launder_invariant_group, {PtrType});
1206
1207 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1208 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1209 PtrType &&
1210 "LaunderInvariantGroup should take and return the same type");
1211
1212 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1213}
1214
1217 "strip.invariant.group only applies to pointers.");
1218
1219 auto *PtrType = Ptr->getType();
1220 Module *M = BB->getParent()->getParent();
1221 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1222 M, Intrinsic::strip_invariant_group, {PtrType});
1223
1224 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1225 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1226 PtrType &&
1227 "StripInvariantGroup should take and return the same type");
1228
1229 return CreateCall(FnStripInvariantGroup, {Ptr});
1230}
1231
1233 auto *Ty = cast<VectorType>(V->getType());
1234 if (isa<ScalableVectorType>(Ty)) {
1235 Module *M = BB->getParent()->getParent();
1236 Function *F =
1237 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1238 return Insert(CallInst::Create(F, V), Name);
1239 }
1240 // Keep the original behaviour for fixed vector
1241 SmallVector<int, 8> ShuffleMask;
1242 int NumElts = Ty->getElementCount().getKnownMinValue();
1243 for (int i = 0; i < NumElts; ++i)
1244 ShuffleMask.push_back(NumElts - i - 1);
1245 return CreateShuffleVector(V, ShuffleMask, Name);
1246}
1247
1248static SmallVector<int, 8> getSpliceMask(int64_t Imm, unsigned NumElts) {
1249 unsigned Idx = (NumElts + Imm) % NumElts;
1251 for (unsigned I = 0; I < NumElts; ++I)
1252 Mask.push_back(Idx + I);
1253 return Mask;
1254}
1255
1257 Value *Offset, const Twine &Name) {
1258 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1259 assert(V1->getType() == V2->getType() &&
1260 "Splice expects matching operand types!");
1261
1262 // Emit a shufflevector for fixed vectors with a constant offset
1263 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1264 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1265 return CreateShuffleVector(
1266 V1, V2,
1267 getSpliceMask(COffset->getZExtValue(), FVTy->getNumElements()));
1268
1269 return CreateIntrinsic(Intrinsic::vector_splice_left, V1->getType(),
1270 {V1, V2, Offset}, {}, Name);
1271}
1272
1274 Value *Offset,
1275 const Twine &Name) {
1276 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1277 assert(V1->getType() == V2->getType() &&
1278 "Splice expects matching operand types!");
1279
1280 // Emit a shufflevector for fixed vectors with a constant offset
1281 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1282 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1283 return CreateShuffleVector(
1284 V1, V2,
1285 getSpliceMask(-COffset->getZExtValue(), FVTy->getNumElements()));
1286
1287 return CreateIntrinsic(Intrinsic::vector_splice_right, V1->getType(),
1288 {V1, V2, Offset}, {}, Name);
1289}
1290
1292 const Twine &Name) {
1293 auto EC = ElementCount::getFixed(NumElts);
1294 return CreateVectorSplat(EC, V, Name);
1295}
1296
1298 const Twine &Name) {
1299 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1300
1301 // First insert it into a poison vector so we can shuffle it.
1302 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1303 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1304
1305 // Shuffle the value across the desired number of elements.
1307 Zeros.resize(EC.getKnownMinValue());
1308 return CreateShuffleVector(V, Zeros, Name + ".splat");
1309}
1310
1312 const Twine &Name) {
1313 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1314 "Unexpected number of operands to interleave");
1315
1316 // Make sure all operands are the same type.
1317 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1318
1319#ifndef NDEBUG
1320 for (unsigned I = 1; I < Ops.size(); I++) {
1321 assert(Ops[I]->getType() == Ops[0]->getType() &&
1322 "Vector interleave expects matching operand types!");
1323 }
1324#endif
1325
1326 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1327 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1328 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1329 SubvecTy->getElementCount() * Ops.size());
1330 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1331}
1332
1334 unsigned Dimension,
1335 unsigned LastIndex,
1336 MDNode *DbgInfo) {
1337 auto *BaseType = Base->getType();
1339 "Invalid Base ptr type for preserve.array.access.index.");
1340
1341 Value *LastIndexV = getInt32(LastIndex);
1342 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1343 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1344 IdxList.push_back(LastIndexV);
1345
1346 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1347
1348 Value *DimV = getInt32(Dimension);
1350 Intrinsic::preserve_array_access_index, {ResultType, BaseType},
1351 {Base, DimV, LastIndexV});
1352 Fn->addParamAttr(
1353 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1354 if (DbgInfo)
1355 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1356
1357 return Fn;
1358}
1359
1361 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1362 assert(isa<PointerType>(Base->getType()) &&
1363 "Invalid Base ptr type for preserve.union.access.index.");
1364 auto *BaseType = Base->getType();
1365
1366 Value *DIIndex = getInt32(FieldIndex);
1367 CallInst *Fn =
1368 CreateIntrinsicWithoutFolding(Intrinsic::preserve_union_access_index,
1369 {BaseType, BaseType}, {Base, DIIndex});
1370 if (DbgInfo)
1371 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1372
1373 return Fn;
1374}
1375
1377 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1378 MDNode *DbgInfo) {
1379 auto *BaseType = Base->getType();
1381 "Invalid Base ptr type for preserve.struct.access.index.");
1382
1383 Value *GEPIndex = getInt32(Index);
1384 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1385 Type *ResultType =
1386 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1387
1388 Value *DIIndex = getInt32(FieldIndex);
1390 Intrinsic::preserve_struct_access_index, {ResultType, BaseType},
1391 {Base, GEPIndex, DIIndex});
1392 Fn->addParamAttr(
1393 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1394 if (DbgInfo)
1395 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1396
1397 return Fn;
1398}
1399
1401 ConstantInt *TestV = getInt32(Test);
1402 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1403 {FPNum, TestV});
1404}
1405
1406CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1407 Value *PtrValue,
1408 Value *AlignValue,
1409 Value *OffsetValue) {
1410 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1411 if (OffsetValue)
1412 Vals.push_back(OffsetValue);
1413 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1414 return CreateAssumption({AlignOpB});
1415}
1416
1418 Value *PtrValue,
1419 uint64_t Alignment,
1420 Value *OffsetValue) {
1421 assert(isa<PointerType>(PtrValue->getType()) &&
1422 "trying to create an alignment assumption on a non-pointer?");
1423 assert(Alignment != 0 && "Invalid Alignment");
1424 Value *AlignValue = ConstantInt::get(getInt64Ty(), Alignment);
1425 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1426}
1427
1429 Value *PtrValue,
1430 Value *Alignment,
1431 Value *OffsetValue) {
1432 assert(isa<PointerType>(PtrValue->getType()) &&
1433 "trying to create an alignment assumption on a non-pointer?");
1434 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1435}
1436
1438 Value *SizeValue) {
1439 assert(isa<PointerType>(PtrValue->getType()) &&
1440 "trying to create a deferenceable assumption on a non-pointer?");
1441 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1442 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1443 return CreateAssumption({DereferenceableOpB});
1444}
1445
1447 assert(isa<PointerType>(PtrValue->getType()) &&
1448 "trying to create a nonnull assumption on a non-pointer?");
1449 return CreateAssumption(OperandBundleDef("nonnull", PtrValue));
1450}
1451
1455void ConstantFolder::anchor() {}
1456void 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
LLVM_ABI TypeSize getAllocationBaseSize(const DataLayout &DL) const
Get the size of the allocated type.
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:212
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:217
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:2679
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:2733
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:2726
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:2342
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:2701
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:2571
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:2333
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:68
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
bool isByteOrByteVectorTy() const
Return true if this is a byte type or a vector of byte types.
Definition Type.h:248
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:577
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