LLVM 23.0.0git
IRBuilder.cpp
Go to the documentation of this file.
1//===- IRBuilder.cpp - Builder for LLVM Instrs ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the IRBuilder class, which is used as a convenient way
10// to create LLVM instructions with a consistent and simplified interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/IRBuilder.h"
15#include "llvm/ADT/ArrayRef.h"
17#include "llvm/IR/Constant.h"
18#include "llvm/IR/Constants.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/GlobalValue.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/Module.h"
27#include "llvm/IR/NoFolder.h"
28#include "llvm/IR/Operator.h"
30#include "llvm/IR/Statepoint.h"
31#include "llvm/IR/Type.h"
32#include "llvm/IR/Value.h"
34#include <cassert>
35#include <cstdint>
36#include <optional>
37#include <vector>
38
39using namespace llvm;
40
41/// CreateGlobalString - Make a new global variable with an initializer that
42/// has array of i8 type filled in with the nul terminated string value
43/// specified. If Name is specified, it is the name of the global variable
44/// created.
46 const Twine &Name,
47 unsigned AddressSpace,
48 Module *M, bool AddNull) {
49 Constant *StrConstant = ConstantDataArray::getString(Context, Str, AddNull);
50 if (!M)
51 M = BB->getParent()->getParent();
52 auto *GV = new GlobalVariable(
53 *M, StrConstant->getType(), true, GlobalValue::PrivateLinkage,
54 StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace);
55 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
56 GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty()));
57 return GV;
58}
59
61 assert(BB && BB->getParent() && "No current function!");
62 return BB->getParent()->getReturnType();
63}
64
67 // We prefer to set our current debug location if any has been set, but if
68 // our debug location is empty and I has a valid location, we shouldn't
69 // overwrite it.
70 I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
71}
72
74 Type *SrcTy = V->getType();
75 if (SrcTy == DestTy)
76 return V;
77
78 if (SrcTy->isAggregateType()) {
79 unsigned NumElements;
80 if (SrcTy->isStructTy()) {
81 assert(DestTy->isStructTy() && "Expected StructType");
82 assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements() &&
83 "Expected StructTypes with equal number of elements");
84 NumElements = SrcTy->getStructNumElements();
85 } else {
86 assert(SrcTy->isArrayTy() && DestTy->isArrayTy() && "Expected ArrayType");
87 assert(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements() &&
88 "Expected ArrayTypes with equal number of elements");
89 NumElements = SrcTy->getArrayNumElements();
90 }
91
92 Value *Result = PoisonValue::get(DestTy);
93 for (unsigned I = 0; I < NumElements; ++I) {
94 Type *ElementTy = SrcTy->isStructTy() ? DestTy->getStructElementType(I)
95 : DestTy->getArrayElementType();
96 Value *Element =
98
99 Result = CreateInsertValue(Result, Element, ArrayRef(I));
100 }
101 return Result;
102 }
103
104 return CreateBitOrPointerCast(V, DestTy);
105}
106
108 Value *V, Type *NewTy) {
109 Type *OldTy = V->getType();
110
111 if (OldTy == NewTy)
112 return V;
113
114 assert(!(isa<IntegerType>(OldTy) && isa<IntegerType>(NewTy)) &&
115 "Integer types must be the exact same to convert.");
116
117 // A variant of bitcast that supports a mixture of fixed and scalable types
118 // that are know to have the same size.
119 auto CreateBitCastLike = [this](Value *In, Type *Ty) -> Value * {
120 Type *InTy = In->getType();
121 if (InTy == Ty)
122 return In;
123
125 // For vscale_range(2) expand <4 x i32> to <vscale x 4 x i16> -->
126 // <4 x i32> to <vscale x 2 x i32> to <vscale x 4 x i16>
128 return CreateBitCast(
129 CreateInsertVector(VTy, PoisonValue::get(VTy), In, getInt64(0)), Ty);
130 }
131
133 // For vscale_range(2) expand <vscale x 4 x i16> to <4 x i32> -->
134 // <vscale x 4 x i16> to <vscale x 2 x i32> to <4 x i32>
136 return CreateExtractVector(Ty, CreateBitCast(In, VTy), getInt64(0));
137 }
138
139 return CreateBitCast(In, Ty);
140 };
141
142 // See if we need inttoptr for this type pair. May require additional bitcast.
143 if (OldTy->isIntOrIntVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
144 // Expand <2 x i32> to i8* --> <2 x i32> to i64 to i8*
145 // Expand i128 to <2 x i8*> --> i128 to <2 x i64> to <2 x i8*>
146 // Expand <4 x i32> to <2 x i8*> --> <4 x i32> to <2 x i64> to <2 x i8*>
147 // Directly handle i64 to i8*
148 return CreateIntToPtr(CreateBitCastLike(V, DL.getIntPtrType(NewTy)), NewTy);
149 }
150
151 // See if we need ptrtoint for this type pair. May require additional bitcast.
152 if (OldTy->isPtrOrPtrVectorTy() && NewTy->isIntOrIntVectorTy()) {
153 // Expand <2 x i8*> to i128 --> <2 x i8*> to <2 x i64> to i128
154 // Expand i8* to <2 x i32> --> i8* to i64 to <2 x i32>
155 // Expand <2 x i8*> to <4 x i32> --> <2 x i8*> to <2 x i64> to <4 x i32>
156 // Expand i8* to i64 --> i8* to i64 to i64
157 return CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)), NewTy);
158 }
159
160 if (OldTy->isPtrOrPtrVectorTy() && NewTy->isPtrOrPtrVectorTy()) {
161 unsigned OldAS = OldTy->getPointerAddressSpace();
162 unsigned NewAS = NewTy->getPointerAddressSpace();
163 // To convert pointers with different address spaces (they are already
164 // checked convertible, i.e. they have the same pointer size), so far we
165 // cannot use `bitcast` (which has restrict on the same address space) or
166 // `addrspacecast` (which is not always no-op casting). Instead, use a pair
167 // of no-op `ptrtoint`/`inttoptr` casts through an integer with the same bit
168 // size.
169 if (OldAS != NewAS) {
170 return CreateIntToPtr(
171 CreateBitCastLike(CreatePtrToInt(V, DL.getIntPtrType(OldTy)),
172 DL.getIntPtrType(NewTy)),
173 NewTy);
174 }
175 }
176
177 return CreateBitCastLike(V, NewTy);
178}
179
180CallInst *
181IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
182 const Twine &Name, FMFSource FMFSource,
183 ArrayRef<OperandBundleDef> OpBundles) {
184 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
185 if (isa<FPMathOperator>(CI))
187 return CI;
188}
189
191 Value *VScale = B.CreateVScale(Ty);
192 if (Scale == 1)
193 return VScale;
194
195 return B.CreateNUWMul(VScale, ConstantInt::get(Ty, Scale));
196}
197
199 if (EC.isFixed() || EC.isZero())
200 return ConstantInt::get(Ty, EC.getKnownMinValue());
201
202 return CreateVScaleMultiple(*this, Ty, EC.getKnownMinValue());
203}
204
206 if (Size.isFixed() || Size.isZero())
207 return ConstantInt::get(Ty, Size.getKnownMinValue());
208
209 return CreateVScaleMultiple(*this, Ty, Size.getKnownMinValue());
210}
211
213 const DataLayout &DL = BB->getDataLayout();
214 TypeSize ElemSize = DL.getTypeAllocSize(AI->getAllocatedType());
215 Value *Size = CreateTypeSize(DestTy, ElemSize);
216 if (AI->isArrayAllocation())
218 return Size;
219}
220
222 Type *STy = DstType->getScalarType();
223 if (isa<ScalableVectorType>(DstType)) {
224 Type *StepVecType = DstType;
225 // TODO: We expect this special case (element type < 8 bits) to be
226 // temporary - once the intrinsic properly supports < 8 bits this code
227 // can be removed.
228 if (STy->getScalarSizeInBits() < 8)
229 StepVecType =
231 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
232 nullptr, Name);
233 if (StepVecType != DstType)
234 Res = CreateTrunc(Res, DstType);
235 return Res;
236 }
237
238 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
239
240 // Create a vector of consecutive numbers from zero to VF.
241 // It's okay if the values wrap around.
243 for (unsigned i = 0; i < NumEls; ++i)
244 Indices.push_back(
245 ConstantInt::get(STy, i, /*IsSigned=*/false, /*ImplicitTrunc=*/true));
246
247 // Add the consecutive indices to the vector value.
248 return ConstantVector::get(Indices);
249}
250
252 MaybeAlign Align, bool isVolatile,
253 const AAMDNodes &AAInfo) {
254 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
255 Type *Tys[] = {Ptr->getType(), Size->getType()};
256
257 CallInst *CI = CreateIntrinsic(Intrinsic::memset, Tys, Ops);
258
259 if (Align)
260 cast<MemSetInst>(CI)->setDestAlignment(*Align);
261 CI->setAAMetadata(AAInfo);
262 return CI;
263}
264
266 Value *Val, Value *Size,
267 bool IsVolatile,
268 const AAMDNodes &AAInfo) {
269 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
270 Type *Tys[] = {Dst->getType(), Size->getType()};
271
272 CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);
273
274 if (DstAlign)
275 cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);
276 CI->setAAMetadata(AAInfo);
277 return CI;
278}
279
281 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
282 const AAMDNodes &AAInfo) {
283
284 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
285 Type *Tys[] = {Ptr->getType(), Size->getType()};
286
287 CallInst *CI =
288 CreateIntrinsic(Intrinsic::memset_element_unordered_atomic, Tys, Ops);
289
290 cast<AnyMemSetInst>(CI)->setDestAlignment(Alignment);
291 CI->setAAMetadata(AAInfo);
292 return CI;
293}
294
296 MaybeAlign DstAlign, Value *Src,
297 MaybeAlign SrcAlign, Value *Size,
298 bool isVolatile,
299 const AAMDNodes &AAInfo) {
300 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
301 IntrID == Intrinsic::memmove) &&
302 "Unexpected intrinsic ID");
303 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
304 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
305
306 CallInst *CI = CreateIntrinsic(IntrID, Tys, Ops);
307
308 auto* MCI = cast<MemTransferInst>(CI);
309 if (DstAlign)
310 MCI->setDestAlignment(*DstAlign);
311 if (SrcAlign)
312 MCI->setSourceAlignment(*SrcAlign);
313 MCI->setAAMetadata(AAInfo);
314 return CI;
315}
316
318 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
319 uint32_t ElementSize, const AAMDNodes &AAInfo) {
320 assert(DstAlign >= ElementSize &&
321 "Pointer alignment must be at least element size");
322 assert(SrcAlign >= ElementSize &&
323 "Pointer alignment must be at least element size");
324 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
325 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
326
327 CallInst *CI =
328 CreateIntrinsic(Intrinsic::memcpy_element_unordered_atomic, Tys, Ops);
329
330 // Set the alignment of the pointer args.
331 auto *AMCI = cast<AnyMemCpyInst>(CI);
332 AMCI->setDestAlignment(DstAlign);
333 AMCI->setSourceAlignment(SrcAlign);
334 AMCI->setAAMetadata(AAInfo);
335 return CI;
336}
337
338/// isConstantOne - Return true only if val is constant int 1
339static bool isConstantOne(const Value *Val) {
340 assert(Val && "isConstantOne does not work with nullptr Val");
341 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
342 return CVal && CVal->isOne();
343}
344
346 Value *AllocSize, Value *ArraySize,
348 Function *MallocF, const Twine &Name) {
349 // malloc(type) becomes:
350 // i8* malloc(typeSize)
351 // malloc(type, arraySize) becomes:
352 // i8* malloc(typeSize*arraySize)
353 if (!ArraySize)
354 ArraySize = ConstantInt::get(IntPtrTy, 1);
355 else if (ArraySize->getType() != IntPtrTy)
356 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
357
358 if (!isConstantOne(ArraySize)) {
359 if (isConstantOne(AllocSize)) {
360 AllocSize = ArraySize; // Operand * 1 = Operand
361 } else {
362 // Multiply type size by the array size...
363 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
364 }
365 }
366
367 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
368 // Create the call to Malloc.
369 Module *M = BB->getParent()->getParent();
371 FunctionCallee MallocFunc = MallocF;
372 if (!MallocFunc)
373 // prototype malloc as "void *malloc(size_t)"
374 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
375 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
376
377 MCall->setTailCall();
378 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
379 MCall->setCallingConv(F->getCallingConv());
380 F->setReturnDoesNotAlias();
381 }
382
383 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
384
385 return MCall;
386}
387
389 Value *AllocSize, Value *ArraySize,
390 Function *MallocF, const Twine &Name) {
391
392 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
393 Name);
394}
395
396/// CreateFree - Generate the IR for a call to the builtin free function.
399 assert(Source->getType()->isPointerTy() &&
400 "Can not free something of nonpointer type!");
401
402 Module *M = BB->getParent()->getParent();
403
404 Type *VoidTy = Type::getVoidTy(M->getContext());
405 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
406 // prototype free as "void free(void*)"
407 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
408 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
409 Result->setTailCall();
410 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
411 Result->setCallingConv(F->getCallingConv());
412
413 return Result;
414}
415
417 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
418 uint32_t ElementSize, const AAMDNodes &AAInfo) {
419 assert(DstAlign >= ElementSize &&
420 "Pointer alignment must be at least element size");
421 assert(SrcAlign >= ElementSize &&
422 "Pointer alignment must be at least element size");
423 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
424 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
425
426 CallInst *CI =
427 CreateIntrinsic(Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
428
429 // Set the alignment of the pointer args.
430 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
431 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
432 CI->setAAMetadata(AAInfo);
433 return CI;
434}
435
436CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
437 Value *Ops[] = {Src};
438 Type *Tys[] = { Src->getType() };
439 return CreateIntrinsic(ID, Tys, Ops);
440}
441
443 Value *Ops[] = {Acc, Src};
444 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
445}
446
448 Value *Ops[] = {Acc, Src};
449 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
450}
451
453 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
454}
455
457 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
458}
459
461 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
462}
463
465 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
466}
467
469 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
470}
471
473 auto ID =
474 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
475 return getReductionIntrinsic(ID, Src);
476}
477
479 auto ID =
480 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
481 return getReductionIntrinsic(ID, Src);
482}
483
485 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
486}
487
489 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
490}
491
493 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
494}
495
497 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
498}
499
502 "lifetime.start only applies to pointers.");
503 return CreateIntrinsic(Intrinsic::lifetime_start, {Ptr->getType()}, {Ptr});
504}
505
508 "lifetime.end only applies to pointers.");
509 return CreateIntrinsic(Intrinsic::lifetime_end, {Ptr->getType()}, {Ptr});
510}
511
513
515 "invariant.start only applies to pointers.");
516 if (!Size)
517 Size = getInt64(-1);
518 else
519 assert(Size->getType() == getInt64Ty() &&
520 "invariant.start requires the size to be an i64");
521
522 Value *Ops[] = {Size, Ptr};
523 // Fill in the single overloaded type: memory object type.
524 Type *ObjectPtr[1] = {Ptr->getType()};
525 return CreateIntrinsic(Intrinsic::invariant_start, ObjectPtr, Ops);
526}
527
529 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
530 return V->getAlign();
531 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
532 return getAlign(A->getAliaseeObject());
533 return {};
534}
535
537 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
538 "threadlocal_address only applies to thread local variables.");
539 CallInst *CI = CreateIntrinsic(llvm::Intrinsic::threadlocal_address,
540 {Ptr->getType()}, {Ptr});
541 if (MaybeAlign A = getAlign(Ptr)) {
544 }
545 return CI;
546}
547
548CallInst *
550 ArrayRef<OperandBundleDef> OpBundles) {
551 assert(Cond->getType() == getInt1Ty() &&
552 "an assumption condition must be of type i1");
553
554 Value *Ops[] = { Cond };
555 Module *M = BB->getParent()->getParent();
556 Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
557 return CreateCall(FnAssume, Ops, OpBundles);
558}
559
561 return CreateIntrinsic(Intrinsic::experimental_noalias_scope_decl, {},
562 {Scope});
563}
564
565/// Create a call to a Masked Load intrinsic.
566/// \p Ty - vector type to load
567/// \p Ptr - base pointer for the load
568/// \p Alignment - alignment of the source location
569/// \p Mask - vector of booleans which indicates what vector lanes should
570/// be accessed in memory
571/// \p PassThru - pass-through value that is used to fill the masked-off lanes
572/// of the result
573/// \p Name - name of the result variable
575 Value *Mask, Value *PassThru,
576 const Twine &Name) {
577 auto *PtrTy = cast<PointerType>(Ptr->getType());
578 assert(Ty->isVectorTy() && "Type should be vector");
579 assert(Mask && "Mask should not be all-ones (null)");
580 if (!PassThru)
581 PassThru = PoisonValue::get(Ty);
582 Type *OverloadedTypes[] = { Ty, PtrTy };
583 Value *Ops[] = {Ptr, Mask, PassThru};
584 CallInst *CI =
585 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
586 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
587 return CI;
588}
589
590/// Create a call to a Masked Store intrinsic.
591/// \p Val - data to be stored,
592/// \p Ptr - base pointer for the store
593/// \p Alignment - alignment of the destination location
594/// \p Mask - vector of booleans which indicates what vector lanes should
595/// be accessed in memory
597 Align Alignment, Value *Mask) {
598 auto *PtrTy = cast<PointerType>(Ptr->getType());
599 Type *DataTy = Val->getType();
600 assert(DataTy->isVectorTy() && "Val should be a vector");
601 assert(Mask && "Mask should not be all-ones (null)");
602 Type *OverloadedTypes[] = { DataTy, PtrTy };
603 Value *Ops[] = {Val, Ptr, Mask};
604 CallInst *CI =
605 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
606 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
607 return CI;
608}
609
610/// Create a call to a Masked intrinsic, with given intrinsic Id,
611/// an array of operands - Ops, and an array of overloaded types -
612/// OverloadedTypes.
613CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
615 ArrayRef<Type *> OverloadedTypes,
616 const Twine &Name) {
617 return CreateIntrinsic(Id, OverloadedTypes, Ops, {}, Name);
618}
619
620/// Create a call to a Masked Gather intrinsic.
621/// \p Ty - vector type to gather
622/// \p Ptrs - vector of pointers for loading
623/// \p Align - alignment for one element
624/// \p Mask - vector of booleans which indicates what vector lanes should
625/// be accessed in memory
626/// \p PassThru - pass-through value that is used to fill the masked-off lanes
627/// of the result
628/// \p Name - name of the result variable
630 Align Alignment, Value *Mask,
631 Value *PassThru,
632 const Twine &Name) {
633 auto *VecTy = cast<VectorType>(Ty);
634 ElementCount NumElts = VecTy->getElementCount();
635 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
636 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
637
638 if (!Mask)
639 Mask = getAllOnesMask(NumElts);
640
641 if (!PassThru)
642 PassThru = PoisonValue::get(Ty);
643
644 Type *OverloadedTypes[] = {Ty, PtrsTy};
645 Value *Ops[] = {Ptrs, Mask, PassThru};
646
647 // We specify only one type when we create this intrinsic. Types of other
648 // arguments are derived from this type.
649 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
650 OverloadedTypes, Name);
651 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
652 return CI;
653}
654
655/// Create a call to a Masked Scatter intrinsic.
656/// \p Data - data to be stored,
657/// \p Ptrs - the vector of pointers, where the \p Data elements should be
658/// stored
659/// \p Align - alignment for one element
660/// \p Mask - vector of booleans which indicates what vector lanes should
661/// be accessed in memory
663 Align Alignment, Value *Mask) {
664 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
665 auto *DataTy = cast<VectorType>(Data->getType());
666 ElementCount NumElts = PtrsTy->getElementCount();
667
668 if (!Mask)
669 Mask = getAllOnesMask(NumElts);
670
671 Type *OverloadedTypes[] = {DataTy, PtrsTy};
672 Value *Ops[] = {Data, Ptrs, Mask};
673
674 // We specify only one type when we create this intrinsic. Types of other
675 // arguments are derived from this type.
676 CallInst *CI =
677 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
678 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
679 return CI;
680}
681
682/// Create a call to Masked Expand Load intrinsic
683/// \p Ty - vector type to load
684/// \p Ptr - base pointer for the load
685/// \p Align - alignment of \p Ptr
686/// \p Mask - vector of booleans which indicates what vector lanes should
687/// be accessed in memory
688/// \p PassThru - pass-through value that is used to fill the masked-off lanes
689/// of the result
690/// \p Name - name of the result variable
692 MaybeAlign Align, Value *Mask,
693 Value *PassThru,
694 const Twine &Name) {
695 assert(Ty->isVectorTy() && "Type should be vector");
696 assert(Mask && "Mask should not be all-ones (null)");
697 if (!PassThru)
698 PassThru = PoisonValue::get(Ty);
699 Type *OverloadedTypes[] = {Ty};
700 Value *Ops[] = {Ptr, Mask, PassThru};
701 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
702 OverloadedTypes, Name);
703 if (Align)
705 return CI;
706}
707
708/// Create a call to Masked Compress Store intrinsic
709/// \p Val - data to be stored,
710/// \p Ptr - base pointer for the store
711/// \p Align - alignment of \p Ptr
712/// \p Mask - vector of booleans which indicates what vector lanes should
713/// be accessed in memory
716 Value *Mask) {
717 Type *DataTy = Val->getType();
718 assert(DataTy->isVectorTy() && "Val should be a vector");
719 assert(Mask && "Mask should not be all-ones (null)");
720 Type *OverloadedTypes[] = {DataTy};
721 Value *Ops[] = {Val, Ptr, Mask};
722 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
723 OverloadedTypes);
724 if (Align)
726 return CI;
727}
728
729template <typename T0>
730static std::vector<Value *>
732 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
733 std::vector<Value *> Args;
734 Args.push_back(B.getInt64(ID));
735 Args.push_back(B.getInt32(NumPatchBytes));
736 Args.push_back(ActualCallee);
737 Args.push_back(B.getInt32(CallArgs.size()));
738 Args.push_back(B.getInt32(Flags));
739 llvm::append_range(Args, CallArgs);
740 // GC Transition and Deopt args are now always handled via operand bundle.
741 // They will be removed from the signature of gc.statepoint shortly.
742 Args.push_back(B.getInt32(0));
743 Args.push_back(B.getInt32(0));
744 // GC args are now encoded in the gc-live operand bundle
745 return Args;
746}
747
748template<typename T1, typename T2, typename T3>
749static std::vector<OperandBundleDef>
750getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
751 std::optional<ArrayRef<T2>> DeoptArgs,
752 ArrayRef<T3> GCArgs) {
753 std::vector<OperandBundleDef> Rval;
754 if (DeoptArgs)
755 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
756 if (TransitionArgs)
757 Rval.emplace_back("gc-transition",
758 SmallVector<Value *, 16>(*TransitionArgs));
759 if (GCArgs.size())
760 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
761 return Rval;
762}
763
764template <typename T0, typename T1, typename T2, typename T3>
766 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
767 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
768 std::optional<ArrayRef<T1>> TransitionArgs,
769 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
770 const Twine &Name) {
771 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
772 // Fill in the one generic type'd argument (the function is also vararg)
774 M, Intrinsic::experimental_gc_statepoint,
775 {ActualCallee.getCallee()->getType()});
776
777 std::vector<Value *> Args = getStatepointArgs(
778 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
779
780 CallInst *CI = Builder->CreateCall(
781 FnStatepoint, Args,
782 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
783 CI->addParamAttr(2,
784 Attribute::get(Builder->getContext(), Attribute::ElementType,
785 ActualCallee.getFunctionType()));
786 return CI;
787}
788
790 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
791 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
792 ArrayRef<Value *> GCArgs, const Twine &Name) {
794 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
795 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
796}
797
799 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
800 uint32_t Flags, ArrayRef<Value *> CallArgs,
801 std::optional<ArrayRef<Use>> TransitionArgs,
802 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
803 const Twine &Name) {
805 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
806 DeoptArgs, GCArgs, Name);
807}
808
810 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
811 ArrayRef<Use> 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, DeoptArgs, GCArgs, Name);
816}
817
818template <typename T0, typename T1, typename T2, typename T3>
820 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
821 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
822 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
823 std::optional<ArrayRef<T1>> TransitionArgs,
824 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
825 const Twine &Name) {
826 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
827 // Fill in the one generic type'd argument (the function is also vararg)
829 M, Intrinsic::experimental_gc_statepoint,
830 {ActualInvokee.getCallee()->getType()});
831
832 std::vector<Value *> Args =
833 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
834 Flags, InvokeArgs);
835
836 InvokeInst *II = Builder->CreateInvoke(
837 FnStatepoint, NormalDest, UnwindDest, Args,
838 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
839 II->addParamAttr(2,
840 Attribute::get(Builder->getContext(), Attribute::ElementType,
841 ActualInvokee.getFunctionType()));
842 return II;
843}
844
846 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
847 BasicBlock *NormalDest, BasicBlock *UnwindDest,
848 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
849 ArrayRef<Value *> GCArgs, const Twine &Name) {
851 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
852 uint32_t(StatepointFlags::None), InvokeArgs,
853 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
854}
855
857 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
858 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
859 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
860 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
861 const Twine &Name) {
863 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
864 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
865}
866
868 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
869 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
870 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
871 const Twine &Name) {
873 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
874 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
875 GCArgs, Name);
876}
877
879 Type *ResultType, const Twine &Name) {
880 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
881 Type *Types[] = {ResultType};
882
883 Value *Args[] = {Statepoint};
884 return CreateIntrinsic(ID, Types, Args, {}, Name);
885}
886
888 int BaseOffset, int DerivedOffset,
889 Type *ResultType, const Twine &Name) {
890 Type *Types[] = {ResultType};
891
892 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
893 return CreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
894 Name);
895}
896
898 const Twine &Name) {
899 Type *PtrTy = DerivedPtr->getType();
900 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_base,
901 {PtrTy, PtrTy}, {DerivedPtr}, {}, Name);
902}
903
905 const Twine &Name) {
906 Type *PtrTy = DerivedPtr->getType();
907 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
908 {DerivedPtr}, {}, Name);
909}
910
913 const Twine &Name) {
914 Module *M = BB->getModule();
915 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
916 return createCallHelper(Fn, {V}, Name, FMFSource);
917}
918
921 const Twine &Name) {
922 Module *M = BB->getModule();
923 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
924 if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(),
925 /*FMFSource=*/nullptr))
926 return V;
927 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
928}
929
931 ArrayRef<Type *> OverloadTypes,
934 const Twine &Name) {
935 Module *M = BB->getModule();
936 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTypes);
937 return createCallHelper(Fn, Args, Name, FMFSource);
938}
939
943 const Twine &Name) {
944 Module *M = BB->getModule();
946 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, RetTy, ArgTys);
947 return createCallHelper(Fn, Args, Name, FMFSource);
948}
949
952 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
953 std::optional<fp::ExceptionBehavior> Except) {
954 Value *RoundingV = getConstrainedFPRounding(Rounding);
955 Value *ExceptV = getConstrainedFPExcept(Except);
956
957 FastMathFlags UseFMF = FMFSource.get(FMF);
958
959 CallInst *C = CreateIntrinsic(ID, {L->getType()},
960 {L, R, RoundingV, ExceptV}, nullptr, Name);
962 setFPAttrs(C, FPMathTag, UseFMF);
963 return C;
964}
965
968 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
969 std::optional<RoundingMode> Rounding,
970 std::optional<fp::ExceptionBehavior> Except) {
971 Value *RoundingV = getConstrainedFPRounding(Rounding);
972 Value *ExceptV = getConstrainedFPExcept(Except);
973
974 FastMathFlags UseFMF = FMFSource.get(FMF);
975
976 llvm::SmallVector<Value *, 5> ExtArgs(Args);
977 ExtArgs.push_back(RoundingV);
978 ExtArgs.push_back(ExceptV);
979
980 CallInst *C = CreateIntrinsic(ID, Types, ExtArgs, nullptr, Name);
982 setFPAttrs(C, FPMathTag, UseFMF);
983 return C;
984}
985
988 const Twine &Name, MDNode *FPMathTag,
989 std::optional<fp::ExceptionBehavior> Except) {
990 Value *ExceptV = getConstrainedFPExcept(Except);
991
992 FastMathFlags UseFMF = FMFSource.get(FMF);
993
994 CallInst *C =
995 CreateIntrinsic(ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name);
997 setFPAttrs(C, FPMathTag, UseFMF);
998 return C;
999}
1000
1002 const Twine &Name, MDNode *FPMathTag) {
1004 assert(Ops.size() == 2 && "Invalid number of operands!");
1005 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
1006 Ops[0], Ops[1], Name, FPMathTag);
1007 }
1009 assert(Ops.size() == 1 && "Invalid number of operands!");
1010 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
1011 Ops[0], Name, FPMathTag);
1012 }
1013 llvm_unreachable("Unexpected opcode!");
1014}
1015
1018 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
1019 std::optional<fp::ExceptionBehavior> Except) {
1020 Value *ExceptV = getConstrainedFPExcept(Except);
1021
1022 FastMathFlags UseFMF = FMFSource.get(FMF);
1023
1024 CallInst *C;
1026 Value *RoundingV = getConstrainedFPRounding(Rounding);
1027 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
1028 nullptr, Name);
1029 } else
1030 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
1031 Name);
1032
1034
1036 setFPAttrs(C, FPMathTag, UseFMF);
1037 return C;
1038}
1039
1040Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
1041 Value *RHS, const Twine &Name,
1042 MDNode *FPMathTag, FMFSource FMFSource,
1043 bool IsSignaling) {
1044 if (IsFPConstrained) {
1045 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1046 : Intrinsic::experimental_constrained_fcmp;
1047 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1048 }
1049
1050 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1051 return V;
1052 return Insert(
1053 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1054 Name);
1055}
1056
1059 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1060 Value *PredicateV = getConstrainedFPPredicate(P);
1061 Value *ExceptV = getConstrainedFPExcept(Except);
1062
1063 CallInst *C = CreateIntrinsic(ID, {L->getType()},
1064 {L, R, PredicateV, ExceptV}, nullptr, Name);
1066 return C;
1067}
1068
1070 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1071 std::optional<RoundingMode> Rounding,
1072 std::optional<fp::ExceptionBehavior> Except) {
1073 llvm::SmallVector<Value *, 6> UseArgs(Args);
1074
1075 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1076 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1077 UseArgs.push_back(getConstrainedFPExcept(Except));
1078
1079 CallInst *C = CreateCall(Callee, UseArgs, Name);
1081 return C;
1082}
1083
1085 Value *False,
1087 const Twine &Name) {
1088 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1089 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1091 }
1092 return Ret;
1093}
1094
1096 Value *False,
1099 const Twine &Name) {
1100 Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
1101 if (auto *SI = dyn_cast<SelectInst>(Ret))
1103 return Ret;
1104}
1105
1107 const Twine &Name, Instruction *MDFrom) {
1108 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1109}
1110
1112 FMFSource FMFSource, const Twine &Name,
1113 Instruction *MDFrom) {
1114 if (auto *V = Folder.FoldSelect(C, True, False))
1115 return V;
1116
1117 SelectInst *Sel = SelectInst::Create(C, True, False);
1118 if (MDFrom) {
1119 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1120 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1121 Sel = addBranchMetadata(Sel, Prof, Unpred);
1122 }
1123 if (isa<FPMathOperator>(Sel))
1124 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1125 return Insert(Sel, Name);
1126}
1127
1129 bool IsNUW) {
1130 assert(LHS->getType() == RHS->getType() &&
1131 "Pointer subtraction operand types must match!");
1132 Value *LHSAddr = CreatePtrToAddr(LHS);
1133 Value *RHSAddr = CreatePtrToAddr(RHS);
1134 return CreateSub(LHSAddr, RHSAddr, Name, IsNUW);
1135}
1137 const Twine &Name) {
1138 const DataLayout &DL = BB->getDataLayout();
1139 TypeSize ElemSize = DL.getTypeAllocSize(ElemTy);
1140 if (ElemSize == TypeSize::getFixed(1))
1141 return CreatePtrDiff(LHS, RHS, Name);
1142
1143 Value *Diff = CreatePtrDiff(LHS, RHS);
1144 return CreateExactSDiv(Diff, CreateTypeSize(Diff->getType(), ElemSize), Name);
1145}
1146
1149 "launder.invariant.group only applies to pointers.");
1150 auto *PtrType = Ptr->getType();
1151 Module *M = BB->getParent()->getParent();
1152 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1153 M, Intrinsic::launder_invariant_group, {PtrType});
1154
1155 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1156 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1157 PtrType &&
1158 "LaunderInvariantGroup should take and return the same type");
1159
1160 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1161}
1162
1165 "strip.invariant.group only applies to pointers.");
1166
1167 auto *PtrType = Ptr->getType();
1168 Module *M = BB->getParent()->getParent();
1169 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1170 M, Intrinsic::strip_invariant_group, {PtrType});
1171
1172 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1173 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1174 PtrType &&
1175 "StripInvariantGroup should take and return the same type");
1176
1177 return CreateCall(FnStripInvariantGroup, {Ptr});
1178}
1179
1181 auto *Ty = cast<VectorType>(V->getType());
1182 if (isa<ScalableVectorType>(Ty)) {
1183 Module *M = BB->getParent()->getParent();
1184 Function *F =
1185 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1186 return Insert(CallInst::Create(F, V), Name);
1187 }
1188 // Keep the original behaviour for fixed vector
1189 SmallVector<int, 8> ShuffleMask;
1190 int NumElts = Ty->getElementCount().getKnownMinValue();
1191 for (int i = 0; i < NumElts; ++i)
1192 ShuffleMask.push_back(NumElts - i - 1);
1193 return CreateShuffleVector(V, ShuffleMask, Name);
1194}
1195
1196static SmallVector<int, 8> getSpliceMask(int64_t Imm, unsigned NumElts) {
1197 unsigned Idx = (NumElts + Imm) % NumElts;
1199 for (unsigned I = 0; I < NumElts; ++I)
1200 Mask.push_back(Idx + I);
1201 return Mask;
1202}
1203
1205 Value *Offset, const Twine &Name) {
1206 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1207 assert(V1->getType() == V2->getType() &&
1208 "Splice expects matching operand types!");
1209
1210 // Emit a shufflevector for fixed vectors with a constant offset
1211 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1212 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1213 return CreateShuffleVector(
1214 V1, V2,
1215 getSpliceMask(COffset->getZExtValue(), FVTy->getNumElements()));
1216
1217 return CreateIntrinsic(Intrinsic::vector_splice_left, V1->getType(),
1218 {V1, V2, Offset}, {}, Name);
1219}
1220
1222 Value *Offset,
1223 const Twine &Name) {
1224 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1225 assert(V1->getType() == V2->getType() &&
1226 "Splice expects matching operand types!");
1227
1228 // Emit a shufflevector for fixed vectors with a constant offset
1229 if (auto *COffset = dyn_cast<ConstantInt>(Offset))
1230 if (auto *FVTy = dyn_cast<FixedVectorType>(V1->getType()))
1231 return CreateShuffleVector(
1232 V1, V2,
1233 getSpliceMask(-COffset->getZExtValue(), FVTy->getNumElements()));
1234
1235 return CreateIntrinsic(Intrinsic::vector_splice_right, V1->getType(),
1236 {V1, V2, Offset}, {}, Name);
1237}
1238
1240 const Twine &Name) {
1241 auto EC = ElementCount::getFixed(NumElts);
1242 return CreateVectorSplat(EC, V, Name);
1243}
1244
1246 const Twine &Name) {
1247 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1248
1249 // First insert it into a poison vector so we can shuffle it.
1250 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1251 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1252
1253 // Shuffle the value across the desired number of elements.
1255 Zeros.resize(EC.getKnownMinValue());
1256 return CreateShuffleVector(V, Zeros, Name + ".splat");
1257}
1258
1260 const Twine &Name) {
1261 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1262 "Unexpected number of operands to interleave");
1263
1264 // Make sure all operands are the same type.
1265 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1266
1267#ifndef NDEBUG
1268 for (unsigned I = 1; I < Ops.size(); I++) {
1269 assert(Ops[I]->getType() == Ops[0]->getType() &&
1270 "Vector interleave expects matching operand types!");
1271 }
1272#endif
1273
1274 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1275 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1276 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1277 SubvecTy->getElementCount() * Ops.size());
1278 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1279}
1280
1282 unsigned Dimension,
1283 unsigned LastIndex,
1284 MDNode *DbgInfo) {
1285 auto *BaseType = Base->getType();
1287 "Invalid Base ptr type for preserve.array.access.index.");
1288
1289 Value *LastIndexV = getInt32(LastIndex);
1290 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1291 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1292 IdxList.push_back(LastIndexV);
1293
1294 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1295
1296 Value *DimV = getInt32(Dimension);
1297 CallInst *Fn =
1298 CreateIntrinsic(Intrinsic::preserve_array_access_index,
1299 {ResultType, BaseType}, {Base, DimV, LastIndexV});
1300 Fn->addParamAttr(
1301 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1302 if (DbgInfo)
1303 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1304
1305 return Fn;
1306}
1307
1309 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1310 assert(isa<PointerType>(Base->getType()) &&
1311 "Invalid Base ptr type for preserve.union.access.index.");
1312 auto *BaseType = Base->getType();
1313
1314 Value *DIIndex = getInt32(FieldIndex);
1315 CallInst *Fn = CreateIntrinsic(Intrinsic::preserve_union_access_index,
1316 {BaseType, BaseType}, {Base, DIIndex});
1317 if (DbgInfo)
1318 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1319
1320 return Fn;
1321}
1322
1324 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1325 MDNode *DbgInfo) {
1326 auto *BaseType = Base->getType();
1328 "Invalid Base ptr type for preserve.struct.access.index.");
1329
1330 Value *GEPIndex = getInt32(Index);
1331 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1332 Type *ResultType =
1333 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1334
1335 Value *DIIndex = getInt32(FieldIndex);
1336 CallInst *Fn =
1337 CreateIntrinsic(Intrinsic::preserve_struct_access_index,
1338 {ResultType, BaseType}, {Base, GEPIndex, DIIndex});
1339 Fn->addParamAttr(
1340 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1341 if (DbgInfo)
1342 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1343
1344 return Fn;
1345}
1346
1348 ConstantInt *TestV = getInt32(Test);
1349 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1350 {FPNum, TestV});
1351}
1352
1353CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1354 Value *PtrValue,
1355 Value *AlignValue,
1356 Value *OffsetValue) {
1357 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1358 if (OffsetValue)
1359 Vals.push_back(OffsetValue);
1360 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1361 return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1362}
1363
1365 Value *PtrValue,
1366 unsigned Alignment,
1367 Value *OffsetValue) {
1368 assert(isa<PointerType>(PtrValue->getType()) &&
1369 "trying to create an alignment assumption on a non-pointer?");
1370 assert(Alignment != 0 && "Invalid Alignment");
1371 auto *PtrTy = cast<PointerType>(PtrValue->getType());
1372 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1373 Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1374 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1375}
1376
1378 Value *PtrValue,
1379 Value *Alignment,
1380 Value *OffsetValue) {
1381 assert(isa<PointerType>(PtrValue->getType()) &&
1382 "trying to create an alignment assumption on a non-pointer?");
1383 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1384}
1385
1387 Value *SizeValue) {
1388 assert(isa<PointerType>(PtrValue->getType()) &&
1389 "trying to create a deferenceable assumption on a non-pointer?");
1390 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1391 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1393 {DereferenceableOpB});
1394}
1395
1397 assert(isa<PointerType>(PtrValue->getType()) &&
1398 "trying to create a nonnull assumption on a non-pointer?");
1400 OperandBundleDef("nonnull", PtrValue));
1401}
1402
1406void ConstantFolder::anchor() {}
1407void NoFolder::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isConstantOne(const Value *Val)
isConstantOne - Return true only if val is constant int 1
static InvokeInst * CreateGCStatepointInvokeCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, ArrayRef< T0 > InvokeArgs, std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
static CallInst * CreateGCStatepointCallCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs, std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
static Value * CreateVScaleMultiple(IRBuilderBase &B, Type *Ty, uint64_t Scale)
static std::vector< OperandBundleDef > getStatepointBundles(std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs)
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs)
static SmallVector< int, 8 > getSpliceMask(int64_t Imm, unsigned NumElts)
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
This file defines less commonly used SmallVector utilities.
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static const char PassName[]
Value * RHS
Value * LHS
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
const Value * getArraySize() const
Get the number of elements allocated.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:39
size_t size() const
Get the array size.
Definition ArrayRef.h:140
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
void setCallingConv(CallingConv::ID CC)
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, 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:123
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
This instruction compares its operands according to the predicate given to the constructor.
This provides a helper for copying FMF from an instruction or setting specified flags.
Definition IRBuilder.h:93
FastMathFlags get(FastMathFlags Default) const
Definition IRBuilder.h:103
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h: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.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:211
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:216
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1516
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition IRBuilder.h:504
BasicBlock * BB
Definition IRBuilder.h:146
LLVM_ABI CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
LLVM_ABI Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
CallInst * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Definition IRBuilder.h:1134
LLVM_ABI Value * CreateSelectFMFWithUnknownProfile(Value *C, Value *True, Value *False, FMFSource FMFSource, StringRef PassName, const Twine &Name="")
LLVM_ABI CallInst * CreateConstrainedFPUnroundedBinOp(Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2622
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:571
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:2676
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.
CallInst * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Definition IRBuilder.h:1148
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 * 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:2133
LLVM_ABI CallInst * CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, const Twine &Name="", std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVM_ABI Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles={})
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Value * CreatePtrToAddr(Value *V, const Twine &Name="")
Definition IRBuilder.h:2223
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:2669
LLVM_ABI Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
LLVM_ABI CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
LLVM_ABI CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
LLVM_ABI CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVMContext & Context
Definition IRBuilder.h:148
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI CallInst * CreateGCGetPointerOffset(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.get.pointer.offset intrinsic to get the offset of the specified ...
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2232
LLVM_ABI CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateConstrainedFPBinOp(Intrinsic::ID ID, Value *L, Value *R, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type of an integer with size at least as big as that of a pointer in the given address spac...
Definition IRBuilder.h:641
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
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition IRBuilder.h:591
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memmove between the specified pointers.
LLVM_ABI Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
LLVM_ABI CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
FastMathFlags FMF
Definition IRBuilder.h:153
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:534
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:892
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1865
LLVM_ABI CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using OverloadTypes.
LLVM_ABI CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
LLVM_ABI Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
LLVM_ABI Value * createIsFPClass(Value *FPNum, unsigned Test)
LLVM_ABI CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:529
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:2319
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition IRBuilder.h:172
LLVM_ABI DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition IRBuilder.cpp:65
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1460
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2237
LLVM_ABI Value * CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name="", bool IsNUW=false)
Return the difference between two pointer values.
LLVM_ABI CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition IRBuilder.h:681
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:660
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:2644
LLVMContext & getContext() const
Definition IRBuilder.h:203
LLVM_ABI Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
LLVM_ABI CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
LLVM_ABI Value * CreateSelectWithUnknownProfile(Value *C, Value *True, Value *False, StringRef PassName, const Twine &Name="")
LLVM_ABI CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2227
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2548
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:2101
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1748
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:2310
LLVM_ABI CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, const AAMDNodes &AAInfo=AAMDNodes())
Create and insert an element unordered-atomic memcpy between the specified pointers.
void setConstrainedFPCallAttr(CallBase *I)
Definition IRBuilder.h:402
LLVM_ABI InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
LLVM_ABI CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
const IRBuilderFolder & Folder
Definition IRBuilder.h:149
LLVM_ABI CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI Value * CreateVectorInterleave(ArrayRef< Value * > Ops, const Twine &Name="")
LLVM_ABI CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition IRBuilder.cpp:66
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:576
LLVM_ABI CallInst * CreateGCRelocate(Instruction *Statepoint, int BaseOffset, int DerivedOffset, Type *ResultType, const Twine &Name="")
Create a call to the experimental.gc.relocate intrinsics to project the relocated value of one pointe...
LLVM_ABI Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
LLVM_ABI Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
LLVM_ABI CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1477
LLVM_ABI Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
LLVM_ABI CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
LLVM_ABI GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr, bool AddNull=true)
Make a new global variable with initializer type i8*.
Definition IRBuilder.cpp: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 * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
LLVM_ABI CallInst * CreateConstrainedFPCast(Intrinsic::ID ID, Value *V, Type *DestTy, FMFSource FMFSource={}, const Twine &Name="", MDNode *FPMathTag=nullptr, std::optional< RoundingMode > Rounding=std::nullopt, std::optional< fp::ExceptionBehavior > Except=std::nullopt)
LLVM_ABI Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
LLVM_ABI CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
virtual Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
virtual ~IRBuilderFolder()
LLVM_ABI void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
bool isBinaryOp() const
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool isUnaryOp() const
Invoke instruction.
Metadata node.
Definition Metadata.h:1080
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents the LLVM 'select' instruction.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
void 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:55
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:290
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition Type.h:281
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:313
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:427
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:286
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
bool isStructTy() const
True if this is an instance of StructType.
Definition Type.h:278
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:236
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition Type.h:287
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI 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.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
MaybeAlign getAlign(const CallInst &I, unsigned Index)
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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:2207
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
OperandBundleDefT< Value * > OperandBundleDef
Definition AutoUpgrade.h:34
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