LLVM  6.0.0svn
LanaiTargetTransformInfo.h
Go to the documentation of this file.
1 //===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file a TargetTransformInfo::Concept conforming object specific to the
11 // Lanai target machine. It uses the target's detailed information to
12 // provide more precise answers to certain TTI queries, while letting the
13 // target independent and default TTI implementations handle the rest.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
18 #define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
19 
20 #include "Lanai.h"
21 #include "LanaiSubtarget.h"
22 #include "LanaiTargetMachine.h"
27 
28 namespace llvm {
29 class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
31  typedef TargetTransformInfo TTI;
32  friend BaseT;
33 
34  const LanaiSubtarget *ST;
35  const LanaiTargetLowering *TLI;
36 
37  const LanaiSubtarget *getST() const { return ST; }
38  const LanaiTargetLowering *getTLI() const { return TLI; }
39 
40 public:
41  explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
42  : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
43  TLI(ST->getTargetLowering()) {}
44 
45  bool shouldBuildLookupTables() const { return false; }
46 
48  if (TyWidth == 32)
49  return TTI::PSK_FastHardware;
50  return TTI::PSK_Software;
51  }
52 
53  int getIntImmCost(const APInt &Imm, Type *Ty) {
54  assert(Ty->isIntegerTy());
55  if (Imm == 0)
56  return TTI::TCC_Free;
57  if (isInt<16>(Imm.getSExtValue()))
58  return TTI::TCC_Basic;
59  if (isInt<21>(Imm.getZExtValue()))
60  return TTI::TCC_Basic;
61  if (isInt<32>(Imm.getSExtValue())) {
62  if ((Imm.getSExtValue() & 0xFFFF) == 0)
63  return TTI::TCC_Basic;
64  return 2 * TTI::TCC_Basic;
65  }
66 
67  return 4 * TTI::TCC_Basic;
68  }
69 
70  int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) {
71  return getIntImmCost(Imm, Ty);
72  }
73 
74  int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
75  Type *Ty) {
76  return getIntImmCost(Imm, Ty);
77  }
78 
80  unsigned Opcode, Type *Ty,
86  int ISD = TLI->InstructionOpcodeToISD(Opcode);
87 
88  switch (ISD) {
89  default:
90  return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
91  Opd1PropInfo, Opd2PropInfo);
92  case ISD::MUL:
93  case ISD::SDIV:
94  case ISD::UDIV:
95  case ISD::UREM:
96  // This increases the cost associated with multiplication and division
97  // to 64 times what the baseline arithmetic cost is. The arithmetic
98  // instruction cost was arbitrarily chosen to reduce the desirability
99  // of emitting arithmetic instructions that are emulated in software.
100  // TODO: Investigate the performance impact given specialized lowerings.
101  return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
102  Opd1PropInfo, Opd2PropInfo);
103  }
104  }
105 };
106 
107 } // end namespace llvm
108 
109 #endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >())
Definition: BasicTTIImpl.h:469
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1542
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:298
F(f)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:78
int getIntImmCost(const APInt &Imm, Type *Ty)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1554
PopcntSupportKind
Flags indicating the kind of support for population count.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Expected to fold away in lowering.
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
OperandValueProperties
Additional properties of an operand&#39;s values.
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:301
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>())
Class for arbitrary precision integers.
Definition: APInt.h:69
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty)
LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
bool shouldBuildLookupTables() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
The cost of a typical &#39;add&#39; instruction.
static const Function * getParent(const Value *V)
const DataLayout & getDataLayout() const
OperandValueKind
Additional information about an operand&#39;s possible values.
This pass exposes codegen information to IR-level passes.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
This file describes how to lower LLVM code to machine code.