Coverage Report

Created: 2018-09-19 20:53

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Line
Count
Source (jump to first uncovered line)
1
//===- TargetTransformInfoImpl.h --------------------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
/// \file
10
/// This file provides helpers for the implementation of
11
/// a TargetTransformInfo-conforming class.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
16
#define LLVM_ANALYSIS_TARGETTRANSFORMINFOIMPL_H
17
18
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
19
#include "llvm/Analysis/TargetTransformInfo.h"
20
#include "llvm/Analysis/VectorUtils.h"
21
#include "llvm/IR/CallSite.h"
22
#include "llvm/IR/DataLayout.h"
23
#include "llvm/IR/Function.h"
24
#include "llvm/IR/GetElementPtrTypeIterator.h"
25
#include "llvm/IR/Operator.h"
26
#include "llvm/IR/Type.h"
27
28
namespace llvm {
29
30
/// Base class for use as a mix-in that aids implementing
31
/// a TargetTransformInfo-compatible class.
32
class TargetTransformInfoImplBase {
33
protected:
34
  typedef TargetTransformInfo TTI;
35
36
  const DataLayout &DL;
37
38
14.7M
  explicit TargetTransformInfoImplBase(const DataLayout &DL) : DL(DL) {}
39
40
public:
41
  // Provide value semantics. MSVC requires that we spell all of these out.
42
  TargetTransformInfoImplBase(const TargetTransformInfoImplBase &Arg)
43
14.7M
      : DL(Arg.DL) {}
44
14.7M
  TargetTransformInfoImplBase(TargetTransformInfoImplBase &&Arg) : DL(Arg.DL) {}
45
46
40.7k
  const DataLayout &getDataLayout() const { return DL; }
47
48
25.4M
  unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) {
49
25.4M
    switch (Opcode) {
50
25.4M
    default:
51
22.2M
      // By default, just classify everything as 'basic'.
52
22.2M
      return TTI::TCC_Basic;
53
25.4M
54
25.4M
    case Instruction::GetElementPtr:
55
0
      llvm_unreachable("Use getGEPCost for GEP operations!");
56
25.4M
57
25.4M
    case Instruction::BitCast:
58
1.88M
      assert(OpTy && "Cast instructions must provide the operand type");
59
1.88M
      if (Ty == OpTy || 
(1.88M
Ty->isPointerTy()1.88M
&&
OpTy->isPointerTy()1.88M
))
60
1.88M
        // Identity and pointer-to-pointer casts are free.
61
1.88M
        return TTI::TCC_Free;
62
3.08k
63
3.08k
      // Otherwise, the default basic cost is used.
64
3.08k
      return TTI::TCC_Basic;
65
3.08k
66
278k
    case Instruction::FDiv:
67
278k
    case Instruction::FRem:
68
278k
    case Instruction::SDiv:
69
278k
    case Instruction::SRem:
70
278k
    case Instruction::UDiv:
71
278k
    case Instruction::URem:
72
278k
      return TTI::TCC_Expensive;
73
278k
74
427k
    case Instruction::IntToPtr: {
75
427k
      // An inttoptr cast is free so long as the input is a legal integer type
76
427k
      // which doesn't contain values outside the range of a pointer.
77
427k
      unsigned OpSize = OpTy->getScalarSizeInBits();
78
427k
      if (DL.isLegalInteger(OpSize) &&
79
427k
          OpSize <= DL.getPointerTypeSizeInBits(Ty))
80
427k
        return TTI::TCC_Free;
81
0
82
0
      // Otherwise it's not a no-op.
83
0
      return TTI::TCC_Basic;
84
0
    }
85
619k
    case Instruction::PtrToInt: {
86
619k
      // A ptrtoint cast is free so long as the result is large enough to store
87
619k
      // the pointer, and a legal integer type.
88
619k
      unsigned DestSize = Ty->getScalarSizeInBits();
89
619k
      if (DL.isLegalInteger(DestSize) &&
90
619k
          DestSize >= DL.getPointerTypeSizeInBits(OpTy))
91
619k
        return TTI::TCC_Free;
92
20
93
20
      // Otherwise it's not a no-op.
94
20
      return TTI::TCC_Basic;
95
20
    }
96
20
    case Instruction::Trunc:
97
0
      // trunc to a native type is free (assuming the target has compare and
98
0
      // shift-right of the same width).
99
0
      if (DL.isLegalInteger(DL.getTypeSizeInBits(Ty)))
100
0
        return TTI::TCC_Free;
101
0
102
0
      return TTI::TCC_Basic;
103
25.4M
    }
104
25.4M
  }
105
106
  int getGEPCost(Type *PointeeType, const Value *Ptr,
107
0
                 ArrayRef<const Value *> Operands) {
108
0
    // In the basic model, we just assume that all-constant GEPs will be folded
109
0
    // into their uses via addressing modes.
110
0
    for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx)
111
0
      if (!isa<Constant>(Operands[Idx]))
112
0
        return TTI::TCC_Basic;
113
0
114
0
    return TTI::TCC_Free;
115
0
  }
116
117
  unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI,
118
0
                                            unsigned &JTSize) {
119
0
    JTSize = 0;
120
0
    return SI.getNumCases();
121
0
  }
122
123
2
  int getExtCost(const Instruction *I, const Value *Src) {
124
2
    return TTI::TCC_Basic;
125
2
  }
126
127
5.44M
  unsigned getCallCost(FunctionType *FTy, int NumArgs) {
128
5.44M
    assert(FTy && "FunctionType must be provided to this routine.");
129
5.44M
130
5.44M
    // The target-independent implementation just measures the size of the
131
5.44M
    // function by approximating that each argument will take on average one
132
5.44M
    // instruction to prepare.
133
5.44M
134
5.44M
    if (NumArgs < 0)
135
0
      // Set the argument number to the number of explicit arguments in the
136
0
      // function.
137
0
      NumArgs = FTy->getNumParams();
138
5.44M
139
5.44M
    return TTI::TCC_Basic * (NumArgs + 1);
140
5.44M
  }
141
142
0
  unsigned getInliningThresholdMultiplier() { return 1; }
143
144
  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
145
1.25M
                            ArrayRef<Type *> ParamTys) {
146
1.25M
    switch (IID) {
147
1.25M
    default:
148
216k
      // Intrinsics rarely (if ever) have normal argument setup constraints.
149
216k
      // Model them as having a basic instruction cost.
150
216k
      // FIXME: This is wrong for libc intrinsics.
151
216k
      return TTI::TCC_Basic;
152
1.25M
153
1.25M
    case Intrinsic::annotation:
154
1.04M
    case Intrinsic::assume:
155
1.04M
    case Intrinsic::sideeffect:
156
1.04M
    case Intrinsic::dbg_declare:
157
1.04M
    case Intrinsic::dbg_value:
158
1.04M
    case Intrinsic::dbg_label:
159
1.04M
    case Intrinsic::invariant_start:
160
1.04M
    case Intrinsic::invariant_end:
161
1.04M
    case Intrinsic::launder_invariant_group:
162
1.04M
    case Intrinsic::strip_invariant_group:
163
1.04M
    case Intrinsic::lifetime_start:
164
1.04M
    case Intrinsic::lifetime_end:
165
1.04M
    case Intrinsic::objectsize:
166
1.04M
    case Intrinsic::ptr_annotation:
167
1.04M
    case Intrinsic::var_annotation:
168
1.04M
    case Intrinsic::experimental_gc_result:
169
1.04M
    case Intrinsic::experimental_gc_relocate:
170
1.04M
    case Intrinsic::coro_alloc:
171
1.04M
    case Intrinsic::coro_begin:
172
1.04M
    case Intrinsic::coro_free:
173
1.04M
    case Intrinsic::coro_end:
174
1.04M
    case Intrinsic::coro_frame:
175
1.04M
    case Intrinsic::coro_size:
176
1.04M
    case Intrinsic::coro_suspend:
177
1.04M
    case Intrinsic::coro_param:
178
1.04M
    case Intrinsic::coro_subfn_addr:
179
1.04M
      // These intrinsics don't actually represent code after lowering.
180
1.04M
      return TTI::TCC_Free;
181
1.25M
    }
182
1.25M
  }
183
184
0
  bool hasBranchDivergence() { return false; }
185
186
0
  bool isSourceOfDivergence(const Value *V) { return false; }
187
188
0
  bool isAlwaysUniform(const Value *V) { return false; }
189
190
0
  unsigned getFlatAddressSpace () {
191
0
    return -1;
192
0
  }
193
194
9.72M
  bool isLoweredToCall(const Function *F) {
195
9.72M
    assert(F && "A concrete function must be provided to this routine.");
196
9.72M
197
9.72M
    // FIXME: These should almost certainly not be handled here, and instead
198
9.72M
    // handled with the help of TLI or the target itself. This was largely
199
9.72M
    // ported from existing analysis heuristics here so that such refactorings
200
9.72M
    // can take place in the future.
201
9.72M
202
9.72M
    if (F->isIntrinsic())
203
235k
      return false;
204
9.48M
205
9.48M
    if (F->hasLocalLinkage() || 
!F->hasName()8.22M
)
206
1.25M
      return true;
207
8.22M
208
8.22M
    StringRef Name = F->getName();
209
8.22M
210
8.22M
    // These will all likely lower to a single selection DAG node.
211
8.22M
    if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" ||
212
8.22M
        Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" ||
213
8.22M
        Name == "fmin" || Name == "fminf" || Name == "fminl" ||
214
8.22M
        Name == "fmax" || Name == "fmaxf" || Name == "fmaxl" ||
215
8.22M
        Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" ||
216
8.22M
        Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl")
217
0
      return false;
218
8.22M
219
8.22M
    // These are all likely to be optimized into something smaller.
220
8.22M
    if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" ||
221
8.22M
        Name == "exp2l" || Name == "exp2f" || Name == "floor" ||
222
8.22M
        Name == "floorf" || Name == "ceil" || Name == "round" ||
223
8.22M
        Name == "ffs" || Name == "ffsl" || Name == "abs" || 
Name == "labs"8.22M
||
224
8.22M
        
Name == "llabs"8.22M
)
225
2
      return false;
226
8.22M
227
8.22M
    return true;
228
8.22M
  }
229
230
  void getUnrollingPreferences(Loop *, ScalarEvolution &,
231
0
                               TTI::UnrollingPreferences &) {}
232
233
0
  bool isLegalAddImmediate(int64_t Imm) { return false; }
234
235
0
  bool isLegalICmpImmediate(int64_t Imm) { return false; }
236
237
  bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
238
                             bool HasBaseReg, int64_t Scale,
239
8
                             unsigned AddrSpace, Instruction *I = nullptr) {
240
8
    // Guess that only reg and reg+reg addressing is allowed. This heuristic is
241
8
    // taken from the implementation of LSR.
242
8
    return !BaseGV && BaseOffset == 0 && (Scale == 0 || Scale == 1);
243
8
  }
244
245
3.81M
  bool isLSRCostLess(TTI::LSRCost &C1, TTI::LSRCost &C2) {
246
3.81M
    return std::tie(C1.NumRegs, C1.AddRecCost, C1.NumIVMuls, C1.NumBaseAdds,
247
3.81M
                    C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
248
3.81M
           std::tie(C2.NumRegs, C2.AddRecCost, C2.NumIVMuls, C2.NumBaseAdds,
249
3.81M
                    C2.ScaleCost, C2.ImmCost, C2.SetupCost);
250
3.81M
  }
251
252
684k
  bool canMacroFuseCmp() { return false; }
253
254
11.9M
  bool shouldFavorPostInc() const { return false; }
255
256
2.17k
  bool isLegalMaskedStore(Type *DataType) { return false; }
257
258
1.31k
  bool isLegalMaskedLoad(Type *DataType) { return false; }
259
260
8.26k
  bool isLegalMaskedScatter(Type *DataType) { return false; }
261
262
12.1k
  bool isLegalMaskedGather(Type *DataType) { return false; }
263
264
1.20k
  bool hasDivRemOp(Type *DataType, bool IsSigned) { return false; }
265
266
0
  bool hasVolatileVariant(Instruction *I, unsigned AddrSpace) { return false; }
267
268
30.2k
  bool prefersVectorizedAddressing() { return true; }
269
270
  int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
271
0
                           bool HasBaseReg, int64_t Scale, unsigned AddrSpace) {
272
0
    // Guess that all legal addressing mode are free.
273
0
    if (isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
274
0
                              Scale, AddrSpace))
275
0
      return 0;
276
0
    return -1;
277
0
  }
278
279
4.18M
  bool LSRWithInstrQueries() { return false; }
280
281
0
  bool isTruncateFree(Type *Ty1, Type *Ty2) { return false; }
282
283
0
  bool isProfitableToHoist(Instruction *I) { return true; }
284
285
0
  bool useAA() { return false; }
286
287
0
  bool isTypeLegal(Type *Ty) { return false; }
288
289
0
  unsigned getJumpBufAlignment() { return 0; }
290
291
0
  unsigned getJumpBufSize() { return 0; }
292
293
0
  bool shouldBuildLookupTables() { return true; }
294
70.2k
  bool shouldBuildLookupTablesForConstant(Constant *C) { return true; }
295
296
3
  bool useColdCCForColdCall(Function &F) { return false; }
297
298
0
  unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) {
299
0
    return 0;
300
0
  }
301
302
  unsigned getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
303
0
                                            unsigned VF) { return 0; }
304
305
15.3k
  bool supportsEfficientVectorElementLoadStore() { return false; }
306
307
933
  bool enableAggressiveInterleaving(bool LoopHasReductions) { return false; }
308
309
  const TTI::MemCmpExpansionOptions *enableMemCmpExpansion(
310
250k
      bool IsZeroCmp) const {
311
250k
    return nullptr;
312
250k
  }
313
314
0
  bool enableInterleavedAccessVectorization() { return false; }
315
316
10.5k
  bool isFPVectorizationPotentiallyUnsafe() { return false; }
317
318
  bool allowsMisalignedMemoryAccesses(LLVMContext &Context,
319
                                      unsigned BitWidth,
320
                                      unsigned AddressSpace,
321
                                      unsigned Alignment,
322
0
                                      bool *Fast) { return false; }
323
324
3.75k
  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) {
325
3.75k
    return TTI::PSK_Software;
326
3.75k
  }
327
328
0
  bool haveFastSqrt(Type *Ty) { return false; }
329
330
0
  bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) { return true; }
331
332
0
  unsigned getFPOpCost(Type *Ty) { return TargetTransformInfo::TCC_Basic; }
333
334
  int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
335
662
                            Type *Ty) {
336
662
    return 0;
337
662
  }
338
339
0
  unsigned getIntImmCost(const APInt &Imm, Type *Ty) { return TTI::TCC_Basic; }
340
341
  unsigned getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
342
0
                         Type *Ty) {
343
0
    return TTI::TCC_Free;
344
0
  }
345
346
  unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
347
20.9k
                         Type *Ty) {
348
20.9k
    return TTI::TCC_Free;
349
20.9k
  }
350
351
0
  unsigned getNumberOfRegisters(bool Vector) { return 8; }
352
353
0
  unsigned getRegisterBitWidth(bool Vector) const { return 32; }
354
355
32.3k
  unsigned getMinVectorRegisterBitWidth() { return 128; }
356
357
18.5k
  bool shouldMaximizeVectorBandwidth(bool OptSize) const { return false; }
358
359
0
  unsigned getMinimumVF(unsigned ElemWidth) const { return 0; }
360
361
  bool
362
  shouldConsiderAddressTypePromotion(const Instruction &I,
363
37.3k
                                     bool &AllowPromotionWithoutCommonHeader) {
364
37.3k
    AllowPromotionWithoutCommonHeader = false;
365
37.3k
    return false;
366
37.3k
  }
367
368
0
  unsigned getCacheLineSize() { return 0; }
369
370
2
  llvm::Optional<unsigned> getCacheSize(TargetTransformInfo::CacheLevel Level) {
371
2
    switch (Level) {
372
2
    case TargetTransformInfo::CacheLevel::L1D:
373
1
      LLVM_FALLTHROUGH;
374
2
    case TargetTransformInfo::CacheLevel::L2D:
375
2
      return llvm::Optional<unsigned>();
376
0
    }
377
0
378
0
    llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
379
0
  }
380
381
  llvm::Optional<unsigned> getCacheAssociativity(
382
1
    TargetTransformInfo::CacheLevel Level) {
383
1
    switch (Level) {
384
1
    case TargetTransformInfo::CacheLevel::L1D:
385
0
      LLVM_FALLTHROUGH;
386
1
    case TargetTransformInfo::CacheLevel::L2D:
387
1
      return llvm::Optional<unsigned>();
388
0
    }
389
0
390
0
    llvm_unreachable("Unknown TargetTransformInfo::CacheLevel");
391
0
  }
392
393
0
  unsigned getPrefetchDistance() { return 0; }
394
395
0
  unsigned getMinPrefetchStride() { return 1; }
396
397
0
  unsigned getMaxPrefetchIterationsAhead() { return UINT_MAX; }
398
399
0
  unsigned getMaxInterleaveFactor(unsigned VF) { return 1; }
400
401
  unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
402
                                  TTI::OperandValueKind Opd1Info,
403
                                  TTI::OperandValueKind Opd2Info,
404
                                  TTI::OperandValueProperties Opd1PropInfo,
405
                                  TTI::OperandValueProperties Opd2PropInfo,
406
0
                                  ArrayRef<const Value *> Args) {
407
0
    return 1;
408
0
  }
409
410
  unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Ty, int Index,
411
0
                          Type *SubTp) {
412
0
    return 1;
413
0
  }
414
415
  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
416
0
                            const Instruction *I) { return 1; }
417
418
  unsigned getExtractWithExtendCost(unsigned Opcode, Type *Dst,
419
0
                                    VectorType *VecTy, unsigned Index) {
420
0
    return 1;
421
0
  }
422
423
0
  unsigned getCFInstrCost(unsigned Opcode) { return 1; }
424
425
  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
426
0
                              const Instruction *I) {
427
0
    return 1;
428
0
  }
429
430
0
  unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {
431
0
    return 1;
432
0
  }
433
434
  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
435
0
                           unsigned AddressSpace, const Instruction *I) {
436
0
    return 1;
437
0
  }
438
439
  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
440
0
                                 unsigned AddressSpace) {
441
0
    return 1;
442
0
  }
443
444
  unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
445
                                  bool VariableMask,
446
0
                                  unsigned Alignment) {
447
0
    return 1;
448
0
  }
449
450
  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
451
                                      unsigned Factor,
452
                                      ArrayRef<unsigned> Indices,
453
                                      unsigned Alignment,
454
0
                                      unsigned AddressSpace) {
455
0
    return 1;
456
0
  }
457
458
  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
459
                                 ArrayRef<Type *> Tys, FastMathFlags FMF,
460
0
                                 unsigned ScalarizationCostPassed) {
461
0
    return 1;
462
0
  }
463
  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
464
0
            ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) {
465
0
    return 1;
466
0
  }
467
468
0
  unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef<Type *> Tys) {
469
0
    return 1;
470
0
  }
471
472
0
  unsigned getNumberOfParts(Type *Tp) { return 0; }
473
474
  unsigned getAddressComputationCost(Type *Tp, ScalarEvolution *,
475
0
                                     const SCEV *) {
476
0
    return 0;
477
0
  }
478
479
0
  unsigned getArithmeticReductionCost(unsigned, Type *, bool) { return 1; }
480
481
0
  unsigned getMinMaxReductionCost(Type *, Type *, bool, bool) { return 1; }
482
483
26.0k
  unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) { return 0; }
484
485
125k
  bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) {
486
125k
    return false;
487
125k
  }
488
489
0
  unsigned getAtomicMemIntrinsicMaxElementSize() const {
490
0
    // Note for overrides: You must ensure for all element unordered-atomic
491
0
    // memory intrinsics that all power-of-2 element sizes up to, and
492
0
    // including, the return value of this method have a corresponding
493
0
    // runtime lib call. These runtime lib call definitions can be found
494
0
    // in RuntimeLibcalls.h
495
0
    return 0;
496
0
  }
497
498
  Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
499
0
                                           Type *ExpectedType) {
500
0
    return nullptr;
501
0
  }
502
503
  Type *getMemcpyLoopLoweringType(LLVMContext &Context, Value *Length,
504
0
                                  unsigned SrcAlign, unsigned DestAlign) const {
505
0
    return Type::getInt8Ty(Context);
506
0
  }
507
508
  void getMemcpyLoopResidualLoweringType(SmallVectorImpl<Type *> &OpsOut,
509
                                         LLVMContext &Context,
510
                                         unsigned RemainingBytes,
511
                                         unsigned SrcAlign,
512
0
                                         unsigned DestAlign) const {
513
0
    for (unsigned i = 0; i != RemainingBytes; ++i)
514
0
      OpsOut.push_back(Type::getInt8Ty(Context));
515
0
  }
516
517
  bool areInlineCompatible(const Function *Caller,
518
0
                           const Function *Callee) const {
519
0
    return (Caller->getFnAttribute("target-cpu") ==
520
0
            Callee->getFnAttribute("target-cpu")) &&
521
0
           (Caller->getFnAttribute("target-features") ==
522
0
            Callee->getFnAttribute("target-features"));
523
0
  }
524
525
  bool isIndexedLoadLegal(TTI::MemIndexedMode Mode, Type *Ty,
526
0
                          const DataLayout &DL) const {
527
0
    return false;
528
0
  }
529
530
  bool isIndexedStoreLegal(TTI::MemIndexedMode Mode, Type *Ty,
531
0
                           const DataLayout &DL) const {
532
0
    return false;
533
0
  }
534
535
0
  unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const { return 128; }
536
537
0
  bool isLegalToVectorizeLoad(LoadInst *LI) const { return true; }
538
539
0
  bool isLegalToVectorizeStore(StoreInst *SI) const { return true; }
540
541
  bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
542
                                   unsigned Alignment,
543
0
                                   unsigned AddrSpace) const {
544
0
    return true;
545
0
  }
546
547
  bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
548
                                    unsigned Alignment,
549
0
                                    unsigned AddrSpace) const {
550
0
    return true;
551
0
  }
552
553
  unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
554
                               unsigned ChainSizeInBytes,
555
0
                               VectorType *VecTy) const {
556
0
    return VF;
557
0
  }
558
559
  unsigned getStoreVectorFactor(unsigned VF, unsigned StoreSize,
560
                                unsigned ChainSizeInBytes,
561
0
                                VectorType *VecTy) const {
562
0
    return VF;
563
0
  }
564
565
  bool useReductionIntrinsic(unsigned Opcode, Type *Ty,
566
121
                             TTI::ReductionFlags Flags) const {
567
121
    return false;
568
121
  }
569
570
0
  bool shouldExpandReduction(const IntrinsicInst *II) const {
571
0
    return true;
572
0
  }
573
574
protected:
575
  // Obtain the minimum required size to hold the value (without the sign)
576
  // In case of a vector it returns the min required size for one element.
577
0
  unsigned minRequiredElementSize(const Value* Val, bool &isSigned) {
578
0
    if (isa<ConstantDataVector>(Val) || isa<ConstantVector>(Val)) {
579
0
      const auto* VectorValue = cast<Constant>(Val);
580
0
581
0
      // In case of a vector need to pick the max between the min
582
0
      // required size for each element
583
0
      auto *VT = cast<VectorType>(Val->getType());
584
0
585
0
      // Assume unsigned elements
586
0
      isSigned = false;
587
0
588
0
      // The max required size is the total vector width divided by num
589
0
      // of elements in the vector
590
0
      unsigned MaxRequiredSize = VT->getBitWidth() / VT->getNumElements();
591
0
592
0
      unsigned MinRequiredSize = 0;
593
0
      for(unsigned i = 0, e = VT->getNumElements(); i < e; ++i) {
594
0
        if (auto* IntElement =
595
0
              dyn_cast<ConstantInt>(VectorValue->getAggregateElement(i))) {
596
0
          bool signedElement = IntElement->getValue().isNegative();
597
0
          // Get the element min required size.
598
0
          unsigned ElementMinRequiredSize =
599
0
            IntElement->getValue().getMinSignedBits() - 1;
600
0
          // In case one element is signed then all the vector is signed.
601
0
          isSigned |= signedElement;
602
0
          // Save the max required bit size between all the elements.
603
0
          MinRequiredSize = std::max(MinRequiredSize, ElementMinRequiredSize);
604
0
        }
605
0
        else {
606
0
          // not an int constant element
607
0
          return MaxRequiredSize;
608
0
        }
609
0
      }
610
0
      return MinRequiredSize;
611
0
    }
612
0
613
0
    if (const auto* CI = dyn_cast<ConstantInt>(Val)) {
614
0
      isSigned = CI->getValue().isNegative();
615
0
      return CI->getValue().getMinSignedBits() - 1;
616
0
    }
617
0
618
0
    if (const auto* Cast = dyn_cast<SExtInst>(Val)) {
619
0
      isSigned = true;
620
0
      return Cast->getSrcTy()->getScalarSizeInBits() - 1;
621
0
    }
622
0
623
0
    if (const auto* Cast = dyn_cast<ZExtInst>(Val)) {
624
0
      isSigned = false;
625
0
      return Cast->getSrcTy()->getScalarSizeInBits();
626
0
    }
627
0
628
0
    isSigned = false;
629
0
    return Val->getType()->getScalarSizeInBits();
630
0
  }
631
632
15.9k
  bool isStridedAccess(const SCEV *Ptr) {
633
15.9k
    return Ptr && 
isa<SCEVAddRecExpr>(Ptr)8.65k
;
634
15.9k
  }
635
636
  const SCEVConstant *getConstantStrideStep(ScalarEvolution *SE,
637
15.1k
                                            const SCEV *Ptr) {
638
15.1k
    if (!isStridedAccess(Ptr))
639
8.17k
      return nullptr;
640
6.96k
    const SCEVAddRecExpr *AddRec = cast<SCEVAddRecExpr>(Ptr);
641
6.96k
    return dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(*SE));
642
6.96k
  }
643
644
  bool isConstantStridedAccessLessThan(ScalarEvolution *SE, const SCEV *Ptr,
645
14.5k
                                       int64_t MergeDistance) {
646
14.5k
    const SCEVConstant *Step = getConstantStrideStep(SE, Ptr);
647
14.5k
    if (!Step)
648
8.21k
      return false;
649
6.30k
    APInt StrideVal = Step->getAPInt();
650
6.30k
    if (StrideVal.getBitWidth() > 64)
651
0
      return false;
652
6.30k
    // FIXME: Need to take absolute value for negative stride case.
653
6.30k
    return StrideVal.getSExtValue() < MergeDistance;
654
6.30k
  }
655
};
656
657
/// CRTP base class for use as a mix-in that aids implementing
658
/// a TargetTransformInfo-compatible class.
659
template <typename T>
660
class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
661
private:
662
  typedef TargetTransformInfoImplBase BaseT;
663
664
protected:
665
14.7M
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
12.3M
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
22
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
llvm::TargetTransformInfoImplCRTPBase<llvm::AMDGPUTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
48
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
26
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
575k
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
1.79M
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
Line
Count
Source
665
73
  explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {}
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::TargetTransformInfoImplCRTPBase(llvm::DataLayout const&)
666
667
public:
668
  using BaseT::getCallCost;
669
670
6.45M
  unsigned getCallCost(const Function *F, int NumArgs) {
671
6.45M
    assert(F && "A concrete function must be provided to this routine.");
672
6.45M
673
6.45M
    if (NumArgs < 0)
674
0
      // Set the argument number to the number of explicit arguments in the
675
0
      // function.
676
0
      NumArgs = F->arg_size();
677
6.45M
678
6.45M
    if (Intrinsic::ID IID = F->getIntrinsicID()) {
679
1.28M
      FunctionType *FTy = F->getFunctionType();
680
1.28M
      SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
681
1.28M
      return static_cast<T *>(this)
682
1.28M
          ->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
683
1.28M
    }
684
5.17M
685
5.17M
    if (!static_cast<T *>(this)->isLoweredToCall(F))
686
2
      return TTI::TCC_Basic; // Give a basic cost if it will be lowered
687
5.17M
                             // directly.
688
5.17M
689
5.17M
    return static_cast<T *>(this)->getCallCost(F->getFunctionType(), NumArgs);
690
5.17M
  }
llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getCallCost(llvm::Function const*, int)
Line
Count
Source
670
5.00M
  unsigned getCallCost(const Function *F, int NumArgs) {
671
5.00M
    assert(F && "A concrete function must be provided to this routine.");
672
5.00M
673
5.00M
    if (NumArgs < 0)
674
0
      // Set the argument number to the number of explicit arguments in the
675
0
      // function.
676
0
      NumArgs = F->arg_size();
677
5.00M
678
5.00M
    if (Intrinsic::ID IID = F->getIntrinsicID()) {
679
1.00M
      FunctionType *FTy = F->getFunctionType();
680
1.00M
      SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
681
1.00M
      return static_cast<T *>(this)
682
1.00M
          ->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
683
1.00M
    }
684
3.99M
685
3.99M
    if (!static_cast<T *>(this)->isLoweredToCall(F))
686
2
      return TTI::TCC_Basic; // Give a basic cost if it will be lowered
687
3.99M
                             // directly.
688
3.99M
689
3.99M
    return static_cast<T *>(this)->getCallCost(F->getFunctionType(), NumArgs);
690
3.99M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getCallCost(llvm::Function const*, int)
llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getCallCost(llvm::Function const*, int)
Line
Count
Source
670
404k
  unsigned getCallCost(const Function *F, int NumArgs) {
671
404k
    assert(F && "A concrete function must be provided to this routine.");
672
404k
673
404k
    if (NumArgs < 0)
674
0
      // Set the argument number to the number of explicit arguments in the
675
0
      // function.
676
0
      NumArgs = F->arg_size();
677
404k
678
404k
    if (Intrinsic::ID IID = F->getIntrinsicID()) {
679
78.3k
      FunctionType *FTy = F->getFunctionType();
680
78.3k
      SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
681
78.3k
      return static_cast<T *>(this)
682
78.3k
          ->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
683
78.3k
    }
684
326k
685
326k
    if (!static_cast<T *>(this)->isLoweredToCall(F))
686
0
      return TTI::TCC_Basic; // Give a basic cost if it will be lowered
687
326k
                             // directly.
688
326k
689
326k
    return static_cast<T *>(this)->getCallCost(F->getFunctionType(), NumArgs);
690
326k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getCallCost(llvm::Function const*, int)
llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getCallCost(llvm::Function const*, int)
Line
Count
Source
670
1.05M
  unsigned getCallCost(const Function *F, int NumArgs) {
671
1.05M
    assert(F && "A concrete function must be provided to this routine.");
672
1.05M
673
1.05M
    if (NumArgs < 0)
674
0
      // Set the argument number to the number of explicit arguments in the
675
0
      // function.
676
0
      NumArgs = F->arg_size();
677
1.05M
678
1.05M
    if (Intrinsic::ID IID = F->getIntrinsicID()) {
679
201k
      FunctionType *FTy = F->getFunctionType();
680
201k
      SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end());
681
201k
      return static_cast<T *>(this)
682
201k
          ->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys);
683
201k
    }
684
848k
685
848k
    if (!static_cast<T *>(this)->isLoweredToCall(F))
686
0
      return TTI::TCC_Basic; // Give a basic cost if it will be lowered
687
848k
                             // directly.
688
848k
689
848k
    return static_cast<T *>(this)->getCallCost(F->getFunctionType(), NumArgs);
690
848k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getCallCost(llvm::Function const*, int)
Unexecuted instantiation: TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getCallCost(llvm::Function const*, int)
691
692
6.45M
  unsigned getCallCost(const Function *F, ArrayRef<const Value *> Arguments) {
693
6.45M
    // Simply delegate to generic handling of the call.
694
6.45M
    // FIXME: We should use instsimplify or something else to catch calls which
695
6.45M
    // will constant fold with these arguments.
696
6.45M
    return static_cast<T *>(this)->getCallCost(F, Arguments.size());
697
6.45M
  }
llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
692
5.00M
  unsigned getCallCost(const Function *F, ArrayRef<const Value *> Arguments) {
693
5.00M
    // Simply delegate to generic handling of the call.
694
5.00M
    // FIXME: We should use instsimplify or something else to catch calls which
695
5.00M
    // will constant fold with these arguments.
696
5.00M
    return static_cast<T *>(this)->getCallCost(F, Arguments.size());
697
5.00M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
692
404k
  unsigned getCallCost(const Function *F, ArrayRef<const Value *> Arguments) {
693
404k
    // Simply delegate to generic handling of the call.
694
404k
    // FIXME: We should use instsimplify or something else to catch calls which
695
404k
    // will constant fold with these arguments.
696
404k
    return static_cast<T *>(this)->getCallCost(F, Arguments.size());
697
404k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
692
1.05M
  unsigned getCallCost(const Function *F, ArrayRef<const Value *> Arguments) {
693
1.05M
    // Simply delegate to generic handling of the call.
694
1.05M
    // FIXME: We should use instsimplify or something else to catch calls which
695
1.05M
    // will constant fold with these arguments.
696
1.05M
    return static_cast<T *>(this)->getCallCost(F, Arguments.size());
697
1.05M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getCallCost(llvm::Function const*, llvm::ArrayRef<llvm::Value const*>)
698
699
  using BaseT::getGEPCost;
700
701
  int getGEPCost(Type *PointeeType, const Value *Ptr,
702
6.09M
                 ArrayRef<const Value *> Operands) {
703
6.09M
    const GlobalValue *BaseGV = nullptr;
704
6.09M
    if (Ptr != nullptr) {
705
6.09M
      // TODO: will remove this when pointers have an opaque type.
706
6.09M
      assert(Ptr->getType()->getScalarType()->getPointerElementType() ==
707
6.09M
                 PointeeType &&
708
6.09M
             "explicit pointee type doesn't match operand's pointee type");
709
6.09M
      BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
710
6.09M
    }
711
6.09M
    bool HasBaseReg = (BaseGV == nullptr);
712
6.09M
713
6.09M
    auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
714
6.09M
    APInt BaseOffset(PtrSizeBits, 0);
715
6.09M
    int64_t Scale = 0;
716
6.09M
717
6.09M
    auto GTI = gep_type_begin(PointeeType, Operands);
718
6.09M
    Type *TargetType = nullptr;
719
6.09M
720
6.09M
    // Handle the case where the GEP instruction has a single operand,
721
6.09M
    // the basis, therefore TargetType is a nullptr.
722
6.09M
    if (Operands.empty())
723
0
      return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
724
6.09M
725
17.9M
    
for (auto I = Operands.begin(); 6.09M
I != Operands.end();
++I, ++GTI11.8M
) {
726
12.0M
      TargetType = GTI.getIndexedType();
727
12.0M
      // We assume that the cost of Scalar GEP with constant index and the
728
12.0M
      // cost of Vector GEP with splat constant index are the same.
729
12.0M
      const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
730
12.0M
      if (!ConstIdx)
731
3.22M
        if (auto Splat = getSplatValue(*I))
732
18
          ConstIdx = dyn_cast<ConstantInt>(Splat);
733
12.0M
      if (StructType *STy = GTI.getStructTypeOrNull()) {
734
4.42M
        // For structures the index is always splat or scalar constant
735
4.42M
        assert(ConstIdx && "Unexpected GEP index");
736
4.42M
        uint64_t Field = ConstIdx->getZExtValue();
737
4.42M
        BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
738
7.59M
      } else {
739
7.59M
        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
740
7.59M
        if (ConstIdx) {
741
4.37M
          BaseOffset +=
742
4.37M
              ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
743
4.37M
        } else {
744
3.22M
          // Needs scale register.
745
3.22M
          if (Scale != 0)
746
127k
            // No addressing mode takes two scale registers.
747
127k
            return TTI::TCC_Basic;
748
3.09M
          Scale = ElementSize;
749
3.09M
        }
750
7.59M
      }
751
12.0M
    }
752
6.09M
753
6.09M
    // Assumes the address space is 0 when Ptr is nullptr.
754
6.09M
    unsigned AS =
755
5.97M
        (Ptr == nullptr ? 
00
: Ptr->getType()->getPointerAddressSpace());
756
5.97M
757
5.97M
    if (static_cast<T *>(this)->isLegalAddressingMode(
758
5.97M
            TargetType, const_cast<GlobalValue *>(BaseGV),
759
5.97M
            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
760
4.63M
      return TTI::TCC_Free;
761
1.33M
    return TTI::TCC_Basic;
762
1.33M
  }
llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
702
5.55M
                 ArrayRef<const Value *> Operands) {
703
5.55M
    const GlobalValue *BaseGV = nullptr;
704
5.55M
    if (Ptr != nullptr) {
705
5.55M
      // TODO: will remove this when pointers have an opaque type.
706
5.55M
      assert(Ptr->getType()->getScalarType()->getPointerElementType() ==
707
5.55M
                 PointeeType &&
708
5.55M
             "explicit pointee type doesn't match operand's pointee type");
709
5.55M
      BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
710
5.55M
    }
711
5.55M
    bool HasBaseReg = (BaseGV == nullptr);
712
5.55M
713
5.55M
    auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
714
5.55M
    APInt BaseOffset(PtrSizeBits, 0);
715
5.55M
    int64_t Scale = 0;
716
5.55M
717
5.55M
    auto GTI = gep_type_begin(PointeeType, Operands);
718
5.55M
    Type *TargetType = nullptr;
719
5.55M
720
5.55M
    // Handle the case where the GEP instruction has a single operand,
721
5.55M
    // the basis, therefore TargetType is a nullptr.
722
5.55M
    if (Operands.empty())
723
0
      return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
724
5.55M
725
16.1M
    
for (auto I = Operands.begin(); 5.55M
I != Operands.end();
++I, ++GTI10.5M
) {
726
10.6M
      TargetType = GTI.getIndexedType();
727
10.6M
      // We assume that the cost of Scalar GEP with constant index and the
728
10.6M
      // cost of Vector GEP with splat constant index are the same.
729
10.6M
      const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
730
10.6M
      if (!ConstIdx)
731
2.90M
        if (auto Splat = getSplatValue(*I))
732
18
          ConstIdx = dyn_cast<ConstantInt>(Splat);
733
10.6M
      if (StructType *STy = GTI.getStructTypeOrNull()) {
734
3.82M
        // For structures the index is always splat or scalar constant
735
3.82M
        assert(ConstIdx && "Unexpected GEP index");
736
3.82M
        uint64_t Field = ConstIdx->getZExtValue();
737
3.82M
        BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
738
6.85M
      } else {
739
6.85M
        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
740
6.85M
        if (ConstIdx) {
741
3.95M
          BaseOffset +=
742
3.95M
              ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
743
3.95M
        } else {
744
2.90M
          // Needs scale register.
745
2.90M
          if (Scale != 0)
746
108k
            // No addressing mode takes two scale registers.
747
108k
            return TTI::TCC_Basic;
748
2.79M
          Scale = ElementSize;
749
2.79M
        }
750
6.85M
      }
751
10.6M
    }
752
5.55M
753
5.55M
    // Assumes the address space is 0 when Ptr is nullptr.
754
5.55M
    unsigned AS =
755
5.44M
        (Ptr == nullptr ? 
00
: Ptr->getType()->getPointerAddressSpace());
756
5.44M
757
5.44M
    if (static_cast<T *>(this)->isLegalAddressingMode(
758
5.44M
            TargetType, const_cast<GlobalValue *>(BaseGV),
759
5.44M
            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
760
4.24M
      return TTI::TCC_Free;
761
1.19M
    return TTI::TCC_Basic;
762
1.19M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
702
98.3k
                 ArrayRef<const Value *> Operands) {
703
98.3k
    const GlobalValue *BaseGV = nullptr;
704
98.3k
    if (Ptr != nullptr) {
705
98.3k
      // TODO: will remove this when pointers have an opaque type.
706
98.3k
      assert(Ptr->getType()->getScalarType()->getPointerElementType() ==
707
98.3k
                 PointeeType &&
708
98.3k
             "explicit pointee type doesn't match operand's pointee type");
709
98.3k
      BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
710
98.3k
    }
711
98.3k
    bool HasBaseReg = (BaseGV == nullptr);
712
98.3k
713
98.3k
    auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
714
98.3k
    APInt BaseOffset(PtrSizeBits, 0);
715
98.3k
    int64_t Scale = 0;
716
98.3k
717
98.3k
    auto GTI = gep_type_begin(PointeeType, Operands);
718
98.3k
    Type *TargetType = nullptr;
719
98.3k
720
98.3k
    // Handle the case where the GEP instruction has a single operand,
721
98.3k
    // the basis, therefore TargetType is a nullptr.
722
98.3k
    if (Operands.empty())
723
0
      return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
724
98.3k
725
324k
    
for (auto I = Operands.begin(); 98.3k
I != Operands.end();
++I, ++GTI226k
) {
726
232k
      TargetType = GTI.getIndexedType();
727
232k
      // We assume that the cost of Scalar GEP with constant index and the
728
232k
      // cost of Vector GEP with splat constant index are the same.
729
232k
      const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
730
232k
      if (!ConstIdx)
731
71.4k
        if (auto Splat = getSplatValue(*I))
732
0
          ConstIdx = dyn_cast<ConstantInt>(Splat);
733
232k
      if (StructType *STy = GTI.getStructTypeOrNull()) {
734
88.2k
        // For structures the index is always splat or scalar constant
735
88.2k
        assert(ConstIdx && "Unexpected GEP index");
736
88.2k
        uint64_t Field = ConstIdx->getZExtValue();
737
88.2k
        BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
738
144k
      } else {
739
144k
        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
740
144k
        if (ConstIdx) {
741
73.0k
          BaseOffset +=
742
73.0k
              ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
743
73.0k
        } else {
744
71.4k
          // Needs scale register.
745
71.4k
          if (Scale != 0)
746
6.23k
            // No addressing mode takes two scale registers.
747
6.23k
            return TTI::TCC_Basic;
748
65.1k
          Scale = ElementSize;
749
65.1k
        }
750
144k
      }
751
232k
    }
752
98.3k
753
98.3k
    // Assumes the address space is 0 when Ptr is nullptr.
754
98.3k
    unsigned AS =
755
92.1k
        (Ptr == nullptr ? 
00
: Ptr->getType()->getPointerAddressSpace());
756
92.1k
757
92.1k
    if (static_cast<T *>(this)->isLegalAddressingMode(
758
92.1k
            TargetType, const_cast<GlobalValue *>(BaseGV),
759
92.1k
            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
760
55.6k
      return TTI::TCC_Free;
761
36.4k
    return TTI::TCC_Basic;
762
36.4k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
702
448k
                 ArrayRef<const Value *> Operands) {
703
448k
    const GlobalValue *BaseGV = nullptr;
704
448k
    if (Ptr != nullptr) {
705
448k
      // TODO: will remove this when pointers have an opaque type.
706
448k
      assert(Ptr->getType()->getScalarType()->getPointerElementType() ==
707
448k
                 PointeeType &&
708
448k
             "explicit pointee type doesn't match operand's pointee type");
709
448k
      BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
710
448k
    }
711
448k
    bool HasBaseReg = (BaseGV == nullptr);
712
448k
713
448k
    auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
714
448k
    APInt BaseOffset(PtrSizeBits, 0);
715
448k
    int64_t Scale = 0;
716
448k
717
448k
    auto GTI = gep_type_begin(PointeeType, Operands);
718
448k
    Type *TargetType = nullptr;
719
448k
720
448k
    // Handle the case where the GEP instruction has a single operand,
721
448k
    // the basis, therefore TargetType is a nullptr.
722
448k
    if (Operands.empty())
723
0
      return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
724
448k
725
1.55M
    
for (auto I = Operands.begin(); 448k
I != Operands.end();
++I, ++GTI1.10M
) {
726
1.11M
      TargetType = GTI.getIndexedType();
727
1.11M
      // We assume that the cost of Scalar GEP with constant index and the
728
1.11M
      // cost of Vector GEP with splat constant index are the same.
729
1.11M
      const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
730
1.11M
      if (!ConstIdx)
731
249k
        if (auto Splat = getSplatValue(*I))
732
0
          ConstIdx = dyn_cast<ConstantInt>(Splat);
733
1.11M
      if (StructType *STy = GTI.getStructTypeOrNull()) {
734
518k
        // For structures the index is always splat or scalar constant
735
518k
        assert(ConstIdx && "Unexpected GEP index");
736
518k
        uint64_t Field = ConstIdx->getZExtValue();
737
518k
        BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
738
597k
      } else {
739
597k
        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
740
597k
        if (ConstIdx) {
741
347k
          BaseOffset +=
742
347k
              ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
743
347k
        } else {
744
249k
          // Needs scale register.
745
249k
          if (Scale != 0)
746
12.8k
            // No addressing mode takes two scale registers.
747
12.8k
            return TTI::TCC_Basic;
748
236k
          Scale = ElementSize;
749
236k
        }
750
597k
      }
751
1.11M
    }
752
448k
753
448k
    // Assumes the address space is 0 when Ptr is nullptr.
754
448k
    unsigned AS =
755
435k
        (Ptr == nullptr ? 
00
: Ptr->getType()->getPointerAddressSpace());
756
435k
757
435k
    if (static_cast<T *>(this)->isLegalAddressingMode(
758
435k
            TargetType, const_cast<GlobalValue *>(BaseGV),
759
435k
            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
760
333k
      return TTI::TCC_Free;
761
101k
    return TTI::TCC_Basic;
762
101k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getGEPCost(llvm::Type*, llvm::Value const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
702
8
                 ArrayRef<const Value *> Operands) {
703
8
    const GlobalValue *BaseGV = nullptr;
704
8
    if (Ptr != nullptr) {
705
8
      // TODO: will remove this when pointers have an opaque type.
706
8
      assert(Ptr->getType()->getScalarType()->getPointerElementType() ==
707
8
                 PointeeType &&
708
8
             "explicit pointee type doesn't match operand's pointee type");
709
8
      BaseGV = dyn_cast<GlobalValue>(Ptr->stripPointerCasts());
710
8
    }
711
8
    bool HasBaseReg = (BaseGV == nullptr);
712
8
713
8
    auto PtrSizeBits = DL.getPointerTypeSizeInBits(Ptr->getType());
714
8
    APInt BaseOffset(PtrSizeBits, 0);
715
8
    int64_t Scale = 0;
716
8
717
8
    auto GTI = gep_type_begin(PointeeType, Operands);
718
8
    Type *TargetType = nullptr;
719
8
720
8
    // Handle the case where the GEP instruction has a single operand,
721
8
    // the basis, therefore TargetType is a nullptr.
722
8
    if (Operands.empty())
723
0
      return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;
724
8
725
16
    
for (auto I = Operands.begin(); 8
I != Operands.end();
++I, ++GTI8
) {
726
8
      TargetType = GTI.getIndexedType();
727
8
      // We assume that the cost of Scalar GEP with constant index and the
728
8
      // cost of Vector GEP with splat constant index are the same.
729
8
      const ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
730
8
      if (!ConstIdx)
731
8
        if (auto Splat = getSplatValue(*I))
732
0
          ConstIdx = dyn_cast<ConstantInt>(Splat);
733
8
      if (StructType *STy = GTI.getStructTypeOrNull()) {
734
0
        // For structures the index is always splat or scalar constant
735
0
        assert(ConstIdx && "Unexpected GEP index");
736
0
        uint64_t Field = ConstIdx->getZExtValue();
737
0
        BaseOffset += DL.getStructLayout(STy)->getElementOffset(Field);
738
8
      } else {
739
8
        int64_t ElementSize = DL.getTypeAllocSize(GTI.getIndexedType());
740
8
        if (ConstIdx) {
741
0
          BaseOffset +=
742
0
              ConstIdx->getValue().sextOrTrunc(PtrSizeBits) * ElementSize;
743
8
        } else {
744
8
          // Needs scale register.
745
8
          if (Scale != 0)
746
0
            // No addressing mode takes two scale registers.
747
0
            return TTI::TCC_Basic;
748
8
          Scale = ElementSize;
749
8
        }
750
8
      }
751
8
    }
752
8
753
8
    // Assumes the address space is 0 when Ptr is nullptr.
754
8
    unsigned AS =
755
8
        (Ptr == nullptr ? 
00
: Ptr->getType()->getPointerAddressSpace());
756
8
757
8
    if (static_cast<T *>(this)->isLegalAddressingMode(
758
8
            TargetType, const_cast<GlobalValue *>(BaseGV),
759
8
            BaseOffset.sextOrTrunc(64).getSExtValue(), HasBaseReg, Scale, AS))
760
0
      return TTI::TCC_Free;
761
8
    return TTI::TCC_Basic;
762
8
  }
763
764
  using BaseT::getIntrinsicCost;
765
766
  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
767
0
                            ArrayRef<const Value *> Arguments) {
768
0
    // Delegate to the generic intrinsic handling code. This mostly provides an
769
0
    // opportunity for targets to (for example) special case the cost of
770
0
    // certain intrinsics based on constants used as arguments.
771
0
    SmallVector<Type *, 8> ParamTys;
772
0
    ParamTys.reserve(Arguments.size());
773
0
    for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx)
774
0
      ParamTys.push_back(Arguments[Idx]->getType());
775
0
    return static_cast<T *>(this)->getIntrinsicCost(IID, RetTy, ParamTys);
776
0
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getIntrinsicCost(llvm::Intrinsic::ID, llvm::Type*, llvm::ArrayRef<llvm::Value const*>)
777
778
44.4M
  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands) {
779
44.4M
    if (isa<PHINode>(U))
780
3.60M
      return TTI::TCC_Free; // Model all PHI nodes as free.
781
40.8M
782
40.8M
    // Static alloca doesn't generate target instructions.
783
40.8M
    if (auto *A = dyn_cast<AllocaInst>(U))
784
106
      if (A->isStaticAlloca())
785
0
        return TTI::TCC_Free;
786
40.8M
787
40.8M
    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
788
6.09M
      return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
789
6.09M
                                                GEP->getPointerOperand(),
790
6.09M
                                                Operands.drop_front());
791
6.09M
    }
792
34.7M
793
34.7M
    if (auto CS = ImmutableCallSite(U)) {
794
6.72M
      const Function *F = CS.getCalledFunction();
795
6.72M
      if (!F) {
796
270k
        // Just use the called value type.
797
270k
        Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
798
270k
        return static_cast<T *>(this)
799
270k
            ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
800
270k
      }
801
6.45M
802
6.45M
      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
803
6.45M
      return static_cast<T *>(this)->getCallCost(F, Arguments);
804
6.45M
    }
805
28.0M
806
28.0M
    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
807
5.88M
      // Result of a cmp instruction is often extended (to be used by other
808
5.88M
      // cmp instructions, logical or return instructions). These are usually
809
5.88M
      // nop on most sane targets.
810
5.88M
      if (isa<CmpInst>(CI->getOperand(0)))
811
115k
        return TTI::TCC_Free;
812
5.76M
      if (isa<SExtInst>(CI) || 
isa<ZExtInst>(CI)4.85M
||
isa<FPExtInst>(CI)4.13M
)
813
1.70M
        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
814
26.2M
    }
815
26.2M
816
26.2M
    return static_cast<T *>(this)->getOperationCost(
817
26.2M
        Operator::getOpcode(U), U->getType(),
818
26.2M
        U->getNumOperands() == 1 ? 
U->getOperand(0)->getType()10.8M
:
nullptr15.4M
);
819
26.2M
  }
llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
778
39.6M
  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands) {
779
39.6M
    if (isa<PHINode>(U))
780
3.35M
      return TTI::TCC_Free; // Model all PHI nodes as free.
781
36.2M
782
36.2M
    // Static alloca doesn't generate target instructions.
783
36.2M
    if (auto *A = dyn_cast<AllocaInst>(U))
784
64
      if (A->isStaticAlloca())
785
0
        return TTI::TCC_Free;
786
36.2M
787
36.2M
    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
788
5.55M
      return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
789
5.55M
                                                GEP->getPointerOperand(),
790
5.55M
                                                Operands.drop_front());
791
5.55M
    }
792
30.7M
793
30.7M
    if (auto CS = ImmutableCallSite(U)) {
794
5.18M
      const Function *F = CS.getCalledFunction();
795
5.18M
      if (!F) {
796
183k
        // Just use the called value type.
797
183k
        Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
798
183k
        return static_cast<T *>(this)
799
183k
            ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
800
183k
      }
801
5.00M
802
5.00M
      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
803
5.00M
      return static_cast<T *>(this)->getCallCost(F, Arguments);
804
5.00M
    }
805
25.5M
806
25.5M
    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
807
5.12M
      // Result of a cmp instruction is often extended (to be used by other
808
5.12M
      // cmp instructions, logical or return instructions). These are usually
809
5.12M
      // nop on most sane targets.
810
5.12M
      if (isa<CmpInst>(CI->getOperand(0)))
811
98.0k
        return TTI::TCC_Free;
812
5.02M
      if (isa<SExtInst>(CI) || 
isa<ZExtInst>(CI)4.25M
||
isa<FPExtInst>(CI)3.65M
)
813
1.44M
        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
814
24.0M
    }
815
24.0M
816
24.0M
    return static_cast<T *>(this)->getOperationCost(
817
24.0M
        Operator::getOpcode(U), U->getType(),
818
24.0M
        U->getNumOperands() == 1 ? 
U->getOperand(0)->getType()9.81M
:
nullptr14.2M
);
819
24.0M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
778
1.17M
  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands) {
779
1.17M
    if (isa<PHINode>(U))
780
52.3k
      return TTI::TCC_Free; // Model all PHI nodes as free.
781
1.12M
782
1.12M
    // Static alloca doesn't generate target instructions.
783
1.12M
    if (auto *A = dyn_cast<AllocaInst>(U))
784
18
      if (A->isStaticAlloca())
785
0
        return TTI::TCC_Free;
786
1.12M
787
1.12M
    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
788
98.3k
      return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
789
98.3k
                                                GEP->getPointerOperand(),
790
98.3k
                                                Operands.drop_front());
791
98.3k
    }
792
1.02M
793
1.02M
    if (auto CS = ImmutableCallSite(U)) {
794
415k
      const Function *F = CS.getCalledFunction();
795
415k
      if (!F) {
796
10.5k
        // Just use the called value type.
797
10.5k
        Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
798
10.5k
        return static_cast<T *>(this)
799
10.5k
            ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
800
10.5k
      }
801
404k
802
404k
      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
803
404k
      return static_cast<T *>(this)->getCallCost(F, Arguments);
804
404k
    }
805
612k
806
612k
    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
807
201k
      // Result of a cmp instruction is often extended (to be used by other
808
201k
      // cmp instructions, logical or return instructions). These are usually
809
201k
      // nop on most sane targets.
810
201k
      if (isa<CmpInst>(CI->getOperand(0)))
811
5.66k
        return TTI::TCC_Free;
812
195k
      if (isa<SExtInst>(CI) || 
isa<ZExtInst>(CI)152k
||
isa<FPExtInst>(CI)109k
)
813
86.6k
        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
814
520k
    }
815
520k
816
520k
    return static_cast<T *>(this)->getOperationCost(
817
520k
        Operator::getOpcode(U), U->getType(),
818
520k
        U->getNumOperands() == 1 ? 
U->getOperand(0)->getType()219k
:
nullptr300k
);
819
520k
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
778
3.64M
  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands) {
779
3.64M
    if (isa<PHINode>(U))
780
197k
      return TTI::TCC_Free; // Model all PHI nodes as free.
781
3.44M
782
3.44M
    // Static alloca doesn't generate target instructions.
783
3.44M
    if (auto *A = dyn_cast<AllocaInst>(U))
784
24
      if (A->isStaticAlloca())
785
0
        return TTI::TCC_Free;
786
3.44M
787
3.44M
    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
788
448k
      return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
789
448k
                                                GEP->getPointerOperand(),
790
448k
                                                Operands.drop_front());
791
448k
    }
792
2.99M
793
2.99M
    if (auto CS = ImmutableCallSite(U)) {
794
1.12M
      const Function *F = CS.getCalledFunction();
795
1.12M
      if (!F) {
796
76.4k
        // Just use the called value type.
797
76.4k
        Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
798
76.4k
        return static_cast<T *>(this)
799
76.4k
            ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
800
76.4k
      }
801
1.05M
802
1.05M
      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
803
1.05M
      return static_cast<T *>(this)->getCallCost(F, Arguments);
804
1.05M
    }
805
1.87M
806
1.87M
    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
807
554k
      // Result of a cmp instruction is often extended (to be used by other
808
554k
      // cmp instructions, logical or return instructions). These are usually
809
554k
      // nop on most sane targets.
810
554k
      if (isa<CmpInst>(CI->getOperand(0)))
811
11.4k
        return TTI::TCC_Free;
812
542k
      if (isa<SExtInst>(CI) || 
isa<ZExtInst>(CI)453k
||
isa<FPExtInst>(CI)371k
)
813
171k
        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
814
1.68M
    }
815
1.68M
816
1.68M
    return static_cast<T *>(this)->getOperationCost(
817
1.68M
        Operator::getOpcode(U), U->getType(),
818
1.68M
        U->getNumOperands() == 1 ? 
U->getOperand(0)->getType()783k
:
nullptr906k
);
819
1.68M
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getUserCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>)
Line
Count
Source
778
113
  unsigned getUserCost(const User *U, ArrayRef<const Value *> Operands) {
779
113
    if (isa<PHINode>(U))
780
27
      return TTI::TCC_Free; // Model all PHI nodes as free.
781
86
782
86
    // Static alloca doesn't generate target instructions.
783
86
    if (auto *A = dyn_cast<AllocaInst>(U))
784
0
      if (A->isStaticAlloca())
785
0
        return TTI::TCC_Free;
786
86
787
86
    if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) {
788
8
      return static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),
789
8
                                                GEP->getPointerOperand(),
790
8
                                                Operands.drop_front());
791
8
    }
792
78
793
78
    if (auto CS = ImmutableCallSite(U)) {
794
0
      const Function *F = CS.getCalledFunction();
795
0
      if (!F) {
796
0
        // Just use the called value type.
797
0
        Type *FTy = CS.getCalledValue()->getType()->getPointerElementType();
798
0
        return static_cast<T *>(this)
799
0
            ->getCallCost(cast<FunctionType>(FTy), CS.arg_size());
800
0
      }
801
0
802
0
      SmallVector<const Value *, 8> Arguments(CS.arg_begin(), CS.arg_end());
803
0
      return static_cast<T *>(this)->getCallCost(F, Arguments);
804
0
    }
805
78
806
78
    if (const CastInst *CI = dyn_cast<CastInst>(U)) {
807
7
      // Result of a cmp instruction is often extended (to be used by other
808
7
      // cmp instructions, logical or return instructions). These are usually
809
7
      // nop on most sane targets.
810
7
      if (isa<CmpInst>(CI->getOperand(0)))
811
0
        return TTI::TCC_Free;
812
7
      if (isa<SExtInst>(CI) || 
isa<ZExtInst>(CI)5
||
isa<FPExtInst>(CI)5
)
813
2
        return static_cast<T *>(this)->getExtCost(CI, Operands.back());
814
76
    }
815
76
816
76
    return static_cast<T *>(this)->getOperationCost(
817
76
        Operator::getOpcode(U), U->getType(),
818
76
        U->getNumOperands() == 1 ? 
U->getOperand(0)->getType()18
:
nullptr58
);
819
76
  }
820
821
0
  int getInstructionLatency(const Instruction *I) {
822
0
    SmallVector<const Value *, 4> Operands(I->value_op_begin(),
823
0
                                           I->value_op_end());
824
0
    if (getUserCost(I, Operands) == TTI::TCC_Free)
825
0
      return 0;
826
0
827
0
    if (isa<LoadInst>(I))
828
0
      return 4;
829
0
830
0
    Type *DstTy = I->getType();
831
0
832
0
    // Usually an intrinsic is a simple instruction.
833
0
    // A real function call is much slower.
834
0
    if (auto *CI = dyn_cast<CallInst>(I)) {
835
0
      const Function *F = CI->getCalledFunction();
836
0
      if (!F || static_cast<T *>(this)->isLoweredToCall(F))
837
0
        return 40;
838
0
      // Some intrinsics return a value and a flag, we use the value type
839
0
      // to decide its latency.
840
0
      if (StructType* StructTy = dyn_cast<StructType>(DstTy))
841
0
        DstTy = StructTy->getElementType(0);
842
0
      // Fall through to simple instructions.
843
0
    }
844
0
845
0
    if (VectorType *VectorTy = dyn_cast<VectorType>(DstTy))
846
0
      DstTy = VectorTy->getElementType();
847
0
    if (DstTy->isFloatingPointTy())
848
0
      return 3;
849
0
850
0
    return 1;
851
0
  }
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::AArch64TTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::R600TTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::GCNTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::ARMTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::HexagonTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::LanaiTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::BasicTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::NVPTXTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::PPCTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::SystemZTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: llvm::TargetTransformInfoImplCRTPBase<llvm::XCoreTTIImpl>::getInstructionLatency(llvm::Instruction const*)
Unexecuted instantiation: TargetTransformInfo.cpp:llvm::TargetTransformInfoImplCRTPBase<(anonymous namespace)::NoTTIImpl>::getInstructionLatency(llvm::Instruction const*)
852
};
853
}
854
855
#endif