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