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 *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 *ArraySize, Function *MallocF,
394 const Twine &Name) {
395
396 return CreateMalloc(IntPtrTy, AllocSize, ArraySize, {}, MallocF, Name);
397}
398
399/// CreateFree - Generate the IR for a call to the builtin free function.
402 assert(Source->getType()->isPointerTy() &&
403 "Can not free something of nonpointer type!");
404
405 Module *M = BB->getParent()->getParent();
406
407 Type *VoidTy = Type::getVoidTy(M->getContext());
408 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
409 // prototype free as "void free(void*)"
410 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
411 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
412 Result->setTailCall();
413 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
414 Result->setCallingConv(F->getCallingConv());
415
416 return Result;
417}
418
420 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
421 uint32_t ElementSize, const AAMDNodes &AAInfo) {
422 assert(DstAlign >= ElementSize &&
423 "Pointer alignment must be at least element size");
424 assert(SrcAlign >= ElementSize &&
425 "Pointer alignment must be at least element size");
426 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
427 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
428
430 Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
431
432 // Set the alignment of the pointer args.
433 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
434 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
435 CI->setAAMetadata(AAInfo);
436 return CI;
437}
438
439Value *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
440 Value *Ops[] = {Src};
441 Type *Tys[] = { Src->getType() };
442 return CreateIntrinsic(ID, Tys, Ops);
443}
444
446 Value *Ops[] = {Acc, Src};
447 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
448}
449
451 Value *Ops[] = {Acc, Src};
452 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
453}
454
456 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
457}
458
460 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
461}
462
464 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
465}
466
468 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
469}
470
472 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
473}
474
476 auto ID =
477 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
478 return getReductionIntrinsic(ID, Src);
479}
480
482 auto ID =
483 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
484 return getReductionIntrinsic(ID, Src);
485}
486
488 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
489}
490
492 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
493}
494
496 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
497}
498
500 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
501}
502
504 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximumnum, Src);
505}
506
508 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimumnum, Src);
509}
510
513 "lifetime.start only applies to pointers.");
514 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_start,
515 {Ptr->getType()}, {Ptr});
516}
517
520 "lifetime.end only applies to pointers.");
521 return CreateIntrinsicWithoutFolding(Intrinsic::lifetime_end,
522 {Ptr->getType()}, {Ptr});
523}
524
526
528 "invariant.start only applies to pointers.");
529 if (!Size)
530 Size = getInt64(-1);
531 else
532 assert(Size->getType() == getInt64Ty() &&
533 "invariant.start requires the size to be an i64");
534
535 Value *Ops[] = {Size, Ptr};
536 // Fill in the single overloaded type: memory object type.
537 Type *ObjectPtr[1] = {Ptr->getType()};
538 return CreateIntrinsicWithoutFolding(Intrinsic::invariant_start, ObjectPtr,
539 Ops);
540}
541
543 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
544 return V->getAlign();
545 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
546 return getAlign(A->getAliaseeObject());
547 return {};
548}
549
551 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
552 "threadlocal_address only applies to thread local variables.");
554 llvm::Intrinsic::threadlocal_address, {Ptr->getType()}, {Ptr});
555 if (MaybeAlign A = getAlign(Ptr)) {
558 }
559 return CI;
560}
561
563 assert(Cond->getType() == getInt1Ty() &&
564 "an assumption condition must be of type i1");
565 return CreateIntrinsicWithoutFolding(Intrinsic::assume, /*OverloadTypes=*/{},
566 {Cond});
567}
568
569CallInst *
573 Intrinsic::assume, /*OverloadTypes=*/{}, Args,
574 /*FMFSource=*/nullptr, /*Name=*/"", OpBundles);
575}
576
579 Intrinsic::experimental_noalias_scope_decl, {}, {Scope});
580}
581
582/// Create a call to a Masked Load intrinsic.
583/// \p Ty - vector type to load
584/// \p Ptr - base pointer for the load
585/// \p Alignment - alignment of the source location
586/// \p Mask - vector of booleans which indicates what vector lanes should
587/// be accessed in memory
588/// \p PassThru - pass-through value that is used to fill the masked-off lanes
589/// of the result
590/// \p Name - name of the result variable
592 Value *Mask, Value *PassThru,
593 const Twine &Name) {
594 auto *PtrTy = cast<PointerType>(Ptr->getType());
595 assert(Ty->isVectorTy() && "Type should be vector");
596 assert(Mask && "Mask should not be all-ones (null)");
597 if (!PassThru)
598 PassThru = PoisonValue::get(Ty);
599 Type *OverloadedTypes[] = { Ty, PtrTy };
600 Value *Ops[] = {Ptr, Mask, PassThru};
601 CallInst *CI =
602 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
603 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
604 return CI;
605}
606
607/// Create a call to a Masked Store intrinsic.
608/// \p Val - data to be stored,
609/// \p Ptr - base pointer for the store
610/// \p Alignment - alignment of the destination location
611/// \p Mask - vector of booleans which indicates what vector lanes should
612/// be accessed in memory
614 Align Alignment, Value *Mask) {
615 auto *PtrTy = cast<PointerType>(Ptr->getType());
616 Type *DataTy = Val->getType();
617 assert(DataTy->isVectorTy() && "Val should be a vector");
618 assert(Mask && "Mask should not be all-ones (null)");
619 Type *OverloadedTypes[] = { DataTy, PtrTy };
620 Value *Ops[] = {Val, Ptr, Mask};
621 CallInst *CI =
622 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
623 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
624 return CI;
625}
626
627/// Create a call to a Masked intrinsic, with given intrinsic Id,
628/// an array of operands - Ops, and an array of overloaded types -
629/// OverloadedTypes.
630CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
632 ArrayRef<Type *> OverloadedTypes,
633 const Twine &Name) {
634 return CreateIntrinsicWithoutFolding(Id, OverloadedTypes, Ops, {}, Name);
635}
636
637/// Create a call to a Masked Gather intrinsic.
638/// \p Ty - vector type to gather
639/// \p Ptrs - vector of pointers for loading
640/// \p Align - alignment for one element
641/// \p Mask - vector of booleans which indicates what vector lanes should
642/// be accessed in memory
643/// \p PassThru - pass-through value that is used to fill the masked-off lanes
644/// of the result
645/// \p Name - name of the result variable
647 Align Alignment, Value *Mask,
648 Value *PassThru,
649 const Twine &Name) {
650 auto *VecTy = cast<VectorType>(Ty);
651 ElementCount NumElts = VecTy->getElementCount();
652 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
653 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
654
655 if (!Mask)
656 Mask = getAllOnesMask(NumElts);
657
658 if (!PassThru)
659 PassThru = PoisonValue::get(Ty);
660
661 Type *OverloadedTypes[] = {Ty, PtrsTy};
662 Value *Ops[] = {Ptrs, Mask, PassThru};
663
664 // We specify only one type when we create this intrinsic. Types of other
665 // arguments are derived from this type.
666 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
667 OverloadedTypes, Name);
668 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
669 return CI;
670}
671
672/// Create a call to a Masked Scatter intrinsic.
673/// \p Data - data to be stored,
674/// \p Ptrs - the vector of pointers, where the \p Data elements should be
675/// stored
676/// \p Align - alignment for one element
677/// \p Mask - vector of booleans which indicates what vector lanes should
678/// be accessed in memory
680 Align Alignment, Value *Mask) {
681 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
682 auto *DataTy = cast<VectorType>(Data->getType());
683 ElementCount NumElts = PtrsTy->getElementCount();
684
685 if (!Mask)
686 Mask = getAllOnesMask(NumElts);
687
688 Type *OverloadedTypes[] = {DataTy, PtrsTy};
689 Value *Ops[] = {Data, Ptrs, Mask};
690
691 // We specify only one type when we create this intrinsic. Types of other
692 // arguments are derived from this type.
693 CallInst *CI =
694 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
695 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
696 return CI;
697}
698
699/// Create a call to Masked Expand Load intrinsic
700/// \p Ty - vector type to load
701/// \p Ptr - base pointer for the load
702/// \p Align - alignment of \p Ptr
703/// \p Mask - vector of booleans which indicates what vector lanes should
704/// be accessed in memory
705/// \p PassThru - pass-through value that is used to fill the masked-off lanes
706/// of the result
707/// \p Name - name of the result variable
709 MaybeAlign Align, Value *Mask,
710 Value *PassThru,
711 const Twine &Name) {
712 assert(Ty->isVectorTy() && "Type should be vector");
713 assert(Mask && "Mask should not be all-ones (null)");
714 if (!PassThru)
715 PassThru = PoisonValue::get(Ty);
716 Type *PtrTy = Ptr->getType();
717 Type *OverloadedTypes[] = {Ty, PtrTy};
718 Value *Ops[] = {Ptr, Mask, PassThru};
719 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
720 OverloadedTypes, Name);
721 if (Align)
723 return CI;
724}
725
726/// Create a call to Masked Compress Store intrinsic
727/// \p Val - data to be stored,
728/// \p Ptr - base pointer for the store
729/// \p Align - alignment of \p Ptr
730/// \p Mask - vector of booleans which indicates what vector lanes should
731/// be accessed in memory
734 Value *Mask) {
735 Type *DataTy = Val->getType();
736 assert(DataTy->isVectorTy() && "Val should be a vector");
737 assert(Mask && "Mask should not be all-ones (null)");
738 Type *PtrTy = Ptr->getType();
739 Type *OverloadedTypes[] = {DataTy, PtrTy};
740 Value *Ops[] = {Val, Ptr, Mask};
741 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
742 OverloadedTypes);
743 if (Align)
745 return CI;
746}
747
748template <typename T0>
749static std::vector<Value *>
751 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
752 std::vector<Value *> Args;
753 Args.push_back(B.getInt64(ID));
754 Args.push_back(B.getInt32(NumPatchBytes));
755 Args.push_back(ActualCallee);
756 Args.push_back(B.getInt32(CallArgs.size()));
757 Args.push_back(B.getInt32(Flags));
758 llvm::append_range(Args, CallArgs);
759 // GC Transition and Deopt args are now always handled via operand bundle.
760 // They will be removed from the signature of gc.statepoint shortly.
761 Args.push_back(B.getInt32(0));
762 Args.push_back(B.getInt32(0));
763 // GC args are now encoded in the gc-live operand bundle
764 return Args;
765}
766
767template<typename T1, typename T2, typename T3>
768static std::vector<OperandBundleDef>
769getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
770 std::optional<ArrayRef<T2>> DeoptArgs,
771 ArrayRef<T3> GCArgs) {
772 std::vector<OperandBundleDef> Rval;
773 if (DeoptArgs)
774 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
775 if (TransitionArgs)
776 Rval.emplace_back("gc-transition",
777 SmallVector<Value *, 16>(*TransitionArgs));
778 if (GCArgs.size())
779 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
780 return Rval;
781}
782
783template <typename T0, typename T1, typename T2, typename T3>
785 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
786 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
787 std::optional<ArrayRef<T1>> TransitionArgs,
788 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
789 const Twine &Name) {
790 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
791 // Fill in the one generic type'd argument (the function is also vararg)
793 M, Intrinsic::experimental_gc_statepoint,
794 {ActualCallee.getCallee()->getType()});
795
796 std::vector<Value *> Args = getStatepointArgs(
797 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
798
799 CallInst *CI = Builder->CreateCall(
800 FnStatepoint, Args,
801 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
802 CI->addParamAttr(2,
803 Attribute::get(Builder->getContext(), Attribute::ElementType,
804 ActualCallee.getFunctionType()));
805 return CI;
806}
807
809 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
810 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
811 ArrayRef<Value *> GCArgs, const Twine &Name) {
813 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
814 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
815}
816
818 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
819 uint32_t Flags, ArrayRef<Value *> CallArgs,
820 std::optional<ArrayRef<Use>> TransitionArgs,
821 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
822 const Twine &Name) {
824 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
825 DeoptArgs, GCArgs, Name);
826}
827
829 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
830 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
831 ArrayRef<Value *> GCArgs, const Twine &Name) {
833 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
834 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
835}
836
837template <typename T0, typename T1, typename T2, typename T3>
839 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
840 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
841 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
842 std::optional<ArrayRef<T1>> TransitionArgs,
843 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
844 const Twine &Name) {
845 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
846 // Fill in the one generic type'd argument (the function is also vararg)
848 M, Intrinsic::experimental_gc_statepoint,
849 {ActualInvokee.getCallee()->getType()});
850
851 std::vector<Value *> Args =
852 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
853 Flags, InvokeArgs);
854
855 InvokeInst *II = Builder->CreateInvoke(
856 FnStatepoint, NormalDest, UnwindDest, Args,
857 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
858 II->addParamAttr(2,
859 Attribute::get(Builder->getContext(), Attribute::ElementType,
860 ActualInvokee.getFunctionType()));
861 return II;
862}
863
865 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
866 BasicBlock *NormalDest, BasicBlock *UnwindDest,
867 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
868 ArrayRef<Value *> GCArgs, const Twine &Name) {
870 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
871 uint32_t(StatepointFlags::None), InvokeArgs,
872 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
873}
874
876 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
877 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
878 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
879 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
880 const Twine &Name) {
882 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
883 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
884}
885
887 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
888 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
889 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
890 const Twine &Name) {
892 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
893 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
894 GCArgs, Name);
895}
896
898 Type *ResultType, const Twine &Name) {
899 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
900 Type *Types[] = {ResultType};
901
902 Value *Args[] = {Statepoint};
903 return CreateIntrinsicWithoutFolding(ID, Types, Args, {}, Name);
904}
905
907 int BaseOffset, int DerivedOffset,
908 Type *ResultType, const Twine &Name) {
909 Type *Types[] = {ResultType};
910
911 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
912 return CreateIntrinsicWithoutFolding(Intrinsic::experimental_gc_relocate,
913 Types, Args, {}, Name);
914}
915
917 const Twine &Name) {
918 Type *PtrTy = DerivedPtr->getType();
920 Intrinsic::experimental_gc_get_pointer_base, PtrTy, DerivedPtr, {}, Name);
921}
922
924 const Twine &Name) {
925 Type *PtrTy = DerivedPtr->getType();
927 Intrinsic::experimental_gc_get_pointer_offset, {PtrTy}, {DerivedPtr}, {},
928 Name);
929}
930
933 const Twine &Name) {
934 Module *M = BB->getModule();
935 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, Op->getType());
936 if (Value *V =
937 Folder.FoldIntrinsic(ID, Op, Fn->getReturnType(), FMFSource.get(FMF),
939 return V;
940 return createCallHelper(Fn, Op, Name, FMFSource);
941}
942
945 const Twine &Name) {
946 Module *M = BB->getModule();
947 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
948 if (Value *V = Folder.FoldIntrinsic(ID, {LHS, RHS}, Fn->getReturnType(),
951 return V;
952 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
953}
954
956 Intrinsic::ID ID, ArrayRef<Type *> OverloadTypes, ArrayRef<Value *> Args,
957 FMFSource FMFSource, const Twine &Name,
958 ArrayRef<OperandBundleDef> OpBundles) {
959 Module *M = BB->getModule();
960 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTypes);
961 return createCallHelper(Fn, Args, Name, FMFSource, OpBundles);
962}
963
965 Intrinsic::ID ID,
968 const Twine &Name) {
969 Module *M = BB->getModule();
971 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, RetTy, ArgTys);
972 return createCallHelper(Fn, Args, Name, FMFSource);
973}
974
976 ArrayRef<Type *> OverloadTypes,
978 FMFSource FMFSource, const Twine &Name,
980 function_ref<void(CallInst *)> SetFn) {
981 Type *RetTy = Intrinsic::getType(Context, ID, OverloadTypes)->getReturnType();
982 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
984 return V;
985 CallInst *CI = CreateIntrinsicWithoutFolding(ID, OverloadTypes, Args,
986 FMFSource, Name, OpBundles);
987 SetFn(CI);
988 return CI;
989}
990
993 FMFSource FMFSource, const Twine &Name,
994 function_ref<void(CallInst *)> SetFn) {
995 if (Value *V = Folder.FoldIntrinsic(ID, Args, RetTy, FMFSource.get(FMF),
997 return V;
998 CallInst *CI =
999 CreateIntrinsicWithoutFolding(RetTy, ID, Args, FMFSource, Name);
1000 SetFn(CI);
1001 return CI;
1002}
1003
1006 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1007 std::optional<fp::ExceptionBehavior> Except) {
1008 Value *RoundingV = getConstrainedFPRounding(Rounding);
1009 Value *ExceptV = getConstrainedFPExcept(Except);
1010
1011 FastMathFlags UseFMF = FMFSource.get(FMF);
1013 ID, {L->getType()}, {L, R, RoundingV, ExceptV}, nullptr, Name, {});
1015 setFPAttrs(C, FPMathTag, UseFMF);
1016 return C;
1017}
1018
1021 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
1022 std::optional<RoundingMode> Rounding,
1023 std::optional<fp::ExceptionBehavior> Except) {
1024 Value *RoundingV = getConstrainedFPRounding(Rounding);
1025 Value *ExceptV = getConstrainedFPExcept(Except);
1026
1027 FastMathFlags UseFMF = FMFSource.get(FMF);
1028
1029 llvm::SmallVector<Value *, 5> ExtArgs(Args);
1030 ExtArgs.push_back(RoundingV);
1031 ExtArgs.push_back(ExceptV);
1032 CallInst *C =
1033 CreateIntrinsicWithoutFolding(ID, Types, ExtArgs, nullptr, Name, {});
1035 setFPAttrs(C, FPMathTag, UseFMF);
1036 return C;
1037}
1038
1041 const Twine &Name, MDNode *FPMathTag,
1042 std::optional<fp::ExceptionBehavior> Except) {
1043 Value *ExceptV = getConstrainedFPExcept(Except);
1044
1045 FastMathFlags UseFMF = FMFSource.get(FMF);
1047 ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name, {});
1049 setFPAttrs(C, FPMathTag, UseFMF);
1050 return C;
1051}
1052
1054 const Twine &Name, MDNode *FPMathTag) {
1056 assert(Ops.size() == 2 && "Invalid number of operands!");
1057 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
1058 Ops[0], Ops[1], Name, FPMathTag);
1059 }
1061 assert(Ops.size() == 1 && "Invalid number of operands!");
1062 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
1063 Ops[0], Name, FPMathTag);
1064 }
1065 llvm_unreachable("Unexpected opcode!");
1066}
1067
1069 Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource,
1070 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1071 std::optional<fp::ExceptionBehavior> Except) {
1072 Value *ExceptV = getConstrainedFPExcept(Except);
1073
1074 FastMathFlags UseFMF = FMFSource.get(FMF);
1075
1076 CallInst *C;
1078 Value *RoundingV = getConstrainedFPRounding(Rounding);
1080 ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV}, nullptr, Name, {});
1081 } else
1082 C = CreateIntrinsicWithoutFolding(ID, {DestTy, V->getType()}, {V, ExceptV},
1083 nullptr, Name, {});
1085
1087 setFPAttrs(C, FPMathTag, UseFMF);
1088 return C;
1089}
1090
1091Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
1092 Value *RHS, const Twine &Name,
1093 MDNode *FPMathTag, FMFSource FMFSource,
1094 bool IsSignaling) {
1095 if (IsFPConstrained) {
1096 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1097 : Intrinsic::experimental_constrained_fcmp;
1098 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1099 }
1100
1101 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1102 return V;
1103 return Insert(
1104 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1105 Name);
1106}
1107
1110 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1111 Value *PredicateV = getConstrainedFPPredicate(P);
1112 Value *ExceptV = getConstrainedFPExcept(Except);
1113
1115 ID, {L->getType()}, {L, R, PredicateV, ExceptV}, nullptr, Name, {});
1117 return C;
1118}
1119
1121 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1122 std::optional<RoundingMode> Rounding,
1123 std::optional<fp::ExceptionBehavior> Except) {
1124 llvm::SmallVector<Value *, 6> UseArgs(Args);
1125
1126 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1127 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1128 UseArgs.push_back(getConstrainedFPExcept(Except));
1129
1130 CallInst *C = CreateCall(Callee, UseArgs, Name);
1132 return C;
1133}
1134
1136 Value *False,
1138 const Twine &Name) {
1139 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1140 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1142 }
1143 return Ret;
1144}
1145
1147 Value *False,
1150 const Twine &Name) {
1151 Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
1152 if (auto *SI = dyn_cast<SelectInst>(Ret))
1154 return Ret;
1155}
1156
1158 const Twine &Name, Instruction *MDFrom) {
1159 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1160}
1161
1163 FMFSource FMFSource, const Twine &Name,
1164 Instruction *MDFrom) {
1165 if (auto *V = Folder.FoldSelect(C, True, False, FMFSource.get(FMF)))
1166 return V;
1167
1168 SelectInst *Sel = SelectInst::Create(C, True, False);
1169 if (MDFrom) {
1170 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1171 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1172 Sel = addBranchMetadata(Sel, Prof, Unpred);
1173 }
1174 if (isa<FPMathOperator>(Sel))
1175 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1176 return Insert(Sel, Name);
1177}
1178
1180 bool IsNUW) {
1181 assert(LHS->getType() == RHS->getType() &&
1182 "Pointer subtraction operand types must match!");
1183 Value *LHSAddr = CreatePtrToAddr(LHS);
1184 Value *RHSAddr = CreatePtrToAddr(RHS);
1185 return CreateSub(LHSAddr, RHSAddr, Name, IsNUW);
1186}
1188 const Twine &Name) {
1189 const DataLayout &DL = BB->getDataLayout();
1190 TypeSize ElemSize = DL.getTypeAllocSize(ElemTy);
1191 if (ElemSize == TypeSize::getFixed(1))
1192 return CreatePtrDiff(LHS, RHS, Name);
1193
1194 Value *Diff = CreatePtrDiff(LHS, RHS);
1195 return CreateExactSDiv(Diff, CreateTypeSize(Diff->getType(), ElemSize), Name);
1196}
1197
1200 "launder.invariant.group only applies to pointers.");
1201 auto *PtrType = Ptr->getType();
1202 Module *M = BB->getParent()->getParent();
1203 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1204 M, Intrinsic::launder_invariant_group, {PtrType});
1205
1206 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1207 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1208 PtrType &&
1209 "LaunderInvariantGroup should take and return the same type");
1210
1211 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1212}
1213
1216 "strip.invariant.group only applies to pointers.");
1217
1218 auto *PtrType = Ptr->getType();
1219 Module *M = BB->getParent()->getParent();
1220 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1221 M, Intrinsic::strip_invariant_group, {PtrType});
1222
1223 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1224 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1225 PtrType &&
1226 "StripInvariantGroup should take and return the same type");
1227
1228 return CreateCall(FnStripInvariantGroup, {Ptr});
1229}
1230
1232 auto *Ty = cast<VectorType>(V->getType());
1233 if (isa<ScalableVectorType>(Ty)) {
1234 Module *M = BB->getParent()->getParent();
1235 Function *F =
1236 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1237 return Insert(CallInst::Create(F, V), Name);
1238 }
1239 // Keep the original behaviour for fixed vector
1240 SmallVector<int, 8> ShuffleMask;
1241 int NumElts = Ty->getElementCount().getKnownMinValue();
1242 for (int i = 0; i < NumElts; ++i)
1243 ShuffleMask.push_back(NumElts - i - 1);
1244 return CreateShuffleVector(V, ShuffleMask, Name);
1245}
1246
1247static SmallVector<int, 8> getSpliceMask(int64_t Imm, unsigned NumElts) {
1248 unsigned Idx = (NumElts + Imm) % NumElts;
1250 for (unsigned I = 0; I < NumElts; ++I)
1251 Mask.push_back(Idx + I);
1252 return Mask;
1253}
1254
1256 Value *Offset, const Twine &Name) {
1257 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1258 assert(V1->getType() == V2->getType() &&
1259 "Splice expects matching operand types!");
1260
1261 // Emit a shufflevector for fixed vectors with a constant offset
1262 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1263 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1264 return CreateShuffleVector(
1265 V1, V2,
1266 getSpliceMask(COffset->getZExtValue(), FVTy->getNumElements()));
1267
1268 return CreateIntrinsic(Intrinsic::vector_splice_left, V1->getType(),
1269 {V1, V2, Offset}, {}, Name);
1270}
1271
1273 Value *Offset,
1274 const Twine &Name) {
1275 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1276 assert(V1->getType() == V2->getType() &&
1277 "Splice expects matching operand types!");
1278
1279 // Emit a shufflevector for fixed vectors with a constant offset
1280 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1281 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1282 return CreateShuffleVector(
1283 V1, V2,
1284 getSpliceMask(-COffset->getZExtValue(), FVTy->getNumElements()));
1285
1286 return CreateIntrinsic(Intrinsic::vector_splice_right, V1->getType(),
1287 {V1, V2, Offset}, {}, Name);
1288}
1289
1291 const Twine &Name) {
1292 auto EC = ElementCount::getFixed(NumElts);
1293 return CreateVectorSplat(EC, V, Name);
1294}
1295
1297 const Twine &Name) {
1298 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1299
1300 // First insert it into a poison vector so we can shuffle it.
1301 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1302 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1303
1304 // Shuffle the value across the desired number of elements.
1306 Zeros.resize(EC.getKnownMinValue());
1307 return CreateShuffleVector(V, Zeros, Name + ".splat");
1308}
1309
1311 const Twine &Name) {
1312 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1313 "Unexpected number of operands to interleave");
1314
1315 // Make sure all operands are the same type.
1316 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1317
1318#ifndef NDEBUG
1319 for (unsigned I = 1; I < Ops.size(); I++) {
1320 assert(Ops[I]->getType() == Ops[0]->getType() &&
1321 "Vector interleave expects matching operand types!");
1322 }
1323#endif
1324
1325 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1326 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1327 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1328 SubvecTy->getElementCount() * Ops.size());
1329 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1330}
1331
1333 unsigned Dimension,
1334 unsigned LastIndex,
1335 MDNode *DbgInfo) {
1336 auto *BaseType = Base->getType();
1338 "Invalid Base ptr type for preserve.array.access.index.");
1339
1340 Value *LastIndexV = getInt32(LastIndex);
1341 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1342 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1343 IdxList.push_back(LastIndexV);
1344
1345 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1346
1347 Value *DimV = getInt32(Dimension);
1349 Intrinsic::preserve_array_access_index, {ResultType, BaseType},
1350 {Base, DimV, LastIndexV});
1351 Fn->addParamAttr(
1352 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1353 if (DbgInfo)
1354 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1355
1356 return Fn;
1357}
1358
1360 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1361 assert(isa<PointerType>(Base->getType()) &&
1362 "Invalid Base ptr type for preserve.union.access.index.");
1363 auto *BaseType = Base->getType();
1364
1365 Value *DIIndex = getInt32(FieldIndex);
1366 CallInst *Fn =
1367 CreateIntrinsicWithoutFolding(Intrinsic::preserve_union_access_index,
1368 {BaseType, BaseType}, {Base, DIIndex});
1369 if (DbgInfo)
1370 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1371
1372 return Fn;
1373}
1374
1376 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1377 MDNode *DbgInfo) {
1378 auto *BaseType = Base->getType();
1380 "Invalid Base ptr type for preserve.struct.access.index.");
1381
1382 Value *GEPIndex = getInt32(Index);
1383 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1384 Type *ResultType =
1385 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1386
1387 Value *DIIndex = getInt32(FieldIndex);
1389 Intrinsic::preserve_struct_access_index, {ResultType, BaseType},
1390 {Base, GEPIndex, DIIndex});
1391 Fn->addParamAttr(
1392 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1393 if (DbgInfo)
1394 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1395
1396 return Fn;
1397}
1398
1400 ConstantInt *TestV = getInt32(Test);
1401 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1402 {FPNum, TestV});
1403}
1404
1405CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1406 Value *PtrValue,
1407 Value *AlignValue,
1408 Value *OffsetValue) {
1409 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1410 if (OffsetValue)
1411 Vals.push_back(OffsetValue);
1412 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1413 return CreateAssumption({AlignOpB});
1414}
1415
1417 Value *PtrValue,
1418 uint64_t Alignment,
1419 Value *OffsetValue) {
1420 assert(isa<PointerType>(PtrValue->getType()) &&
1421 "trying to create an alignment assumption on a non-pointer?");
1422 assert(Alignment != 0 && "Invalid Alignment");
1423 Value *AlignValue = ConstantInt::get(getInt64Ty(), Alignment);
1424 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1425}
1426
1428 Value *PtrValue,
1429 Value *Alignment,
1430 Value *OffsetValue) {
1431 assert(isa<PointerType>(PtrValue->getType()) &&
1432 "trying to create an alignment assumption on a non-pointer?");
1433 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1434}
1435
1437 Value *SizeValue) {
1438 assert(isa<PointerType>(PtrValue->getType()) &&
1439 "trying to create a deferenceable assumption on a non-pointer?");
1440 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1441 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1442 return CreateAssumption({DereferenceableOpB});
1443}
1444
1446 assert(isa<PointerType>(PtrValue->getType()) &&
1447 "trying to create a nonnull assumption on a non-pointer?");
1448 return CreateAssumption(OperandBundleDef("nonnull", PtrValue));
1449}
1450
1454void ConstantFolder::anchor() {}
1455void 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:305
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:1503
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:2677
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:2731
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:2147
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:2237
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:2724
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 CallInst * CreateMalloc(Type *IntPtrTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
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:2246
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:1120
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:848
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:1866
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:2340
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:1447
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2251
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:2699
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:2241
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2569
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:2115
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:1739
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:2331
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:1134
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:1464
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:339
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:283
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition Type.h:274
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
Type * getArrayElementType() const
Definition Type.h:420
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:272
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:363
bool isStructTy() const
True if this is an instance of StructType.
Definition Type.h:271
bool isByteOrByteVectorTy() const
Return true if this is a byte type or a vector of byte types.
Definition Type.h:243
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:280
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:257
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
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