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 Align - alignment of \p Ptr
648/// \p Mask - vector of booleans which indicates what vector lanes should
649/// be accessed in memory
650/// \p PassThru - pass-through value that is used to fill the masked-off lanes
651/// of the result
652/// \p Name - name of the result variable
654 MaybeAlign Align, Value *Mask,
655 Value *PassThru,
656 const Twine &Name) {
657 assert(Ty->isVectorTy() && "Type should be vector");
658 assert(Mask && "Mask should not be all-ones (null)");
659 if (!PassThru)
660 PassThru = PoisonValue::get(Ty);
661 Type *OverloadedTypes[] = {Ty};
662 Value *Ops[] = {Ptr, Mask, PassThru};
663 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_expandload, Ops,
664 OverloadedTypes, Name);
665 if (Align)
667 return CI;
668}
669
670/// Create a call to Masked Compress Store intrinsic
671/// \p Val - data to be stored,
672/// \p Ptr - base pointer for the store
673/// \p Align - alignment of \p Ptr
674/// \p Mask - vector of booleans which indicates what vector lanes should
675/// be accessed in memory
678 Value *Mask) {
679 Type *DataTy = Val->getType();
680 assert(DataTy->isVectorTy() && "Val should be a vector");
681 assert(Mask && "Mask should not be all-ones (null)");
682 Type *OverloadedTypes[] = {DataTy};
683 Value *Ops[] = {Val, Ptr, Mask};
684 CallInst *CI = CreateMaskedIntrinsic(Intrinsic::masked_compressstore, Ops,
685 OverloadedTypes);
686 if (Align)
688 return CI;
689}
690
691template <typename T0>
692static std::vector<Value *>
694 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
695 std::vector<Value *> Args;
696 Args.push_back(B.getInt64(ID));
697 Args.push_back(B.getInt32(NumPatchBytes));
698 Args.push_back(ActualCallee);
699 Args.push_back(B.getInt32(CallArgs.size()));
700 Args.push_back(B.getInt32(Flags));
701 llvm::append_range(Args, CallArgs);
702 // GC Transition and Deopt args are now always handled via operand bundle.
703 // They will be removed from the signature of gc.statepoint shortly.
704 Args.push_back(B.getInt32(0));
705 Args.push_back(B.getInt32(0));
706 // GC args are now encoded in the gc-live operand bundle
707 return Args;
708}
709
710template<typename T1, typename T2, typename T3>
711static std::vector<OperandBundleDef>
712getStatepointBundles(std::optional<ArrayRef<T1>> TransitionArgs,
713 std::optional<ArrayRef<T2>> DeoptArgs,
714 ArrayRef<T3> GCArgs) {
715 std::vector<OperandBundleDef> Rval;
716 if (DeoptArgs) {
717 SmallVector<Value*, 16> DeoptValues;
718 llvm::append_range(DeoptValues, *DeoptArgs);
719 Rval.emplace_back("deopt", DeoptValues);
720 }
721 if (TransitionArgs) {
722 SmallVector<Value*, 16> TransitionValues;
723 llvm::append_range(TransitionValues, *TransitionArgs);
724 Rval.emplace_back("gc-transition", TransitionValues);
725 }
726 if (GCArgs.size()) {
727 SmallVector<Value*, 16> LiveValues;
728 llvm::append_range(LiveValues, GCArgs);
729 Rval.emplace_back("gc-live", LiveValues);
730 }
731 return Rval;
732}
733
734template <typename T0, typename T1, typename T2, typename T3>
736 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
737 FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
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 {ActualCallee.getCallee()->getType()});
746
747 std::vector<Value *> Args = getStatepointArgs(
748 *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
749
750 CallInst *CI = Builder->CreateCall(
751 FnStatepoint, Args,
752 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
753 CI->addParamAttr(2,
754 Attribute::get(Builder->getContext(), Attribute::ElementType,
755 ActualCallee.getFunctionType()));
756 return CI;
757}
758
760 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
761 ArrayRef<Value *> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
762 ArrayRef<Value *> GCArgs, const Twine &Name) {
763 return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
764 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
765 CallArgs, std::nullopt /* No Transition Args */, DeoptArgs, GCArgs, Name);
766}
767
769 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
770 uint32_t Flags, ArrayRef<Value *> CallArgs,
771 std::optional<ArrayRef<Use>> TransitionArgs,
772 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
773 const Twine &Name) {
774 return CreateGCStatepointCallCommon<Value *, Use, Use, Value *>(
775 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
776 DeoptArgs, GCArgs, Name);
777}
778
780 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
781 ArrayRef<Use> CallArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
782 ArrayRef<Value *> GCArgs, const Twine &Name) {
783 return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
784 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
785 CallArgs, std::nullopt, DeoptArgs, GCArgs, Name);
786}
787
788template <typename T0, typename T1, typename T2, typename T3>
790 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
791 FunctionCallee ActualInvokee, BasicBlock *NormalDest,
792 BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
793 std::optional<ArrayRef<T1>> TransitionArgs,
794 std::optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
795 const Twine &Name) {
796 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
797 // Fill in the one generic type'd argument (the function is also vararg)
799 M, Intrinsic::experimental_gc_statepoint,
800 {ActualInvokee.getCallee()->getType()});
801
802 std::vector<Value *> Args =
803 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
804 Flags, InvokeArgs);
805
806 InvokeInst *II = Builder->CreateInvoke(
807 FnStatepoint, NormalDest, UnwindDest, Args,
808 getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
809 II->addParamAttr(2,
810 Attribute::get(Builder->getContext(), Attribute::ElementType,
811 ActualInvokee.getFunctionType()));
812 return II;
813}
814
816 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
817 BasicBlock *NormalDest, BasicBlock *UnwindDest,
818 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Value *>> DeoptArgs,
819 ArrayRef<Value *> GCArgs, const Twine &Name) {
820 return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
821 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
822 uint32_t(StatepointFlags::None), InvokeArgs,
823 std::nullopt /* No Transition Args*/, DeoptArgs, GCArgs, Name);
824}
825
827 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
828 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
829 ArrayRef<Value *> InvokeArgs, std::optional<ArrayRef<Use>> TransitionArgs,
830 std::optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
831 const Twine &Name) {
832 return CreateGCStatepointInvokeCommon<Value *, Use, Use, Value *>(
833 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
834 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
835}
836
838 uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
839 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
840 std::optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
841 const Twine &Name) {
842 return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
843 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
844 uint32_t(StatepointFlags::None), InvokeArgs, std::nullopt, DeoptArgs,
845 GCArgs, Name);
846}
847
849 Type *ResultType, const Twine &Name) {
850 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
851 Type *Types[] = {ResultType};
852
853 Value *Args[] = {Statepoint};
854 return CreateIntrinsic(ID, Types, Args, {}, Name);
855}
856
858 int BaseOffset, int DerivedOffset,
859 Type *ResultType, const Twine &Name) {
860 Type *Types[] = {ResultType};
861
862 Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
863 return CreateIntrinsic(Intrinsic::experimental_gc_relocate, Types, Args, {},
864 Name);
865}
866
868 const Twine &Name) {
869 Type *PtrTy = DerivedPtr->getType();
870 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_base,
871 {PtrTy, PtrTy}, {DerivedPtr}, {}, Name);
872}
873
875 const Twine &Name) {
876 Type *PtrTy = DerivedPtr->getType();
877 return CreateIntrinsic(Intrinsic::experimental_gc_get_pointer_offset, {PtrTy},
878 {DerivedPtr}, {}, Name);
879}
880
883 const Twine &Name) {
884 Module *M = BB->getModule();
885 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
886 return createCallHelper(Fn, {V}, Name, FMFSource);
887}
888
891 const Twine &Name) {
892 Module *M = BB->getModule();
895 /*FMFSource=*/nullptr))
896 return V;
897 return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource);
898}
899
901 ArrayRef<Type *> Types,
904 const Twine &Name) {
905 Module *M = BB->getModule();
907 return createCallHelper(Fn, Args, Name, FMFSource);
908}
909
913 const Twine &Name) {
914 Module *M = BB->getModule();
915
919
920 SmallVector<Type *> ArgTys;
921 ArgTys.reserve(Args.size());
922 for (auto &I : Args)
923 ArgTys.push_back(I->getType());
924 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, false);
925 SmallVector<Type *> OverloadTys;
927 matchIntrinsicSignature(FTy, TableRef, OverloadTys);
928 (void)Res;
930 "Wrong types for intrinsic!");
931 // TODO: Handle varargs intrinsics.
932
933 Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTys);
934 return createCallHelper(Fn, Args, Name, FMFSource);
935}
936
939 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
940 std::optional<fp::ExceptionBehavior> Except) {
941 Value *RoundingV = getConstrainedFPRounding(Rounding);
942 Value *ExceptV = getConstrainedFPExcept(Except);
943
944 FastMathFlags UseFMF = FMFSource.get(FMF);
945
946 CallInst *C = CreateIntrinsic(ID, {L->getType()},
947 {L, R, RoundingV, ExceptV}, nullptr, Name);
949 setFPAttrs(C, FPMathTag, UseFMF);
950 return C;
951}
952
955 const Twine &Name, MDNode *FPMathTag,
956 std::optional<fp::ExceptionBehavior> Except) {
957 Value *ExceptV = getConstrainedFPExcept(Except);
958
959 FastMathFlags UseFMF = FMFSource.get(FMF);
960
961 CallInst *C =
962 CreateIntrinsic(ID, {L->getType()}, {L, R, ExceptV}, nullptr, Name);
964 setFPAttrs(C, FPMathTag, UseFMF);
965 return C;
966}
967
969 const Twine &Name, MDNode *FPMathTag) {
970 if (Instruction::isBinaryOp(Opc)) {
971 assert(Ops.size() == 2 && "Invalid number of operands!");
972 return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
973 Ops[0], Ops[1], Name, FPMathTag);
974 }
975 if (Instruction::isUnaryOp(Opc)) {
976 assert(Ops.size() == 1 && "Invalid number of operands!");
977 return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
978 Ops[0], Name, FPMathTag);
979 }
980 llvm_unreachable("Unexpected opcode!");
981}
982
985 const Twine &Name, MDNode *FPMathTag, std::optional<RoundingMode> Rounding,
986 std::optional<fp::ExceptionBehavior> Except) {
987 Value *ExceptV = getConstrainedFPExcept(Except);
988
989 FastMathFlags UseFMF = FMFSource.get(FMF);
990
991 CallInst *C;
993 Value *RoundingV = getConstrainedFPRounding(Rounding);
994 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
995 nullptr, Name);
996 } else
997 C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
998 Name);
999
1001
1002 if (isa<FPMathOperator>(C))
1003 setFPAttrs(C, FPMathTag, UseFMF);
1004 return C;
1005}
1006
1007Value *IRBuilderBase::CreateFCmpHelper(CmpInst::Predicate P, Value *LHS,
1008 Value *RHS, const Twine &Name,
1009 MDNode *FPMathTag, FMFSource FMFSource,
1010 bool IsSignaling) {
1011 if (IsFPConstrained) {
1012 auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
1013 : Intrinsic::experimental_constrained_fcmp;
1014 return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
1015 }
1016
1017 if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1018 return V;
1019 return Insert(
1020 setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMFSource.get(FMF)),
1021 Name);
1022}
1023
1026 const Twine &Name, std::optional<fp::ExceptionBehavior> Except) {
1027 Value *PredicateV = getConstrainedFPPredicate(P);
1028 Value *ExceptV = getConstrainedFPExcept(Except);
1029
1030 CallInst *C = CreateIntrinsic(ID, {L->getType()},
1031 {L, R, PredicateV, ExceptV}, nullptr, Name);
1033 return C;
1034}
1035
1037 Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
1038 std::optional<RoundingMode> Rounding,
1039 std::optional<fp::ExceptionBehavior> Except) {
1041
1042 append_range(UseArgs, Args);
1043
1044 if (Intrinsic::hasConstrainedFPRoundingModeOperand(Callee->getIntrinsicID()))
1045 UseArgs.push_back(getConstrainedFPRounding(Rounding));
1046 UseArgs.push_back(getConstrainedFPExcept(Except));
1047
1048 CallInst *C = CreateCall(Callee, UseArgs, Name);
1050 return C;
1051}
1052
1054 const Twine &Name, Instruction *MDFrom) {
1055 return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
1056}
1057
1059 FMFSource FMFSource, const Twine &Name,
1060 Instruction *MDFrom) {
1061 if (auto *V = Folder.FoldSelect(C, True, False))
1062 return V;
1063
1064 SelectInst *Sel = SelectInst::Create(C, True, False);
1065 if (MDFrom) {
1066 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1067 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1068 Sel = addBranchMetadata(Sel, Prof, Unpred);
1069 }
1070 if (isa<FPMathOperator>(Sel))
1071 setFPAttrs(Sel, /*MDNode=*/nullptr, FMFSource.get(FMF));
1072 return Insert(Sel, Name);
1073}
1074
1076 const Twine &Name) {
1077 assert(LHS->getType() == RHS->getType() &&
1078 "Pointer subtraction operand types must match!");
1081 Value *Difference = CreateSub(LHS_int, RHS_int);
1082 return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ElemTy),
1083 Name);
1084}
1085
1087 assert(isa<PointerType>(Ptr->getType()) &&
1088 "launder.invariant.group only applies to pointers.");
1089 auto *PtrType = Ptr->getType();
1090 Module *M = BB->getParent()->getParent();
1091 Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
1092 M, Intrinsic::launder_invariant_group, {PtrType});
1093
1094 assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
1095 FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1096 PtrType &&
1097 "LaunderInvariantGroup should take and return the same type");
1098
1099 return CreateCall(FnLaunderInvariantGroup, {Ptr});
1100}
1101
1103 assert(isa<PointerType>(Ptr->getType()) &&
1104 "strip.invariant.group only applies to pointers.");
1105
1106 auto *PtrType = Ptr->getType();
1107 Module *M = BB->getParent()->getParent();
1108 Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
1109 M, Intrinsic::strip_invariant_group, {PtrType});
1110
1111 assert(FnStripInvariantGroup->getReturnType() == PtrType &&
1112 FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1113 PtrType &&
1114 "StripInvariantGroup should take and return the same type");
1115
1116 return CreateCall(FnStripInvariantGroup, {Ptr});
1117}
1118
1120 auto *Ty = cast<VectorType>(V->getType());
1121 if (isa<ScalableVectorType>(Ty)) {
1122 Module *M = BB->getParent()->getParent();
1123 Function *F =
1124 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
1125 return Insert(CallInst::Create(F, V), Name);
1126 }
1127 // Keep the original behaviour for fixed vector
1128 SmallVector<int, 8> ShuffleMask;
1129 int NumElts = Ty->getElementCount().getKnownMinValue();
1130 for (int i = 0; i < NumElts; ++i)
1131 ShuffleMask.push_back(NumElts - i - 1);
1132 return CreateShuffleVector(V, ShuffleMask, Name);
1133}
1134
1136 const Twine &Name) {
1137 assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1138 assert(V1->getType() == V2->getType() &&
1139 "Splice expects matching operand types!");
1140
1141 if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) {
1142 Module *M = BB->getParent()->getParent();
1143 Function *F =
1144 Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_splice, VTy);
1145
1146 Value *Ops[] = {V1, V2, getInt32(Imm)};
1147 return Insert(CallInst::Create(F, Ops), Name);
1148 }
1149
1150 unsigned NumElts = cast<FixedVectorType>(V1->getType())->getNumElements();
1151 assert(((-Imm <= NumElts) || (Imm < NumElts)) &&
1152 "Invalid immediate for vector splice!");
1153
1154 // Keep the original behaviour for fixed vector
1155 unsigned Idx = (NumElts + Imm) % NumElts;
1157 for (unsigned I = 0; I < NumElts; ++I)
1158 Mask.push_back(Idx + I);
1159
1160 return CreateShuffleVector(V1, V2, Mask);
1161}
1162
1164 const Twine &Name) {
1165 auto EC = ElementCount::getFixed(NumElts);
1166 return CreateVectorSplat(EC, V, Name);
1167}
1168
1170 const Twine &Name) {
1171 assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1172
1173 // First insert it into a poison vector so we can shuffle it.
1174 Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1175 V = CreateInsertElement(Poison, V, getInt64(0), Name + ".splatinsert");
1176
1177 // Shuffle the value across the desired number of elements.
1179 Zeros.resize(EC.getKnownMinValue());
1180 return CreateShuffleVector(V, Zeros, Name + ".splat");
1181}
1182
1184 Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex,
1185 MDNode *DbgInfo) {
1186 auto *BaseType = Base->getType();
1187 assert(isa<PointerType>(BaseType) &&
1188 "Invalid Base ptr type for preserve.array.access.index.");
1189
1190 Value *LastIndexV = getInt32(LastIndex);
1191 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1192 SmallVector<Value *, 4> IdxList(Dimension, Zero);
1193 IdxList.push_back(LastIndexV);
1194
1195 Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
1196
1197 Value *DimV = getInt32(Dimension);
1198 CallInst *Fn =
1199 CreateIntrinsic(Intrinsic::preserve_array_access_index,
1200 {ResultType, BaseType}, {Base, DimV, LastIndexV});
1201 Fn->addParamAttr(
1202 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1203 if (DbgInfo)
1204 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1205
1206 return Fn;
1207}
1208
1210 Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1211 assert(isa<PointerType>(Base->getType()) &&
1212 "Invalid Base ptr type for preserve.union.access.index.");
1213 auto *BaseType = Base->getType();
1214
1215 Value *DIIndex = getInt32(FieldIndex);
1216 CallInst *Fn = CreateIntrinsic(Intrinsic::preserve_union_access_index,
1217 {BaseType, BaseType}, {Base, DIIndex});
1218 if (DbgInfo)
1219 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1220
1221 return Fn;
1222}
1223
1225 Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1226 MDNode *DbgInfo) {
1227 auto *BaseType = Base->getType();
1228 assert(isa<PointerType>(BaseType) &&
1229 "Invalid Base ptr type for preserve.struct.access.index.");
1230
1231 Value *GEPIndex = getInt32(Index);
1232 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1233 Type *ResultType =
1234 GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
1235
1236 Value *DIIndex = getInt32(FieldIndex);
1237 CallInst *Fn =
1238 CreateIntrinsic(Intrinsic::preserve_struct_access_index,
1239 {ResultType, BaseType}, {Base, GEPIndex, DIIndex});
1240 Fn->addParamAttr(
1241 0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1242 if (DbgInfo)
1243 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1244
1245 return Fn;
1246}
1247
1249 ConstantInt *TestV = getInt32(Test);
1250 return CreateIntrinsic(Intrinsic::is_fpclass, {FPNum->getType()},
1251 {FPNum, TestV});
1252}
1253
1254CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1255 Value *PtrValue,
1256 Value *AlignValue,
1257 Value *OffsetValue) {
1258 SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1259 if (OffsetValue)
1260 Vals.push_back(OffsetValue);
1261 OperandBundleDefT<Value *> AlignOpB("align", Vals);
1262 return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1263}
1264
1266 Value *PtrValue,
1267 unsigned Alignment,
1268 Value *OffsetValue) {
1269 assert(isa<PointerType>(PtrValue->getType()) &&
1270 "trying to create an alignment assumption on a non-pointer?");
1271 assert(Alignment != 0 && "Invalid Alignment");
1272 auto *PtrTy = cast<PointerType>(PtrValue->getType());
1273 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1274 Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1275 return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1276}
1277
1279 Value *PtrValue,
1280 Value *Alignment,
1281 Value *OffsetValue) {
1282 assert(isa<PointerType>(PtrValue->getType()) &&
1283 "trying to create an alignment assumption on a non-pointer?");
1284 return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1285}
1286
1290void ConstantFolder::anchor() {}
1291void 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:789
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:735
static std::vector< OperandBundleDef > getStatepointBundles(std::optional< ArrayRef< T1 > > TransitionArgs, std::optional< ArrayRef< T2 > > DeoptArgs, ArrayRef< T3 > GCArgs)
Definition: IRBuilder.cpp:712
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs)
Definition: IRBuilder.cpp:693
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:557
#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:1403
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
Definition: InstrTypes.h:1484
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1494
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:113
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1443
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:480
BasicBlock * BB
Definition: IRBuilder.h:138
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:1075
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
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:1086
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:953
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2511
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:530
CallInst * CreateMaskedCompressStore(Value *Val, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr)
Create a call to Masked Compress Store intrinsic.
Definition: IRBuilder.cpp:676
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:867
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:759
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:1024
Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:1058
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:1135
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:1163
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1224
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:1265
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:1036
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:614
LLVMContext & Context
Definition: IRBuilder.h:140
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:1053
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:1202
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:874
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:937
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:594
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:193
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:550
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:1119
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:428
FastMathFlags FMF
Definition: IRBuilder.h:145
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:510
Value * getAllOnesMask(ElementCount NumElts)
Return an all true boolean vector (mask) with NumElts lanes.
Definition: IRBuilder.h:867
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1761
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:889
Value * createIsFPClass(Value *FPNum, unsigned Test)
Definition: IRBuilder.cpp:1248
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:900
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:505
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:164
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:1387
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:881
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:968
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2533
LLVMContext & getContext() const
Definition: IRBuilder.h:195
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1209
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:2142
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2449
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:848
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Definition: IRBuilder.h:2019
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:1671
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:2225
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:380
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:815
CallInst * CreateMaskedExpandLoad(Type *Ty, Value *Ptr, MaybeAlign Align, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Expand Load intrinsic.
Definition: IRBuilder.cpp:653
const IRBuilderFolder & Folder
Definition: IRBuilder.h:141
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:639
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:535
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:857
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:1183
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:1404
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:983
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1102
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:1073
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:1065
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