1 //===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the IRBuilder class, which is used as a convenient way
11 // to create LLVM instructions with a consistent and simplified interface.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/Function.h"
16 #include "llvm/IR/GlobalVariable.h"
17 #include "llvm/IR/IRBuilder.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Statepoint.h"
23 /// CreateGlobalString - Make a new global variable with an initializer that
24 /// has array of i8 type filled in with the nul terminated string value
25 /// specified. If Name is specified, it is the name of the global variable
27 GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str,
29 unsigned AddressSpace) {
30 Constant *StrConstant = ConstantDataArray::getString(Context, Str);
31 Module &M = *BB->getParent()->getParent();
32 GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(),
33 true, GlobalValue::PrivateLinkage,
34 StrConstant, Name, nullptr,
35 GlobalVariable::NotThreadLocal,
37 GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
41 Type *IRBuilderBase::getCurrentFunctionReturnType() const {
42 assert(BB && BB->getParent() && "No current function!");
43 return BB->getParent()->getReturnType();
46 Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) {
47 PointerType *PT = cast<PointerType>(Ptr->getType());
48 if (PT->getElementType()->isIntegerTy(8))
51 // Otherwise, we need to insert a bitcast.
52 PT = getInt8PtrTy(PT->getAddressSpace());
53 BitCastInst *BCI = new BitCastInst(Ptr, PT, "");
54 BB->getInstList().insert(InsertPt, BCI);
55 SetInstDebugLocation(BCI);
59 static CallInst *createCallHelper(Value *Callee, ArrayRef<Value *> Ops,
60 IRBuilderBase *Builder,
61 const Twine& Name="") {
62 CallInst *CI = CallInst::Create(Callee, Ops, Name);
63 Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(),CI);
64 Builder->SetInstDebugLocation(CI);
68 static InvokeInst *createInvokeHelper(Value *Invokee, BasicBlock *NormalDest,
69 BasicBlock *UnwindDest,
70 ArrayRef<Value *> Ops,
71 IRBuilderBase *Builder,
72 const Twine &Name = "") {
74 InvokeInst::Create(Invokee, NormalDest, UnwindDest, Ops, Name);
75 Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(),
77 Builder->SetInstDebugLocation(II);
81 CallInst *IRBuilderBase::
82 CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
83 bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
85 Ptr = getCastedInt8PtrValue(Ptr);
86 Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) };
87 Type *Tys[] = { Ptr->getType(), Size->getType() };
88 Module *M = BB->getParent()->getParent();
89 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys);
91 CallInst *CI = createCallHelper(TheFn, Ops, this);
93 // Set the TBAA info if present.
95 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
98 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
101 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
106 CallInst *IRBuilderBase::
107 CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
108 bool isVolatile, MDNode *TBAATag, MDNode *TBAAStructTag,
109 MDNode *ScopeTag, MDNode *NoAliasTag) {
110 Dst = getCastedInt8PtrValue(Dst);
111 Src = getCastedInt8PtrValue(Src);
113 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
114 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
115 Module *M = BB->getParent()->getParent();
116 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys);
118 CallInst *CI = createCallHelper(TheFn, Ops, this);
120 // Set the TBAA info if present.
122 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
124 // Set the TBAA Struct info if present.
126 CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
129 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
132 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
137 CallInst *IRBuilderBase::
138 CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
139 bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
140 MDNode *NoAliasTag) {
141 Dst = getCastedInt8PtrValue(Dst);
142 Src = getCastedInt8PtrValue(Src);
144 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
145 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
146 Module *M = BB->getParent()->getParent();
147 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys);
149 CallInst *CI = createCallHelper(TheFn, Ops, this);
151 // Set the TBAA info if present.
153 CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
156 CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
159 CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
164 static CallInst *getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID,
166 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
167 Value *Ops[] = {Src};
168 Type *Tys[] = { Src->getType()->getVectorElementType(), Src->getType() };
169 auto Decl = Intrinsic::getDeclaration(M, ID, Tys);
170 return createCallHelper(Decl, Ops, Builder);
173 CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) {
174 Module *M = GetInsertBlock()->getParent()->getParent();
175 Value *Ops[] = {Acc, Src};
176 Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(),
178 auto Decl = Intrinsic::getDeclaration(
179 M, Intrinsic::experimental_vector_reduce_fadd, Tys);
180 return createCallHelper(Decl, Ops, this);
183 CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) {
184 Module *M = GetInsertBlock()->getParent()->getParent();
185 Value *Ops[] = {Acc, Src};
186 Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(),
188 auto Decl = Intrinsic::getDeclaration(
189 M, Intrinsic::experimental_vector_reduce_fmul, Tys);
190 return createCallHelper(Decl, Ops, this);
193 CallInst *IRBuilderBase::CreateAddReduce(Value *Src) {
194 return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_add,
198 CallInst *IRBuilderBase::CreateMulReduce(Value *Src) {
199 return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_mul,
203 CallInst *IRBuilderBase::CreateAndReduce(Value *Src) {
204 return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_and,
208 CallInst *IRBuilderBase::CreateOrReduce(Value *Src) {
209 return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_or,
213 CallInst *IRBuilderBase::CreateXorReduce(Value *Src) {
214 return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_xor,
218 CallInst *IRBuilderBase::CreateIntMaxReduce(Value *Src, bool IsSigned) {
219 auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smax
220 : Intrinsic::experimental_vector_reduce_umax;
221 return getReductionIntrinsic(this, ID, Src);
224 CallInst *IRBuilderBase::CreateIntMinReduce(Value *Src, bool IsSigned) {
225 auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smin
226 : Intrinsic::experimental_vector_reduce_umin;
227 return getReductionIntrinsic(this, ID, Src);
230 CallInst *IRBuilderBase::CreateFPMaxReduce(Value *Src, bool NoNaN) {
231 auto Rdx = getReductionIntrinsic(
232 this, Intrinsic::experimental_vector_reduce_fmax, Src);
236 Rdx->setFastMathFlags(FMF);
241 CallInst *IRBuilderBase::CreateFPMinReduce(Value *Src, bool NoNaN) {
242 auto Rdx = getReductionIntrinsic(
243 this, Intrinsic::experimental_vector_reduce_fmin, Src);
247 Rdx->setFastMathFlags(FMF);
252 CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
253 assert(isa<PointerType>(Ptr->getType()) &&
254 "lifetime.start only applies to pointers.");
255 Ptr = getCastedInt8PtrValue(Ptr);
259 assert(Size->getType() == getInt64Ty() &&
260 "lifetime.start requires the size to be an i64");
261 Value *Ops[] = { Size, Ptr };
262 Module *M = BB->getParent()->getParent();
263 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start,
265 return createCallHelper(TheFn, Ops, this);
268 CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
269 assert(isa<PointerType>(Ptr->getType()) &&
270 "lifetime.end only applies to pointers.");
271 Ptr = getCastedInt8PtrValue(Ptr);
275 assert(Size->getType() == getInt64Ty() &&
276 "lifetime.end requires the size to be an i64");
277 Value *Ops[] = { Size, Ptr };
278 Module *M = BB->getParent()->getParent();
279 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end,
281 return createCallHelper(TheFn, Ops, this);
284 CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) {
286 assert(isa<PointerType>(Ptr->getType()) &&
287 "invariant.start only applies to pointers.");
288 Ptr = getCastedInt8PtrValue(Ptr);
292 assert(Size->getType() == getInt64Ty() &&
293 "invariant.start requires the size to be an i64");
295 Value *Ops[] = {Size, Ptr};
296 // Fill in the single overloaded type: memory object type.
297 Type *ObjectPtr[1] = {Ptr->getType()};
298 Module *M = BB->getParent()->getParent();
300 Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr);
301 return createCallHelper(TheFn, Ops, this);
304 CallInst *IRBuilderBase::CreateAssumption(Value *Cond) {
305 assert(Cond->getType() == getInt1Ty() &&
306 "an assumption condition must be of type i1");
308 Value *Ops[] = { Cond };
309 Module *M = BB->getParent()->getParent();
310 Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume);
311 return createCallHelper(FnAssume, Ops, this);
314 /// \brief Create a call to a Masked Load intrinsic.
315 /// \p Ptr - base pointer for the load
316 /// \p Align - alignment of the source location
317 /// \p Mask - vector of booleans which indicates what vector lanes should
318 /// be accessed in memory
319 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
321 /// \p Name - name of the result variable
322 CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align,
323 Value *Mask, Value *PassThru,
325 PointerType *PtrTy = cast<PointerType>(Ptr->getType());
326 Type *DataTy = PtrTy->getElementType();
327 assert(DataTy->isVectorTy() && "Ptr should point to a vector");
329 PassThru = UndefValue::get(DataTy);
330 Type *OverloadedTypes[] = { DataTy, PtrTy };
331 Value *Ops[] = { Ptr, getInt32(Align), Mask, PassThru};
332 return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
333 OverloadedTypes, Name);
336 /// \brief Create a call to a Masked Store intrinsic.
337 /// \p Val - data to be stored,
338 /// \p Ptr - base pointer for the store
339 /// \p Align - alignment of the destination location
340 /// \p Mask - vector of booleans which indicates what vector lanes should
341 /// be accessed in memory
342 CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr,
343 unsigned Align, Value *Mask) {
344 PointerType *PtrTy = cast<PointerType>(Ptr->getType());
345 Type *DataTy = PtrTy->getElementType();
346 assert(DataTy->isVectorTy() && "Ptr should point to a vector");
347 Type *OverloadedTypes[] = { DataTy, PtrTy };
348 Value *Ops[] = { Val, Ptr, getInt32(Align), Mask };
349 return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
352 /// Create a call to a Masked intrinsic, with given intrinsic Id,
353 /// an array of operands - Ops, and an array of overloaded types -
355 CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
356 ArrayRef<Value *> Ops,
357 ArrayRef<Type *> OverloadedTypes,
359 Module *M = BB->getParent()->getParent();
360 Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes);
361 return createCallHelper(TheFn, Ops, this, Name);
364 /// \brief Create a call to a Masked Gather intrinsic.
365 /// \p Ptrs - vector of pointers for loading
366 /// \p Align - alignment for one element
367 /// \p Mask - vector of booleans which indicates what vector lanes should
368 /// be accessed in memory
369 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
371 /// \p Name - name of the result variable
372 CallInst *IRBuilderBase::CreateMaskedGather(Value *Ptrs, unsigned Align,
373 Value *Mask, Value *PassThru,
375 auto PtrsTy = cast<VectorType>(Ptrs->getType());
376 auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
377 unsigned NumElts = PtrsTy->getVectorNumElements();
378 Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts);
381 Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context),
384 Type *OverloadedTypes[] = {DataTy, PtrsTy};
385 Value * Ops[] = {Ptrs, getInt32(Align), Mask, UndefValue::get(DataTy)};
387 // We specify only one type when we create this intrinsic. Types of other
388 // arguments are derived from this type.
389 return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
393 /// \brief Create a call to a Masked Scatter intrinsic.
394 /// \p Data - data to be stored,
395 /// \p Ptrs - the vector of pointers, where the \p Data elements should be
397 /// \p Align - alignment for one element
398 /// \p Mask - vector of booleans which indicates what vector lanes should
399 /// be accessed in memory
400 CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs,
401 unsigned Align, Value *Mask) {
402 auto PtrsTy = cast<VectorType>(Ptrs->getType());
403 auto DataTy = cast<VectorType>(Data->getType());
404 unsigned NumElts = PtrsTy->getVectorNumElements();
407 auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
408 assert(NumElts == DataTy->getVectorNumElements() &&
409 PtrTy->getElementType() == DataTy->getElementType() &&
410 "Incompatible pointer and data types");
414 Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context),
417 Type *OverloadedTypes[] = {DataTy, PtrsTy};
418 Value * Ops[] = {Data, Ptrs, getInt32(Align), Mask};
420 // We specify only one type when we create this intrinsic. Types of other
421 // arguments are derived from this type.
422 return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
425 template <typename T0, typename T1, typename T2, typename T3>
426 static std::vector<Value *>
427 getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes,
428 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
429 ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs,
430 ArrayRef<T3> GCArgs) {
431 std::vector<Value *> Args;
432 Args.push_back(B.getInt64(ID));
433 Args.push_back(B.getInt32(NumPatchBytes));
434 Args.push_back(ActualCallee);
435 Args.push_back(B.getInt32(CallArgs.size()));
436 Args.push_back(B.getInt32(Flags));
437 Args.insert(Args.end(), CallArgs.begin(), CallArgs.end());
438 Args.push_back(B.getInt32(TransitionArgs.size()));
439 Args.insert(Args.end(), TransitionArgs.begin(), TransitionArgs.end());
440 Args.push_back(B.getInt32(DeoptArgs.size()));
441 Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end());
442 Args.insert(Args.end(), GCArgs.begin(), GCArgs.end());
447 template <typename T0, typename T1, typename T2, typename T3>
448 static CallInst *CreateGCStatepointCallCommon(
449 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
450 Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
451 ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs,
453 // Extract out the type of the callee.
454 PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType());
455 assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
456 "actual callee must be a callable value");
458 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
459 // Fill in the one generic type'd argument (the function is also vararg)
460 Type *ArgTypes[] = { FuncPtrType };
461 Function *FnStatepoint =
462 Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
465 std::vector<llvm::Value *> Args =
466 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags,
467 CallArgs, TransitionArgs, DeoptArgs, GCArgs);
468 return createCallHelper(FnStatepoint, Args, Builder, Name);
471 CallInst *IRBuilderBase::CreateGCStatepointCall(
472 uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
473 ArrayRef<Value *> CallArgs, ArrayRef<Value *> DeoptArgs,
474 ArrayRef<Value *> GCArgs, const Twine &Name) {
475 return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
476 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
477 CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name);
480 CallInst *IRBuilderBase::CreateGCStatepointCall(
481 uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags,
482 ArrayRef<Use> CallArgs, ArrayRef<Use> TransitionArgs,
483 ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
484 return CreateGCStatepointCallCommon<Use, Use, Use, Value *>(
485 this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
486 DeoptArgs, GCArgs, Name);
489 CallInst *IRBuilderBase::CreateGCStatepointCall(
490 uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
491 ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs,
492 ArrayRef<Value *> GCArgs, const Twine &Name) {
493 return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
494 this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
495 CallArgs, None, DeoptArgs, GCArgs, Name);
498 template <typename T0, typename T1, typename T2, typename T3>
499 static InvokeInst *CreateGCStatepointInvokeCommon(
500 IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
501 Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest,
502 uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs,
503 ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) {
504 // Extract out the type of the callee.
505 PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType());
506 assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
507 "actual callee must be a callable value");
509 Module *M = Builder->GetInsertBlock()->getParent()->getParent();
510 // Fill in the one generic type'd argument (the function is also vararg)
511 Function *FnStatepoint = Intrinsic::getDeclaration(
512 M, Intrinsic::experimental_gc_statepoint, {FuncPtrType});
514 std::vector<llvm::Value *> Args =
515 getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags,
516 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs);
517 return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder,
521 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
522 uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
523 BasicBlock *NormalDest, BasicBlock *UnwindDest,
524 ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs,
525 ArrayRef<Value *> GCArgs, const Twine &Name) {
526 return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
527 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
528 uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/,
529 DeoptArgs, GCArgs, Name);
532 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
533 uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
534 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
535 ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
536 ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
537 return CreateGCStatepointInvokeCommon<Use, Use, Use, Value *>(
538 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
539 InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
542 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
543 uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
544 BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
545 ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
546 return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
547 this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
548 uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs,
552 CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint,
555 Intrinsic::ID ID = Intrinsic::experimental_gc_result;
556 Module *M = BB->getParent()->getParent();
557 Type *Types[] = {ResultType};
558 Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types);
560 Value *Args[] = {Statepoint};
561 return createCallHelper(FnGCResult, Args, this, Name);
564 CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint,
569 Module *M = BB->getParent()->getParent();
570 Type *Types[] = {ResultType};
571 Value *FnGCRelocate =
572 Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types);
574 Value *Args[] = {Statepoint,
575 getInt32(BaseOffset),
576 getInt32(DerivedOffset)};
577 return createCallHelper(FnGCRelocate, Args, this, Name);
580 CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID,
581 Value *LHS, Value *RHS,
583 Module *M = BB->getParent()->getParent();
584 Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() });
585 return createCallHelper(Fn, { LHS, RHS }, this, Name);