LLVM  10.0.0
AMDGPUTargetTransformInfo.cpp
Go to the documentation of this file.
1 //===- AMDGPUTargetTransformInfo.cpp - AMDGPU specific TTI pass -----------===//
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 // \file
10 // This file implements a TargetTransformInfo analysis pass specific to the
11 // AMDGPU target machine. It uses the target's detailed information to provide
12 // more precise answers to certain TTI queries, while letting the target
13 // independent and default TTI implementations handle the rest.
14 //
15 //===----------------------------------------------------------------------===//
16 
18 #include "AMDGPUSubtarget.h"
19 #include "Utils/AMDGPUBaseInfo.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/IR/Argument.h"
27 #include "llvm/IR/Attributes.h"
28 #include "llvm/IR/BasicBlock.h"
29 #include "llvm/IR/CallingConv.h"
30 #include "llvm/IR/DataLayout.h"
31 #include "llvm/IR/DerivedTypes.h"
32 #include "llvm/IR/Function.h"
33 #include "llvm/IR/Instruction.h"
34 #include "llvm/IR/Instructions.h"
35 #include "llvm/IR/IntrinsicInst.h"
36 #include "llvm/IR/Module.h"
37 #include "llvm/IR/PatternMatch.h"
38 #include "llvm/IR/Type.h"
39 #include "llvm/IR/Value.h"
41 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Debug.h"
48 #include <algorithm>
49 #include <cassert>
50 #include <limits>
51 #include <utility>
52 
53 using namespace llvm;
54 
55 #define DEBUG_TYPE "AMDGPUtti"
56 
58  "amdgpu-unroll-threshold-private",
59  cl::desc("Unroll threshold for AMDGPU if private memory used in a loop"),
60  cl::init(2700), cl::Hidden);
61 
63  "amdgpu-unroll-threshold-local",
64  cl::desc("Unroll threshold for AMDGPU if local memory used in a loop"),
65  cl::init(1000), cl::Hidden);
66 
68  "amdgpu-unroll-threshold-if",
69  cl::desc("Unroll threshold increment for AMDGPU for each if statement inside loop"),
70  cl::init(150), cl::Hidden);
71 
72 static bool dependsOnLocalPhi(const Loop *L, const Value *Cond,
73  unsigned Depth = 0) {
74  const Instruction *I = dyn_cast<Instruction>(Cond);
75  if (!I)
76  return false;
77 
78  for (const Value *V : I->operand_values()) {
79  if (!L->contains(I))
80  continue;
81  if (const PHINode *PHI = dyn_cast<PHINode>(V)) {
82  if (llvm::none_of(L->getSubLoops(), [PHI](const Loop* SubLoop) {
83  return SubLoop->contains(PHI); }))
84  return true;
85  } else if (Depth < 10 && dependsOnLocalPhi(L, V, Depth+1))
86  return true;
87  }
88  return false;
89 }
90 
93  const Function &F = *L->getHeader()->getParent();
94  UP.Threshold = AMDGPU::getIntegerAttribute(F, "amdgpu-unroll-threshold", 300);
96  UP.Partial = true;
97 
98  // TODO: Do we want runtime unrolling?
99 
100  // Maximum alloca size than can fit registers. Reserve 16 registers.
101  const unsigned MaxAlloca = (256 - 16) * 4;
102  unsigned ThresholdPrivate = UnrollThresholdPrivate;
103  unsigned ThresholdLocal = UnrollThresholdLocal;
104  unsigned MaxBoost = std::max(ThresholdPrivate, ThresholdLocal);
105  for (const BasicBlock *BB : L->getBlocks()) {
106  const DataLayout &DL = BB->getModule()->getDataLayout();
107  unsigned LocalGEPsSeen = 0;
108 
109  if (llvm::any_of(L->getSubLoops(), [BB](const Loop* SubLoop) {
110  return SubLoop->contains(BB); }))
111  continue; // Block belongs to an inner loop.
112 
113  for (const Instruction &I : *BB) {
114  // Unroll a loop which contains an "if" statement whose condition
115  // defined by a PHI belonging to the loop. This may help to eliminate
116  // if region and potentially even PHI itself, saving on both divergence
117  // and registers used for the PHI.
118  // Add a small bonus for each of such "if" statements.
119  if (const BranchInst *Br = dyn_cast<BranchInst>(&I)) {
120  if (UP.Threshold < MaxBoost && Br->isConditional()) {
121  BasicBlock *Succ0 = Br->getSuccessor(0);
122  BasicBlock *Succ1 = Br->getSuccessor(1);
123  if ((L->contains(Succ0) && L->isLoopExiting(Succ0)) ||
124  (L->contains(Succ1) && L->isLoopExiting(Succ1)))
125  continue;
126  if (dependsOnLocalPhi(L, Br->getCondition())) {
128  LLVM_DEBUG(dbgs() << "Set unroll threshold " << UP.Threshold
129  << " for loop:\n"
130  << *L << " due to " << *Br << '\n');
131  if (UP.Threshold >= MaxBoost)
132  return;
133  }
134  }
135  continue;
136  }
137 
139  if (!GEP)
140  continue;
141 
142  unsigned AS = GEP->getAddressSpace();
143  unsigned Threshold = 0;
144  if (AS == AMDGPUAS::PRIVATE_ADDRESS)
145  Threshold = ThresholdPrivate;
146  else if (AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::REGION_ADDRESS)
147  Threshold = ThresholdLocal;
148  else
149  continue;
150 
151  if (UP.Threshold >= Threshold)
152  continue;
153 
154  if (AS == AMDGPUAS::PRIVATE_ADDRESS) {
155  const Value *Ptr = GEP->getPointerOperand();
156  const AllocaInst *Alloca =
158  if (!Alloca || !Alloca->isStaticAlloca())
159  continue;
160  Type *Ty = Alloca->getAllocatedType();
161  unsigned AllocaSize = Ty->isSized() ? DL.getTypeAllocSize(Ty) : 0;
162  if (AllocaSize > MaxAlloca)
163  continue;
164  } else if (AS == AMDGPUAS::LOCAL_ADDRESS ||
165  AS == AMDGPUAS::REGION_ADDRESS) {
166  LocalGEPsSeen++;
167  // Inhibit unroll for local memory if we have seen addressing not to
168  // a variable, most likely we will be unable to combine it.
169  // Do not unroll too deep inner loops for local memory to give a chance
170  // to unroll an outer loop for a more important reason.
171  if (LocalGEPsSeen > 1 || L->getLoopDepth() > 2 ||
172  (!isa<GlobalVariable>(GEP->getPointerOperand()) &&
173  !isa<Argument>(GEP->getPointerOperand())))
174  continue;
175  }
176 
177  // Check if GEP depends on a value defined by this loop itself.
178  bool HasLoopDef = false;
179  for (const Value *Op : GEP->operands()) {
180  const Instruction *Inst = dyn_cast<Instruction>(Op);
181  if (!Inst || L->isLoopInvariant(Op))
182  continue;
183 
184  if (llvm::any_of(L->getSubLoops(), [Inst](const Loop* SubLoop) {
185  return SubLoop->contains(Inst); }))
186  continue;
187  HasLoopDef = true;
188  break;
189  }
190  if (!HasLoopDef)
191  continue;
192 
193  // We want to do whatever we can to limit the number of alloca
194  // instructions that make it through to the code generator. allocas
195  // require us to use indirect addressing, which is slow and prone to
196  // compiler bugs. If this loop does an address calculation on an
197  // alloca ptr, then we want to use a higher than normal loop unroll
198  // threshold. This will give SROA a better chance to eliminate these
199  // allocas.
200  //
201  // We also want to have more unrolling for local memory to let ds
202  // instructions with different offsets combine.
203  //
204  // Don't use the maximum allowed value here as it will make some
205  // programs way too big.
206  UP.Threshold = Threshold;
207  LLVM_DEBUG(dbgs() << "Set unroll threshold " << Threshold
208  << " for loop:\n"
209  << *L << " due to " << *GEP << '\n');
210  if (UP.Threshold >= MaxBoost)
211  return;
212  }
213  }
214 }
215 
217  // The concept of vector registers doesn't really exist. Some packed vector
218  // operations operate on the normal 32-bit registers.
219  return 256;
220 }
221 
222 unsigned GCNTTIImpl::getNumberOfRegisters(bool Vec) const {
223  // This is really the number of registers to fill when vectorizing /
224  // interleaving loops, so we lie to avoid trying to use all registers.
225  return getHardwareNumberOfRegisters(Vec) >> 3;
226 }
227 
229  return 32;
230 }
231 
233  return 32;
234 }
235 
236 unsigned GCNTTIImpl::getLoadVectorFactor(unsigned VF, unsigned LoadSize,
237  unsigned ChainSizeInBytes,
238  VectorType *VecTy) const {
239  unsigned VecRegBitWidth = VF * LoadSize;
240  if (VecRegBitWidth > 128 && VecTy->getScalarSizeInBits() < 32)
241  // TODO: Support element-size less than 32bit?
242  return 128 / LoadSize;
243 
244  return VF;
245 }
246 
247 unsigned GCNTTIImpl::getStoreVectorFactor(unsigned VF, unsigned StoreSize,
248  unsigned ChainSizeInBytes,
249  VectorType *VecTy) const {
250  unsigned VecRegBitWidth = VF * StoreSize;
251  if (VecRegBitWidth > 128)
252  return 128 / StoreSize;
253 
254  return VF;
255 }
256 
257 unsigned GCNTTIImpl::getLoadStoreVecRegBitWidth(unsigned AddrSpace) const {
258  if (AddrSpace == AMDGPUAS::GLOBAL_ADDRESS ||
259  AddrSpace == AMDGPUAS::CONSTANT_ADDRESS ||
260  AddrSpace == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
261  AddrSpace == AMDGPUAS::BUFFER_FAT_POINTER) {
262  return 512;
263  }
264 
265  if (AddrSpace == AMDGPUAS::FLAT_ADDRESS ||
266  AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
267  AddrSpace == AMDGPUAS::REGION_ADDRESS)
268  return 128;
269 
270  if (AddrSpace == AMDGPUAS::PRIVATE_ADDRESS)
271  return 8 * ST->getMaxPrivateElementSize();
272 
273  llvm_unreachable("unhandled address space");
274 }
275 
276 bool GCNTTIImpl::isLegalToVectorizeMemChain(unsigned ChainSizeInBytes,
277  unsigned Alignment,
278  unsigned AddrSpace) const {
279  // We allow vectorization of flat stores, even though we may need to decompose
280  // them later if they may access private memory. We don't have enough context
281  // here, and legalization can handle it.
282  if (AddrSpace == AMDGPUAS::PRIVATE_ADDRESS) {
283  return (Alignment >= 4 || ST->hasUnalignedScratchAccess()) &&
284  ChainSizeInBytes <= ST->getMaxPrivateElementSize();
285  }
286  return true;
287 }
288 
289 bool GCNTTIImpl::isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
290  unsigned Alignment,
291  unsigned AddrSpace) const {
292  return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
293 }
294 
295 bool GCNTTIImpl::isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
296  unsigned Alignment,
297  unsigned AddrSpace) const {
298  return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
299 }
300 
301 unsigned GCNTTIImpl::getMaxInterleaveFactor(unsigned VF) {
302  // Disable unrolling if the loop is not vectorized.
303  // TODO: Enable this again.
304  if (VF == 1)
305  return 1;
306 
307  return 8;
308 }
309 
311  MemIntrinsicInfo &Info) const {
312  switch (Inst->getIntrinsicID()) {
313  case Intrinsic::amdgcn_atomic_inc:
314  case Intrinsic::amdgcn_atomic_dec:
315  case Intrinsic::amdgcn_ds_ordered_add:
316  case Intrinsic::amdgcn_ds_ordered_swap:
317  case Intrinsic::amdgcn_ds_fadd:
318  case Intrinsic::amdgcn_ds_fmin:
319  case Intrinsic::amdgcn_ds_fmax: {
320  auto *Ordering = dyn_cast<ConstantInt>(Inst->getArgOperand(2));
321  auto *Volatile = dyn_cast<ConstantInt>(Inst->getArgOperand(4));
322  if (!Ordering || !Volatile)
323  return false; // Invalid.
324 
325  unsigned OrderingVal = Ordering->getZExtValue();
326  if (OrderingVal > static_cast<unsigned>(AtomicOrdering::SequentiallyConsistent))
327  return false;
328 
329  Info.PtrVal = Inst->getArgOperand(0);
330  Info.Ordering = static_cast<AtomicOrdering>(OrderingVal);
331  Info.ReadMem = true;
332  Info.WriteMem = true;
333  Info.IsVolatile = !Volatile->isNullValue();
334  return true;
335  }
336  default:
337  return false;
338  }
339 }
340 
341 int GCNTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
342  TTI::OperandValueKind Opd1Info,
343  TTI::OperandValueKind Opd2Info,
344  TTI::OperandValueProperties Opd1PropInfo,
345  TTI::OperandValueProperties Opd2PropInfo,
347  const Instruction *CxtI) {
348  EVT OrigTy = TLI->getValueType(DL, Ty);
349  if (!OrigTy.isSimple()) {
350  return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
351  Opd1PropInfo, Opd2PropInfo);
352  }
353 
354  // Legalize the type.
355  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
356  int ISD = TLI->InstructionOpcodeToISD(Opcode);
357 
358  // Because we don't have any legal vector operations, but the legal types, we
359  // need to account for split vectors.
360  unsigned NElts = LT.second.isVector() ?
361  LT.second.getVectorNumElements() : 1;
362 
363  MVT::SimpleValueType SLT = LT.second.getScalarType().SimpleTy;
364 
365  switch (ISD) {
366  case ISD::SHL:
367  case ISD::SRL:
368  case ISD::SRA:
369  if (SLT == MVT::i64)
370  return get64BitInstrCost() * LT.first * NElts;
371 
372  if (ST->has16BitInsts() && SLT == MVT::i16)
373  NElts = (NElts + 1) / 2;
374 
375  // i32
376  return getFullRateInstrCost() * LT.first * NElts;
377  case ISD::ADD:
378  case ISD::SUB:
379  case ISD::AND:
380  case ISD::OR:
381  case ISD::XOR:
382  if (SLT == MVT::i64) {
383  // and, or and xor are typically split into 2 VALU instructions.
384  return 2 * getFullRateInstrCost() * LT.first * NElts;
385  }
386 
387  if (ST->has16BitInsts() && SLT == MVT::i16)
388  NElts = (NElts + 1) / 2;
389 
390  return LT.first * NElts * getFullRateInstrCost();
391  case ISD::MUL: {
392  const int QuarterRateCost = getQuarterRateInstrCost();
393  if (SLT == MVT::i64) {
394  const int FullRateCost = getFullRateInstrCost();
395  return (4 * QuarterRateCost + (2 * 2) * FullRateCost) * LT.first * NElts;
396  }
397 
398  if (ST->has16BitInsts() && SLT == MVT::i16)
399  NElts = (NElts + 1) / 2;
400 
401  // i32
402  return QuarterRateCost * NElts * LT.first;
403  }
404  case ISD::FADD:
405  case ISD::FSUB:
406  case ISD::FMUL:
407  if (SLT == MVT::f64)
408  return LT.first * NElts * get64BitInstrCost();
409 
410  if (ST->has16BitInsts() && SLT == MVT::f16)
411  NElts = (NElts + 1) / 2;
412 
413  if (SLT == MVT::f32 || SLT == MVT::f16)
414  return LT.first * NElts * getFullRateInstrCost();
415  break;
416  case ISD::FDIV:
417  case ISD::FREM:
418  // FIXME: frem should be handled separately. The fdiv in it is most of it,
419  // but the current lowering is also not entirely correct.
420  if (SLT == MVT::f64) {
421  int Cost = 4 * get64BitInstrCost() + 7 * getQuarterRateInstrCost();
422  // Add cost of workaround.
424  Cost += 3 * getFullRateInstrCost();
425 
426  return LT.first * Cost * NElts;
427  }
428 
429  if (!Args.empty() && match(Args[0], PatternMatch::m_FPOne())) {
430  // TODO: This is more complicated, unsafe flags etc.
431  if ((SLT == MVT::f32 && !HasFP32Denormals) ||
432  (SLT == MVT::f16 && ST->has16BitInsts())) {
433  return LT.first * getQuarterRateInstrCost() * NElts;
434  }
435  }
436 
437  if (SLT == MVT::f16 && ST->has16BitInsts()) {
438  // 2 x v_cvt_f32_f16
439  // f32 rcp
440  // f32 fmul
441  // v_cvt_f16_f32
442  // f16 div_fixup
443  int Cost = 4 * getFullRateInstrCost() + 2 * getQuarterRateInstrCost();
444  return LT.first * Cost * NElts;
445  }
446 
447  if (SLT == MVT::f32 || SLT == MVT::f16) {
448  int Cost = 7 * getFullRateInstrCost() + 1 * getQuarterRateInstrCost();
449 
450  if (!HasFP32Denormals) {
451  // FP mode switches.
452  Cost += 2 * getFullRateInstrCost();
453  }
454 
455  return LT.first * NElts * Cost;
456  }
457  break;
458  default:
459  break;
460  }
461 
462  return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
463  Opd1PropInfo, Opd2PropInfo);
464 }
465 
466 template <typename T>
469  FastMathFlags FMF, unsigned VF) {
470  if (ID != Intrinsic::fma)
471  return BaseT::getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
472 
473  EVT OrigTy = TLI->getValueType(DL, RetTy);
474  if (!OrigTy.isSimple()) {
475  return BaseT::getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF);
476  }
477 
478  // Legalize the type.
479  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, RetTy);
480 
481  unsigned NElts = LT.second.isVector() ?
482  LT.second.getVectorNumElements() : 1;
483 
484  MVT::SimpleValueType SLT = LT.second.getScalarType().SimpleTy;
485 
486  if (SLT == MVT::f64)
487  return LT.first * NElts * get64BitInstrCost();
488 
489  if (ST->has16BitInsts() && SLT == MVT::f16)
490  NElts = (NElts + 1) / 2;
491 
492  return LT.first * NElts * (ST->hasFastFMAF32() ? getHalfRateInstrCost()
493  : getQuarterRateInstrCost());
494 }
495 
498  unsigned VF) {
499  return getIntrinsicInstrCost<Value>(ID, RetTy, Args, FMF, VF);
500 }
501 
504  unsigned ScalarizationCostPassed) {
505  return getIntrinsicInstrCost<Type>(ID, RetTy, Tys, FMF,
506  ScalarizationCostPassed);
507 }
508 
509 unsigned GCNTTIImpl::getCFInstrCost(unsigned Opcode) {
510  // XXX - For some reason this isn't called for switch.
511  switch (Opcode) {
512  case Instruction::Br:
513  case Instruction::Ret:
514  return 10;
515  default:
516  return BaseT::getCFInstrCost(Opcode);
517  }
518 }
519 
521  bool IsPairwise) {
522  EVT OrigTy = TLI->getValueType(DL, Ty);
523 
524  // Computes cost on targets that have packed math instructions(which support
525  // 16-bit types only).
526  if (IsPairwise ||
527  !ST->hasVOP3PInsts() ||
528  OrigTy.getScalarSizeInBits() != 16)
529  return BaseT::getArithmeticReductionCost(Opcode, Ty, IsPairwise);
530 
531  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
532  return LT.first * getFullRateInstrCost();
533 }
534 
536  bool IsPairwise,
537  bool IsUnsigned) {
538  EVT OrigTy = TLI->getValueType(DL, Ty);
539 
540  // Computes cost on targets that have packed math instructions(which support
541  // 16-bit types only).
542  if (IsPairwise ||
543  !ST->hasVOP3PInsts() ||
544  OrigTy.getScalarSizeInBits() != 16)
545  return BaseT::getMinMaxReductionCost(Ty, CondTy, IsPairwise, IsUnsigned);
546 
547  std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Ty);
548  return LT.first * getHalfRateInstrCost();
549 }
550 
551 int GCNTTIImpl::getVectorInstrCost(unsigned Opcode, Type *ValTy,
552  unsigned Index) {
553  switch (Opcode) {
554  case Instruction::ExtractElement:
555  case Instruction::InsertElement: {
556  unsigned EltSize
557  = DL.getTypeSizeInBits(cast<VectorType>(ValTy)->getElementType());
558  if (EltSize < 32) {
559  if (EltSize == 16 && Index == 0 && ST->has16BitInsts())
560  return 0;
561  return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
562  }
563 
564  // Extracts are just reads of a subregister, so are free. Inserts are
565  // considered free because we don't want to have any cost for scalarizing
566  // operations, and we don't have to copy into a different register class.
567 
568  // Dynamic indexing isn't free and is best avoided.
569  return Index == ~0u ? 2 : 0;
570  }
571  default:
572  return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
573  }
574 }
575 
576 
577 
578 static bool isArgPassedInSGPR(const Argument *A) {
579  const Function *F = A->getParent();
580 
581  // Arguments to compute shaders are never a source of divergence.
583  switch (CC) {
586  return true;
594  // For non-compute shaders, SGPR inputs are marked with either inreg or byval.
595  // Everything else is in VGPRs.
596  return F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::InReg) ||
597  F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::ByVal);
598  default:
599  // TODO: Should calls support inreg for SGPR inputs?
600  return false;
601  }
602 }
603 
604 /// \returns true if the result of the value could potentially be
605 /// different across workitems in a wavefront.
607  if (const Argument *A = dyn_cast<Argument>(V))
608  return !isArgPassedInSGPR(A);
609 
610  // Loads from the private and flat address spaces are divergent, because
611  // threads can execute the load instruction with the same inputs and get
612  // different results.
613  //
614  // All other loads are not divergent, because if threads issue loads with the
615  // same arguments, they will always get the same result.
616  if (const LoadInst *Load = dyn_cast<LoadInst>(V))
617  return Load->getPointerAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS ||
618  Load->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS;
619 
620  // Atomics are divergent because they are executed sequentially: when an
621  // atomic operation refers to the same address in each thread, then each
622  // thread after the first sees the value written by the previous thread as
623  // original value.
624  if (isa<AtomicRMWInst>(V) || isa<AtomicCmpXchgInst>(V))
625  return true;
626 
627  if (const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V))
628  return AMDGPU::isIntrinsicSourceOfDivergence(Intrinsic->getIntrinsicID());
629 
630  // Assume all function calls are a source of divergence.
631  if (isa<CallInst>(V) || isa<InvokeInst>(V))
632  return true;
633 
634  return false;
635 }
636 
637 bool GCNTTIImpl::isAlwaysUniform(const Value *V) const {
638  if (const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V)) {
639  switch (Intrinsic->getIntrinsicID()) {
640  default:
641  return false;
642  case Intrinsic::amdgcn_readfirstlane:
643  case Intrinsic::amdgcn_readlane:
644  case Intrinsic::amdgcn_icmp:
645  case Intrinsic::amdgcn_fcmp:
646  return true;
647  }
648  }
649  return false;
650 }
651 
653  Intrinsic::ID IID) const {
654  switch (IID) {
655  case Intrinsic::amdgcn_atomic_inc:
656  case Intrinsic::amdgcn_atomic_dec:
657  case Intrinsic::amdgcn_ds_fadd:
658  case Intrinsic::amdgcn_ds_fmin:
659  case Intrinsic::amdgcn_ds_fmax:
660  case Intrinsic::amdgcn_is_shared:
661  case Intrinsic::amdgcn_is_private:
662  OpIndexes.push_back(0);
663  return true;
664  default:
665  return false;
666  }
667 }
668 
670  IntrinsicInst *II, Value *OldV, Value *NewV) const {
671  auto IntrID = II->getIntrinsicID();
672  switch (IntrID) {
673  case Intrinsic::amdgcn_atomic_inc:
674  case Intrinsic::amdgcn_atomic_dec:
675  case Intrinsic::amdgcn_ds_fadd:
676  case Intrinsic::amdgcn_ds_fmin:
677  case Intrinsic::amdgcn_ds_fmax: {
678  const ConstantInt *IsVolatile = cast<ConstantInt>(II->getArgOperand(4));
679  if (!IsVolatile->isZero())
680  return false;
681  Module *M = II->getParent()->getParent()->getParent();
682  Type *DestTy = II->getType();
683  Type *SrcTy = NewV->getType();
684  Function *NewDecl =
685  Intrinsic::getDeclaration(M, II->getIntrinsicID(), {DestTy, SrcTy});
686  II->setArgOperand(0, NewV);
687  II->setCalledFunction(NewDecl);
688  return true;
689  }
690  case Intrinsic::amdgcn_is_shared:
691  case Intrinsic::amdgcn_is_private: {
692  unsigned TrueAS = IntrID == Intrinsic::amdgcn_is_shared ?
694  unsigned NewAS = NewV->getType()->getPointerAddressSpace();
695  LLVMContext &Ctx = NewV->getType()->getContext();
696  ConstantInt *NewVal = (TrueAS == NewAS) ?
698  II->replaceAllUsesWith(NewVal);
699  II->eraseFromParent();
700  return true;
701  }
702  default:
703  return false;
704  }
705 }
706 
708  Type *SubTp) {
709  if (ST->hasVOP3PInsts()) {
710  VectorType *VT = cast<VectorType>(Tp);
711  if (VT->getNumElements() == 2 &&
712  DL.getTypeSizeInBits(VT->getElementType()) == 16) {
713  // With op_sel VOP3P instructions freely can access the low half or high
714  // half of a register, so any swizzle is free.
715 
716  switch (Kind) {
717  case TTI::SK_Broadcast:
718  case TTI::SK_Reverse:
720  return 0;
721  default:
722  break;
723  }
724  }
725  }
726 
727  return BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
728 }
729 
731  const Function *Callee) const {
732  const TargetMachine &TM = getTLI()->getTargetMachine();
733  const GCNSubtarget *CallerST
734  = static_cast<const GCNSubtarget *>(TM.getSubtargetImpl(*Caller));
735  const GCNSubtarget *CalleeST
736  = static_cast<const GCNSubtarget *>(TM.getSubtargetImpl(*Callee));
737 
738  const FeatureBitset &CallerBits = CallerST->getFeatureBits();
739  const FeatureBitset &CalleeBits = CalleeST->getFeatureBits();
740 
741  FeatureBitset RealCallerBits = CallerBits & ~InlineFeatureIgnoreList;
742  FeatureBitset RealCalleeBits = CalleeBits & ~InlineFeatureIgnoreList;
743  if ((RealCallerBits & RealCalleeBits) != RealCalleeBits)
744  return false;
745 
746  // FIXME: dx10_clamp can just take the caller setting, but there seems to be
747  // no way to support merge for backend defined attributes.
748  AMDGPU::SIModeRegisterDefaults CallerMode(*Caller, *CallerST);
749  AMDGPU::SIModeRegisterDefaults CalleeMode(*Callee, *CalleeST);
750  return CallerMode.isInlineCompatible(CalleeMode);
751 }
752 
755  CommonTTI.getUnrollingPreferences(L, SE, UP);
756 }
757 
758 unsigned GCNTTIImpl::getUserCost(const User *U,
760  const Instruction *I = dyn_cast<Instruction>(U);
761  if (!I)
762  return BaseT::getUserCost(U, Operands);
763 
764  // Estimate different operations to be optimized out
765  switch (I->getOpcode()) {
766  case Instruction::ExtractElement: {
768  unsigned Idx = -1;
769  if (CI)
770  Idx = CI->getZExtValue();
771  return getVectorInstrCost(I->getOpcode(), I->getOperand(0)->getType(), Idx);
772  }
773  case Instruction::InsertElement: {
775  unsigned Idx = -1;
776  if (CI)
777  Idx = CI->getZExtValue();
778  return getVectorInstrCost(I->getOpcode(), I->getType(), Idx);
779  }
780  case Instruction::Call: {
781  if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(U)) {
782  SmallVector<Value *, 4> Args(II->arg_operands());
783  FastMathFlags FMF;
784  if (auto *FPMO = dyn_cast<FPMathOperator>(II))
785  FMF = FPMO->getFastMathFlags();
786  return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(), Args,
787  FMF);
788  } else {
789  return BaseT::getUserCost(U, Operands);
790  }
791  }
792  case Instruction::ShuffleVector: {
793  const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
794  Type *Ty = Shuffle->getType();
795  Type *SrcTy = Shuffle->getOperand(0)->getType();
796 
797  // TODO: Identify and add costs for insert subvector, etc.
798  int SubIndex;
799  if (Shuffle->isExtractSubvectorMask(SubIndex))
800  return getShuffleCost(TTI::SK_ExtractSubvector, SrcTy, SubIndex, Ty);
801 
802  if (Shuffle->changesLength())
803  return BaseT::getUserCost(U, Operands);
804 
805  if (Shuffle->isIdentity())
806  return 0;
807 
808  if (Shuffle->isReverse())
809  return getShuffleCost(TTI::SK_Reverse, Ty, 0, nullptr);
810 
811  if (Shuffle->isSelect())
812  return getShuffleCost(TTI::SK_Select, Ty, 0, nullptr);
813 
814  if (Shuffle->isTranspose())
815  return getShuffleCost(TTI::SK_Transpose, Ty, 0, nullptr);
816 
817  if (Shuffle->isZeroEltSplat())
818  return getShuffleCost(TTI::SK_Broadcast, Ty, 0, nullptr);
819 
820  if (Shuffle->isSingleSource())
821  return getShuffleCost(TTI::SK_PermuteSingleSrc, Ty, 0, nullptr);
822 
823  return getShuffleCost(TTI::SK_PermuteTwoSrc, Ty, 0, nullptr);
824  }
825  case Instruction::ZExt:
826  case Instruction::SExt:
827  case Instruction::FPToUI:
828  case Instruction::FPToSI:
829  case Instruction::FPExt:
830  case Instruction::PtrToInt:
831  case Instruction::IntToPtr:
832  case Instruction::SIToFP:
833  case Instruction::UIToFP:
834  case Instruction::Trunc:
835  case Instruction::FPTrunc:
836  case Instruction::BitCast:
837  case Instruction::AddrSpaceCast: {
838  return getCastInstrCost(I->getOpcode(), I->getType(),
839  I->getOperand(0)->getType(), I);
840  }
841  case Instruction::Add:
842  case Instruction::FAdd:
843  case Instruction::Sub:
844  case Instruction::FSub:
845  case Instruction::Mul:
846  case Instruction::FMul:
847  case Instruction::UDiv:
848  case Instruction::SDiv:
849  case Instruction::FDiv:
850  case Instruction::URem:
851  case Instruction::SRem:
852  case Instruction::FRem:
853  case Instruction::Shl:
854  case Instruction::LShr:
855  case Instruction::AShr:
856  case Instruction::And:
857  case Instruction::Or:
858  case Instruction::Xor:
859  case Instruction::FNeg: {
860  return getArithmeticInstrCost(I->getOpcode(), I->getType(),
863  }
864  default:
865  break;
866  }
867 
868  return BaseT::getUserCost(U, Operands);
869 }
870 
872  return 4 * 128; // XXX - 4 channels. Should these count as vector instead?
873 }
874 
875 unsigned R600TTIImpl::getNumberOfRegisters(bool Vec) const {
876  return getHardwareNumberOfRegisters(Vec);
877 }
878 
880  return 32;
881 }
882 
884  return 32;
885 }
886 
887 unsigned R600TTIImpl::getLoadStoreVecRegBitWidth(unsigned AddrSpace) const {
888  if (AddrSpace == AMDGPUAS::GLOBAL_ADDRESS ||
889  AddrSpace == AMDGPUAS::CONSTANT_ADDRESS)
890  return 128;
891  if (AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
892  AddrSpace == AMDGPUAS::REGION_ADDRESS)
893  return 64;
894  if (AddrSpace == AMDGPUAS::PRIVATE_ADDRESS)
895  return 32;
896 
897  if ((AddrSpace == AMDGPUAS::PARAM_D_ADDRESS ||
898  AddrSpace == AMDGPUAS::PARAM_I_ADDRESS ||
899  (AddrSpace >= AMDGPUAS::CONSTANT_BUFFER_0 &&
900  AddrSpace <= AMDGPUAS::CONSTANT_BUFFER_15)))
901  return 128;
902  llvm_unreachable("unhandled address space");
903 }
904 
905 bool R600TTIImpl::isLegalToVectorizeMemChain(unsigned ChainSizeInBytes,
906  unsigned Alignment,
907  unsigned AddrSpace) const {
908  // We allow vectorization of flat stores, even though we may need to decompose
909  // them later if they may access private memory. We don't have enough context
910  // here, and legalization can handle it.
911  return (AddrSpace != AMDGPUAS::PRIVATE_ADDRESS);
912 }
913 
914 bool R600TTIImpl::isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
915  unsigned Alignment,
916  unsigned AddrSpace) const {
917  return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
918 }
919 
920 bool R600TTIImpl::isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
921  unsigned Alignment,
922  unsigned AddrSpace) const {
923  return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
924 }
925 
926 unsigned R600TTIImpl::getMaxInterleaveFactor(unsigned VF) {
927  // Disable unrolling if the loop is not vectorized.
928  // TODO: Enable this again.
929  if (VF == 1)
930  return 1;
931 
932  return 8;
933 }
934 
935 unsigned R600TTIImpl::getCFInstrCost(unsigned Opcode) {
936  // XXX - For some reason this isn't called for switch.
937  switch (Opcode) {
938  case Instruction::Br:
939  case Instruction::Ret:
940  return 10;
941  default:
942  return BaseT::getCFInstrCost(Opcode);
943  }
944 }
945 
946 int R600TTIImpl::getVectorInstrCost(unsigned Opcode, Type *ValTy,
947  unsigned Index) {
948  switch (Opcode) {
949  case Instruction::ExtractElement:
950  case Instruction::InsertElement: {
951  unsigned EltSize
952  = DL.getTypeSizeInBits(cast<VectorType>(ValTy)->getElementType());
953  if (EltSize < 32) {
954  return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
955  }
956 
957  // Extracts are just reads of a subregister, so are free. Inserts are
958  // considered free because we don't want to have any cost for scalarizing
959  // operations, and we don't have to copy into a different register class.
960 
961  // Dynamic indexing isn't free and is best avoided.
962  return Index == ~0u ? 2 : 0;
963  }
964  default:
965  return BaseT::getVectorInstrCost(Opcode, ValTy, Index);
966  }
967 }
968 
971  CommonTTI.getUnrollingPreferences(L, SE, UP);
972 }
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:67
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:667
bool Partial
Allow partial unrolling (unrolling of loops to expand the size of the loop body, not only to eliminat...
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:218
This file a TargetTransformInfo::Concept conforming object specific to the AMDGPU target machine...
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Address space for 160-bit buffer fat pointers.
Definition: AMDGPU.h:281
bool hasUsableDivScaleConditionOutput() const
Condition output from div_scale is usable.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:265
static cl::opt< unsigned > UnrollThresholdIf("amdgpu-unroll-threshold-if", cl::desc("Unroll threshold increment for AMDGPU for each if statement inside loop"), cl::init(150), cl::Hidden)
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
unsigned getCFInstrCost(unsigned Opcode)
unsigned getLoopDepth() const
Return the nesting level of this loop.
Definition: LoopInfo.h:97
void push_back(const T &Elt)
Definition: SmallVector.h:211
The main scalar evolution driver.
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Address space for global memory (RAT0, VTX0).
Definition: AMDGPU.h:272
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index)
bool isReverse() const
Return true if this shuffle swaps the order of elements from exactly one source vector.
unsigned getMinVectorRegisterBitWidth() const
This instruction constructs a fixed permutation of two input vectors.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1251
F(f)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:635
An instruction for reading from memory.
Definition: Instructions.h:169
int getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Hexagon Common GEP
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:624
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:226
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
bool hasFastFMAF32() const
Address space for flat memory.
Definition: AMDGPU.h:271
bool isSingleSource() const
Return true if this shuffle chooses elements from exactly one source vector without changing the leng...
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:202
bool hasVOP3PInsts() const
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1246
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:48
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
bool collectFlatAddressOperands(SmallVectorImpl< int > &OpIndexes, Intrinsic::ID IID) const
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:147
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
bool isAlwaysUniform(const Value *V) const
Shift and rotation operations.
Definition: ISDOpcodes.h:471
unsigned getNumberOfRegisters(bool Vector) const
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< T *> Args, FastMathFlags FMF, unsigned VF)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1196
This file contains the simple types necessary to represent the attributes associated with functions a...
unsigned getArithmeticReductionCost(unsigned Opcode, Type *Ty, bool IsPairwise)
Try to calculate arithmetic and shuffle op costs for reduction operations.
Address space for 32-bit constant memory.
Definition: AMDGPU.h:279
mir Rename Register Operands
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
Definition: DerivedTypes.h:398
BlockT * getHeader() const
Definition: LoopInfo.h:105
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
Address space for region memory. (GDS)
Definition: AMDGPU.h:273
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Definition: BasicTTIImpl.h:697
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
bool isInlineCompatible(SIModeRegisterDefaults CalleeMode) const
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
Definition: InstrTypes.h:1341
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:202
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
Selects elements from the corresponding lane of either source operand.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:125
unsigned getRegisterBitWidth(bool Vector) const
unsigned getMaxInterleaveFactor(unsigned VF)
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:223
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:430
static bool dependsOnLocalPhi(const Loop *L, const Value *Cond, unsigned Depth=0)
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
Reverse the order of the vector.
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:1112
Value * getOperand(unsigned i) const
Definition: User.h:169
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
static bool isExtractSubvectorMask(ArrayRef< int > Mask, int NumSrcElts, int &Index)
Return true if this shuffle mask is an extract subvector mask.
unsigned getAddressSpace() const
Returns the address space of this instruction&#39;s pointer type.
unsigned getCFInstrCost(unsigned Opcode)
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:208
ExtractSubvector Index indicates start offset.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:892
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:148
Container class for subtarget features.
Address space for direct addressible parameter memory (CONST0).
Definition: AMDGPU.h:284
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop...
Definition: LoopInfo.h:208
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool rewriteIntrinsicWithAddressSpace(IntrinsicInst *II, Value *OldV, Value *NewV) const
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
unsigned getUserCost(const User *U, ArrayRef< const Value *> Operands)
Simple binary floating point operators.
Definition: ISDOpcodes.h:295
Conditional or Unconditional Branch instruction.
bool isIdentity() const
Return true if this shuffle chooses elements from exactly one source vector without lane crossings an...
unsigned getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwise, bool)
Try to calculate op costs for min/max reduction operations.
static cl::opt< unsigned > UnrollThresholdPrivate("amdgpu-unroll-threshold-private", cl::desc("Unroll threshold for AMDGPU if private memory used in a loop"), cl::init(2700), cl::Hidden)
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
bool has16BitInsts() const
unsigned getUserCost(const User *U, ArrayRef< const Value * > Operands)
bool isIntrinsicSourceOfDivergence(unsigned IntrID)
unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1189
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
unsigned getNumberOfRegisters(bool Vec) const
op_range operands()
Definition: User.h:237
Merge elements from two source vectors into one with any shuffle mask.
static bool isArgPassedInSGPR(const Argument *A)
Extended Value Type.
Definition: ValueTypes.h:34
unsigned getHardwareNumberOfRegisters(bool Vec) const
bool hasUnalignedScratchAccess() const
const TargetMachine & getTargetMachine() const
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:105
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Definition: LoopInfo.cpp:62
OperandValueProperties
Additional properties of an operand&#39;s values.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:51
unsigned getCFInstrCost(unsigned Opcode)
Definition: BasicTTIImpl.h:831
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
Definition: BasicTTIImpl.h:678
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Definition: LoopInfo.h:115
unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, unsigned ChainSizeInBytes, VectorType *VecTy) const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
bool isSourceOfDivergence(const Value *V) const
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:134
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
Address space for local memory.
Definition: AMDGPU.h:276
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:205
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Module.h This file contains the declarations for the Module class.
int getMinMaxReductionCost(Type *Ty, Type *CondTy, bool IsPairwiseForm, bool IsUnsigned)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:630
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const
bool changesLength() const
Return true if this shuffle returns a vector with a different number of elements than its source vect...
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:660
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target&#39;s TargetSubtargetInf...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
unsigned getMaxInterleaveFactor(unsigned VF)
bool isZeroEltSplat() const
Return true if all elements of this shuffle are the same value as the first element of exactly one so...
Class to represent vector types.
Definition: DerivedTypes.h:432
bool areInlineCompatible(const Function *Caller, const Function *Callee) const
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:47
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
int getVectorInstrCost(unsigned Opcode, Type *ValTy, unsigned Index)
const std::vector< LoopT * > & getSubLoops() const
Return the loops contained entirely within this loop.
Definition: LoopInfo.h:136
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Definition: PatternMatch.h:653
bool isTranspose() const
Return true if this shuffle transposes the elements of its inputs without changing the length of the ...
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:448
unsigned Threshold
The cost threshold for the unrolled loop.
const Function * getParent() const
Definition: Argument.h:41
unsigned getHardwareNumberOfRegisters(bool Vector) const
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
Definition: LoopInfo.h:154
Parameters that control the generic loop unrolling transformation.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:106
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:199
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
int getIntegerAttribute(const Function &F, StringRef Name, int Default)
#define I(x, y, z)
Definition: MD5.cpp:58
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:192
iterator_range< value_op_iterator > operand_values()
Definition: User.h:261
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: BasicTTIImpl.h:876
Address space for private memory.
Definition: AMDGPU.h:277
static cl::opt< unsigned > UnrollThresholdLocal("amdgpu-unroll-threshold-local", cl::desc("Unroll threshold for AMDGPU if local memory used in a loop"), cl::init(1000), cl::Hidden)
TypeSize getScalarSizeInBits() const
Definition: ValueTypes.h:304
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
Broadcast element 0 to all other elements.
unsigned getMinVectorRegisterBitWidth() const
Address space for indirect addressible parameter memory (VTX1).
Definition: AMDGPU.h:286
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
Type * getElementType() const
Definition: DerivedTypes.h:399
Value * PtrVal
This is the pointer that the intrinsic is loading from or storing to.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
OperandValueKind
Additional information about an operand&#39;s possible values.
This pass exposes codegen information to IR-level passes.
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
#define LLVM_DEBUG(X)
Definition: Debug.h:122
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:211
unsigned getMaxPrivateElementSize() const
VectorType * getType() const
Overload to return most specific vector type.
Information about a load/store intrinsic defined by the target.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
unsigned getRegisterBitWidth(bool Vector) const
Address space for constant memory (VTX2).
Definition: AMDGPU.h:275
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:153
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:231
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
const BasicBlock * getParent() const
Definition: Instruction.h:66
an instruction to allocate memory on the stack
Definition: Instructions.h:59
ShuffleKind
The various kinds of shuffle patterns for vector queries.
Shuffle elements of single source vector with any shuffle mask.