LLVM 20.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"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/GlobalValue.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/Module.h"
27#include "llvm/IR/NoFolder.h"
28#include "llvm/IR/Operator.h"
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(Align(1));
56 return GV;
57}
58
60 assert(BB && BB->getParent() && "No current function!");
61 return BB->getParent()->getReturnType();
62}
63
65 for (auto &KV : MetadataToCopy)
66 if (KV.first == LLVMContext::MD_dbg)
67 return {cast<DILocation>(KV.second)};
68
69 return {};
70}
72 for (const auto &KV : MetadataToCopy)
73 if (KV.first == LLVMContext::MD_dbg) {
74 I->setDebugLoc(DebugLoc(KV.second));
75 return;
76 }
77}
78
80IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
83 CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
84 if (isa<FPMathOperator>(CI))
86 return CI;
87}
88
90 assert(isa<ConstantInt>(Scaling) && "Expected constant integer");
91 if (cast<ConstantInt>(Scaling)->isZero())
92 return Scaling;
93 CallInst *CI =
94 CreateIntrinsic(Intrinsic::vscale, {Scaling->getType()}, {}, {}, Name);
95 return cast<ConstantInt>(Scaling)->isOne() ? CI : CreateMul(CI, Scaling);
96}
97
99 Constant *MinEC = ConstantInt::get(DstType, EC.getKnownMinValue());
100 return EC.isScalable() ? CreateVScale(MinEC) : MinEC;
101}
102
104 Constant *MinSize = ConstantInt::get(DstType, Size.getKnownMinValue());
105 return Size.isScalable() ? CreateVScale(MinSize) : MinSize;
106}
107
109 Type *STy = DstType->getScalarType();
110 if (isa<ScalableVectorType>(DstType)) {
111 Type *StepVecType = DstType;
112 // TODO: We expect this special case (element type < 8 bits) to be
113 // temporary - once the intrinsic properly supports < 8 bits this code
114 // can be removed.
115 if (STy->getScalarSizeInBits() < 8)
116 StepVecType =
117 VectorType::get(getInt8Ty(), cast<ScalableVectorType>(DstType));
118 Value *Res = CreateIntrinsic(Intrinsic::stepvector, {StepVecType}, {},
119 nullptr, Name);
120 if (StepVecType != DstType)
121 Res = CreateTrunc(Res, DstType);
122 return Res;
123 }
124
125 unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
126
127 // Create a vector of consecutive numbers from zero to VF.
129 for (unsigned i = 0; i < NumEls; ++i)
130 Indices.push_back(ConstantInt::get(STy, i));
131
132 // Add the consecutive indices to the vector value.
133 return ConstantVector::get(Indices);
134}
135
137 MaybeAlign Align, bool isVolatile,
138 MDNode *TBAATag, MDNode *ScopeTag,
139 MDNode *NoAliasTag) {
140 Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
141 Type *Tys[] = {Ptr->getType(), Size->getType()};
142
143 CallInst *CI = CreateIntrinsic(Intrinsic::memset, Tys, Ops);
144
145 if (Align)
146 cast<MemSetInst>(CI)->setDestAlignment(*Align);
147
148 // Set the TBAA info if present.
149 if (TBAATag)
150 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
151
152 if (ScopeTag)
153 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
154
155 if (NoAliasTag)
156 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
157
158 return CI;
159}
160
162 Value *Val, Value *Size,
163 bool IsVolatile, MDNode *TBAATag,
164 MDNode *ScopeTag,
165 MDNode *NoAliasTag) {
166 Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
167 Type *Tys[] = {Dst->getType(), Size->getType()};
168
169 CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);
170
171 if (DstAlign)
172 cast<MemSetInlineInst>(CI)->setDestAlignment(*DstAlign);
173
174 // Set the TBAA info if present.
175 if (TBAATag)
176 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
177
178 if (ScopeTag)
179 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
180
181 if (NoAliasTag)
182 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
183
184 return CI;
185}
186
188 Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
189 MDNode *TBAATag, MDNode *ScopeTag, MDNode *NoAliasTag) {
190
191 Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
192 Type *Tys[] = {Ptr->getType(), Size->getType()};
193
194 CallInst *CI =
195 CreateIntrinsic(Intrinsic::memset_element_unordered_atomic, Tys, Ops);
196
197 cast<AtomicMemSetInst>(CI)->setDestAlignment(Alignment);
198
199 // Set the TBAA info if present.
200 if (TBAATag)
201 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
202
203 if (ScopeTag)
204 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
205
206 if (NoAliasTag)
207 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
208
209 return CI;
210}
211
213 Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
214 MaybeAlign SrcAlign, Value *Size, bool isVolatile, MDNode *TBAATag,
215 MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
216 assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
217 IntrID == Intrinsic::memmove) &&
218 "Unexpected intrinsic ID");
219 Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
220 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
221
222 CallInst *CI = CreateIntrinsic(IntrID, Tys, Ops);
223
224 auto* MCI = cast<MemTransferInst>(CI);
225 if (DstAlign)
226 MCI->setDestAlignment(*DstAlign);
227 if (SrcAlign)
228 MCI->setSourceAlignment(*SrcAlign);
229
230 // Set the TBAA info if present.
231 if (TBAATag)
232 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
233
234 // Set the TBAA Struct info if present.
235 if (TBAAStructTag)
236 CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
237
238 if (ScopeTag)
239 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
240
241 if (NoAliasTag)
242 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
243
244 return CI;
245}
246
248 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
249 uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
250 MDNode *ScopeTag, MDNode *NoAliasTag) {
251 assert(DstAlign >= ElementSize &&
252 "Pointer alignment must be at least element size");
253 assert(SrcAlign >= ElementSize &&
254 "Pointer alignment must be at least element size");
255 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
256 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
257
258 CallInst *CI =
259 CreateIntrinsic(Intrinsic::memcpy_element_unordered_atomic, Tys, Ops);
260
261 // Set the alignment of the pointer args.
262 auto *AMCI = cast<AtomicMemCpyInst>(CI);
263 AMCI->setDestAlignment(DstAlign);
264 AMCI->setSourceAlignment(SrcAlign);
265
266 // Set the TBAA info if present.
267 if (TBAATag)
268 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
269
270 // Set the TBAA Struct info if present.
271 if (TBAAStructTag)
272 CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
273
274 if (ScopeTag)
275 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
276
277 if (NoAliasTag)
278 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
279
280 return CI;
281}
282
283/// isConstantOne - Return true only if val is constant int 1
284static bool isConstantOne(const Value *Val) {
285 assert(Val && "isConstantOne does not work with nullptr Val");
286 const ConstantInt *CVal = dyn_cast<ConstantInt>(Val);
287 return CVal && CVal->isOne();
288}
289
291 Value *AllocSize, Value *ArraySize,
293 Function *MallocF, const Twine &Name) {
294 // malloc(type) becomes:
295 // i8* malloc(typeSize)
296 // malloc(type, arraySize) becomes:
297 // i8* malloc(typeSize*arraySize)
298 if (!ArraySize)
299 ArraySize = ConstantInt::get(IntPtrTy, 1);
300 else if (ArraySize->getType() != IntPtrTy)
301 ArraySize = CreateIntCast(ArraySize, IntPtrTy, false);
302
303 if (!isConstantOne(ArraySize)) {
304 if (isConstantOne(AllocSize)) {
305 AllocSize = ArraySize; // Operand * 1 = Operand
306 } else {
307 // Multiply type size by the array size...
308 AllocSize = CreateMul(ArraySize, AllocSize, "mallocsize");
309 }
310 }
311
312 assert(AllocSize->getType() == IntPtrTy && "malloc arg is wrong size");
313 // Create the call to Malloc.
314 Module *M = BB->getParent()->getParent();
316 FunctionCallee MallocFunc = MallocF;
317 if (!MallocFunc)
318 // prototype malloc as "void *malloc(size_t)"
319 MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy);
320 CallInst *MCall = CreateCall(MallocFunc, AllocSize, OpB, Name);
321
322 MCall->setTailCall();
323 if (Function *F = dyn_cast<Function>(MallocFunc.getCallee())) {
324 MCall->setCallingConv(F->getCallingConv());
325 F->setReturnDoesNotAlias();
326 }
327
328 assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
329
330 return MCall;
331}
332
334 Value *AllocSize, Value *ArraySize,
335 Function *MallocF, const Twine &Name) {
336
337 return CreateMalloc(IntPtrTy, AllocTy, AllocSize, ArraySize, {}, MallocF,
338 Name);
339}
340
341/// CreateFree - Generate the IR for a call to the builtin free function.
344 assert(Source->getType()->isPointerTy() &&
345 "Can not free something of nonpointer type!");
346
347 Module *M = BB->getParent()->getParent();
348
349 Type *VoidTy = Type::getVoidTy(M->getContext());
350 Type *VoidPtrTy = PointerType::getUnqual(M->getContext());
351 // prototype free as "void free(void*)"
352 FunctionCallee FreeFunc = M->getOrInsertFunction("free", VoidTy, VoidPtrTy);
353 CallInst *Result = CreateCall(FreeFunc, Source, Bundles, "");
354 Result->setTailCall();
355 if (Function *F = dyn_cast<Function>(FreeFunc.getCallee()))
356 Result->setCallingConv(F->getCallingConv());
357
358 return Result;
359}
360
362 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
363 uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
364 MDNode *ScopeTag, MDNode *NoAliasTag) {
365 assert(DstAlign >= ElementSize &&
366 "Pointer alignment must be at least element size");
367 assert(SrcAlign >= ElementSize &&
368 "Pointer alignment must be at least element size");
369 Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
370 Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
371
372 CallInst *CI =
373 CreateIntrinsic(Intrinsic::memmove_element_unordered_atomic, Tys, Ops);
374
375 // Set the alignment of the pointer args.
376 CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
377 CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
378
379 // Set the TBAA info if present.
380 if (TBAATag)
381 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
382
383 // Set the TBAA Struct info if present.
384 if (TBAAStructTag)
385 CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
386
387 if (ScopeTag)
388 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
389
390 if (NoAliasTag)
391 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
392
393 return CI;
394}
395
396CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
397 Value *Ops[] = {Src};
398 Type *Tys[] = { Src->getType() };
399 return CreateIntrinsic(ID, Tys, Ops);
400}
401
403 Value *Ops[] = {Acc, Src};
404 return CreateIntrinsic(Intrinsic::vector_reduce_fadd, {Src->getType()}, Ops);
405}
406
408 Value *Ops[] = {Acc, Src};
409 return CreateIntrinsic(Intrinsic::vector_reduce_fmul, {Src->getType()}, Ops);
410}
411
413 return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src);
414}
415
417 return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src);
418}
419
421 return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src);
422}
423
425 return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src);
426}
427
429 return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src);
430}
431
433 auto ID =
434 IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
435 return getReductionIntrinsic(ID, Src);
436}
437
439 auto ID =
440 IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
441 return getReductionIntrinsic(ID, Src);
442}
443
445 return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src);
446}
447
449 return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src);
450}
451
453 return getReductionIntrinsic(Intrinsic::vector_reduce_fmaximum, Src);
454}
455
457 return getReductionIntrinsic(Intrinsic::vector_reduce_fminimum, Src);
458}
459
461 assert(isa<PointerType>(Ptr->getType()) &&
462 "lifetime.start only applies to pointers.");
463 if (!Size)
464 Size = getInt64(-1);
465 else
466 assert(Size->getType() == getInt64Ty() &&
467 "lifetime.start requires the size to be an i64");
468 Value *Ops[] = { Size, Ptr };
469 return CreateIntrinsic(Intrinsic::lifetime_start, {Ptr->getType()}, Ops);
470}
471
473 assert(isa<PointerType>(Ptr->getType()) &&
474 "lifetime.end only applies to pointers.");
475 if (!Size)
476 Size = getInt64(-1);
477 else
478 assert(Size->getType() == getInt64Ty() &&
479 "lifetime.end requires the size to be an i64");
480 Value *Ops[] = { Size, Ptr };
481 return CreateIntrinsic(Intrinsic::lifetime_end, {Ptr->getType()}, Ops);
482}
483
485
486 assert(isa<PointerType>(Ptr->getType()) &&
487 "invariant.start only applies to pointers.");
488 if (!Size)
489 Size = getInt64(-1);
490 else
491 assert(Size->getType() == getInt64Ty() &&
492 "invariant.start requires the size to be an i64");
493
494 Value *Ops[] = {Size, Ptr};
495 // Fill in the single overloaded type: memory object type.
496 Type *ObjectPtr[1] = {Ptr->getType()};
497 return CreateIntrinsic(Intrinsic::invariant_start, ObjectPtr, Ops);
498}
499
501 if (auto *O = dyn_cast<GlobalObject>(Ptr))
502 return O->getAlign();
503 if (auto *A = dyn_cast<GlobalAlias>(Ptr))
504 return A->getAliaseeObject()->getAlign();
505 return {};
506}
507
509 assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
510 "threadlocal_address only applies to thread local variables.");
511 CallInst *CI = CreateIntrinsic(llvm::Intrinsic::threadlocal_address,
512 {Ptr->getType()}, {Ptr});
513 if (MaybeAlign A = getAlign(Ptr)) {
516 }
517 return CI;
518}
519
520CallInst *
522 ArrayRef<OperandBundleDef> OpBundles) {
523 assert(Cond->getType() == getInt1Ty() &&
524 "an assumption condition must be of type i1");
525
526 Value *Ops[] = { Cond };
527 Module *M = BB->getParent()->getParent();
528 Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
529 return CreateCall(FnAssume, Ops, OpBundles);
530}
531
533 return CreateIntrinsic(Intrinsic::experimental_noalias_scope_decl, {},
534 {Scope});
535}
536
537/// Create a call to a Masked Load intrinsic.
538/// \p Ty - vector type to load
539/// \p Ptr - base pointer for the load
540/// \p Alignment - alignment of the source location
541/// \p Mask - vector of booleans which indicates what vector lanes should
542/// be accessed in memory
543/// \p PassThru - pass-through value that is used to fill the masked-off lanes
544/// of the result
545/// \p Name - name of the result variable
547 Value *Mask, Value *PassThru,
548 const Twine &Name) {
549 auto *PtrTy = cast<PointerType>(Ptr->getType());
550 assert(Ty->isVectorTy() && "Type should be vector");
551 assert(Mask && "Mask should not be all-ones (null)");
552 if (!PassThru)
553 PassThru = PoisonValue::get(Ty);
554 Type *OverloadedTypes[] = { Ty, PtrTy };
555 Value *Ops[] = {Ptr, getInt32(Alignment.value()), Mask, PassThru};
556 return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
557 OverloadedTypes, Name);
558}
559
560/// Create a call to a Masked Store intrinsic.
561/// \p Val - data to be stored,
562/// \p Ptr - base pointer for the store
563/// \p Alignment - alignment of the destination location
564/// \p Mask - vector of booleans which indicates what vector lanes should
565/// be accessed in memory
567 Align Alignment, Value *Mask) {
568 auto *PtrTy = cast<PointerType>(Ptr->getType());
569 Type *DataTy = Val->getType();
570 assert(DataTy->isVectorTy() && "Val should be a vector");
571 assert(Mask && "Mask should not be all-ones (null)");
572 Type *OverloadedTypes[] = { DataTy, PtrTy };
573 Value *Ops[] = {Val, Ptr, getInt32(Alignment.value()), Mask};
574 return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
575}
576
577/// Create a call to a Masked intrinsic, with given intrinsic Id,
578/// an array of operands - Ops, and an array of overloaded types -
579/// OverloadedTypes.
580CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
582 ArrayRef<Type *> OverloadedTypes,
583 const Twine &Name) {
584 return CreateIntrinsic(Id, OverloadedTypes, Ops, {}, Name);
585}
586
587/// Create a call to a Masked Gather intrinsic.
588/// \p Ty - vector type to gather
589/// \p Ptrs - vector of pointers for loading
590/// \p Align - alignment for one element
591/// \p Mask - vector of booleans which indicates what vector lanes should
592/// be accessed in memory
593/// \p PassThru - pass-through value that is used to fill the masked-off lanes
594/// of the result
595/// \p Name - name of the result variable
597 Align Alignment, Value *Mask,
598 Value *PassThru,
599 const Twine &Name) {
600 auto *VecTy = cast<VectorType>(Ty);
601 ElementCount NumElts = VecTy->getElementCount();
602 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
603 assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
604
605 if (!Mask)
606 Mask = getAllOnesMask(NumElts);
607
608 if (!PassThru)
609 PassThru = PoisonValue::get(Ty);
610
611 Type *OverloadedTypes[] = {Ty, PtrsTy};
612 Value *Ops[] = {Ptrs, getInt32(Alignment.value()), Mask, PassThru};
613
614 // We specify only one type when we create this intrinsic. Types of other
615 // arguments are derived from this type.
616 return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
617 Name);
618}
619
620/// Create a call to a Masked Scatter intrinsic.
621/// \p Data - data to be stored,
622/// \p Ptrs - the vector of pointers, where the \p Data elements should be
623/// stored
624/// \p Align - alignment for one element
625/// \p Mask - vector of booleans which indicates what vector lanes should
626/// be accessed in memory
628 Align Alignment, Value *Mask) {
629 auto *PtrsTy = cast<VectorType>(Ptrs->getType());
630 auto *DataTy = cast<VectorType>(Data->getType());
631 ElementCount NumElts = PtrsTy->getElementCount();
632
633 if (!Mask)
634 Mask = getAllOnesMask(NumElts);
635
636 Type *OverloadedTypes[] = {DataTy, PtrsTy};
637 Value *Ops[] = {Data, Ptrs, getInt32(Alignment.value()), Mask};
638
639 // We specify only one type when we create this intrinsic. Types of other
640 // arguments are derived from this type.
641 return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
642}
643
644/// Create a call to Masked Expand Load intrinsic
645/// \p Ty - vector type to load
646/// \p Ptr - base pointer for the load
647/// \p Mask - vector of booleans which indicates what vector lanes should
648/// be accessed in memory
649/// \p PassThru - pass-through value that is used to fill the masked-off lanes
650/// of the result
651/// \p Name - name of the result variable
653 Value *Mask, Value *PassThru,
654 const Twine &Name) {
655 assert(Ty->isVectorTy() && "Type should be vector");
656 assert(Mask && "Mask should not be all-ones (null)");
657 if (!PassThru)
658 PassThru = PoisonValue::get(Ty);
659 Type *OverloadedTypes[] = {Ty};
660 Value *Ops[] = {Ptr, Mask, PassThru};
661 return CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
662 OverloadedTypes, Name);
663}
664
665/// Create a call to Masked Compress Store intrinsic
666/// \p Val - data to be stored,
667/// \p Ptr - base pointer for the store
668/// \p Mask - vector of booleans which indicates what vector lanes should
669/// be accessed in memory
671 Value *Mask) {
672 Type *DataTy = Val->getType();
673 assert(DataTy->isVectorTy() && "Val should be a vector");
674 assert(Mask && "Mask should not be all-ones (null)");
675 Type *OverloadedTypes[] = {DataTy};
676 Value *Ops[] = {Val, Ptr, Mask};
677 return CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
678 OverloadedTypes);
679}
680
681template <typename T0>
682static std::vector<Value *>
684 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
685 std::vector<Value *> Args;
686 Args.push_back(B.getInt64(ID));
687 Args.push_back(B.getInt32(NumPatchBytes));
688 Args.push_back(ActualCallee);
689 Args.push_back(B.getInt32(CallArgs.size()));
690 Args.push_back(B.getInt32(Flags));
691 llvm::append_range(Args, CallArgs);
692 // GC Transition and Deopt args are now always handled via operand bundle.
693 // They will be removed from the signature of gc.statepoint shortly.
694 Args.push_back(B.getInt32(0));
695 Args.push_back(B.getInt32(0));
696 // GC args are now encoded in the gc-live operand bundle
697 return Args;
698}
699
700template<typename T1, typename T2, typename T3>
701static std::vector<OperandBundleDef>
702getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
703 std::optional<ArrayRef<T2>> DeoptArgs,
704 ArrayRef<T3> GCArgs) {
705 std::vector<OperandBundleDef> Rval;
706 if (DeoptArgs) {
707 SmallVector<Value*, 16> DeoptValues;
708 llvm::append_range(DeoptValues, *DeoptArgs);
709 Rval.emplace_back("deopt", DeoptValues);
710 }
711 if (TransitionArgs) {
712 SmallVector<Value*, 16> TransitionValues;
713 llvm::append_range(TransitionValues, *TransitionArgs);
714 Rval.emplace_back("gc-transition", TransitionValues);
715 }
716 if (GCArgs.size()) {
717 SmallVector<Value*, 16> LiveValues;
718 llvm::append_range(LiveValues, GCArgs);
719 Rval.emplace_back("gc-live", LiveValues);
720 }
721 return Rval;
722}
723
724template <typename T0, typename T1, typename T2, typename T3>
726 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
727 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
728 std::optional<ArrayRef<T1>> TransitionArgs,
729 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
730 const Twine &Name) {
731 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
732 // Fill in the one generic type'd argument (the function is also vararg)
734 M, Intrinsic::experimental_gc_statepoint,
735 {ActualCallee.getCallee()->getType()});
736
737 std::vector<Value *> Args = getStatepointArgs(
738 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
739
740 CallInst *CI = Builder->CreateCall(
741 FnStatepoint, Args,
742 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
743 CI->addParamAttr(2,
744 Attribute::get(Builder->getContext(), Attribute::ElementType,
745 ActualCallee.getFunctionType()));
746 return CI;
747}
748
750 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
751 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
752 ArrayRef<Value *> GCArgs, const Twine &Name) {
753 return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
754 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
755 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
756}
757
759 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
760 uint32_t Flags, ArrayRef<Value *> CallArgs,
761 std::optional<ArrayRef<Use>> TransitionArgs,
762 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
763 const Twine &Name) {
764 return CreateGCStatepointCallCommon<Value *, Use, Use, Value *>(
765 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
766 DeoptArgs, GCArgs, Name);
767}
768
770 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
771 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
772 ArrayRef<Value *> GCArgs, const Twine &Name) {
773 return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
774 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
775 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
776}
777
778template <typename T0, typename T1, typename T2, typename T3>
780 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
781 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
782 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
783 std::optional<ArrayRef<T1>> TransitionArgs,
784 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
785 const Twine &Name) {
786 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
787 // Fill in the one generic type'd argument (the function is also vararg)
789 M, Intrinsic::experimental_gc_statepoint,
790 {ActualInvokee.getCallee()->getType()});
791
792 std::vector<Value *> Args =
793 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
794 Flags, InvokeArgs);
795
796 InvokeInst *II = Builder->CreateInvoke(
797 FnStatepoint, NormalDest, UnwindDest, Args,
798 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
799 II->addParamAttr(2,
800 Attribute::get(Builder->getContext(), Attribute::ElementType,
801 ActualInvokee.getFunctionType()));
802 return II;
803}
804
806 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
807 BasicBlock *NormalDest, BasicBlock *UnwindDest,
808 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
809 ArrayRef<Value *> GCArgs, const Twine &Name) {
810 return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
811 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
812 uint32_t(StatepointFlags::None), InvokeArgs,
813 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
814}
815
817 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
818 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
819 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
820 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
821 const Twine &Name) {
822 return CreateGCStatepointInvokeCommon<Value *, Use, Use, Value *>(
823 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
824 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
825}
826
828 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
829 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
830 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
831 const Twine &Name) {
832 return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
833 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
834 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
835 GCArgs, Name);
836}
837
839 Type *ResultType, const Twine &Name) {
840 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
841 Type *Types[] = {ResultType};
842
843 Value *Args[] = {Statepoint};
844 return CreateIntrinsic(ID, Types, Args, {}, Name);
845}
846
848 int BaseOffset, int DerivedOffset,
849 Type *ResultType, const Twine &Name) {
850 Type *Types[] = {ResultType};
851
852 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
853 return CreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
854 Name);
855}
856
858 const Twine &Name) {
859 Type *PtrTy = DerivedPtr->getType();
860 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_base,
861 {PtrTy, PtrTy}, {DerivedPtr}, {}, Name);
862}
863
865 const Twine &Name) {
866 Type *PtrTy = DerivedPtr->getType();
867 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
868 {DerivedPtr}, {}, Name);
869}
870
873 const Twine &Name) {
874 Module *M = BB->getModule();
875 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
876 return createCallHelper(Fn, {V}, Name, FMFSource);
877}
878
881 const Twine &Name) {
882 Module *M = BB->getModule();
885 /*FMFSource=*/nullptr))
886 return V;
887 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
888}
889
891 ArrayRef<Type *> Types,
894 const Twine &Name) {
895 Module *M = BB->getModule();
897 return createCallHelper(Fn, Args, Name, FMFSource);
898}
899
903 const Twine &Name) {
904 Module *M = BB->getModule();
905
909
910 SmallVector<Type *> ArgTys;
911 ArgTys.reserve(Args.size());
912 for (auto &I : Args)
913 ArgTys.push_back(I->getType());
914 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, false);
915 SmallVector<Type *> OverloadTys;
917 matchIntrinsicSignature(FTy, TableRef, OverloadTys);
918 (void)Res;
920 "Wrong types for intrinsic!");
921 // TODO: Handle varargs intrinsics.
922
923 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTys);
924 return createCallHelper(Fn, Args, Name, FMFSource);
925}
926
929 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
930 std::optional<fp::ExceptionBehavior> Except) {
931 Value *RoundingV = getConstrainedFPRounding(Rounding);
932 Value *ExceptV = getConstrainedFPExcept(Except);
933
934 FastMathFlags UseFMF = FMFSource.get(FMF);
935
936 CallInst *C = CreateIntrinsic(ID, {L->getType()},
937 {L, R, RoundingV, ExceptV}, nullptr, Name);
939 setFPAttrs(C, FPMathTag, UseFMF);
940 return C;
941}
942
945 const Twine &Name, MDNode *FPMathTag,
946 std::optional<fp::ExceptionBehavior> Except) {
947 Value *ExceptV = getConstrainedFPExcept(Except);
948
949 FastMathFlags UseFMF = FMFSource.get(FMF);
950
951 CallInst *C =
952 CreateIntrinsic(ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name);
954 setFPAttrs(C, FPMathTag, UseFMF);
955 return C;
956}
957
959 const Twine &Name, MDNode *FPMathTag) {
960 if (Instruction::isBinaryOp(Opc)) {
961 assert(Ops.size() == 2 && "Invalid number of operands!");
962 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
963 Ops[0], Ops[1], Name, FPMathTag);
964 }
965 if (Instruction::isUnaryOp(Opc)) {
966 assert(Ops.size() == 1 && "Invalid number of operands!");
967 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
968 Ops[0], Name, FPMathTag);
969 }
970 llvm_unreachable("Unexpected opcode!");
971}
972
975 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
976 std::optional<fp::ExceptionBehavior> Except) {
977 Value *ExceptV = getConstrainedFPExcept(Except);
978
979 FastMathFlags UseFMF = FMFSource.get(FMF);
980
981 CallInst *C;
983 Value *RoundingV = getConstrainedFPRounding(Rounding);
984 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
985 nullptr, Name);
986 } else
987 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
988 Name);
989
991
992 if (isa<FPMathOperator>(C))
993 setFPAttrs(C, FPMathTag, UseFMF);
994 return C;
995}
996
997Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
998 Value *RHS, const Twine &Name,
999 MDNode *FPMathTag, FMFSource FMFSource,
1000 bool IsSignaling) {
1001 if (IsFPConstrained) {
1002 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1003 : Intrinsic::experimental_constrained_fcmp;
1004 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1005 }
1006
1007 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1008 return V;
1009 return Insert(
1010 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1011 Name);
1012}
1013
1016 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1017 Value *PredicateV = getConstrainedFPPredicate(P);
1018 Value *ExceptV = getConstrainedFPExcept(Except);
1019
1020 CallInst *C = CreateIntrinsic(ID, {L->getType()},
1021 {L, R, PredicateV, ExceptV}, nullptr, Name);
1023 return C;
1024}
1025
1027 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1028 std::optional<RoundingMode> Rounding,
1029 std::optional<fp::ExceptionBehavior> Except) {
1031
1032 append_range(UseArgs, Args);
1033
1034 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1035 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1036 UseArgs.push_back(getConstrainedFPExcept(Except));
1037
1038 CallInst *C = CreateCall(Callee, UseArgs, Name);
1040 return C;
1041}
1042
1044 const Twine &Name, Instruction *MDFrom) {
1045 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1046}
1047
1049 FMFSource FMFSource, const Twine &Name,
1050 Instruction *MDFrom) {
1051 if (auto *V = Folder.FoldSelect(C, True, False))
1052 return V;
1053
1054 SelectInst *Sel = SelectInst::Create(C, True, False);
1055 if (MDFrom) {
1056 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1057 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1058 Sel = addBranchMetadata(Sel, Prof, Unpred);
1059 }
1060 if (isa<FPMathOperator>(Sel))
1061 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1062 return Insert(Sel, Name);
1063}
1064
1066 const Twine &Name) {
1067 assert(LHS->getType() == RHS->getType() &&
1068 "Pointer subtraction operand types must match!");
1071 Value *Difference = CreateSub(LHS_int, RHS_int);
1072 return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ElemTy),
1073 Name);
1074}
1075
1077 assert(isa<PointerType>(Ptr->getType()) &&
1078 "launder.invariant.group only applies to pointers.");
1079 auto *PtrType = Ptr->getType();
1080 Module *M = BB->getParent()->getParent();
1081 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1082 M, Intrinsic::launder_invariant_group, {PtrType});
1083
1084 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1085 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1086 PtrType &&
1087 "LaunderInvariantGroup should take and return the same type");
1088
1089 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1090}
1091
1093 assert(isa<PointerType>(Ptr->getType()) &&
1094 "strip.invariant.group only applies to pointers.");
1095
1096 auto *PtrType = Ptr->getType();
1097 Module *M = BB->getParent()->getParent();
1098 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1099 M, Intrinsic::strip_invariant_group, {PtrType});
1100
1101 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1102 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1103 PtrType &&
1104 "StripInvariantGroup should take and return the same type");
1105
1106 return CreateCall(FnStripInvariantGroup, {Ptr});
1107}
1108
1110 auto *Ty = cast<VectorType>(V->getType());
1111 if (isa<ScalableVectorType>(Ty)) {
1112 Module *M = BB->getParent()->getParent();
1113 Function *F =
1114 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1115 return Insert(CallInst::Create(F, V), Name);
1116 }
1117 // Keep the original behaviour for fixed vector
1118 SmallVector<int, 8> ShuffleMask;
1119 int NumElts = Ty->getElementCount().getKnownMinValue();
1120 for (int i = 0; i < NumElts; ++i)
1121 ShuffleMask.push_back(NumElts - i - 1);
1122 return CreateShuffleVector(V, ShuffleMask, Name);
1123}
1124
1126 const Twine &Name) {
1127 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1128 assert(V1->getType() == V2->getType() &&
1129 "Splice expects matching operand types!");
1130
1131 if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) {
1132 Module *M = BB->getParent()->getParent();
1133 Function *F =
1134 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_splice, VTy);
1135
1136 Value *Ops[] = {V1, V2, getInt32(Imm)};
1137 return Insert(CallInst::Create(F, Ops), Name);
1138 }
1139
1140 unsigned NumElts = cast<FixedVectorType>(V1->getType())->getNumElements();
1141 assert(((-Imm <= NumElts) || (Imm < NumElts)) &&
1142 "Invalid immediate for vector splice!");
1143
1144 // Keep the original behaviour for fixed vector
1145 unsigned Idx = (NumElts + Imm) % NumElts;
1147 for (unsigned I = 0; I < NumElts; ++I)
1148 Mask.push_back(Idx + I);
1149
1150 return CreateShuffleVector(V1, V2, Mask);
1151}
1152
1154 const Twine &Name) {
1155 auto EC = ElementCount::getFixed(NumElts);
1156 return CreateVectorSplat(EC, V, Name);
1157}
1158
1160 const Twine &Name) {
1161 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1162
1163 // First insert it into a poison vector so we can shuffle it.
1164 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1165 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1166
1167 // Shuffle the value across the desired number of elements.
1169 Zeros.resize(EC.getKnownMinValue());
1170 return CreateShuffleVector(V, Zeros, Name + ".splat");
1171}
1172
1174 Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex,
1175 MDNode *DbgInfo) {
1176 auto *BaseType = Base->getType();
1177 assert(isa<PointerType>(BaseType) &&
1178 "Invalid Base ptr type for preserve.array.access.index.");
1179
1180 Value *LastIndexV = getInt32(LastIndex);
1181 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1182 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1183 IdxList.push_back(LastIndexV);
1184
1185 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1186
1187 Value *DimV = getInt32(Dimension);
1188 CallInst *Fn =
1189 CreateIntrinsic(Intrinsic::preserve_array_access_index,
1190 {ResultType, BaseType}, {Base, DimV, LastIndexV});
1191 Fn->addParamAttr(
1192 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1193 if (DbgInfo)
1194 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1195
1196 return Fn;
1197}
1198
1200 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1201 assert(isa<PointerType>(Base->getType()) &&
1202 "Invalid Base ptr type for preserve.union.access.index.");
1203 auto *BaseType = Base->getType();
1204
1205 Value *DIIndex = getInt32(FieldIndex);
1206 CallInst *Fn = CreateIntrinsic(Intrinsic::preserve_union_access_index,
1207 {BaseType, BaseType}, {Base, DIIndex});
1208 if (DbgInfo)
1209 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1210
1211 return Fn;
1212}
1213
1215 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1216 MDNode *DbgInfo) {
1217 auto *BaseType = Base->getType();
1218 assert(isa<PointerType>(BaseType) &&
1219 "Invalid Base ptr type for preserve.struct.access.index.");
1220
1221 Value *GEPIndex = getInt32(Index);
1222 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1223 Type *ResultType =
1224 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1225
1226 Value *DIIndex = getInt32(FieldIndex);
1227 CallInst *Fn =
1228 CreateIntrinsic(Intrinsic::preserve_struct_access_index,
1229 {ResultType, BaseType}, {Base, GEPIndex, DIIndex});
1230 Fn->addParamAttr(
1231 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1232 if (DbgInfo)
1233 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1234
1235 return Fn;
1236}
1237
1239 ConstantInt *TestV = getInt32(Test);
1240 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1241 {FPNum, TestV});
1242}
1243
1244CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1245 Value *PtrValue,
1246 Value *AlignValue,
1247 Value *OffsetValue) {
1248 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1249 if (OffsetValue)
1250 Vals.push_back(OffsetValue);
1251 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1252 return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1253}
1254
1256 Value *PtrValue,
1257 unsigned Alignment,
1258 Value *OffsetValue) {
1259 assert(isa<PointerType>(PtrValue->getType()) &&
1260 "trying to create an alignment assumption on a non-pointer?");
1261 assert(Alignment != 0 && "Invalid Alignment");
1262 auto *PtrTy = cast<PointerType>(PtrValue->getType());
1263 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1264 Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1265 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1266}
1267
1269 Value *PtrValue,
1270 Value *Alignment,
1271 Value *OffsetValue) {
1272 assert(isa<PointerType>(PtrValue->getType()) &&
1273 "trying to create an alignment assumption on a non-pointer?");
1274 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1275}
1276
1280void ConstantFolder::anchor() {}
1281void NoFolder::anchor() {}
@ Poison
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:284
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:779
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:725
static std::vector< OperandBundleDef > getStatepointBundles(std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs)
Definition: IRBuilder.cpp:702
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs)
Definition: IRBuilder.cpp:683
Module.h This file contains the declarations for the Module class.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:533
#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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:168
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:163
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:95
static 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:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:219
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:292
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1411
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
Definition: InstrTypes.h:1492
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1502
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:673
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:2990
static 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:2480
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:214
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:866
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1421
This is an important base class in LLVM.
Definition: Constant.h:42
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:33
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:311
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:92
FastMathFlags get(FastMathFlags Default) const
Definition: IRBuilder.h:102
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
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 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:216
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:221
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:656
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:60
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:108
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1437
CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memcpy between the specified pointers.
Definition: IRBuilder.cpp:247
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:475
CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Definition: IRBuilder.cpp:670
BasicBlock * BB
Definition: IRBuilder.h:133
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:1065
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:416
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:402
CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
Definition: IRBuilder.cpp:652
Value * CreateVScale(Constant *Scaling, const Twine &Name="")
Create a call to llvm.vscale, multiplied by Scaling.
Definition: IRBuilder.cpp:89
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1076
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:943
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2505
CallInst * CreateThreadLocalAddress(Value *Ptr)
Create a call to llvm.threadlocal.address intrinsic.
Definition: IRBuilder.cpp:508
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:525
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition: IRBuilder.cpp:59
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:857
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:749
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:460
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:1014
Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:1048
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:420
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:1125
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:521
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.cpp:1153
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1214
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:1255
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:546
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:1026
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
Definition: IRBuilder.h:609
LLVMContext & Context
Definition: IRBuilder.h:135
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:1043
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:1196
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:864
Value * CreateTypeSize(Type *DstType, TypeSize Size)
Create an expression which evaluates to the number of units in Size at runtime.
Definition: IRBuilder.cpp:103
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:412
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:927
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:589
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:188
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:545
CallInst * CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, Value *Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.cpp:212
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Definition: IRBuilder.cpp:1109
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:428
FastMathFlags FMF
Definition: IRBuilder.h:140
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:505
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition: IRBuilder.h:861
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1755
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:424
CallInst * CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize, ArrayRef< OperandBundleDef > OpB, Function *MallocF=nullptr, const Twine &Name="")
Definition: IRBuilder.cpp:290
CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:448
CallInst * CreateFPMaximumReduce(Value *Src)
Create a vector float maximum reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:452
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:879
Value * createIsFPClass(Value *FPNum, unsigned Test)
Definition: IRBuilder.cpp:1238
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:890
CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:444
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:500
CallInst * CreateFree(Value *Source, ArrayRef< OperandBundleDef > Bundles={})
Generate the IR for a call to the builtin free function.
Definition: IRBuilder.cpp:342
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:159
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:1381
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:871
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:958
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2527
LLVMContext & getContext() const
Definition: IRBuilder.h:190
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1199
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:432
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:566
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2136
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2443
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:838
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition: IRBuilder.h:2013
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:472
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1665
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Definition: IRBuilder.cpp:98
CallInst * CreateElementUnorderedAtomicMemMove(Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memmove between the specified pointers.
Definition: IRBuilder.cpp:361
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:2219
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:438
void setConstrainedFPCallAttr(CallBase *I)
Definition: IRBuilder.h:375
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:805
const IRBuilderFolder & Folder
Definition: IRBuilder.h:136
CallInst * CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val, Value *Size, bool IsVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.cpp:161
CallInst * CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size, Align Alignment, uint32_t ElementSize, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert an element unordered-atomic memset of the region of memory starting at the given po...
Definition: IRBuilder.h:634
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:407
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.cpp:71
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:530
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:847
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Definition: IRBuilder.cpp:108
Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1173
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Definition: IRBuilder.cpp:484
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1398
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
Definition: IRBuilder.cpp:532
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
Definition: IRBuilder.cpp:627
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
CallInst * CreateFPMinimumReduce(Value *Src)
Create a vector float minimum reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:456
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:973
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1092
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:596
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
bool isBinaryOp() const
Definition: Instruction.h:279
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:390
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1679
bool isUnaryOp() const
Definition: Instruction.h:278
Invoke instruction.
Metadata node.
Definition: Metadata.h:1069
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A container for an operand bundle being viewed as a set of values rather than a set of uses.
Definition: InstrTypes.h:1073
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:686
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1878
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:663
void resize(size_type N)
Definition: SmallVector.h:638
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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:270
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:355
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1075
static 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
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:731
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Intrinsics.cpp:446
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:230
bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...
Definition: Intrinsics.cpp:774
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2115
MaybeAlign getAlign(const Function &F, unsigned Index)
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