LLVM  10.0.0svn
LanaiTargetTransformInfo.h
Go to the documentation of this file.
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"
26 
27 namespace llvm {
28 class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
30  typedef TargetTransformInfo TTI;
31  friend BaseT;
32 
33  const LanaiSubtarget *ST;
34  const LanaiTargetLowering *TLI;
35 
36  const LanaiSubtarget *getST() const { return ST; }
37  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  TLI(ST->getTargetLowering()) {}
43 
44  bool shouldBuildLookupTables() const { return false; }
45 
47  if (TyWidth == 32)
48  return TTI::PSK_FastHardware;
49  return TTI::PSK_Software;
50  }
51 
52  int getIntImmCost(const APInt &Imm, Type *Ty) {
53  assert(Ty->isIntegerTy());
54  if (Imm == 0)
55  return TTI::TCC_Free;
56  if (isInt<16>(Imm.getSExtValue()))
57  return TTI::TCC_Basic;
58  if (isInt<21>(Imm.getZExtValue()))
59  return TTI::TCC_Basic;
60  if (isInt<32>(Imm.getSExtValue())) {
61  if ((Imm.getSExtValue() & 0xFFFF) == 0)
62  return TTI::TCC_Basic;
63  return 2 * TTI::TCC_Basic;
64  }
65 
66  return 4 * TTI::TCC_Basic;
67  }
68 
69  int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) {
70  return getIntImmCost(Imm, Ty);
71  }
72 
73  int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
74  Type *Ty) {
75  return getIntImmCost(Imm, Ty);
76  }
77 
79  unsigned Opcode, Type *Ty,
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
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:583
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1562
This class represents lattice values for constants.
Definition: AllocatorList.h:23
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:305
F(f)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
int getIntImmCost(const APInt &Imm, Type *Ty)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:196
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1574
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:32
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:45
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:308
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.