LLVM  6.0.0svn
IRBuilder.cpp
Go to the documentation of this file.
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/IRBuilder.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/GlobalVariable.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.
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(),
34  StrConstant, Name, nullptr,
36  AddressSpace);
38  return GV;
39 }
40 
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);
56  return BCI;
57 }
58 
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,
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 
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)
99 
100  if (NoAliasTag)
101  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
102 
103  return CI;
104 }
105 
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)
130 
131  if (NoAliasTag)
132  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
133 
134  return CI;
135 }
136 
138  Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size,
139  uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
140  MDNode *ScopeTag, MDNode *NoAliasTag) {
141  assert(DstAlign >= ElementSize &&
142  "Pointer alignment must be at least element size");
143  assert(SrcAlign >= ElementSize &&
144  "Pointer alignment must be at least element size");
145  Dst = getCastedInt8PtrValue(Dst);
146  Src = getCastedInt8PtrValue(Src);
147 
148  Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
149  Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
150  Module *M = BB->getParent()->getParent();
152  M, Intrinsic::memcpy_element_unordered_atomic, Tys);
153 
154  CallInst *CI = createCallHelper(TheFn, Ops, this);
155 
156  // Set the alignment of the pointer args.
157  CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
158  CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
159 
160  // Set the TBAA info if present.
161  if (TBAATag)
162  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
163 
164  // Set the TBAA Struct info if present.
165  if (TBAAStructTag)
166  CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
167 
168  if (ScopeTag)
170 
171  if (NoAliasTag)
172  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
173 
174  return CI;
175 }
176 
178 CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
179  bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
180  MDNode *NoAliasTag) {
181  Dst = getCastedInt8PtrValue(Dst);
182  Src = getCastedInt8PtrValue(Src);
183 
184  Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
185  Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
186  Module *M = BB->getParent()->getParent();
187  Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys);
188 
189  CallInst *CI = createCallHelper(TheFn, Ops, this);
190 
191  // Set the TBAA info if present.
192  if (TBAATag)
193  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
194 
195  if (ScopeTag)
197 
198  if (NoAliasTag)
199  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
200 
201  return CI;
202 }
203 
205  Value *Src) {
206  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
207  Value *Ops[] = {Src};
208  Type *Tys[] = { Src->getType()->getVectorElementType(), Src->getType() };
209  auto Decl = Intrinsic::getDeclaration(M, ID, Tys);
210  return createCallHelper(Decl, Ops, Builder);
211 }
212 
215  Value *Ops[] = {Acc, Src};
216  Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(),
217  Src->getType()};
218  auto Decl = Intrinsic::getDeclaration(
219  M, Intrinsic::experimental_vector_reduce_fadd, Tys);
220  return createCallHelper(Decl, Ops, this);
221 }
222 
225  Value *Ops[] = {Acc, Src};
226  Type *Tys[] = {Src->getType()->getVectorElementType(), Acc->getType(),
227  Src->getType()};
228  auto Decl = Intrinsic::getDeclaration(
229  M, Intrinsic::experimental_vector_reduce_fmul, Tys);
230  return createCallHelper(Decl, Ops, this);
231 }
232 
234  return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_add,
235  Src);
236 }
237 
239  return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_mul,
240  Src);
241 }
242 
244  return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_and,
245  Src);
246 }
247 
249  return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_or,
250  Src);
251 }
252 
254  return getReductionIntrinsic(this, Intrinsic::experimental_vector_reduce_xor,
255  Src);
256 }
257 
259  auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smax
260  : Intrinsic::experimental_vector_reduce_umax;
261  return getReductionIntrinsic(this, ID, Src);
262 }
263 
265  auto ID = IsSigned ? Intrinsic::experimental_vector_reduce_smin
266  : Intrinsic::experimental_vector_reduce_umin;
267  return getReductionIntrinsic(this, ID, Src);
268 }
269 
271  auto Rdx = getReductionIntrinsic(
272  this, Intrinsic::experimental_vector_reduce_fmax, Src);
273  if (NoNaN) {
275  FMF.setNoNaNs();
276  Rdx->setFastMathFlags(FMF);
277  }
278  return Rdx;
279 }
280 
282  auto Rdx = getReductionIntrinsic(
283  this, Intrinsic::experimental_vector_reduce_fmin, Src);
284  if (NoNaN) {
286  FMF.setNoNaNs();
287  Rdx->setFastMathFlags(FMF);
288  }
289  return Rdx;
290 }
291 
293  assert(isa<PointerType>(Ptr->getType()) &&
294  "lifetime.start only applies to pointers.");
295  Ptr = getCastedInt8PtrValue(Ptr);
296  if (!Size)
297  Size = getInt64(-1);
298  else
299  assert(Size->getType() == getInt64Ty() &&
300  "lifetime.start requires the size to be an i64");
301  Value *Ops[] = { Size, Ptr };
302  Module *M = BB->getParent()->getParent();
303  Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start,
304  { Ptr->getType() });
305  return createCallHelper(TheFn, Ops, this);
306 }
307 
309  assert(isa<PointerType>(Ptr->getType()) &&
310  "lifetime.end only applies to pointers.");
311  Ptr = getCastedInt8PtrValue(Ptr);
312  if (!Size)
313  Size = getInt64(-1);
314  else
315  assert(Size->getType() == getInt64Ty() &&
316  "lifetime.end requires the size to be an i64");
317  Value *Ops[] = { Size, Ptr };
318  Module *M = BB->getParent()->getParent();
319  Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end,
320  { Ptr->getType() });
321  return createCallHelper(TheFn, Ops, this);
322 }
323 
325 
326  assert(isa<PointerType>(Ptr->getType()) &&
327  "invariant.start only applies to pointers.");
328  Ptr = getCastedInt8PtrValue(Ptr);
329  if (!Size)
330  Size = getInt64(-1);
331  else
332  assert(Size->getType() == getInt64Ty() &&
333  "invariant.start requires the size to be an i64");
334 
335  Value *Ops[] = {Size, Ptr};
336  // Fill in the single overloaded type: memory object type.
337  Type *ObjectPtr[1] = {Ptr->getType()};
338  Module *M = BB->getParent()->getParent();
339  Value *TheFn =
340  Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr);
341  return createCallHelper(TheFn, Ops, this);
342 }
343 
345  assert(Cond->getType() == getInt1Ty() &&
346  "an assumption condition must be of type i1");
347 
348  Value *Ops[] = { Cond };
349  Module *M = BB->getParent()->getParent();
350  Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume);
351  return createCallHelper(FnAssume, Ops, this);
352 }
353 
354 /// \brief Create a call to a Masked Load intrinsic.
355 /// \p Ptr - base pointer for the load
356 /// \p Align - alignment of the source location
357 /// \p Mask - vector of booleans which indicates what vector lanes should
358 /// be accessed in memory
359 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
360 /// of the result
361 /// \p Name - name of the result variable
363  Value *Mask, Value *PassThru,
364  const Twine &Name) {
365  PointerType *PtrTy = cast<PointerType>(Ptr->getType());
366  Type *DataTy = PtrTy->getElementType();
367  assert(DataTy->isVectorTy() && "Ptr should point to a vector");
368  assert(Mask && "Mask should not be all-ones (null)");
369  if (!PassThru)
370  PassThru = UndefValue::get(DataTy);
371  Type *OverloadedTypes[] = { DataTy, PtrTy };
372  Value *Ops[] = { Ptr, getInt32(Align), Mask, PassThru};
373  return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
374  OverloadedTypes, Name);
375 }
376 
377 /// \brief Create a call to a Masked Store intrinsic.
378 /// \p Val - data to be stored,
379 /// \p Ptr - base pointer for the store
380 /// \p Align - alignment of the destination location
381 /// \p Mask - vector of booleans which indicates what vector lanes should
382 /// be accessed in memory
384  unsigned Align, Value *Mask) {
385  PointerType *PtrTy = cast<PointerType>(Ptr->getType());
386  Type *DataTy = PtrTy->getElementType();
387  assert(DataTy->isVectorTy() && "Ptr should point to a vector");
388  assert(Mask && "Mask should not be all-ones (null)");
389  Type *OverloadedTypes[] = { DataTy, PtrTy };
390  Value *Ops[] = { Val, Ptr, getInt32(Align), Mask };
391  return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
392 }
393 
394 /// Create a call to a Masked intrinsic, with given intrinsic Id,
395 /// an array of operands - Ops, and an array of overloaded types -
396 /// OverloadedTypes.
397 CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
398  ArrayRef<Value *> Ops,
399  ArrayRef<Type *> OverloadedTypes,
400  const Twine &Name) {
401  Module *M = BB->getParent()->getParent();
402  Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes);
403  return createCallHelper(TheFn, Ops, this, Name);
404 }
405 
406 /// \brief Create a call to a Masked Gather intrinsic.
407 /// \p Ptrs - vector of pointers for loading
408 /// \p Align - alignment for one element
409 /// \p Mask - vector of booleans which indicates what vector lanes should
410 /// be accessed in memory
411 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
412 /// of the result
413 /// \p Name - name of the result variable
415  Value *Mask, Value *PassThru,
416  const Twine& Name) {
417  auto PtrsTy = cast<VectorType>(Ptrs->getType());
418  auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
419  unsigned NumElts = PtrsTy->getVectorNumElements();
420  Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts);
421 
422  if (!Mask)
424  NumElts));
425 
426  if (!PassThru)
427  PassThru = UndefValue::get(DataTy);
428 
429  Type *OverloadedTypes[] = {DataTy, PtrsTy};
430  Value * Ops[] = {Ptrs, getInt32(Align), Mask, PassThru};
431 
432  // We specify only one type when we create this intrinsic. Types of other
433  // arguments are derived from this type.
434  return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
435  Name);
436 }
437 
438 /// \brief Create a call to a Masked Scatter intrinsic.
439 /// \p Data - data to be stored,
440 /// \p Ptrs - the vector of pointers, where the \p Data elements should be
441 /// stored
442 /// \p Align - alignment for one element
443 /// \p Mask - vector of booleans which indicates what vector lanes should
444 /// be accessed in memory
446  unsigned Align, Value *Mask) {
447  auto PtrsTy = cast<VectorType>(Ptrs->getType());
448  auto DataTy = cast<VectorType>(Data->getType());
449  unsigned NumElts = PtrsTy->getVectorNumElements();
450 
451 #ifndef NDEBUG
452  auto PtrTy = cast<PointerType>(PtrsTy->getElementType());
453  assert(NumElts == DataTy->getVectorNumElements() &&
454  PtrTy->getElementType() == DataTy->getElementType() &&
455  "Incompatible pointer and data types");
456 #endif
457 
458  if (!Mask)
460  NumElts));
461 
462  Type *OverloadedTypes[] = {DataTy, PtrsTy};
463  Value * Ops[] = {Data, Ptrs, getInt32(Align), Mask};
464 
465  // We specify only one type when we create this intrinsic. Types of other
466  // arguments are derived from this type.
467  return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
468 }
469 
470 template <typename T0, typename T1, typename T2, typename T3>
471 static std::vector<Value *>
472 getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes,
473  Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
474  ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs,
475  ArrayRef<T3> GCArgs) {
476  std::vector<Value *> Args;
477  Args.push_back(B.getInt64(ID));
478  Args.push_back(B.getInt32(NumPatchBytes));
479  Args.push_back(ActualCallee);
480  Args.push_back(B.getInt32(CallArgs.size()));
481  Args.push_back(B.getInt32(Flags));
482  Args.insert(Args.end(), CallArgs.begin(), CallArgs.end());
483  Args.push_back(B.getInt32(TransitionArgs.size()));
484  Args.insert(Args.end(), TransitionArgs.begin(), TransitionArgs.end());
485  Args.push_back(B.getInt32(DeoptArgs.size()));
486  Args.insert(Args.end(), DeoptArgs.begin(), DeoptArgs.end());
487  Args.insert(Args.end(), GCArgs.begin(), GCArgs.end());
488 
489  return Args;
490 }
491 
492 template <typename T0, typename T1, typename T2, typename T3>
494  IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
495  Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
496  ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs,
497  const Twine &Name) {
498  // Extract out the type of the callee.
499  PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType());
500  assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
501  "actual callee must be a callable value");
502 
503  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
504  // Fill in the one generic type'd argument (the function is also vararg)
505  Type *ArgTypes[] = { FuncPtrType };
506  Function *FnStatepoint =
507  Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
508  ArgTypes);
509 
510  std::vector<llvm::Value *> Args =
511  getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags,
512  CallArgs, TransitionArgs, DeoptArgs, GCArgs);
513  return createCallHelper(FnStatepoint, Args, Builder, Name);
514 }
515 
517  uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
518  ArrayRef<Value *> CallArgs, ArrayRef<Value *> DeoptArgs,
519  ArrayRef<Value *> GCArgs, const Twine &Name) {
520  return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
521  this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
522  CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name);
523 }
524 
526  uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags,
527  ArrayRef<Use> CallArgs, ArrayRef<Use> TransitionArgs,
528  ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
529  return CreateGCStatepointCallCommon<Use, Use, Use, Value *>(
530  this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
531  DeoptArgs, GCArgs, Name);
532 }
533 
535  uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee,
536  ArrayRef<Use> CallArgs, ArrayRef<Value *> DeoptArgs,
537  ArrayRef<Value *> GCArgs, const Twine &Name) {
538  return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
539  this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
540  CallArgs, None, DeoptArgs, GCArgs, Name);
541 }
542 
543 template <typename T0, typename T1, typename T2, typename T3>
545  IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
546  Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest,
547  uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs,
548  ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) {
549  // Extract out the type of the callee.
550  PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType());
551  assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
552  "actual callee must be a callable value");
553 
554  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
555  // Fill in the one generic type'd argument (the function is also vararg)
556  Function *FnStatepoint = Intrinsic::getDeclaration(
557  M, Intrinsic::experimental_gc_statepoint, {FuncPtrType});
558 
559  std::vector<llvm::Value *> Args =
560  getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags,
561  InvokeArgs, TransitionArgs, DeoptArgs, GCArgs);
562  return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder,
563  Name);
564 }
565 
567  uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
568  BasicBlock *NormalDest, BasicBlock *UnwindDest,
569  ArrayRef<Value *> InvokeArgs, ArrayRef<Value *> DeoptArgs,
570  ArrayRef<Value *> GCArgs, const Twine &Name) {
571  return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
572  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
573  uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/,
574  DeoptArgs, GCArgs, Name);
575 }
576 
578  uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
579  BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
580  ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
581  ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
582  return CreateGCStatepointInvokeCommon<Use, Use, Use, Value *>(
583  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
584  InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
585 }
586 
588  uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
589  BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
590  ArrayRef<Value *> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
591  return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
592  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
593  uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs,
594  Name);
595 }
596 
598  Type *ResultType,
599  const Twine &Name) {
600  Intrinsic::ID ID = Intrinsic::experimental_gc_result;
601  Module *M = BB->getParent()->getParent();
602  Type *Types[] = {ResultType};
603  Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types);
604 
605  Value *Args[] = {Statepoint};
606  return createCallHelper(FnGCResult, Args, this, Name);
607 }
608 
610  int BaseOffset,
611  int DerivedOffset,
612  Type *ResultType,
613  const Twine &Name) {
614  Module *M = BB->getParent()->getParent();
615  Type *Types[] = {ResultType};
616  Value *FnGCRelocate =
617  Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types);
618 
619  Value *Args[] = {Statepoint,
620  getInt32(BaseOffset),
621  getInt32(DerivedOffset)};
622  return createCallHelper(FnGCRelocate, Args, this, Name);
623 }
624 
626  Value *LHS, Value *RHS,
627  const Twine &Name) {
628  Module *M = BB->getParent()->getParent();
629  Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() });
630  return createCallHelper(Fn, { LHS, RHS }, this, Name);
631 }
Type * getVectorElementType() const
Definition: Type.h:368
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:90
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:172
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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:2451
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Definition: IRBuilder.cpp:324
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:125
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
iterator begin() const
Definition: ArrayRef.h:137
FastMathFlags FMF
Definition: IRBuilder.h:99
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:609
This class represents a function call, abstracting a target machine&#39;s calling convention.
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:57
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:728
Metadata node.
Definition: Metadata.h:862
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned 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:405
static CallInst * createCallHelper(Value *Callee, ArrayRef< Value *> Ops, IRBuilderBase *Builder, const Twine &Name="")
Definition: IRBuilder.cpp:59
LLVMContext & Context
Definition: IRBuilder.h:96
static CallInst * CreateGCStatepointCallCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs, ArrayRef< T1 > TransitionArgs, ArrayRef< T2 > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
Definition: IRBuilder.cpp:493
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:353
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a vector fadd reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:213
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
CallInst * CreateMaskedGather(Value *Ptrs, unsigned Align, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
Definition: IRBuilder.cpp:414
BasicBlock * BB
Definition: IRBuilder.h:94
CallInst * CreateFPMinReduce(Value *Src, bool NoNaN=false)
Create a vector float min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:281
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:122
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.h:159
CallInst * CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memmove between the specified pointers.
Definition: IRBuilder.h:468
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
amdgpu Simplify well known AMD library false Value * Callee
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:980
Class to represent pointers.
Definition: DerivedTypes.h:467
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:253
CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, ArrayRef< Value *> CallArgs, 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:516
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:150
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:283
This is an important base class in LLVM.
Definition: Constant.h:42
static InvokeInst * CreateGCStatepointInvokeCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, ArrayRef< T0 > InvokeArgs, ArrayRef< T1 > TransitionArgs, ArrayRef< T2 > DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
Definition: IRBuilder.cpp:544
InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> InvokeArgs, ArrayRef< Value *> DeoptArgs, ArrayRef< Value *> GCArgs, const Twine &Name="")
brief Create an invoke to the experimental.gc.statepoint intrinsic to start a new statepoint sequence...
Definition: IRBuilder.cpp:566
A specialization of it&#39;s base class for read-write access to a gc.statepoint.
Definition: Statepoint.h:319
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:495
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:313
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
Definition: Constants.cpp:261
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we&#39;re emitting into.
Definition: IRBuilder.cpp:41
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1320
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:386
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1214
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:308
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:317
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:233
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:258
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Make a new global variable with initializer type i8*.
Definition: IRBuilder.cpp:27
CallInst * CreateAssumption(Value *Cond)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Definition: IRBuilder.cpp:344
static CallInst * getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID, Value *Src)
Definition: IRBuilder.cpp:204
AddressSpace
Definition: NVPTXBaseInfo.h:22
iterator end() const
Definition: ArrayRef.h:138
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:383
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:308
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs, ArrayRef< T1 > TransitionArgs, ArrayRef< T2 > DeoptArgs, ArrayRef< T3 > GCArgs)
Definition: IRBuilder.cpp:472
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a vector fmul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:223
CallInst * CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
Definition: IRBuilder.cpp:362
static InvokeInst * createInvokeHelper(Value *Invokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value *> Ops, IRBuilderBase *Builder, const Twine &Name="")
Definition: IRBuilder.cpp:68
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:333
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:243
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:248
CallInst * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type. ...
Definition: IRBuilder.cpp:625
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:264
iterator insert(iterator where, pointer New)
Definition: ilist.h:241
CallInst * CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memcpy between the specified pointers.
Definition: IRBuilder.h:423
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:208
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
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:597
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:238
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, unsigned Align, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
Definition: IRBuilder.cpp:445
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:556
LLVM Value Representation.
Definition: Value.h:73
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:593
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
BasicBlock::iterator GetInsertPoint() const
Definition: IRBuilder.h:123
Invoke instruction.
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:292
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static bool isVolatile(Instruction *Inst)
CallInst * CreateElementUnorderedAtomicMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, uint64_t 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.h:446
CallInst * CreateFPMaxReduce(Value *Src, bool NoNaN=false)
Create a vector float max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:270
BasicBlock::iterator InsertPt
Definition: IRBuilder.h:95
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
Definition: DerivedTypes.h:486
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.