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