LLVM  14.0.0git
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 
54  assert(Ty->isIntegerTy());
55  unsigned BitSize = Ty->getPrimitiveSizeInBits();
56  // There is no cost model for constants with a bit size of 0. Return
57  // TCC_Free here, so that constant hoisting will ignore this constant.
58  if (BitSize == 0)
59  return TTI::TCC_Free;
60  // No cost model for operations on integers larger than 64 bit implemented
61  // yet.
62  if (BitSize > 64)
63  return TTI::TCC_Free;
64 
65  if (Imm == 0)
66  return TTI::TCC_Free;
67  if (isInt<16>(Imm.getSExtValue()))
68  return TTI::TCC_Basic;
69  if (isInt<21>(Imm.getZExtValue()))
70  return TTI::TCC_Basic;
71  if (isInt<32>(Imm.getSExtValue())) {
72  if ((Imm.getSExtValue() & 0xFFFF) == 0)
73  return TTI::TCC_Basic;
74  return 2 * TTI::TCC_Basic;
75  }
76 
77  return 4 * TTI::TCC_Basic;
78  }
79 
80  InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
81  const APInt &Imm, Type *Ty,
83  Instruction *Inst = nullptr) {
84  return getIntImmCost(Imm, Ty, CostKind);
85  }
86 
88  const APInt &Imm, Type *Ty,
90  return getIntImmCost(Imm, Ty, CostKind);
91  }
92 
94  unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
100  const Instruction *CxtI = nullptr) {
101  int ISD = TLI->InstructionOpcodeToISD(Opcode);
102 
103  switch (ISD) {
104  default:
105  return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info,
106  Opd2Info,
107  Opd1PropInfo, Opd2PropInfo);
108  case ISD::MUL:
109  case ISD::SDIV:
110  case ISD::UDIV:
111  case ISD::UREM:
112  // This increases the cost associated with multiplication and division
113  // to 64 times what the baseline arithmetic cost is. The arithmetic
114  // instruction cost was arbitrarily chosen to reduce the desirability
115  // of emitting arithmetic instructions that are emulated in software.
116  // TODO: Investigate the performance impact given specialized lowerings.
117  return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Opd1Info,
118  Opd2Info,
119  Opd1PropInfo, Opd2PropInfo);
120  }
121  }
122 };
123 
124 } // end namespace llvm
125 
126 #endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
llvm::InstructionCost
Definition: InstructionCost.h:29
llvm::TargetTransformInfo::PSK_FastHardware
@ PSK_FastHardware
Definition: TargetTransformInfo.h:596
llvm::TargetTransformInfo::TargetCostKind
TargetCostKind
The kind of cost model.
Definition: TargetTransformInfo.h:212
MathExtras.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:62
llvm::ISD::UDIV
@ UDIV
Definition: ISDOpcodes.h:243
llvm::TargetTransformInfo::PopcntSupportKind
PopcntSupportKind
Flags indicating the kind of support for population count.
Definition: TargetTransformInfo.h:596
llvm::LanaiTTIImpl::getIntImmCost
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind)
Definition: LanaiTargetTransformInfo.h:52
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1474
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:169
llvm::BasicTTIImplBase< LanaiTTIImpl >::getArithmeticInstrCost
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, 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 * >(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:757
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Lanai.h
llvm::LanaiTTIImpl
Definition: LanaiTargetTransformInfo.h:28
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::TargetTransformInfoImplBase::getDataLayout
const DataLayout & getDataLayout() const
Definition: TargetTransformInfoImpl.h:49
TargetLowering.h
llvm::TargetTransformInfo::OP_None
@ OP_None
Definition: TargetTransformInfo.h:890
llvm::Instruction
Definition: Instruction.h:45
llvm::APInt::getZExtValue
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1460
llvm::LanaiTargetLowering
Definition: LanaiISelLowering.h:67
llvm::TargetTransformInfo::PSK_Software
@ PSK_Software
Definition: TargetTransformInfo.h:596
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:190
llvm::isInt< 32 >
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:373
llvm::LanaiTTIImpl::getPopcntSupport
TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
Definition: LanaiTargetTransformInfo.h:46
llvm::TargetTransformInfo::OperandValueProperties
OperandValueProperties
Additional properties of an operand's values.
Definition: TargetTransformInfo.h:890
llvm::BasicTTIImplBase
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetTransformInfo::OperandValueKind
OperandValueKind
Additional information about an operand's possible values.
Definition: TargetTransformInfo.h:882
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::TargetTransformInfo::TCC_Free
@ TCC_Free
Expected to fold away in lowering.
Definition: TargetTransformInfo.h:263
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::LanaiSubtarget
Definition: LanaiSubtarget.h:29
CostKind
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:870
llvm::TargetLoweringBase::InstructionOpcodeToISD
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
Definition: TargetLoweringBase.cpp:1767
llvm::TargetTransformInfo::OK_AnyValue
@ OK_AnyValue
Definition: TargetTransformInfo.h:883
llvm::LanaiTTIImpl::LanaiTTIImpl
LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
Definition: LanaiTargetTransformInfo.h:40
llvm::isInt< 16 >
constexpr bool isInt< 16 >(int64_t x)
Definition: MathExtras.h:370
llvm::LanaiTTIImpl::getIntImmCostIntrin
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind)
Definition: LanaiTargetTransformInfo.h:87
llvm::ISD::SDIV
@ SDIV
Definition: ISDOpcodes.h:242
llvm::LanaiTargetMachine
Definition: LanaiTargetMachine.h:24
llvm::LanaiTTIImpl::shouldBuildLookupTables
bool shouldBuildLookupTables() const
Definition: LanaiTargetTransformInfo.h:44
llvm::ISD::MUL
@ MUL
Definition: ISDOpcodes.h:241
llvm::ISD::UREM
@ UREM
Definition: ISDOpcodes.h:245
llvm::LanaiTTIImpl::getArithmeticInstrCost
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, 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 * >(), const Instruction *CxtI=nullptr)
Definition: LanaiTargetTransformInfo.h:93
TargetTransformInfo.h
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
LanaiTargetMachine.h
llvm::LanaiTTIImpl::getIntImmCostInst
InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr)
Definition: LanaiTargetTransformInfo.h:80
llvm::TargetTransformInfo::TCC_Basic
@ TCC_Basic
The cost of a typical 'add' instruction.
Definition: TargetTransformInfo.h:264
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
BasicTTIImpl.h
LanaiSubtarget.h
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:166
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38