1 //===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
17 #define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_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"
28 class LanaiTTIImpl
: public BasicTTIImplBase
<LanaiTTIImpl
> {
29 typedef BasicTTIImplBase
<LanaiTTIImpl
> BaseT
;
30 typedef TargetTransformInfo TTI
;
33 const LanaiSubtarget
*ST
;
34 const LanaiTargetLowering
*TLI
;
36 const LanaiSubtarget
*getST() const { return ST
; }
37 const LanaiTargetLowering
*getTLI() const { return TLI
; }
40 explicit LanaiTTIImpl(const LanaiTargetMachine
*TM
, const Function
&F
)
41 : BaseT(TM
, F
.getParent()->getDataLayout()), ST(TM
->getSubtargetImpl(F
)),
42 TLI(ST
->getTargetLowering()) {}
44 bool shouldBuildLookupTables() const { return false; }
46 TargetTransformInfo::PopcntSupportKind
getPopcntSupport(unsigned TyWidth
) {
48 return TTI::PSK_FastHardware
;
49 return TTI::PSK_Software
;
52 InstructionCost
getIntImmCost(const APInt
&Imm
, Type
*Ty
,
53 TTI::TargetCostKind CostKind
) {
54 assert(Ty
->isIntegerTy());
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
;
67 return 4 * TTI::TCC_Basic
;
70 InstructionCost
getIntImmCostInst(unsigned Opc
, unsigned Idx
,
71 const APInt
&Imm
, Type
*Ty
,
72 TTI::TargetCostKind CostKind
,
73 Instruction
*Inst
= nullptr) {
74 return getIntImmCost(Imm
, Ty
, CostKind
);
77 InstructionCost
getIntImmCostIntrin(Intrinsic::ID IID
, unsigned Idx
,
78 const APInt
&Imm
, Type
*Ty
,
79 TTI::TargetCostKind CostKind
) {
80 return getIntImmCost(Imm
, Ty
, CostKind
);
83 InstructionCost
getArithmeticInstrCost(
84 unsigned Opcode
, Type
*Ty
,
85 TTI::TargetCostKind CostKind
= TTI::TCK_RecipThroughput
,
86 TTI::OperandValueKind Opd1Info
= TTI::OK_AnyValue
,
87 TTI::OperandValueKind Opd2Info
= TTI::OK_AnyValue
,
88 TTI::OperandValueProperties Opd1PropInfo
= TTI::OP_None
,
89 TTI::OperandValueProperties Opd2PropInfo
= TTI::OP_None
,
90 ArrayRef
<const Value
*> Args
= ArrayRef
<const Value
*>(),
91 const Instruction
*CxtI
= nullptr) {
92 int ISD
= TLI
->InstructionOpcodeToISD(Opcode
);
96 return BaseT::getArithmeticInstrCost(Opcode
, Ty
, CostKind
, Opd1Info
,
98 Opd1PropInfo
, Opd2PropInfo
);
103 // This increases the cost associated with multiplication and division
104 // to 64 times what the baseline arithmetic cost is. The arithmetic
105 // instruction cost was arbitrarily chosen to reduce the desirability
106 // of emitting arithmetic instructions that are emulated in software.
107 // TODO: Investigate the performance impact given specialized lowerings.
108 return 64 * BaseT::getArithmeticInstrCost(Opcode
, Ty
, CostKind
, Opd1Info
,
110 Opd1PropInfo
, Opd2PropInfo
);
115 } // end namespace llvm
117 #endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H