]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/IR/IRBuilder.cpp
Merge ^/head r317503 through r317807.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / IR / IRBuilder.cpp
1 //===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
12 //
13 //===----------------------------------------------------------------------===//
14
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"
21 using namespace llvm;
22
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
26 /// created.
27 GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str,
28                                                   const Twine &Name,
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,
36                                           AddressSpace);
37   GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
38   return GV;
39 }
40
41 Type *IRBuilderBase::getCurrentFunctionReturnType() const {
42   assert(BB && BB->getParent() && "No current function!");
43   return BB->getParent()->getReturnType();
44 }
45
46 Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) {
47   PointerType *PT = cast<PointerType>(Ptr->getType());
48   if (PT->getElementType()->isIntegerTy(8))
49     return Ptr;
50   
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);
56   return BCI;
57 }
58
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);
65   return CI;  
66 }
67
68 static InvokeInst *createInvokeHelper(Value *Invokee, BasicBlock *NormalDest,
69                                       BasicBlock *UnwindDest,
70                                       ArrayRef<Value *> Ops,
71                                       IRBuilderBase *Builder,
72                                       const Twine &Name = "") {
73   InvokeInst *II =
74       InvokeInst::Create(Invokee, NormalDest, UnwindDest, Ops, Name);
75   Builder->GetInsertBlock()->getInstList().insert(Builder->GetInsertPoint(),
76                                                   II);
77   Builder->SetInstDebugLocation(II);
78   return II;
79 }
80
81 CallInst *IRBuilderBase::
82 CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
83              bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
84              MDNode *NoAliasTag) {
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);
90   
91   CallInst *CI = createCallHelper(TheFn, Ops, this);
92   
93   // Set the TBAA info if present.
94   if (TBAATag)
95     CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
96
97   if (ScopeTag)
98     CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
99  
100   if (NoAliasTag)
101     CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
102  
103   return CI;
104 }
105
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);
112
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);
117   
118   CallInst *CI = createCallHelper(TheFn, Ops, this);
119   
120   // Set the TBAA info if present.
121   if (TBAATag)
122     CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
123
124   // Set the TBAA Struct info if present.
125   if (TBAAStructTag)
126     CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
127  
128   if (ScopeTag)
129     CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
130  
131   if (NoAliasTag)
132     CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
133  
134   return CI;  
135 }
136
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);
143   
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);
148   
149   CallInst *CI = createCallHelper(TheFn, Ops, this);
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
164 CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
165   assert(isa<PointerType>(Ptr->getType()) &&
166          "lifetime.start only applies to pointers.");
167   Ptr = getCastedInt8PtrValue(Ptr);
168   if (!Size)
169     Size = getInt64(-1);
170   else
171     assert(Size->getType() == getInt64Ty() &&
172            "lifetime.start requires the size to be an i64");
173   Value *Ops[] = { Size, Ptr };
174   Module *M = BB->getParent()->getParent();
175   Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start,
176                                            { Ptr->getType() });
177   return createCallHelper(TheFn, Ops, this);
178 }
179
180 CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
181   assert(isa<PointerType>(Ptr->getType()) &&
182          "lifetime.end only applies to pointers.");
183   Ptr = getCastedInt8PtrValue(Ptr);
184   if (!Size)
185     Size = getInt64(-1);
186   else
187     assert(Size->getType() == getInt64Ty() &&
188            "lifetime.end requires the size to be an i64");
189   Value *Ops[] = { Size, Ptr };
190   Module *M = BB->getParent()->getParent();
191   Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end,
192                                            { Ptr->getType() });
193   return createCallHelper(TheFn, Ops, this);
194 }
195
196 CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) {
197
198   assert(isa<PointerType>(Ptr->getType()) &&
199          "invariant.start only applies to pointers.");
200   Ptr = getCastedInt8PtrValue(Ptr);
201   if (!Size)
202     Size = getInt64(-1);
203   else
204     assert(Size->getType() == getInt64Ty() &&
205            "invariant.start requires the size to be an i64");
206
207   Value *Ops[] = {Size, Ptr};
208   // Fill in the single overloaded type: memory object type.
209   Type *ObjectPtr[1] = {Ptr->getType()};
210   Module *M = BB->getParent()->getParent();
211   Value *TheFn =
212       Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr);
213   return createCallHelper(TheFn, Ops, this);
214 }
215
216 CallInst *IRBuilderBase::CreateAssumption(Value *Cond) {
217   assert(Cond->getType() == getInt1Ty() &&
218          "an assumption condition must be of type i1");
219
220   Value *Ops[] = { Cond };
221   Module *M = BB->getParent()->getParent();
222   Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume);
223   return createCallHelper(FnAssume, Ops, this);
224 }
225
226 /// \brief Create a call to a Masked Load intrinsic.
227 /// \p Ptr      - base pointer for the load
228 /// \p Align    - alignment of the source location
229 /// \p Mask     - vector of booleans which indicates what vector lanes should
230 ///               be accessed in memory
231 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
232 ///               of the result
233 /// \p Name     - name of the result variable
234 CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align,
235                                           Value *Mask, Value *PassThru,
236                                           const Twine &Name) {
237   PointerType *PtrTy = cast<PointerType>(Ptr->getType());
238   Type *DataTy = PtrTy->getElementType();
239   assert(DataTy->isVectorTy() && "Ptr should point to a vector");
240   if (!PassThru)
241     PassThru = UndefValue::get(DataTy);
242   Type *OverloadedTypes[] = { DataTy, PtrTy };
243   Value *Ops[] = { Ptr, getInt32(Align), Mask,  PassThru};
244   return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
245                                OverloadedTypes, Name);
246 }
247
248 /// \brief Create a call to a Masked Store intrinsic.
249 /// \p Val   - data to be stored,
250 /// \p Ptr   - base pointer for the store
251 /// \p Align - alignment of the destination location
252 /// \p Mask  - vector of booleans which indicates what vector lanes should
253 ///            be accessed in memory
254 CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr,
255                                            unsigned Align, Value *Mask) {
256   PointerType *PtrTy = cast<PointerType>(Ptr->getType());
257   Type *DataTy = PtrTy->getElementType();
258   assert(DataTy->isVectorTy() && "Ptr should point to a vector");
259   Type *OverloadedTypes[] = { DataTy, PtrTy };
260   Value *Ops[] = { Val, Ptr, getInt32(Align), Mask };
261   return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
262 }
263
264 /// Create a call to a Masked intrinsic, with given intrinsic Id,
265 /// an array of operands - Ops, and an array of overloaded types -
266 /// OverloadedTypes.
267 CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
268                                                ArrayRef<Value *> Ops,
269                                                ArrayRef<Type *> OverloadedTypes,
270                                                const Twine &Name) {
271   Module *M = BB->getParent()->getParent();
272   Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes);
273   return createCallHelper(TheFn, Ops, this, Name);
274 }
275
276 /// \brief Create a call to a Masked Gather intrinsic.
277 /// \p Ptrs     - vector of pointers for loading
278 /// \p Align    - alignment for one element
279 /// \p Mask     - vector of booleans which indicates what vector lanes should
280 ///               be accessed in memory
281 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
282 ///               of the result
283 /// \p Name     - name of the result variable
284 CallInst *IRBuilderBase::CreateMaskedGather(Value *Ptrs, unsigned Align,
285                                             Value *Mask,  Value *PassThru,
286                                             const Twine& Name) {
287   auto PtrsTy = cast<VectorType>(Ptrs->getType());
288   auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
289   unsigned NumElts = PtrsTy->getVectorNumElements();
290   Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts);
291
292   if (!Mask)
293     Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context),
294                                      NumElts));
295
296   Type *OverloadedTypes[] = {DataTy, PtrsTy};
297   Value * Ops[] = {Ptrs, getInt32(Align), Mask, UndefValue::get(DataTy)};
298
299   // We specify only one type when we create this intrinsic. Types of other
300   // arguments are derived from this type.
301   return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
302                                Name);
303 }
304
305 /// \brief Create a call to a Masked Scatter intrinsic.
306 /// \p Data  - data to be stored,
307 /// \p Ptrs  - the vector of pointers, where the \p Data elements should be
308 ///            stored
309 /// \p Align - alignment for one element
310 /// \p Mask  - vector of booleans which indicates what vector lanes should
311 ///            be accessed in memory
312 CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs,
313                                              unsigned Align, Value *Mask) {
314   auto PtrsTy = cast<VectorType>(Ptrs->getType());
315   auto DataTy = cast<VectorType>(Data->getType());
316   unsigned NumElts = PtrsTy->getVectorNumElements();
317
318 #ifndef NDEBUG
319   auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
320   assert(NumElts == DataTy->getVectorNumElements() &&
321          PtrTy->getElementType() == DataTy->getElementType() &&
322          "Incompatible pointer and data types");
323 #endif
324
325   if (!Mask)
326     Mask = Constant::getAllOnesValue(VectorType::get(Type::getInt1Ty(Context),
327                                      NumElts));
328
329   Type *OverloadedTypes[] = {DataTy, PtrsTy};
330   Value * Ops[] = {Data, Ptrs, getInt32(Align), Mask};
331
332   // We specify only one type when we create this intrinsic. Types of other
333   // arguments are derived from this type.
334   return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
335 }
336
337 template <typename T0, typename T1, typename T2, typename T3>
338 static std::vector<Value *>
339 getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes,
340                   Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
341                   ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs,
342                   ArrayRef<T3> GCArgs) {
343   std::vector<Value *> Args;
344   Args.push_back(B.getInt64(ID));
345   Args.push_back(B.getInt32(NumPatchBytes));
346   Args.push_back(ActualCallee);
347   Args.push_back(B.getInt32(CallArgs.size()));
348   Args.push_back(B.getInt32(Flags));
349   Args.insert(Args.end(), CallArgs.begin(), CallArgs.end());
350   Args.push_back(B.getInt32(TransitionArgs.size()));
351   Args.insert(Args.end(), TransitionArgs.begin(), TransitionArgs.end());
352   Args.push_back(B.getInt32(DeoptArgs.size()));
353   Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end());
354   Args.insert(Args.end(), GCArgs.begin(), GCArgs.end());
355
356   return Args;
357 }
358
359 template <typename T0, typename T1, typename T2, typename T3>
360 static CallInst *CreateGCStatepointCallCommon(
361     IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
362     Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
363     ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs,
364     const Twine &Name) {
365   // Extract out the type of the callee.
366   PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType());
367   assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
368          "actual callee must be a callable value");
369
370   Module *M = Builder->GetInsertBlock()->getParent()->getParent();
371   // Fill in the one generic type'd argument (the function is also vararg)
372   Type *ArgTypes[] = { FuncPtrType };
373   Function *FnStatepoint =
374     Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
375                               ArgTypes);
376
377   std::vector<llvm::Value *> Args =
378       getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags,
379                         CallArgs, TransitionArgs, DeoptArgs, GCArgs);
380   return createCallHelper(FnStatepoint, Args, Builder, Name);
381 }
382
383 CallInst *IRBuilderBase::CreateGCStatepointCall(
384     uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
385     ArrayRef<Value *> CallArgs, ArrayRef<Value *> DeoptArgs,
386     ArrayRef<Value *> GCArgs, const Twine &Name) {
387   return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
388       this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
389       CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name);
390 }
391
392 CallInst *IRBuilderBase::CreateGCStatepointCall(
393     uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags,
394     ArrayRef<Use> CallArgs, ArrayRef<Use> TransitionArgs,
395     ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
396   return CreateGCStatepointCallCommon<Use, Use, Use, Value *>(
397       this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
398       DeoptArgs, GCArgs, Name);
399 }
400
401 CallInst *IRBuilderBase::CreateGCStatepointCall(
402     uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
403     ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs,
404     ArrayRef<Value *> GCArgs, const Twine &Name) {
405   return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
406       this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
407       CallArgs, None, DeoptArgs, GCArgs, Name);
408 }
409
410 template <typename T0, typename T1, typename T2, typename T3>
411 static InvokeInst *CreateGCStatepointInvokeCommon(
412     IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
413     Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest,
414     uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs,
415     ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) {
416   // Extract out the type of the callee.
417   PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType());
418   assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
419          "actual callee must be a callable value");
420
421   Module *M = Builder->GetInsertBlock()->getParent()->getParent();
422   // Fill in the one generic type'd argument (the function is also vararg)
423   Function *FnStatepoint = Intrinsic::getDeclaration(
424       M, Intrinsic::experimental_gc_statepoint, {FuncPtrType});
425
426   std::vector<llvm::Value *> Args =
427       getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags,
428                         InvokeArgs, TransitionArgs, DeoptArgs, GCArgs);
429   return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder,
430                             Name);
431 }
432
433 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
434     uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
435     BasicBlock *NormalDest, BasicBlock *UnwindDest,
436     ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs,
437     ArrayRef<Value *> GCArgs, const Twine &Name) {
438   return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
439       this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
440       uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/,
441       DeoptArgs, GCArgs, Name);
442 }
443
444 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
445     uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
446     BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
447     ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
448     ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
449   return CreateGCStatepointInvokeCommon<Use, Use, Use, Value *>(
450       this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
451       InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
452 }
453
454 InvokeInst *IRBuilderBase::CreateGCStatepointInvoke(
455     uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
456     BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
457     ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
458   return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
459       this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
460       uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs,
461       Name);
462 }
463
464 CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint,
465                                        Type *ResultType,
466                                        const Twine &Name) {
467  Intrinsic::ID ID = Intrinsic::experimental_gc_result;
468  Module *M = BB->getParent()->getParent();
469  Type *Types[] = {ResultType};
470  Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types);
471
472  Value *Args[] = {Statepoint};
473  return createCallHelper(FnGCResult, Args, this, Name);
474 }
475
476 CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint,
477                                          int BaseOffset,
478                                          int DerivedOffset,
479                                          Type *ResultType,
480                                          const Twine &Name) {
481  Module *M = BB->getParent()->getParent();
482  Type *Types[] = {ResultType};
483  Value *FnGCRelocate =
484    Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types);
485
486  Value *Args[] = {Statepoint,
487                   getInt32(BaseOffset),
488                   getInt32(DerivedOffset)};
489  return createCallHelper(FnGCRelocate, Args, this, Name);
490 }
491
492 CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID,
493                                                Value *LHS, Value *RHS,
494                                                const Twine &Name) {
495   Module *M = BB->getParent()->getParent();
496   Function *Fn =  Intrinsic::getDeclaration(M, ID, { LHS->getType() });
497   return createCallHelper(Fn, { LHS, RHS }, this, Name);
498 }