Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- 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
//
9
// This file a TargetTransformInfo::Concept conforming object specific to the
10
// Lanai target machine. It uses the target's detailed information to
11
// provide more precise answers to certain TTI queries, while letting the
12
// target independent and default TTI implementations handle the rest.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
17
#define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
18
19
#include "Lanai.h"
20
#include "LanaiSubtarget.h"
21
#include "LanaiTargetMachine.h"
22
#include "llvm/Analysis/TargetTransformInfo.h"
23
#include "llvm/CodeGen/BasicTTIImpl.h"
24
#include "llvm/CodeGen/TargetLowering.h"
25
#include "llvm/Support/MathExtras.h"
26
27
namespace llvm {
28
class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
29
  typedef BasicTTIImplBase<LanaiTTIImpl> BaseT;
30
  typedef TargetTransformInfo TTI;
31
  friend BaseT;
32
33
  const LanaiSubtarget *ST;
34
  const LanaiTargetLowering *TLI;
35
36
0
  const LanaiSubtarget *getST() const { return ST; }
37
268
  const LanaiTargetLowering *getTLI() const { return TLI; }
38
39
public:
40
  explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
41
      : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
42
648
        TLI(ST->getTargetLowering()) {}
43
44
0
  bool shouldBuildLookupTables() const { return false; }
45
46
0
  TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) {
47
0
    if (TyWidth == 32)
48
0
      return TTI::PSK_FastHardware;
49
0
    return TTI::PSK_Software;
50
0
  }
51
52
72
  int getIntImmCost(const APInt &Imm, Type *Ty) {
53
72
    assert(Ty->isIntegerTy());
54
72
    if (Imm == 0)
55
30
      return TTI::TCC_Free;
56
42
    if (isInt<16>(Imm.getSExtValue()))
57
40
      return TTI::TCC_Basic;
58
2
    if (isInt<21>(Imm.getZExtValue()))
59
0
      return TTI::TCC_Basic;
60
2
    if (isInt<32>(Imm.getSExtValue())) {
61
2
      if ((Imm.getSExtValue() & 0xFFFF) == 0)
62
0
        return TTI::TCC_Basic;
63
2
      return 2 * TTI::TCC_Basic;
64
2
    }
65
0
66
0
    return 4 * TTI::TCC_Basic;
67
0
  }
68
69
68
  int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) {
70
68
    return getIntImmCost(Imm, Ty);
71
68
  }
72
73
  int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
74
4
                    Type *Ty) {
75
4
    return getIntImmCost(Imm, Ty);
76
4
  }
77
78
  unsigned getArithmeticInstrCost(
79
      unsigned Opcode, Type *Ty,
80
      TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
81
      TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
82
      TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
83
      TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
84
      ArrayRef<const Value *> Args = ArrayRef<const Value *>()) {
85
    int ISD = TLI->InstructionOpcodeToISD(Opcode);
86
87
    switch (ISD) {
88
    default:
89
      return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
90
                                           Opd1PropInfo, Opd2PropInfo);
91
    case ISD::MUL:
92
    case ISD::SDIV:
93
    case ISD::UDIV:
94
    case ISD::UREM:
95
      // This increases the cost associated with multiplication and division
96
      // to 64 times what the baseline arithmetic cost is. The arithmetic
97
      // instruction cost was arbitrarily chosen to reduce the desirability
98
      // of emitting arithmetic instructions that are emulated in software.
99
      // TODO: Investigate the performance impact given specialized lowerings.
100
      return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
101
                                                Opd1PropInfo, Opd2PropInfo);
102
    }
103
  }
104
};
105
106
} // end namespace llvm
107
108
#endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H