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"
29#include "llvm/IR/Statepoint.h"
30#include "llvm/IR/Type.h"
31#include "llvm/IR/Value.h"
33#include <cassert>
34#include <cstdint>
35#include <optional>
36#include <vector>
37
38using namespace llvm;
39
40/// CreateGlobalString - Make a new global variable with an initializer that
41/// has array of i8 type filled in with the nul terminated string value
42/// specified. If Name is specified, it is the name of the global variable
43/// created.
45 const Twine &Name,
46 unsigned AddressSpace,
47 Module *M, bool AddNull) {
48 Constant *StrConstant = ConstantDataArray::getString(Context, Str, AddNull);
49 if (!M)
50 M = BB->getParent()->getParent();
51 auto *GV = new GlobalVariable(
52 *M, StrConstant->getType(), true, GlobalValue::PrivateLinkage,
53 StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace);
54 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
55 GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty()));
56 return GV;
57}
58
60 assert(BB && BB->getParent() && "No current function!");
61 return BB->getParent()->getReturnType();
62}
63
66 // We prefer to set our current debug location if any has been set, but if
67 // our debug location is empty and I has a valid location, we shouldn't
68 // overwrite it.
69 I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
70}
71
73 Type *SrcTy = V->getType();
74 if (SrcTy == DestTy)
75 return V;
76
77 if (SrcTy->isAggregateType()) {
78 unsigned NumElements;
79 if (SrcTy->isStructTy()) {
80 assert(DestTy->isStructTy() && "Expected StructType");
81 assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements() &&
82 "Expected StructTypes with equal number of elements");
83 NumElements = SrcTy->getStructNumElements();
84 } else {
85 assert(SrcTy->isArrayTy() && DestTy->isArrayTy() && "Expected ArrayType");
86 assert(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements() &&
87 "Expected ArrayTypes with equal number of elements");
88 NumElements = SrcTy->getArrayNumElements();
89 }
90
91 Value *Result = PoisonValue::get(DestTy);
92 for (unsigned I = 0; I < NumElements; ++I) {
93 Type *ElementTy = SrcTy->isStructTy() ? DestTy->getStructElementType(I)
94 : DestTy->getArrayElementType();
95 Value *Element =
97
98 Result = CreateInsertValue(Result, Element, ArrayRef(I));
99 }
100 return Result;
101 }
102
103 return CreateBitOrPointerCast(V, DestTy);
104}
105
106CallInst *
107IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
108 const Twine &Name, FMFSource FMFSource,
109 ArrayRef<OperandBundleDef> OpBundles) {
110 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
111 if (isa<FPMathOperator>(CI))
113 return CI;
114}
115
117 Value *VScale = B.CreateVScale(Ty);
118 if (Scale == 1)
119 return VScale;
120
121 return B.CreateNUWMul(VScale, ConstantInt::get(Ty, Scale));
122}
123
125 if (EC.isFixed() || EC.isZero())
126 return ConstantInt::get(Ty, EC.getKnownMinValue());
127
128 return CreateVScaleMultiple(*this, Ty, EC.getKnownMinValue());
129}
130
132 if (Size.isFixed() || Size.isZero())
133 return ConstantInt::get(Ty, Size.getKnownMinValue());
134
135 return CreateVScaleMultiple(*this, Ty, Size.getKnownMinValue());
136}
137
139 Type *STy = DstType->getScalarType();
140 if (isa<ScalableVectorType>(DstType)) {
141 Type *StepVecType = DstType;
142 // TODO: We expect this special case (element type < 8 bits) to be
143 // temporary - once the intrinsic properly supports < 8 bits this code
144 // can be removed.
145 if (STy->getScalarSizeInBits() < 8)
146 StepVecType =
148 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
149 nullptr, Name);
150 if (StepVecType != DstType)
151 Res = CreateTrunc(Res, DstType);
152 return Res;
153 }
154
155 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
156
157 // Create a vector of consecutive numbers from zero to VF.
159 for (unsigned i = 0; i < NumEls; ++i)
160 Indices.push_back(ConstantInt::get(STy, i));
161
162 // Add the consecutive indices to the vector value.
163 return ConstantVector::get(Indices);
164}
165
167 MaybeAlign Align, bool isVolatile,
168 const AAMDNodes &AAInfo) {
169 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
170 Type *Tys[] = {Ptr->getType(), Size->getType()};
171
172 CallInst *CI = CreateIntrinsic(Intrinsic::memset, Tys, Ops);
173
174 if (Align)
175 cast<MemSetInst>(CI)->setDestAlignment(*Align);
176 CI->setAAMetadata(AAInfo);
177 return CI;
178}
179
181 Value *Val, Value *Size,
182 bool IsVolatile,
183 const AAMDNodes &AAInfo) {
184 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
185 Type *Tys[] = {Dst->getType(), Size->getType()};
186
187 CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);
188
189 if (DstAlign)
190 cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);
191 CI->setAAMetadata(AAInfo);
192 return CI;
193}
194
196 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
197 const AAMDNodes &AAInfo) {
198
199 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
200 Type *Tys[] = {Ptr->getType(), Size->getType()};
201
202 CallInst *CI =
203 CreateIntrinsic(Intrinsic::memset_element_unordered_atomic, Tys, Ops);
204
205 cast<AnyMemSetInst>(CI)->setDestAlignment(Alignment);
206 CI->setAAMetadata(AAInfo);
207 return CI;
208}
209
211 MaybeAlign DstAlign, Value *Src,
212 MaybeAlign SrcAlign, Value *Size,
213 bool isVolatile,
214 const AAMDNodes &AAInfo) {
215 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
216 IntrID == Intrinsic::memmove) &&
217 "Unexpected intrinsic ID");
218 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
219 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
220
221 CallInst *CI = CreateIntrinsic(IntrID, Tys, Ops);
222
223 auto* MCI = cast<MemTransferInst>(CI);
224 if (DstAlign)
225 MCI->setDestAlignment(*DstAlign);
226 if (SrcAlign)
227 MCI->setSourceAlignment(*SrcAlign);
228 MCI->setAAMetadata(AAInfo);
229 return CI;
230}
231
233 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
234 uint32_t ElementSize, const AAMDNodes &AAInfo) {
235 assert(DstAlign >= ElementSize &&
236 "Pointer alignment must be at least element size");
237 assert(SrcAlign >= ElementSize &&
238 "Pointer alignment must be at least element size");
239 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
240 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
241
242 CallInst *CI =
243 CreateIntrinsic(Intrinsic::memcpy_element_unordered_atomic, Tys, Ops);
244
245 // Set the alignment of the pointer args.
246 auto *AMCI = cast<AnyMemCpyInst>(CI);
247 AMCI->setDestAlignment(DstAlign);
248 AMCI->setSourceAlignment(SrcAlign);
249 AMCI->setAAMetadata(AAInfo);
250 return CI;
251}
252
253/// isConstantOne - Return true only if val is constant int 1
254static bool isConstantOne(const Value *Val) {
255 assert(Val && "isConstantOne does not work with nullptr Val");
256 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
257 return CVal && CVal->isOne();
258}
259
261 Value *AllocSize, Value *ArraySize,
263 Function *MallocF, const Twine &Name) {
264 // malloc(type) becomes:
265 // i8* malloc(typeSize)
266 // malloc(type, arraySize) becomes:
267 // i8* malloc(typeSize*arraySize)
268 if (!ArraySize)
269 ArraySize = ConstantInt::get(IntPtrTy, 1);
270 else if (ArraySize->getType() != IntPtrTy)
271 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
272
273 if (!isConstantOne(ArraySize)) {
274 if (isConstantOne(AllocSize)) {
275 AllocSize = ArraySize; // Operand * 1 = Operand
276 } else {
277 // Multiply type size by the array size...
278 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
279 }
280 }
281
282 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
283 // Create the call to Malloc.
284 Module *M = BB->getParent()->getParent();
286 FunctionCallee MallocFunc = MallocF;
287 if (!MallocFunc)
288 // prototype malloc as "void *malloc(size_t)"
289 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
290 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
291
292 MCall->setTailCall();
293 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
294 MCall->setCallingConv(F->getCallingConv());
295 F->setReturnDoesNotAlias();
296 }
297
298 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
299
300 return MCall;
301}
302
304 Value *AllocSize, Value *ArraySize,
305 Function *MallocF, const Twine &Name) {
306
307 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
308 Name);
309}
310
311/// CreateFree - Generate the IR for a call to the builtin free function.
314 assert(Source->getType()->isPointerTy() &&
315 "Can not free something of nonpointer type!");
316
317 Module *M = BB->getParent()->getParent();
318
319 Type *VoidTy = Type::getVoidTy(M->getContext());
320 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
321 // prototype free as "void free(void*)"
322 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
323 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
324 Result->setTailCall();
325 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
326 Result->setCallingConv(F->getCallingConv());
327
328 return Result;
329}
330
332 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
333 uint32_t ElementSize, const AAMDNodes &AAInfo) {
334 assert(DstAlign >= ElementSize &&
335 "Pointer alignment must be at least element size");
336 assert(SrcAlign >= ElementSize &&
337 "Pointer alignment must be at least element size");
338 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
339 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
340
341 CallInst *CI =
342 CreateIntrinsic(Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
343
344 // Set the alignment of the pointer args.
345 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
346 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
347 CI->setAAMetadata(AAInfo);
348 return CI;
349}
350
351CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
352 Value *Ops[] = {Src};
353 Type *Tys[] = { Src->getType() };
354 return CreateIntrinsic(ID, Tys, Ops);
355}
356
358 Value *Ops[] = {Acc, Src};
359 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
360}
361
363 Value *Ops[] = {Acc, Src};
364 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
365}
366
368 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
369}
370
372 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
373}
374
376 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
377}
378
380 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
381}
382
384 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
385}
386
388 auto ID =
389 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
390 return getReductionIntrinsic(ID, Src);
391}
392
394 auto ID =
395 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
396 return getReductionIntrinsic(ID, Src);
397}
398
400 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
401}
402
404 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
405}
406
408 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
409}
410
412 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
413}
414
416 assert(isa<PointerType>(Ptr->getType()) &&
417 "lifetime.start only applies to pointers.");
418 return CreateIntrinsic(Intrinsic::lifetime_start, {Ptr->getType()}, {Ptr});
419}
420
422 assert(isa<PointerType>(Ptr->getType()) &&
423 "lifetime.end only applies to pointers.");
424 return CreateIntrinsic(Intrinsic::lifetime_end, {Ptr->getType()}, {Ptr});
425}
426
428
429 assert(isa<PointerType>(Ptr->getType()) &&
430 "invariant.start only applies to pointers.");
431 if (!Size)
432 Size = getInt64(-1);
433 else
434 assert(Size->getType() == getInt64Ty() &&
435 "invariant.start requires the size to be an i64");
436
437 Value *Ops[] = {Size, Ptr};
438 // Fill in the single overloaded type: memory object type.
439 Type *ObjectPtr[1] = {Ptr->getType()};
440 return CreateIntrinsic(Intrinsic::invariant_start, ObjectPtr, Ops);
441}
442
444 if (auto *V = dyn_cast<GlobalVariable>(Ptr))
445 return V->getAlign();
446 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
447 return getAlign(A->getAliaseeObject());
448 return {};
449}
450
452 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
453 "threadlocal_address only applies to thread local variables.");
454 CallInst *CI = CreateIntrinsic(llvm::Intrinsic::threadlocal_address,
455 {Ptr->getType()}, {Ptr});
456 if (MaybeAlign A = getAlign(Ptr)) {
459 }
460 return CI;
461}
462
463CallInst *
465 ArrayRef<OperandBundleDef> OpBundles) {
466 assert(Cond->getType() == getInt1Ty() &&
467 "an assumption condition must be of type i1");
468
469 Value *Ops[] = { Cond };
470 Module *M = BB->getParent()->getParent();
471 Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
472 return CreateCall(FnAssume, Ops, OpBundles);
473}
474
476 return CreateIntrinsic(Intrinsic::experimental_noalias_scope_decl, {},
477 {Scope});
478}
479
480/// Create a call to a Masked Load intrinsic.
481/// \p Ty - vector type to load
482/// \p Ptr - base pointer for the load
483/// \p Alignment - alignment of the source location
484/// \p Mask - vector of booleans which indicates what vector lanes should
485/// be accessed in memory
486/// \p PassThru - pass-through value that is used to fill the masked-off lanes
487/// of the result
488/// \p Name - name of the result variable
490 Value *Mask, Value *PassThru,
491 const Twine &Name) {
492 auto *PtrTy = cast<PointerType>(Ptr->getType());
493 assert(Ty->isVectorTy() && "Type should be vector");
494 assert(Mask && "Mask should not be all-ones (null)");
495 if (!PassThru)
496 PassThru = PoisonValue::get(Ty);
497 Type *OverloadedTypes[] = { Ty, PtrTy };
498 Value *Ops[] = {Ptr, Mask, PassThru};
499 CallInst *CI =
500 CreateMaskedIntrinsic(Intrinsic::masked_load, Ops, OverloadedTypes, Name);
501 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
502 return CI;
503}
504
505/// Create a call to a Masked Store intrinsic.
506/// \p Val - data to be stored,
507/// \p Ptr - base pointer for the store
508/// \p Alignment - alignment of the destination location
509/// \p Mask - vector of booleans which indicates what vector lanes should
510/// be accessed in memory
512 Align Alignment, Value *Mask) {
513 auto *PtrTy = cast<PointerType>(Ptr->getType());
514 Type *DataTy = Val->getType();
515 assert(DataTy->isVectorTy() && "Val should be a vector");
516 assert(Mask && "Mask should not be all-ones (null)");
517 Type *OverloadedTypes[] = { DataTy, PtrTy };
518 Value *Ops[] = {Val, Ptr, Mask};
519 CallInst *CI =
520 CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
521 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
522 return CI;
523}
524
525/// Create a call to a Masked intrinsic, with given intrinsic Id,
526/// an array of operands - Ops, and an array of overloaded types -
527/// OverloadedTypes.
528CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
530 ArrayRef<Type *> OverloadedTypes,
531 const Twine &Name) {
532 return CreateIntrinsic(Id, OverloadedTypes, Ops, {}, Name);
533}
534
535/// Create a call to a Masked Gather intrinsic.
536/// \p Ty - vector type to gather
537/// \p Ptrs - vector of pointers for loading
538/// \p Align - alignment for one element
539/// \p Mask - vector of booleans which indicates what vector lanes should
540/// be accessed in memory
541/// \p PassThru - pass-through value that is used to fill the masked-off lanes
542/// of the result
543/// \p Name - name of the result variable
545 Align Alignment, Value *Mask,
546 Value *PassThru,
547 const Twine &Name) {
548 auto *VecTy = cast<VectorType>(Ty);
549 ElementCount NumElts = VecTy->getElementCount();
550 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
551 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
552
553 if (!Mask)
554 Mask = getAllOnesMask(NumElts);
555
556 if (!PassThru)
557 PassThru = PoisonValue::get(Ty);
558
559 Type *OverloadedTypes[] = {Ty, PtrsTy};
560 Value *Ops[] = {Ptrs, Mask, PassThru};
561
562 // We specify only one type when we create this intrinsic. Types of other
563 // arguments are derived from this type.
564 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops,
565 OverloadedTypes, Name);
566 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), Alignment));
567 return CI;
568}
569
570/// Create a call to a Masked Scatter intrinsic.
571/// \p Data - data to be stored,
572/// \p Ptrs - the vector of pointers, where the \p Data elements should be
573/// stored
574/// \p Align - alignment for one element
575/// \p Mask - vector of booleans which indicates what vector lanes should
576/// be accessed in memory
578 Align Alignment, Value *Mask) {
579 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
580 auto *DataTy = cast<VectorType>(Data->getType());
581 ElementCount NumElts = PtrsTy->getElementCount();
582
583 if (!Mask)
584 Mask = getAllOnesMask(NumElts);
585
586 Type *OverloadedTypes[] = {DataTy, PtrsTy};
587 Value *Ops[] = {Data, Ptrs, Mask};
588
589 // We specify only one type when we create this intrinsic. Types of other
590 // arguments are derived from this type.
591 CallInst *CI =
592 CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
593 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), Alignment));
594 return CI;
595}
596
597/// Create a call to Masked Expand Load intrinsic
598/// \p Ty - vector type to load
599/// \p Ptr - base pointer for the load
600/// \p Align - alignment of \p Ptr
601/// \p Mask - vector of booleans which indicates what vector lanes should
602/// be accessed in memory
603/// \p PassThru - pass-through value that is used to fill the masked-off lanes
604/// of the result
605/// \p Name - name of the result variable
607 MaybeAlign Align, Value *Mask,
608 Value *PassThru,
609 const Twine &Name) {
610 assert(Ty->isVectorTy() && "Type should be vector");
611 assert(Mask && "Mask should not be all-ones (null)");
612 if (!PassThru)
613 PassThru = PoisonValue::get(Ty);
614 Type *OverloadedTypes[] = {Ty};
615 Value *Ops[] = {Ptr, Mask, PassThru};
616 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
617 OverloadedTypes, Name);
618 if (Align)
620 return CI;
621}
622
623/// Create a call to Masked Compress Store intrinsic
624/// \p Val - data to be stored,
625/// \p Ptr - base pointer for the store
626/// \p Align - alignment of \p Ptr
627/// \p Mask - vector of booleans which indicates what vector lanes should
628/// be accessed in memory
631 Value *Mask) {
632 Type *DataTy = Val->getType();
633 assert(DataTy->isVectorTy() && "Val should be a vector");
634 assert(Mask && "Mask should not be all-ones (null)");
635 Type *OverloadedTypes[] = {DataTy};
636 Value *Ops[] = {Val, Ptr, Mask};
637 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
638 OverloadedTypes);
639 if (Align)
641 return CI;
642}
643
644template <typename T0>
645static std::vector<Value *>
647 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
648 std::vector<Value *> Args;
649 Args.push_back(B.getInt64(ID));
650 Args.push_back(B.getInt32(NumPatchBytes));
651 Args.push_back(ActualCallee);
652 Args.push_back(B.getInt32(CallArgs.size()));
653 Args.push_back(B.getInt32(Flags));
654 llvm::append_range(Args, CallArgs);
655 // GC Transition and Deopt args are now always handled via operand bundle.
656 // They will be removed from the signature of gc.statepoint shortly.
657 Args.push_back(B.getInt32(0));
658 Args.push_back(B.getInt32(0));
659 // GC args are now encoded in the gc-live operand bundle
660 return Args;
661}
662
663template<typename T1, typename T2, typename T3>
664static std::vector<OperandBundleDef>
665getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
666 std::optional<ArrayRef<T2>> DeoptArgs,
667 ArrayRef<T3> GCArgs) {
668 std::vector<OperandBundleDef> Rval;
669 if (DeoptArgs)
670 Rval.emplace_back("deopt", SmallVector<Value *, 16>(*DeoptArgs));
671 if (TransitionArgs)
672 Rval.emplace_back("gc-transition",
673 SmallVector<Value *, 16>(*TransitionArgs));
674 if (GCArgs.size())
675 Rval.emplace_back("gc-live", SmallVector<Value *, 16>(GCArgs));
676 return Rval;
677}
678
679template <typename T0, typename T1, typename T2, typename T3>
681 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
682 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
683 std::optional<ArrayRef<T1>> TransitionArgs,
684 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
685 const Twine &Name) {
686 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
687 // Fill in the one generic type'd argument (the function is also vararg)
689 M, Intrinsic::experimental_gc_statepoint,
690 {ActualCallee.getCallee()->getType()});
691
692 std::vector<Value *> Args = getStatepointArgs(
693 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
694
695 CallInst *CI = Builder->CreateCall(
696 FnStatepoint, Args,
697 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
698 CI->addParamAttr(2,
699 Attribute::get(Builder->getContext(), Attribute::ElementType,
700 ActualCallee.getFunctionType()));
701 return CI;
702}
703
705 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
706 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
707 ArrayRef<Value *> GCArgs, const Twine &Name) {
709 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
710 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
711}
712
714 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
715 uint32_t Flags, ArrayRef<Value *> CallArgs,
716 std::optional<ArrayRef<Use>> TransitionArgs,
717 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
718 const Twine &Name) {
720 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
721 DeoptArgs, GCArgs, Name);
722}
723
725 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
726 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
727 ArrayRef<Value *> GCArgs, const Twine &Name) {
729 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
730 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
731}
732
733template <typename T0, typename T1, typename T2, typename T3>
735 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
736 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
737 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
738 std::optional<ArrayRef<T1>> TransitionArgs,
739 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
740 const Twine &Name) {
741 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
742 // Fill in the one generic type'd argument (the function is also vararg)
744 M, Intrinsic::experimental_gc_statepoint,
745 {ActualInvokee.getCallee()->getType()});
746
747 std::vector<Value *> Args =
748 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
749 Flags, InvokeArgs);
750
751 InvokeInst *II = Builder->CreateInvoke(
752 FnStatepoint, NormalDest, UnwindDest, Args,
753 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
754 II->addParamAttr(2,
755 Attribute::get(Builder->getContext(), Attribute::ElementType,
756 ActualInvokee.getFunctionType()));
757 return II;
758}
759
761 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
762 BasicBlock *NormalDest, BasicBlock *UnwindDest,
763 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
764 ArrayRef<Value *> GCArgs, const Twine &Name) {
766 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
767 uint32_t(StatepointFlags::None), InvokeArgs,
768 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
769}
770
772 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
773 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
774 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
775 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
776 const Twine &Name) {
778 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
779 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
780}
781
783 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
784 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
785 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
786 const Twine &Name) {
788 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
789 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
790 GCArgs, Name);
791}
792
794 Type *ResultType, const Twine &Name) {
795 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
796 Type *Types[] = {ResultType};
797
798 Value *Args[] = {Statepoint};
799 return CreateIntrinsic(ID, Types, Args, {}, Name);
800}
801
803 int BaseOffset, int DerivedOffset,
804 Type *ResultType, const Twine &Name) {
805 Type *Types[] = {ResultType};
806
807 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
808 return CreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
809 Name);
810}
811
813 const Twine &Name) {
814 Type *PtrTy = DerivedPtr->getType();
815 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_base,
816 {PtrTy, PtrTy}, {DerivedPtr}, {}, Name);
817}
818
820 const Twine &Name) {
821 Type *PtrTy = DerivedPtr->getType();
822 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
823 {DerivedPtr}, {}, Name);
824}
825
828 const Twine &Name) {
829 Module *M = BB->getModule();
830 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
831 return createCallHelper(Fn, {V}, Name, FMFSource);
832}
833
836 const Twine &Name) {
837 Module *M = BB->getModule();
838 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
839 if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(),
840 /*FMFSource=*/nullptr))
841 return V;
842 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
843}
844
846 ArrayRef<Type *> Types,
849 const Twine &Name) {
850 Module *M = BB->getModule();
852 return createCallHelper(Fn, Args, Name, FMFSource);
853}
854
858 const Twine &Name) {
859 Module *M = BB->getModule();
860
864
865 SmallVector<Type *> ArgTys;
866 ArgTys.reserve(Args.size());
867 for (auto &I : Args)
868 ArgTys.push_back(I->getType());
869 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, false);
870 SmallVector<Type *> OverloadTys;
872 matchIntrinsicSignature(FTy, TableRef, OverloadTys);
873 (void)Res;
875 "Wrong types for intrinsic!");
876 // TODO: Handle varargs intrinsics.
877
878 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTys);
879 return createCallHelper(Fn, Args, Name, FMFSource);
880}
881
884 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
885 std::optional<fp::ExceptionBehavior> Except) {
886 Value *RoundingV = getConstrainedFPRounding(Rounding);
887 Value *ExceptV = getConstrainedFPExcept(Except);
888
889 FastMathFlags UseFMF = FMFSource.get(FMF);
890
891 CallInst *C = CreateIntrinsic(ID, {L->getType()},
892 {L, R, RoundingV, ExceptV}, nullptr, Name);
894 setFPAttrs(C, FPMathTag, UseFMF);
895 return C;
896}
897
900 FMFSource FMFSource, const Twine &Name, MDNode *FPMathTag,
901 std::optional<RoundingMode> Rounding,
902 std::optional<fp::ExceptionBehavior> Except) {
903 Value *RoundingV = getConstrainedFPRounding(Rounding);
904 Value *ExceptV = getConstrainedFPExcept(Except);
905
906 FastMathFlags UseFMF = FMFSource.get(FMF);
907
908 llvm::SmallVector<Value *, 5> ExtArgs(Args);
909 ExtArgs.push_back(RoundingV);
910 ExtArgs.push_back(ExceptV);
911
912 CallInst *C = CreateIntrinsic(ID, Types, ExtArgs, nullptr, Name);
914 setFPAttrs(C, FPMathTag, UseFMF);
915 return C;
916}
917
920 const Twine &Name, MDNode *FPMathTag,
921 std::optional<fp::ExceptionBehavior> Except) {
922 Value *ExceptV = getConstrainedFPExcept(Except);
923
924 FastMathFlags UseFMF = FMFSource.get(FMF);
925
926 CallInst *C =
927 CreateIntrinsic(ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name);
929 setFPAttrs(C, FPMathTag, UseFMF);
930 return C;
931}
932
934 const Twine &Name, MDNode *FPMathTag) {
936 assert(Ops.size() == 2 && "Invalid number of operands!");
937 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
938 Ops[0], Ops[1], Name, FPMathTag);
939 }
941 assert(Ops.size() == 1 && "Invalid number of operands!");
942 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
943 Ops[0], Name, FPMathTag);
944 }
945 llvm_unreachable("Unexpected opcode!");
946}
947
950 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
951 std::optional<fp::ExceptionBehavior> Except) {
952 Value *ExceptV = getConstrainedFPExcept(Except);
953
954 FastMathFlags UseFMF = FMFSource.get(FMF);
955
956 CallInst *C;
958 Value *RoundingV = getConstrainedFPRounding(Rounding);
959 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
960 nullptr, Name);
961 } else
962 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
963 Name);
964
966
968 setFPAttrs(C, FPMathTag, UseFMF);
969 return C;
970}
971
972Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
973 Value *RHS, const Twine &Name,
974 MDNode *FPMathTag, FMFSource FMFSource,
975 bool IsSignaling) {
976 if (IsFPConstrained) {
977 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
978 : Intrinsic::experimental_constrained_fcmp;
979 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
980 }
981
982 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
983 return V;
984 return Insert(
985 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
986 Name);
987}
988
991 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
992 Value *PredicateV = getConstrainedFPPredicate(P);
993 Value *ExceptV = getConstrainedFPExcept(Except);
994
995 CallInst *C = CreateIntrinsic(ID, {L->getType()},
996 {L, R, PredicateV, ExceptV}, nullptr, Name);
998 return C;
999}
1000
1002 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1003 std::optional<RoundingMode> Rounding,
1004 std::optional<fp::ExceptionBehavior> Except) {
1005 llvm::SmallVector<Value *, 6> UseArgs(Args);
1006
1007 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1008 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1009 UseArgs.push_back(getConstrainedFPExcept(Except));
1010
1011 CallInst *C = CreateCall(Callee, UseArgs, Name);
1013 return C;
1014}
1015
1017 Value *False,
1019 const Twine &Name) {
1020 Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1021 if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1023 *SI, *SI->getParent()->getParent(), PassName);
1024 }
1025 return Ret;
1026}
1027
1029 const Twine &Name, Instruction *MDFrom) {
1030 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1031}
1032
1034 FMFSource FMFSource, const Twine &Name,
1035 Instruction *MDFrom) {
1036 if (auto *V = Folder.FoldSelect(C, True, False))
1037 return V;
1038
1039 SelectInst *Sel = SelectInst::Create(C, True, False);
1040 if (MDFrom) {
1041 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1042 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1043 Sel = addBranchMetadata(Sel, Prof, Unpred);
1044 }
1045 if (isa<FPMathOperator>(Sel))
1046 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1047 return Insert(Sel, Name);
1048}
1049
1051 const Twine &Name) {
1052 assert(LHS->getType() == RHS->getType() &&
1053 "Pointer subtraction operand types must match!");
1054 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1055 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1056 Value *Difference = CreateSub(LHS_int, RHS_int);
1057 return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ElemTy),
1058 Name);
1059}
1060
1062 assert(isa<PointerType>(Ptr->getType()) &&
1063 "launder.invariant.group only applies to pointers.");
1064 auto *PtrType = Ptr->getType();
1065 Module *M = BB->getParent()->getParent();
1066 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1067 M, Intrinsic::launder_invariant_group, {PtrType});
1068
1069 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1070 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1071 PtrType &&
1072 "LaunderInvariantGroup should take and return the same type");
1073
1074 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1075}
1076
1078 assert(isa<PointerType>(Ptr->getType()) &&
1079 "strip.invariant.group only applies to pointers.");
1080
1081 auto *PtrType = Ptr->getType();
1082 Module *M = BB->getParent()->getParent();
1083 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1084 M, Intrinsic::strip_invariant_group, {PtrType});
1085
1086 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1087 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1088 PtrType &&
1089 "StripInvariantGroup should take and return the same type");
1090
1091 return CreateCall(FnStripInvariantGroup, {Ptr});
1092}
1093
1095 auto *Ty = cast<VectorType>(V->getType());
1096 if (isa<ScalableVectorType>(Ty)) {
1097 Module *M = BB->getParent()->getParent();
1098 Function *F =
1099 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1100 return Insert(CallInst::Create(F, V), Name);
1101 }
1102 // Keep the original behaviour for fixed vector
1103 SmallVector<int, 8> ShuffleMask;
1104 int NumElts = Ty->getElementCount().getKnownMinValue();
1105 for (int i = 0; i < NumElts; ++i)
1106 ShuffleMask.push_back(NumElts - i - 1);
1107 return CreateShuffleVector(V, ShuffleMask, Name);
1108}
1109
1111 const Twine &Name) {
1112 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1113 assert(V1->getType() == V2->getType() &&
1114 "Splice expects matching operand types!");
1115
1116 if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) {
1117 Module *M = BB->getParent()->getParent();
1118 Function *F =
1119 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_splice, VTy);
1120
1121 Value *Ops[] = {V1, V2, getInt32(Imm)};
1122 return Insert(CallInst::Create(F, Ops), Name);
1123 }
1124
1125 unsigned NumElts = cast<FixedVectorType>(V1->getType())->getNumElements();
1126 assert(((-Imm <= NumElts) || (Imm < NumElts)) &&
1127 "Invalid immediate for vector splice!");
1128
1129 // Keep the original behaviour for fixed vector
1130 unsigned Idx = (NumElts + Imm) % NumElts;
1132 for (unsigned I = 0; I < NumElts; ++I)
1133 Mask.push_back(Idx + I);
1134
1135 return CreateShuffleVector(V1, V2, Mask);
1136}
1137
1139 const Twine &Name) {
1140 auto EC = ElementCount::getFixed(NumElts);
1141 return CreateVectorSplat(EC, V, Name);
1142}
1143
1145 const Twine &Name) {
1146 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1147
1148 // First insert it into a poison vector so we can shuffle it.
1149 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1150 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1151
1152 // Shuffle the value across the desired number of elements.
1154 Zeros.resize(EC.getKnownMinValue());
1155 return CreateShuffleVector(V, Zeros, Name + ".splat");
1156}
1157
1159 const Twine &Name) {
1160 assert(Ops.size() >= 2 && Ops.size() <= 8 &&
1161 "Unexpected number of operands to interleave");
1162
1163 // Make sure all operands are the same type.
1164 assert(isa<VectorType>(Ops[0]->getType()) && "Unexpected type");
1165
1166#ifndef NDEBUG
1167 for (unsigned I = 1; I < Ops.size(); I++) {
1168 assert(Ops[I]->getType() == Ops[0]->getType() &&
1169 "Vector interleave expects matching operand types!");
1170 }
1171#endif
1172
1173 unsigned IID = Intrinsic::getInterleaveIntrinsicID(Ops.size());
1174 auto *SubvecTy = cast<VectorType>(Ops[0]->getType());
1175 Type *DestTy = VectorType::get(SubvecTy->getElementType(),
1176 SubvecTy->getElementCount() * Ops.size());
1177 return CreateIntrinsic(IID, {DestTy}, Ops, {}, Name);
1178}
1179
1181 unsigned Dimension,
1182 unsigned LastIndex,
1183 MDNode *DbgInfo) {
1184 auto *BaseType = Base->getType();
1186 "Invalid Base ptr type for preserve.array.access.index.");
1187
1188 Value *LastIndexV = getInt32(LastIndex);
1189 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1190 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1191 IdxList.push_back(LastIndexV);
1192
1193 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1194
1195 Value *DimV = getInt32(Dimension);
1196 CallInst *Fn =
1197 CreateIntrinsic(Intrinsic::preserve_array_access_index,
1198 {ResultType, BaseType}, {Base, DimV, LastIndexV});
1199 Fn->addParamAttr(
1200 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1201 if (DbgInfo)
1202 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1203
1204 return Fn;
1205}
1206
1208 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1209 assert(isa<PointerType>(Base->getType()) &&
1210 "Invalid Base ptr type for preserve.union.access.index.");
1211 auto *BaseType = Base->getType();
1212
1213 Value *DIIndex = getInt32(FieldIndex);
1214 CallInst *Fn = CreateIntrinsic(Intrinsic::preserve_union_access_index,
1215 {BaseType, BaseType}, {Base, DIIndex});
1216 if (DbgInfo)
1217 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1218
1219 return Fn;
1220}
1221
1223 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1224 MDNode *DbgInfo) {
1225 auto *BaseType = Base->getType();
1227 "Invalid Base ptr type for preserve.struct.access.index.");
1228
1229 Value *GEPIndex = getInt32(Index);
1230 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1231 Type *ResultType =
1232 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1233
1234 Value *DIIndex = getInt32(FieldIndex);
1235 CallInst *Fn =
1236 CreateIntrinsic(Intrinsic::preserve_struct_access_index,
1237 {ResultType, BaseType}, {Base, GEPIndex, DIIndex});
1238 Fn->addParamAttr(
1239 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1240 if (DbgInfo)
1241 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1242
1243 return Fn;
1244}
1245
1247 ConstantInt *TestV = getInt32(Test);
1248 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1249 {FPNum, TestV});
1250}
1251
1252CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1253 Value *PtrValue,
1254 Value *AlignValue,
1255 Value *OffsetValue) {
1256 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1257 if (OffsetValue)
1258 Vals.push_back(OffsetValue);
1259 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1260 return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1261}
1262
1264 Value *PtrValue,
1265 unsigned Alignment,
1266 Value *OffsetValue) {
1267 assert(isa<PointerType>(PtrValue->getType()) &&
1268 "trying to create an alignment assumption on a non-pointer?");
1269 assert(Alignment != 0 && "Invalid Alignment");
1270 auto *PtrTy = cast<PointerType>(PtrValue->getType());
1271 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1272 Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1273 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1274}
1275
1277 Value *PtrValue,
1278 Value *Alignment,
1279 Value *OffsetValue) {
1280 assert(isa<PointerType>(PtrValue->getType()) &&
1281 "trying to create an alignment assumption on a non-pointer?");
1282 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1283}
1284
1286 Value *SizeValue) {
1287 assert(isa<PointerType>(PtrValue->getType()) &&
1288 "trying to create an deferenceable assumption on a non-pointer?");
1289 SmallVector<Value *, 4> Vals({PtrValue, SizeValue});
1290 OperandBundleDefT<Value *> DereferenceableOpB("dereferenceable", Vals);
1292 {DereferenceableOpB});
1293}
1294
1298void ConstantFolder::anchor() {}
1299void NoFolder::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef< TableEntry > TableRef
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)
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:55
#define I(x, y, z)
Definition MD5.cpp:58
uint64_t IntrinsicInst * II
#define P(N)
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static const char PassName[]
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
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)
This method constructs a CDS and initializes it with a text string.
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...
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)
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:63
A debug info location.
Definition DebugLoc.h:124
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:310
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...
FunctionType * getFunctionType()
Class to represent function types.
Type * getParamType(unsigned i) const
Parameter type accessors.
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.
@ 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...
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.
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:2579
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:547
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:2633
LLVM_ABI Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition IRBuilder.cpp:59
LLVM_ABI CallInst * CreateGCGetPointerBase(Value *DerivedPtr, const Twine &Name="")
Create a call to the experimental.gc.pointer.base intrinsic to get the base pointer for the specified...
LLVM_ABI CallInst * CreateLifetimeStart(Value *Ptr)
Create a lifetime.start intrinsic.
LLVM_ABI CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef< Value * > CallArgs, std::optional< ArrayRef< Value * > > DeoptArgs, ArrayRef< Value * > GCArgs, const Twine &Name="")
Create a call to the experimental.gc.statepoint intrinsic to start a new statepoint sequence.
LLVM_ABI CallInst * CreateLifetimeEnd(Value *Ptr)
Create a lifetime.end intrinsic.
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 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.
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 ...
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:2626
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 ...
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: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:72
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.
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
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:1812
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 * 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 * 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.
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:522
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:2289
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:64
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.
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.
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:2601
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:2197
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:2511
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:2071
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.
LLVM_ABI CallInst * CreateDereferenceableAssumption(Value *PtrValue, Value *SizeValue)
Create an assume intrinsic call that represents an dereferencable assumption on the provided pointer.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition IRBuilder.h:2280
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: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.
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:65
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...
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:1437
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:44
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:1078
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 reserve(size_type N)
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.
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
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
LLVM_ABI Type * getStructElementType(unsigned N) const
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)
Definition Type.cpp:297
Type * getArrayElementType() const
Definition Type.h:408
LLVM_ABI unsigned getStructNumElements() const
LLVM_ABI uint64_t getArrayNumElements() const
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:281
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:352
bool isStructTy() const
True if this is an instance of StructType.
Definition Type.h:261
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:231
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:139
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:1099
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.
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 Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
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 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.
MaybeAlign getAlign(const CallInst &I, unsigned Index)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, Function &F, StringRef PassName)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2136
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:189
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:761
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