1 //===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
18 #define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
21 #include "LanaiSubtarget.h"
22 #include "LanaiTargetMachine.h"
23 #include "llvm/Analysis/TargetTransformInfo.h"
24 #include "llvm/CodeGen/BasicTTIImpl.h"
25 #include "llvm/CodeGen/TargetLowering.h"
26 #include "llvm/Support/MathExtras.h"
29 class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
30 typedef BasicTTIImplBase<LanaiTTIImpl> BaseT;
31 typedef TargetTransformInfo TTI;
34 const LanaiSubtarget *ST;
35 const LanaiTargetLowering *TLI;
37 const LanaiSubtarget *getST() const { return ST; }
38 const LanaiTargetLowering *getTLI() const { return TLI; }
41 explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
42 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
43 TLI(ST->getTargetLowering()) {}
45 bool shouldBuildLookupTables() const { return false; }
47 TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) {
49 return TTI::PSK_FastHardware;
50 return TTI::PSK_Software;
53 int getIntImmCost(const APInt &Imm, Type *Ty) {
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 int getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty) {
71 return getIntImmCost(Imm, Ty);
74 int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
76 return getIntImmCost(Imm, Ty);
79 unsigned getArithmeticInstrCost(
80 unsigned Opcode, Type *Ty,
81 TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
82 TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
83 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
84 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
85 ArrayRef<const Value *> Args = ArrayRef<const Value *>()) {
86 int ISD = TLI->InstructionOpcodeToISD(Opcode);
90 return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
91 Opd1PropInfo, Opd2PropInfo);
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);
107 } // end namespace llvm
109 #endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H