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