Coverage Report

Created: 2019-02-20 07:29

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