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