LLVM  15.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/ADT/None.h"
17 #include "llvm/IR/Constant.h"
18 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/DerivedTypes.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/GlobalValue.h"
23 #include "llvm/IR/GlobalVariable.h"
24 #include "llvm/IR/IntrinsicInst.h"
25 #include "llvm/IR/Intrinsics.h"
26 #include "llvm/IR/LLVMContext.h"
27 #include "llvm/IR/NoFolder.h"
28 #include "llvm/IR/Operator.h"
29 #include "llvm/IR/Statepoint.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/IR/Value.h"
32 #include "llvm/Support/Casting.h"
33 #include <cassert>
34 #include <cstdint>
35 #include <vector>
36 
37 using 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) {
47  Constant *StrConstant = ConstantDataArray::getString(Context, Str);
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 
63 Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) {
64  auto *PT = cast<PointerType>(Ptr->getType());
65  if (PT->isOpaqueOrPointeeTypeMatches(getInt8Ty()))
66  return Ptr;
67 
68  // Otherwise, we need to insert a bitcast.
69  return CreateBitCast(Ptr, getInt8PtrTy(PT->getAddressSpace()));
70 }
71 
73  for (auto &KV : MetadataToCopy)
74  if (KV.first == LLVMContext::MD_dbg)
75  return {cast<DILocation>(KV.second)};
76 
77  return {};
78 }
80  for (const auto &KV : MetadataToCopy)
81  if (KV.first == LLVMContext::MD_dbg) {
82  I->setDebugLoc(DebugLoc(KV.second));
83  return;
84  }
85 }
86 
89  const Twine &Name = "",
90  Instruction *FMFSource = nullptr,
91  ArrayRef<OperandBundleDef> OpBundles = {}) {
92  CallInst *CI = Builder->CreateCall(Callee, Ops, OpBundles, Name);
93  if (FMFSource)
94  CI->copyFastMathFlags(FMFSource);
95  return CI;
96 }
97 
99  assert(isa<ConstantInt>(Scaling) && "Expected constant integer");
100  if (cast<ConstantInt>(Scaling)->isZero())
101  return Scaling;
103  Function *TheFn =
104  Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()});
105  CallInst *CI = createCallHelper(TheFn, {}, this, Name);
106  return cast<ConstantInt>(Scaling)->getSExtValue() == 1
107  ? CI
108  : CreateMul(CI, Scaling);
109 }
110 
112  Type *STy = DstType->getScalarType();
113  if (isa<ScalableVectorType>(DstType)) {
114  Type *StepVecType = DstType;
115  // TODO: We expect this special case (element type < 8 bits) to be
116  // temporary - once the intrinsic properly supports < 8 bits this code
117  // can be removed.
118  if (STy->getScalarSizeInBits() < 8)
119  StepVecType =
120  VectorType::get(getInt8Ty(), cast<ScalableVectorType>(DstType));
121  Value *Res = CreateIntrinsic(Intrinsic::experimental_stepvector,
122  {StepVecType}, {}, nullptr, Name);
123  if (StepVecType != DstType)
124  Res = CreateTrunc(Res, DstType);
125  return Res;
126  }
127 
128  unsigned NumEls = cast<FixedVectorType>(DstType)->getNumElements();
129 
130  // Create a vector of consecutive numbers from zero to VF.
132  for (unsigned i = 0; i < NumEls; ++i)
133  Indices.push_back(ConstantInt::get(STy, i));
134 
135  // Add the consecutive indices to the vector value.
136  return ConstantVector::get(Indices);
137 }
138 
140  MaybeAlign Align, bool isVolatile,
141  MDNode *TBAATag, MDNode *ScopeTag,
142  MDNode *NoAliasTag) {
143  Ptr = getCastedInt8PtrValue(Ptr);
144  Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
145  Type *Tys[] = { Ptr->getType(), Size->getType() };
146  Module *M = BB->getParent()->getParent();
147  Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys);
148 
149  CallInst *CI = createCallHelper(TheFn, Ops, this);
150 
151  if (Align)
152  cast<MemSetInst>(CI)->setDestAlignment(Align->value());
153 
154  // Set the TBAA info if present.
155  if (TBAATag)
156  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
157 
158  if (ScopeTag)
159  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
160 
161  if (NoAliasTag)
162  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
163 
164  return CI;
165 }
166 
168  Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
169  MDNode *TBAATag, MDNode *ScopeTag, MDNode *NoAliasTag) {
170 
171  Ptr = getCastedInt8PtrValue(Ptr);
172  Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
173  Type *Tys[] = {Ptr->getType(), Size->getType()};
174  Module *M = BB->getParent()->getParent();
176  M, Intrinsic::memset_element_unordered_atomic, Tys);
177 
178  CallInst *CI = createCallHelper(TheFn, Ops, this);
179 
180  cast<AtomicMemSetInst>(CI)->setDestAlignment(Alignment);
181 
182  // Set the TBAA info if present.
183  if (TBAATag)
184  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
185 
186  if (ScopeTag)
187  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
188 
189  if (NoAliasTag)
190  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
191 
192  return CI;
193 }
194 
196  Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
197  MaybeAlign SrcAlign, Value *Size, bool isVolatile, MDNode *TBAATag,
198  MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
199  Dst = getCastedInt8PtrValue(Dst);
200  Src = getCastedInt8PtrValue(Src);
201 
202  Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
203  Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
204  Module *M = BB->getParent()->getParent();
205  Function *TheFn = Intrinsic::getDeclaration(M, IntrID, Tys);
206 
207  CallInst *CI = createCallHelper(TheFn, Ops, this);
208 
209  auto* MCI = cast<MemTransferInst>(CI);
210  if (DstAlign)
211  MCI->setDestAlignment(*DstAlign);
212  if (SrcAlign)
213  MCI->setSourceAlignment(*SrcAlign);
214 
215  // Set the TBAA info if present.
216  if (TBAATag)
217  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
218 
219  // Set the TBAA Struct info if present.
220  if (TBAAStructTag)
221  CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
222 
223  if (ScopeTag)
224  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
225 
226  if (NoAliasTag)
227  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
228 
229  return CI;
230 }
231 
233  Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign,
234  Value *Size, bool IsVolatile, MDNode *TBAATag, MDNode *TBAAStructTag,
235  MDNode *ScopeTag, MDNode *NoAliasTag) {
236  Dst = getCastedInt8PtrValue(Dst);
237  Src = getCastedInt8PtrValue(Src);
238 
239  Value *Ops[] = {Dst, Src, Size, getInt1(IsVolatile)};
240  Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
241  Function *F = BB->getParent();
242  Module *M = F->getParent();
243  Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy_inline, Tys);
244 
245  CallInst *CI = createCallHelper(TheFn, Ops, this);
246 
247  auto *MCI = cast<MemCpyInlineInst>(CI);
248  if (DstAlign)
249  MCI->setDestAlignment(*DstAlign);
250  if (SrcAlign)
251  MCI->setSourceAlignment(*SrcAlign);
252 
253  // Set the TBAA info if present.
254  if (TBAATag)
255  MCI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
256 
257  // Set the TBAA Struct info if present.
258  if (TBAAStructTag)
259  MCI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
260 
261  if (ScopeTag)
262  MCI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
263 
264  if (NoAliasTag)
265  MCI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
266 
267  return CI;
268 }
269 
271  Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
272  uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
273  MDNode *ScopeTag, MDNode *NoAliasTag) {
274  assert(DstAlign >= ElementSize &&
275  "Pointer alignment must be at least element size");
276  assert(SrcAlign >= ElementSize &&
277  "Pointer alignment must be at least element size");
278  Dst = getCastedInt8PtrValue(Dst);
279  Src = getCastedInt8PtrValue(Src);
280 
281  Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
282  Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
283  Module *M = BB->getParent()->getParent();
285  M, Intrinsic::memcpy_element_unordered_atomic, Tys);
286 
287  CallInst *CI = createCallHelper(TheFn, Ops, this);
288 
289  // Set the alignment of the pointer args.
290  auto *AMCI = cast<AtomicMemCpyInst>(CI);
291  AMCI->setDestAlignment(DstAlign);
292  AMCI->setSourceAlignment(SrcAlign);
293 
294  // Set the TBAA info if present.
295  if (TBAATag)
296  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
297 
298  // Set the TBAA Struct info if present.
299  if (TBAAStructTag)
300  CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
301 
302  if (ScopeTag)
303  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
304 
305  if (NoAliasTag)
306  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
307 
308  return CI;
309 }
310 
312  Value *Src, MaybeAlign SrcAlign,
313  Value *Size, bool isVolatile,
314  MDNode *TBAATag, MDNode *ScopeTag,
315  MDNode *NoAliasTag) {
316  Dst = getCastedInt8PtrValue(Dst);
317  Src = getCastedInt8PtrValue(Src);
318 
319  Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
320  Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
321  Module *M = BB->getParent()->getParent();
322  Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys);
323 
324  CallInst *CI = createCallHelper(TheFn, Ops, this);
325 
326  auto *MMI = cast<MemMoveInst>(CI);
327  if (DstAlign)
328  MMI->setDestAlignment(*DstAlign);
329  if (SrcAlign)
330  MMI->setSourceAlignment(*SrcAlign);
331 
332  // Set the TBAA info if present.
333  if (TBAATag)
334  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
335 
336  if (ScopeTag)
337  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
338 
339  if (NoAliasTag)
340  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
341 
342  return CI;
343 }
344 
346  Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
347  uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
348  MDNode *ScopeTag, MDNode *NoAliasTag) {
349  assert(DstAlign >= ElementSize &&
350  "Pointer alignment must be at least element size");
351  assert(SrcAlign >= ElementSize &&
352  "Pointer alignment must be at least element size");
353  Dst = getCastedInt8PtrValue(Dst);
354  Src = getCastedInt8PtrValue(Src);
355 
356  Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
357  Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
358  Module *M = BB->getParent()->getParent();
360  M, Intrinsic::memmove_element_unordered_atomic, Tys);
361 
362  CallInst *CI = createCallHelper(TheFn, Ops, this);
363 
364  // Set the alignment of the pointer args.
365  CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
366  CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
367 
368  // Set the TBAA info if present.
369  if (TBAATag)
370  CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
371 
372  // Set the TBAA Struct info if present.
373  if (TBAAStructTag)
374  CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
375 
376  if (ScopeTag)
377  CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
378 
379  if (NoAliasTag)
380  CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
381 
382  return CI;
383 }
384 
386  Value *Src) {
387  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
388  Value *Ops[] = {Src};
389  Type *Tys[] = { Src->getType() };
390  auto Decl = Intrinsic::getDeclaration(M, ID, Tys);
391  return createCallHelper(Decl, Ops, Builder);
392 }
393 
396  Value *Ops[] = {Acc, Src};
397  auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fadd,
398  {Src->getType()});
399  return createCallHelper(Decl, Ops, this);
400 }
401 
404  Value *Ops[] = {Acc, Src};
405  auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fmul,
406  {Src->getType()});
407  return createCallHelper(Decl, Ops, this);
408 }
409 
411  return getReductionIntrinsic(this, Intrinsic::vector_reduce_add, Src);
412 }
413 
415  return getReductionIntrinsic(this, Intrinsic::vector_reduce_mul, Src);
416 }
417 
419  return getReductionIntrinsic(this, Intrinsic::vector_reduce_and, Src);
420 }
421 
423  return getReductionIntrinsic(this, Intrinsic::vector_reduce_or, Src);
424 }
425 
427  return getReductionIntrinsic(this, Intrinsic::vector_reduce_xor, Src);
428 }
429 
431  auto ID =
432  IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax;
433  return getReductionIntrinsic(this, ID, Src);
434 }
435 
437  auto ID =
438  IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin;
439  return getReductionIntrinsic(this, ID, Src);
440 }
441 
443  return getReductionIntrinsic(this, Intrinsic::vector_reduce_fmax, Src);
444 }
445 
447  return getReductionIntrinsic(this, Intrinsic::vector_reduce_fmin, Src);
448 }
449 
451  assert(isa<PointerType>(Ptr->getType()) &&
452  "lifetime.start only applies to pointers.");
453  Ptr = getCastedInt8PtrValue(Ptr);
454  if (!Size)
455  Size = getInt64(-1);
456  else
457  assert(Size->getType() == getInt64Ty() &&
458  "lifetime.start requires the size to be an i64");
459  Value *Ops[] = { Size, Ptr };
460  Module *M = BB->getParent()->getParent();
461  Function *TheFn =
462  Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, {Ptr->getType()});
463  return createCallHelper(TheFn, Ops, this);
464 }
465 
467  assert(isa<PointerType>(Ptr->getType()) &&
468  "lifetime.end only applies to pointers.");
469  Ptr = getCastedInt8PtrValue(Ptr);
470  if (!Size)
471  Size = getInt64(-1);
472  else
473  assert(Size->getType() == getInt64Ty() &&
474  "lifetime.end requires the size to be an i64");
475  Value *Ops[] = { Size, Ptr };
476  Module *M = BB->getParent()->getParent();
477  Function *TheFn =
478  Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, {Ptr->getType()});
479  return createCallHelper(TheFn, Ops, this);
480 }
481 
483 
484  assert(isa<PointerType>(Ptr->getType()) &&
485  "invariant.start only applies to pointers.");
486  Ptr = getCastedInt8PtrValue(Ptr);
487  if (!Size)
488  Size = getInt64(-1);
489  else
490  assert(Size->getType() == getInt64Ty() &&
491  "invariant.start requires the size to be an i64");
492 
493  Value *Ops[] = {Size, Ptr};
494  // Fill in the single overloaded type: memory object type.
495  Type *ObjectPtr[1] = {Ptr->getType()};
496  Module *M = BB->getParent()->getParent();
497  Function *TheFn =
498  Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr);
499  return createCallHelper(TheFn, Ops, this);
500 }
501 
502 CallInst *
504  ArrayRef<OperandBundleDef> OpBundles) {
505  assert(Cond->getType() == getInt1Ty() &&
506  "an assumption condition must be of type i1");
507 
508  Value *Ops[] = { Cond };
509  Module *M = BB->getParent()->getParent();
510  Function *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume);
511  return createCallHelper(FnAssume, Ops, this, "", nullptr, OpBundles);
512 }
513 
515  Module *M = BB->getModule();
516  auto *FnIntrinsic = Intrinsic::getDeclaration(
517  M, Intrinsic::experimental_noalias_scope_decl, {});
518  return createCallHelper(FnIntrinsic, {Scope}, this);
519 }
520 
521 /// Create a call to a Masked Load intrinsic.
522 /// \p Ty - vector type to load
523 /// \p Ptr - base pointer for the load
524 /// \p Alignment - alignment of the source location
525 /// \p Mask - vector of booleans which indicates what vector lanes should
526 /// be accessed in memory
527 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
528 /// of the result
529 /// \p Name - name of the result variable
531  Value *Mask, Value *PassThru,
532  const Twine &Name) {
533  auto *PtrTy = cast<PointerType>(Ptr->getType());
534  assert(Ty->isVectorTy() && "Type should be vector");
535  assert(PtrTy->isOpaqueOrPointeeTypeMatches(Ty) && "Wrong element type");
536  assert(Mask && "Mask should not be all-ones (null)");
537  if (!PassThru)
538  PassThru = UndefValue::get(Ty);
539  Type *OverloadedTypes[] = { Ty, PtrTy };
540  Value *Ops[] = {Ptr, getInt32(Alignment.value()), Mask, PassThru};
541  return CreateMaskedIntrinsic(Intrinsic::masked_load, Ops,
542  OverloadedTypes, Name);
543 }
544 
545 /// Create a call to a Masked Store intrinsic.
546 /// \p Val - data to be stored,
547 /// \p Ptr - base pointer for the store
548 /// \p Alignment - alignment of the destination location
549 /// \p Mask - vector of booleans which indicates what vector lanes should
550 /// be accessed in memory
552  Align Alignment, Value *Mask) {
553  auto *PtrTy = cast<PointerType>(Ptr->getType());
554  Type *DataTy = Val->getType();
555  assert(DataTy->isVectorTy() && "Val should be a vector");
556  assert(PtrTy->isOpaqueOrPointeeTypeMatches(DataTy) && "Wrong element type");
557  assert(Mask && "Mask should not be all-ones (null)");
558  Type *OverloadedTypes[] = { DataTy, PtrTy };
559  Value *Ops[] = {Val, Ptr, getInt32(Alignment.value()), Mask};
560  return CreateMaskedIntrinsic(Intrinsic::masked_store, Ops, OverloadedTypes);
561 }
562 
563 /// Create a call to a Masked intrinsic, with given intrinsic Id,
564 /// an array of operands - Ops, and an array of overloaded types -
565 /// OverloadedTypes.
566 CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
567  ArrayRef<Value *> Ops,
568  ArrayRef<Type *> OverloadedTypes,
569  const Twine &Name) {
570  Module *M = BB->getParent()->getParent();
571  Function *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes);
572  return createCallHelper(TheFn, Ops, this, Name);
573 }
574 
575 /// Create a call to a Masked Gather intrinsic.
576 /// \p Ty - vector type to gather
577 /// \p Ptrs - vector of pointers for loading
578 /// \p Align - alignment for one element
579 /// \p Mask - vector of booleans which indicates what vector lanes should
580 /// be accessed in memory
581 /// \p PassThru - pass-through value that is used to fill the masked-off lanes
582 /// of the result
583 /// \p Name - name of the result variable
585  Align Alignment, Value *Mask,
586  Value *PassThru,
587  const Twine &Name) {
588  auto *VecTy = cast<VectorType>(Ty);
589  ElementCount NumElts = VecTy->getElementCount();
590  auto *PtrsTy = cast<VectorType>(Ptrs->getType());
591  assert(cast<PointerType>(PtrsTy->getElementType())
592  ->isOpaqueOrPointeeTypeMatches(
593  cast<VectorType>(Ty)->getElementType()) &&
594  "Element type mismatch");
595  assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
596 
597  if (!Mask)
600 
601  if (!PassThru)
602  PassThru = UndefValue::get(Ty);
603 
604  Type *OverloadedTypes[] = {Ty, PtrsTy};
605  Value *Ops[] = {Ptrs, getInt32(Alignment.value()), Mask, PassThru};
606 
607  // We specify only one type when we create this intrinsic. Types of other
608  // arguments are derived from this type.
609  return CreateMaskedIntrinsic(Intrinsic::masked_gather, Ops, OverloadedTypes,
610  Name);
611 }
612 
613 /// Create a call to a Masked Scatter intrinsic.
614 /// \p Data - data to be stored,
615 /// \p Ptrs - the vector of pointers, where the \p Data elements should be
616 /// stored
617 /// \p Align - alignment for one element
618 /// \p Mask - vector of booleans which indicates what vector lanes should
619 /// be accessed in memory
621  Align Alignment, Value *Mask) {
622  auto *PtrsTy = cast<VectorType>(Ptrs->getType());
623  auto *DataTy = cast<VectorType>(Data->getType());
624  ElementCount NumElts = PtrsTy->getElementCount();
625 
626 #ifndef NDEBUG
627  auto *PtrTy = cast<PointerType>(PtrsTy->getElementType());
628  assert(NumElts == DataTy->getElementCount() &&
629  PtrTy->isOpaqueOrPointeeTypeMatches(DataTy->getElementType()) &&
630  "Incompatible pointer and data types");
631 #endif
632 
633  if (!Mask)
636 
637  Type *OverloadedTypes[] = {DataTy, PtrsTy};
638  Value *Ops[] = {Data, Ptrs, getInt32(Alignment.value()), Mask};
639 
640  // We specify only one type when we create this intrinsic. Types of other
641  // arguments are derived from this type.
642  return CreateMaskedIntrinsic(Intrinsic::masked_scatter, Ops, OverloadedTypes);
643 }
644 
645 template <typename T0>
646 static std::vector<Value *>
648  Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs) {
649  std::vector<Value *> Args;
650  Args.push_back(B.getInt64(ID));
651  Args.push_back(B.getInt32(NumPatchBytes));
652  Args.push_back(ActualCallee);
653  Args.push_back(B.getInt32(CallArgs.size()));
654  Args.push_back(B.getInt32(Flags));
655  llvm::append_range(Args, CallArgs);
656  // GC Transition and Deopt args are now always handled via operand bundle.
657  // They will be removed from the signature of gc.statepoint shortly.
658  Args.push_back(B.getInt32(0));
659  Args.push_back(B.getInt32(0));
660  // GC args are now encoded in the gc-live operand bundle
661  return Args;
662 }
663 
664 template<typename T1, typename T2, typename T3>
665 static std::vector<OperandBundleDef>
667  Optional<ArrayRef<T2>> DeoptArgs,
668  ArrayRef<T3> GCArgs) {
669  std::vector<OperandBundleDef> Rval;
670  if (DeoptArgs) {
671  SmallVector<Value*, 16> DeoptValues;
672  llvm::append_range(DeoptValues, *DeoptArgs);
673  Rval.emplace_back("deopt", DeoptValues);
674  }
675  if (TransitionArgs) {
676  SmallVector<Value*, 16> TransitionValues;
677  llvm::append_range(TransitionValues, *TransitionArgs);
678  Rval.emplace_back("gc-transition", TransitionValues);
679  }
680  if (GCArgs.size()) {
681  SmallVector<Value*, 16> LiveValues;
682  llvm::append_range(LiveValues, GCArgs);
683  Rval.emplace_back("gc-live", LiveValues);
684  }
685  return Rval;
686 }
687 
688 template <typename T0, typename T1, typename T2, typename T3>
690  IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
691  FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
692  Optional<ArrayRef<T1>> TransitionArgs, Optional<ArrayRef<T2>> DeoptArgs,
693  ArrayRef<T3> GCArgs, const Twine &Name) {
694  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
695  // Fill in the one generic type'd argument (the function is also vararg)
696  Function *FnStatepoint =
697  Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
698  {ActualCallee.getCallee()->getType()});
699 
700  std::vector<Value *> Args = getStatepointArgs(
701  *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
702 
703  CallInst *CI = Builder->CreateCall(
704  FnStatepoint, Args,
705  getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
706  CI->addParamAttr(2,
707  Attribute::get(Builder->getContext(), Attribute::ElementType,
708  ActualCallee.getFunctionType()));
709  return CI;
710 }
711 
713  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
714  ArrayRef<Value *> CallArgs, Optional<ArrayRef<Value *>> DeoptArgs,
715  ArrayRef<Value *> GCArgs, const Twine &Name) {
716  return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
717  this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
718  CallArgs, None /* No Transition Args */, DeoptArgs, GCArgs, Name);
719 }
720 
722  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
723  uint32_t Flags, ArrayRef<Value *> CallArgs,
724  Optional<ArrayRef<Use>> TransitionArgs, Optional<ArrayRef<Use>> DeoptArgs,
725  ArrayRef<Value *> GCArgs, const Twine &Name) {
726  return CreateGCStatepointCallCommon<Value *, Use, Use, Value *>(
727  this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs,
728  DeoptArgs, GCArgs, Name);
729 }
730 
732  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
733  ArrayRef<Use> CallArgs, Optional<ArrayRef<Value *>> DeoptArgs,
734  ArrayRef<Value *> GCArgs, const Twine &Name) {
735  return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
736  this, ID, NumPatchBytes, ActualCallee, uint32_t(StatepointFlags::None),
737  CallArgs, None, DeoptArgs, GCArgs, Name);
738 }
739 
740 template <typename T0, typename T1, typename T2, typename T3>
742  IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
743  FunctionCallee ActualInvokee, BasicBlock *NormalDest,
744  BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
745  Optional<ArrayRef<T1>> TransitionArgs, Optional<ArrayRef<T2>> DeoptArgs,
746  ArrayRef<T3> GCArgs, const Twine &Name) {
747  Module *M = Builder->GetInsertBlock()->getParent()->getParent();
748  // Fill in the one generic type'd argument (the function is also vararg)
749  Function *FnStatepoint =
750  Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
751  {ActualInvokee.getCallee()->getType()});
752 
753  std::vector<Value *> Args =
754  getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
755  Flags, InvokeArgs);
756 
757  InvokeInst *II = Builder->CreateInvoke(
758  FnStatepoint, NormalDest, UnwindDest, Args,
759  getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name);
760  II->addParamAttr(2,
761  Attribute::get(Builder->getContext(), Attribute::ElementType,
762  ActualInvokee.getFunctionType()));
763  return II;
764 }
765 
767  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
768  BasicBlock *NormalDest, BasicBlock *UnwindDest,
769  ArrayRef<Value *> InvokeArgs, Optional<ArrayRef<Value *>> DeoptArgs,
770  ArrayRef<Value *> GCArgs, const Twine &Name) {
771  return CreateGCStatepointInvokeCommon<Value *, Value *, Value *, Value *>(
772  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
773  uint32_t(StatepointFlags::None), InvokeArgs, None /* No Transition Args*/,
774  DeoptArgs, GCArgs, Name);
775 }
776 
778  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
779  BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
780  ArrayRef<Value *> InvokeArgs, Optional<ArrayRef<Use>> TransitionArgs,
781  Optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
782  const Twine &Name) {
783  return CreateGCStatepointInvokeCommon<Value *, Use, Use, Value *>(
784  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags,
785  InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name);
786 }
787 
789  uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee,
790  BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
791  Optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
792  const Twine &Name) {
793  return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
794  this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest,
795  uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs,
796  Name);
797 }
798 
800  Type *ResultType, const Twine &Name) {
801  Intrinsic::ID ID = Intrinsic::experimental_gc_result;
802  Module *M = BB->getParent()->getParent();
803  Type *Types[] = {ResultType};
804  Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types);
805 
806  Value *Args[] = {Statepoint};
807  return createCallHelper(FnGCResult, Args, this, Name);
808 }
809 
811  int BaseOffset, int DerivedOffset,
812  Type *ResultType, const Twine &Name) {
813  Module *M = BB->getParent()->getParent();
814  Type *Types[] = {ResultType};
815  Function *FnGCRelocate =
816  Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types);
817 
818  Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
819  return createCallHelper(FnGCRelocate, Args, this, Name);
820 }
821 
823  const Twine &Name) {
824  Module *M = BB->getParent()->getParent();
825  Type *PtrTy = DerivedPtr->getType();
826  Function *FnGCFindBase = Intrinsic::getDeclaration(
827  M, Intrinsic::experimental_gc_get_pointer_base, {PtrTy, PtrTy});
828  return createCallHelper(FnGCFindBase, {DerivedPtr}, this, Name);
829 }
830 
832  const Twine &Name) {
833  Module *M = BB->getParent()->getParent();
834  Type *PtrTy = DerivedPtr->getType();
835  Function *FnGCGetOffset = Intrinsic::getDeclaration(
836  M, Intrinsic::experimental_gc_get_pointer_offset, {PtrTy});
837  return createCallHelper(FnGCGetOffset, {DerivedPtr}, this, Name);
838 }
839 
841  Instruction *FMFSource,
842  const Twine &Name) {
843  Module *M = BB->getModule();
845  return createCallHelper(Fn, {V}, this, Name, FMFSource);
846 }
847 
849  Value *RHS,
850  Instruction *FMFSource,
851  const Twine &Name) {
852  Module *M = BB->getModule();
854  return createCallHelper(Fn, {LHS, RHS}, this, Name, FMFSource);
855 }
856 
858  ArrayRef<Type *> Types,
860  Instruction *FMFSource,
861  const Twine &Name) {
862  Module *M = BB->getModule();
863  Function *Fn = Intrinsic::getDeclaration(M, ID, Types);
864  return createCallHelper(Fn, Args, this, Name, FMFSource);
865 }
866 
868  Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource,
869  const Twine &Name, MDNode *FPMathTag,
872  Value *RoundingV = getConstrainedFPRounding(Rounding);
873  Value *ExceptV = getConstrainedFPExcept(Except);
874 
875  FastMathFlags UseFMF = FMF;
876  if (FMFSource)
877  UseFMF = FMFSource->getFastMathFlags();
878 
879  CallInst *C = CreateIntrinsic(ID, {L->getType()},
880  {L, R, RoundingV, ExceptV}, nullptr, Name);
882  setFPAttrs(C, FPMathTag, UseFMF);
883  return C;
884 }
885 
887  const Twine &Name, MDNode *FPMathTag) {
888  if (Instruction::isBinaryOp(Opc)) {
889  assert(Ops.size() == 2 && "Invalid number of operands!");
890  return CreateBinOp(static_cast<Instruction::BinaryOps>(Opc),
891  Ops[0], Ops[1], Name, FPMathTag);
892  }
893  if (Instruction::isUnaryOp(Opc)) {
894  assert(Ops.size() == 1 && "Invalid number of operands!");
895  return CreateUnOp(static_cast<Instruction::UnaryOps>(Opc),
896  Ops[0], Name, FPMathTag);
897  }
898  llvm_unreachable("Unexpected opcode!");
899 }
900 
902  Intrinsic::ID ID, Value *V, Type *DestTy,
903  Instruction *FMFSource, const Twine &Name, MDNode *FPMathTag,
906  Value *ExceptV = getConstrainedFPExcept(Except);
907 
908  FastMathFlags UseFMF = FMF;
909  if (FMFSource)
910  UseFMF = FMFSource->getFastMathFlags();
911 
912  CallInst *C;
913  bool HasRoundingMD = false;
914  switch (ID) {
915  default:
916  break;
917 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
918  case Intrinsic::INTRINSIC: \
919  HasRoundingMD = ROUND_MODE; \
920  break;
921 #include "llvm/IR/ConstrainedOps.def"
922  }
923  if (HasRoundingMD) {
924  Value *RoundingV = getConstrainedFPRounding(Rounding);
925  C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
926  nullptr, Name);
927  } else
928  C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
929  Name);
930 
932 
933  if (isa<FPMathOperator>(C))
934  setFPAttrs(C, FPMathTag, UseFMF);
935  return C;
936 }
937 
938 Value *IRBuilderBase::CreateFCmpHelper(
940  MDNode *FPMathTag, bool IsSignaling) {
941  if (IsFPConstrained) {
942  auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
943  : Intrinsic::experimental_constrained_fcmp;
944  return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
945  }
946 
947  if (auto *LC = dyn_cast<Constant>(LHS))
948  if (auto *RC = dyn_cast<Constant>(RHS))
949  return Insert(Folder.CreateFCmp(P, LC, RC), Name);
950  return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
951 }
952 
955  const Twine &Name, Optional<fp::ExceptionBehavior> Except) {
956  Value *PredicateV = getConstrainedFPPredicate(P);
957  Value *ExceptV = getConstrainedFPExcept(Except);
958 
959  CallInst *C = CreateIntrinsic(ID, {L->getType()},
960  {L, R, PredicateV, ExceptV}, nullptr, Name);
962  return C;
963 }
964 
966  Function *Callee, ArrayRef<Value *> Args, const Twine &Name,
970 
971  append_range(UseArgs, Args);
972  bool HasRoundingMD = false;
973  switch (Callee->getIntrinsicID()) {
974  default:
975  break;
976 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
977  case Intrinsic::INTRINSIC: \
978  HasRoundingMD = ROUND_MODE; \
979  break;
980 #include "llvm/IR/ConstrainedOps.def"
981  }
982  if (HasRoundingMD)
983  UseArgs.push_back(getConstrainedFPRounding(Rounding));
984  UseArgs.push_back(getConstrainedFPExcept(Except));
985 
986  CallInst *C = CreateCall(Callee, UseArgs, Name);
988  return C;
989 }
990 
992  const Twine &Name, Instruction *MDFrom) {
993  if (auto *V = Folder.FoldSelect(C, True, False))
994  return V;
995 
996  SelectInst *Sel = SelectInst::Create(C, True, False);
997  if (MDFrom) {
998  MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
999  MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1000  Sel = addBranchMetadata(Sel, Prof, Unpred);
1001  }
1002  if (isa<FPMathOperator>(Sel))
1003  setFPAttrs(Sel, nullptr /* MDNode* */, FMF);
1004  return Insert(Sel, Name);
1005 }
1006 
1008  const Twine &Name) {
1009  assert(LHS->getType() == RHS->getType() &&
1010  "Pointer subtraction operand types must match!");
1011  assert(cast<PointerType>(LHS->getType())
1012  ->isOpaqueOrPointeeTypeMatches(ElemTy) &&
1013  "Pointer type must match element type");
1016  Value *Difference = CreateSub(LHS_int, RHS_int);
1017  return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ElemTy),
1018  Name);
1019 }
1020 
1022  assert(isa<PointerType>(Ptr->getType()) &&
1023  "launder.invariant.group only applies to pointers.");
1024  // FIXME: we could potentially avoid casts to/from i8*.
1025  auto *PtrType = Ptr->getType();
1026  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1027  if (PtrType != Int8PtrTy)
1028  Ptr = CreateBitCast(Ptr, Int8PtrTy);
1029  Module *M = BB->getParent()->getParent();
1030  Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration(
1031  M, Intrinsic::launder_invariant_group, {Int8PtrTy});
1032 
1033  assert(FnLaunderInvariantGroup->getReturnType() == Int8PtrTy &&
1034  FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1035  Int8PtrTy &&
1036  "LaunderInvariantGroup should take and return the same type");
1037 
1038  CallInst *Fn = CreateCall(FnLaunderInvariantGroup, {Ptr});
1039 
1040  if (PtrType != Int8PtrTy)
1041  return CreateBitCast(Fn, PtrType);
1042  return Fn;
1043 }
1044 
1046  assert(isa<PointerType>(Ptr->getType()) &&
1047  "strip.invariant.group only applies to pointers.");
1048 
1049  // FIXME: we could potentially avoid casts to/from i8*.
1050  auto *PtrType = Ptr->getType();
1051  auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1052  if (PtrType != Int8PtrTy)
1053  Ptr = CreateBitCast(Ptr, Int8PtrTy);
1054  Module *M = BB->getParent()->getParent();
1055  Function *FnStripInvariantGroup = Intrinsic::getDeclaration(
1056  M, Intrinsic::strip_invariant_group, {Int8PtrTy});
1057 
1058  assert(FnStripInvariantGroup->getReturnType() == Int8PtrTy &&
1059  FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1060  Int8PtrTy &&
1061  "StripInvariantGroup should take and return the same type");
1062 
1063  CallInst *Fn = CreateCall(FnStripInvariantGroup, {Ptr});
1064 
1065  if (PtrType != Int8PtrTy)
1066  return CreateBitCast(Fn, PtrType);
1067  return Fn;
1068 }
1069 
1071  auto *Ty = cast<VectorType>(V->getType());
1072  if (isa<ScalableVectorType>(Ty)) {
1073  Module *M = BB->getParent()->getParent();
1075  M, Intrinsic::experimental_vector_reverse, Ty);
1076  return Insert(CallInst::Create(F, V), Name);
1077  }
1078  // Keep the original behaviour for fixed vector
1079  SmallVector<int, 8> ShuffleMask;
1080  int NumElts = Ty->getElementCount().getKnownMinValue();
1081  for (int i = 0; i < NumElts; ++i)
1082  ShuffleMask.push_back(NumElts - i - 1);
1083  return CreateShuffleVector(V, ShuffleMask, Name);
1084 }
1085 
1087  const Twine &Name) {
1088  assert(isa<VectorType>(V1->getType()) && "Unexpected type");
1089  assert(V1->getType() == V2->getType() &&
1090  "Splice expects matching operand types!");
1091 
1092  if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) {
1093  Module *M = BB->getParent()->getParent();
1095  M, Intrinsic::experimental_vector_splice, VTy);
1096 
1097  Value *Ops[] = {V1, V2, getInt32(Imm)};
1098  return Insert(CallInst::Create(F, Ops), Name);
1099  }
1100 
1101  unsigned NumElts = cast<FixedVectorType>(V1->getType())->getNumElements();
1102  assert(((-Imm <= NumElts) || (Imm < NumElts)) &&
1103  "Invalid immediate for vector splice!");
1104 
1105  // Keep the original behaviour for fixed vector
1106  unsigned Idx = (NumElts + Imm) % NumElts;
1108  for (unsigned I = 0; I < NumElts; ++I)
1109  Mask.push_back(Idx + I);
1110 
1111  return CreateShuffleVector(V1, V2, Mask);
1112 }
1113 
1115  const Twine &Name) {
1116  auto EC = ElementCount::getFixed(NumElts);
1117  return CreateVectorSplat(EC, V, Name);
1118 }
1119 
1121  const Twine &Name) {
1122  assert(EC.isNonZero() && "Cannot splat to an empty vector!");
1123 
1124  // First insert it into a poison vector so we can shuffle it.
1125  Type *I32Ty = getInt32Ty();
1126  Value *Poison = PoisonValue::get(VectorType::get(V->getType(), EC));
1127  V = CreateInsertElement(Poison, V, ConstantInt::get(I32Ty, 0),
1128  Name + ".splatinsert");
1129 
1130  // Shuffle the value across the desired number of elements.
1131  SmallVector<int, 16> Zeros;
1132  Zeros.resize(EC.getKnownMinValue());
1133  return CreateShuffleVector(V, Zeros, Name + ".splat");
1134 }
1135 
1137  const DataLayout &DL, Value *From, IntegerType *ExtractedTy,
1138  uint64_t Offset, const Twine &Name) {
1139  auto *IntTy = cast<IntegerType>(From->getType());
1140  assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
1141  DL.getTypeStoreSize(IntTy) &&
1142  "Element extends past full value");
1143  uint64_t ShAmt = 8 * Offset;
1144  Value *V = From;
1145  if (DL.isBigEndian())
1146  ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
1147  DL.getTypeStoreSize(ExtractedTy) - Offset);
1148  if (ShAmt) {
1149  V = CreateLShr(V, ShAmt, Name + ".shift");
1150  }
1151  assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
1152  "Cannot extract to a larger integer!");
1153  if (ExtractedTy != IntTy) {
1154  V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
1155  }
1156  return V;
1157 }
1158 
1160  Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex,
1161  MDNode *DbgInfo) {
1162  auto *BaseType = Base->getType();
1163  assert(isa<PointerType>(BaseType) &&
1164  "Invalid Base ptr type for preserve.array.access.index.");
1165  assert(cast<PointerType>(BaseType)->isOpaqueOrPointeeTypeMatches(ElTy) &&
1166  "Pointer element type mismatch");
1167 
1168  Value *LastIndexV = getInt32(LastIndex);
1170  SmallVector<Value *, 4> IdxList(Dimension, Zero);
1171  IdxList.push_back(LastIndexV);
1172 
1173  Type *ResultType =
1174  GetElementPtrInst::getGEPReturnType(ElTy, Base, IdxList);
1175 
1176  Module *M = BB->getParent()->getParent();
1177  Function *FnPreserveArrayAccessIndex = Intrinsic::getDeclaration(
1178  M, Intrinsic::preserve_array_access_index, {ResultType, BaseType});
1179 
1180  Value *DimV = getInt32(Dimension);
1181  CallInst *Fn =
1182  CreateCall(FnPreserveArrayAccessIndex, {Base, DimV, LastIndexV});
1183  Fn->addParamAttr(
1184  0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1185  if (DbgInfo)
1186  Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1187 
1188  return Fn;
1189 }
1190 
1192  Value *Base, unsigned FieldIndex, MDNode *DbgInfo) {
1193  assert(isa<PointerType>(Base->getType()) &&
1194  "Invalid Base ptr type for preserve.union.access.index.");
1195  auto *BaseType = Base->getType();
1196 
1197  Module *M = BB->getParent()->getParent();
1198  Function *FnPreserveUnionAccessIndex = Intrinsic::getDeclaration(
1199  M, Intrinsic::preserve_union_access_index, {BaseType, BaseType});
1200 
1201  Value *DIIndex = getInt32(FieldIndex);
1202  CallInst *Fn =
1203  CreateCall(FnPreserveUnionAccessIndex, {Base, DIIndex});
1204  if (DbgInfo)
1205  Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1206 
1207  return Fn;
1208 }
1209 
1211  Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex,
1212  MDNode *DbgInfo) {
1213  auto *BaseType = Base->getType();
1214  assert(isa<PointerType>(BaseType) &&
1215  "Invalid Base ptr type for preserve.struct.access.index.");
1216  assert(cast<PointerType>(BaseType)->isOpaqueOrPointeeTypeMatches(ElTy) &&
1217  "Pointer element type mismatch");
1218 
1219  Value *GEPIndex = getInt32(Index);
1221  Type *ResultType =
1222  GetElementPtrInst::getGEPReturnType(ElTy, Base, {Zero, GEPIndex});
1223 
1224  Module *M = BB->getParent()->getParent();
1225  Function *FnPreserveStructAccessIndex = Intrinsic::getDeclaration(
1226  M, Intrinsic::preserve_struct_access_index, {ResultType, BaseType});
1227 
1228  Value *DIIndex = getInt32(FieldIndex);
1229  CallInst *Fn = CreateCall(FnPreserveStructAccessIndex,
1230  {Base, GEPIndex, DIIndex});
1231  Fn->addParamAttr(
1232  0, Attribute::get(Fn->getContext(), Attribute::ElementType, ElTy));
1233  if (DbgInfo)
1234  Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
1235 
1236  return Fn;
1237 }
1238 
1239 CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
1240  Value *PtrValue,
1241  Value *AlignValue,
1242  Value *OffsetValue) {
1243  SmallVector<Value *, 4> Vals({PtrValue, AlignValue});
1244  if (OffsetValue)
1245  Vals.push_back(OffsetValue);
1246  OperandBundleDefT<Value *> AlignOpB("align", Vals);
1247  return CreateAssumption(ConstantInt::getTrue(getContext()), {AlignOpB});
1248 }
1249 
1251  Value *PtrValue,
1252  unsigned Alignment,
1253  Value *OffsetValue) {
1254  assert(isa<PointerType>(PtrValue->getType()) &&
1255  "trying to create an alignment assumption on a non-pointer?");
1256  assert(Alignment != 0 && "Invalid Alignment");
1257  auto *PtrTy = cast<PointerType>(PtrValue->getType());
1258  Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1259  Value *AlignValue = ConstantInt::get(IntPtrTy, Alignment);
1260  return CreateAlignmentAssumptionHelper(DL, PtrValue, AlignValue, OffsetValue);
1261 }
1262 
1264  Value *PtrValue,
1265  Value *Alignment,
1266  Value *OffsetValue) {
1267  assert(isa<PointerType>(PtrValue->getType()) &&
1268  "trying to create an alignment assumption on a non-pointer?");
1269  return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
1270 }
1271 
1275 void ConstantFolder::anchor() {}
1276 void NoFolder::anchor() {}
i
i
Definition: README.txt:29
llvm::IRBuilderBase::CreateIntMaxReduce
CallInst * CreateIntMaxReduce(Value *Src, bool IsSigned=false)
Create a vector integer max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:430
llvm::IRBuilderBase::getInt32Ty
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:501
llvm::IRBuilderBase::CreateConstrainedFPCall
CallInst * CreateConstrainedFPCall(Function *Callee, ArrayRef< Value * > Args, const Twine &Name="", Optional< RoundingMode > Rounding=None, Optional< fp::ExceptionBehavior > Except=None)
Definition: IRBuilder.cpp:965
getStatepointArgs
static std::vector< Value * > getStatepointArgs(IRBuilderBase &B, uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs)
Definition: IRBuilder.cpp:647
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::IRBuilderBase::CreateMulReduce
CallInst * CreateMulReduce(Value *Src)
Create a vector int mul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:414
llvm::Type::getInt1Ty
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:236
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::IRBuilderBase::getInt64Ty
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Definition: IRBuilder.h:506
llvm::IRBuilderFolder::CreateFCmp
virtual Value * CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const =0
NoFolder.h
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::Instruction::UnaryOps
UnaryOps
Definition: Instruction.h:779
llvm::IRBuilderBase::CreateLifetimeEnd
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:466
llvm::Intrinsic::getDeclaration
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:1410
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
IntrinsicInst.h
llvm::ElementCount
Definition: TypeSize.h:390
DebugInfoMetadata.h
llvm::Function
Definition: Function.h:60
llvm::IRBuilderBase::CreatePtrToInt
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1942
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::IRBuilderBase::CreateVectorReverse
Value * CreateVectorReverse(Value *V, const Twine &Name="")
Return a vector value that contains the vector V reversed.
Definition: IRBuilder.cpp:1070
llvm::IRBuilderBase::CreateGlobalString
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0, Module *M=nullptr)
Make a new global variable with initializer type i8*.
Definition: IRBuilder.cpp:43
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:91
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:309
llvm::GlobalValue::NotThreadLocal
@ NotThreadLocal
Definition: GlobalValue.h:178
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::IRBuilderBase::CreateConstrainedFPCast
CallInst * CreateConstrainedFPCast(Intrinsic::ID ID, Value *V, Type *DestTy, Instruction *FMFSource=nullptr, const Twine &Name="", MDNode *FPMathTag=nullptr, Optional< RoundingMode > Rounding=None, Optional< fp::ExceptionBehavior > Except=None)
Definition: IRBuilder.cpp:901
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::IRBuilderBase::CreateUnaryIntrinsic
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:840
llvm::IRBuilderBase::CreateAssumption
CallInst * CreateAssumption(Value *Cond, ArrayRef< OperandBundleDef > OpBundles=llvm::None)
Create an assume intrinsic call that allows the optimizer to assume that the provided condition will ...
Definition: IRBuilder.cpp:503
llvm::IRBuilderBase::setConstrainedFPCallAttr
void setConstrainedFPCallAttr(CallBase *I)
Definition: IRBuilder.h:336
llvm::IRBuilderBase::CreateStripInvariantGroup
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1045
llvm::IRBuilderBase::CreatePreserveUnionAccessIndex
Value * CreatePreserveUnionAccessIndex(Value *Base, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1191
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::IRBuilderBase::CreateShuffleVector
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Definition: IRBuilder.h:2313
llvm::OperandBundleDefT
A container for an operand bundle being viewed as a set of values rather than a set of uses.
Definition: AutoUpgrade.h:32
llvm::IRBuilderBase::FMF
FastMathFlags FMF
Definition: IRBuilder.h:125
llvm::GlobalValue::UnnamedAddr::Global
@ Global
llvm::IRBuilderBase::Folder
const IRBuilderFolder & Folder
Definition: IRBuilder.h:121
llvm::IRBuilderBase::CreateBinaryIntrinsic
CallInst * 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:848
llvm::Optional
Definition: APInt.h:33
llvm::IRBuilderBase::CreateInsertElement
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2289
Operator.h
llvm::IRBuilderBase::CreateNAryOp
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:886
llvm::GetElementPtrInst::getGEPReturnType
static Type * getGEPReturnType(Type *ElTy, Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
Definition: Instructions.h:1075
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::FastMathFlags
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:21
BaseType
llvm::CallBase::addParamAttr
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1526
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
llvm::IRBuilderBase::getInt1
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Definition: IRBuilder.h:436
llvm::IRBuilderBase::CreateGCGetPointerBase
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:822
llvm::IRBuilderBase::CreateInvariantStart
CallInst * CreateInvariantStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a call to invariant.start intrinsic.
Definition: IRBuilder.cpp:482
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1368
llvm::IRBuilderBase::CreateBinOp
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1532
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::IRBuilderBase::CreateElementUnorderedAtomicMemMove
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:345
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::IRBuilderBase::CreateConstrainedFPBinOp
CallInst * CreateConstrainedFPBinOp(Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource=nullptr, const Twine &Name="", MDNode *FPMathTag=nullptr, Optional< RoundingMode > Rounding=None, Optional< fp::ExceptionBehavior > Except=None)
Definition: IRBuilder.cpp:867
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::IRBuilderBase::CreateElementUnorderedAtomicMemSet
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:587
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1366
llvm::IRBuilderBase::CreateMul
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1234
llvm::SelectInst::Create
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Definition: Instructions.h:1768
GlobalValue.h
createCallHelper
static CallInst * createCallHelper(Function *Callee, ArrayRef< Value * > Ops, IRBuilderBase *Builder, const Twine &Name="", Instruction *FMFSource=nullptr, ArrayRef< OperandBundleDef > OpBundles={})
Definition: IRBuilder.cpp:87
llvm::IRBuilderBase::CreateGCStatepointCall
CallInst * CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef< Value * > CallArgs, 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:712
llvm::IRBuilderBase::CreateElementUnorderedAtomicMemCpy
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:270
Constants.h
isZero
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:518
llvm::IRBuilderFolder::FoldSelect
virtual Value * FoldSelect(Value *C, Value *True, Value *False) const =0
llvm::IRBuilderDefaultInserter::~IRBuilderDefaultInserter
virtual ~IRBuilderDefaultInserter()
llvm::IRBuilderBase::CreateVectorSplice
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:1086
llvm::IRBuilderBase::CreateMemTransferInst
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:195
llvm::IRBuilderBase::CreateMemSet
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:568
Intrinsics.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::IRBuilderBase::CreateExactSDiv
Value * CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1275
llvm::FCmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition: Instructions.h:1360
llvm::CallInst::Create
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1517
llvm::IRBuilderBase::CreateUnOp
Value * CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1612
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:227
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::Constant::getAllOnesValue
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:395
llvm::IRBuilderBase::CreatePreserveStructAccessIndex
Value * CreatePreserveStructAccessIndex(Type *ElTy, Value *Base, unsigned Index, unsigned FieldIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1210
llvm::Instruction
Definition: Instruction.h:42
llvm::Type::getScalarSizeInBits
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition: Type.cpp:189
llvm::IRBuilderBase::CreateXorReduce
CallInst * CreateXorReduce(Value *Src)
Create a vector int XOR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:426
llvm::IRBuilderBase::getInt8Ty
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:491
llvm::IRBuilderBase::getContext
LLVMContext & getContext() const
Definition: IRBuilder.h:175
llvm::IRBuilderBase::CreateMaskedGather
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:584
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:619
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1769
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:919
llvm::FunctionCallee::getFunctionType
FunctionType * getFunctionType()
Definition: DerivedTypes.h:182
llvm::BasicBlock::getModule
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:147
llvm::IRBuilderBase::CreateVScale
Value * CreateVScale(Constant *Scaling, const Twine &Name="")
Create a call to llvm.vscale, multiplied by Scaling.
Definition: IRBuilder.cpp:98
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::IRBuilderBase::CreateFPMaxReduce
CallInst * CreateFPMaxReduce(Value *Src)
Create a vector float max reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:442
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::IRBuilderBase::getCurrentDebugLocation
DebugLoc getCurrentDebugLocation() const
Get location information used by debugging information.
Definition: IRBuilder.cpp:72
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::None
const NoneType None
Definition: None.h:24
llvm::LinearPolySize< ElementCount >::getFixed
static ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:283
Statepoint.h
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:279
llvm::IRBuilderBase::CreateLifetimeStart
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
Definition: IRBuilder.cpp:450
llvm::IRBuilderBase::CreateLaunderInvariantGroup
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Definition: IRBuilder.cpp:1021
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3776
llvm::IRBuilderBase::CreateBitCast
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1952
BaseType
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
Definition: SafepointIRVerifier.cpp:314
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::Function::getReturnType
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:180
llvm::IRBuilderBase::getIntPtrTy
IntegerType * getIntPtrTy(const DataLayout &DL, unsigned AddrSpace=0)
Fetch the type representing a pointer to an integer value.
Definition: IRBuilder.h:554
llvm::StatepointFlags::None
@ None
llvm::IRBuilderBase::CreatePreserveArrayAccessIndex
Value * CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base, unsigned Dimension, unsigned LastIndex, MDNode *DbgInfo)
Definition: IRBuilder.cpp:1159
uint64_t
getReductionIntrinsic
static CallInst * getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID, Value *Src)
Definition: IRBuilder.cpp:385
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:577
llvm::IRBuilderBase::getInt32
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:461
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::FunctionType::getParamType
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
llvm::IRBuilderBase::getInt8PtrTy
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:549
llvm::IRBuilderBase::Context
LLVMContext & Context
Definition: IRBuilder.h:120
llvm::IRBuilderBase::CreateSelect
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition: IRBuilder.cpp:991
llvm::IRBuilderBase::CreateFPMinReduce
CallInst * CreateFPMinReduce(Value *Src)
Create a vector float min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:446
llvm::IRBuilderBase::CreateIntMinReduce
CallInst * CreateIntMinReduce(Value *Src, bool IsSigned=false)
Create a vector integer min reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:436
ArrayRef.h
llvm::IRBuilderBase::CreateConstrainedFPCmp
CallInst * CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, const Twine &Name="", Optional< fp::ExceptionBehavior > Except=None)
Definition: IRBuilder.cpp:953
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::IRBuilderBase::CreateFMulReduce
CallInst * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:402
llvm::IRBuilderBase::CreateGCResult
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:799
llvm::SelectInst
This class represents the LLVM 'select' instruction.
Definition: Instructions.h:1737
llvm::Instruction::isBinaryOp
bool isBinaryOp() const
Definition: Instruction.h:162
llvm::IRBuilderBase::CreateIntrinsic
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:857
CreateGCStatepointInvokeCommon
static InvokeInst * CreateGCStatepointInvokeCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, ArrayRef< T0 > InvokeArgs, Optional< ArrayRef< T1 >> TransitionArgs, Optional< ArrayRef< T2 >> DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
Definition: IRBuilder.cpp:741
llvm::IRBuilderBase::CreateAndReduce
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:418
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:926
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::ConstantExpr::getSizeOf
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:2382
llvm::IRBuilderCallbackInserter::~IRBuilderCallbackInserter
~IRBuilderCallbackInserter() override
llvm::IRBuilderBase::CreateNoAliasScopeDeclaration
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
Definition: IRBuilder.cpp:514
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Instruction::getFastMathFlags
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Definition: Instruction.cpp:289
llvm::IRBuilderBase::IsFPConstrained
bool IsFPConstrained
Definition: IRBuilder.h:127
None.h
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:178
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::IRBuilderBase::CreateGCGetPointerOffset
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:831
uint32_t
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1813
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:991
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:93
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::ConstantDataArray::getString
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:3091
llvm::IRBuilderBase::SetInstDebugLocation
void SetInstDebugLocation(Instruction *I) const
If this builder has a current debug location, set it on the specified instruction.
Definition: IRBuilder.cpp:79
llvm::Instruction::copyFastMathFlags
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
Definition: Instruction.cpp:244
llvm::ConstantVector::get
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1389
llvm::IRBuilderBase::CreateMaskedScatter
CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
Definition: IRBuilder.cpp:620
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::IsVolatile
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
Definition: AMDGPUMetadata.h:199
llvm::IRBuilderBase::BB
BasicBlock * BB
Definition: IRBuilder.h:118
llvm::IRBuilderBase::CreateTrunc
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1856
llvm::FunctionCallee::getCallee
Value * getCallee()
Definition: DerivedTypes.h:184
llvm::IRBuilderBase::CreateAddReduce
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:410
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::Attribute::getWithAlignment
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:165
Constant.h
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
CreateGCStatepointCallCommon
static CallInst * CreateGCStatepointCallCommon(IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, uint32_t Flags, ArrayRef< T0 > CallArgs, Optional< ArrayRef< T1 >> TransitionArgs, Optional< ArrayRef< T2 >> DeoptArgs, ArrayRef< T3 > GCArgs, const Twine &Name)
Definition: IRBuilder.cpp:689
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
llvm::ConstantInt::getTrue
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:867
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::IRBuilderBase::CreateGCStatepointInvoke
InvokeInst * CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > InvokeArgs, 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:766
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::IRBuilderBase::Insert
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Definition: IRBuilder.h:144
GlobalVariable.h
llvm::IRBuilderBase::getInt64
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Definition: IRBuilder.h:466
llvm::IRBuilderBase::GetInsertBlock
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:173
Casting.h
Function.h
llvm::IRBuilderFolder::~IRBuilderFolder
virtual ~IRBuilderFolder()
llvm::IRBuilderBase::CreatePtrDiff
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:1007
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:175
llvm::IRBuilderBase::CreateFAddReduce
CallInst * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:394
llvm::IRBuilderBase::CreateExtractInteger
Value * CreateExtractInteger(const DataLayout &DL, Value *From, IntegerType *ExtractedTy, uint64_t Offset, const Twine &Name)
Return a value that has been extracted from a larger integer type.
Definition: IRBuilder.cpp:1136
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:786
llvm::IRBuilderBase::getInt1Ty
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition: IRBuilder.h:486
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::IRBuilderBase::CreateMemMove
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Definition: IRBuilder.h:658
llvm::IRBuilderBase::CreateLShr
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1310
llvm::IRBuilderBase::CreateMaskedStore
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Definition: IRBuilder.cpp:551
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::IntegerType::getBitWidth
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:72
llvm::Instruction::isUnaryOp
bool isUnaryOp() const
Definition: Instruction.h:161
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
llvm::IRBuilderBase::CreateGCRelocate
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:810
getStatepointBundles
static std::vector< OperandBundleDef > getStatepointBundles(Optional< ArrayRef< T1 >> TransitionArgs, Optional< ArrayRef< T2 >> DeoptArgs, ArrayRef< T3 > GCArgs)
Definition: IRBuilder.cpp:666
llvm::IRBuilderBase::CreateVectorSplat
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.cpp:1114
llvm::IRBuilderBase::CreateStepVector
Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
Definition: IRBuilder.cpp:111
DerivedTypes.h
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
LLVMContext.h
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::IRBuilderBase::CreateSub
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1217
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:235
llvm::IRBuilderBase::getCurrentFunctionReturnType
Type * getCurrentFunctionReturnType() const
Get the return type of the current function that we're emitting into.
Definition: IRBuilder.cpp:58
llvm::IRBuilderBase::CreateAlignmentAssumption
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:1250
Value.h
llvm::IRBuilderBase::CreateMemCpyInline
CallInst * CreateMemCpyInline(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:232
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::VectorType::get
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:668
llvm::IRBuilderBase::CreateOrReduce
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
Definition: IRBuilder.cpp:422
llvm::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2229
llvm::IRBuilderBase::CreateMaskedLoad
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:530
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::AArch64::Rounding
Rounding
Possible values of current rounding mode, which is specified in bits 23:22 of FPCR.
Definition: AArch64ISelLowering.h:478
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1788