1*9880d681SAndroid Build Coastguard Worker //===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file a TargetTransformInfo::Concept conforming object specific to the 11*9880d681SAndroid Build Coastguard Worker // Lanai target machine. It uses the target's detailed information to 12*9880d681SAndroid Build Coastguard Worker // provide more precise answers to certain TTI queries, while letting the 13*9880d681SAndroid Build Coastguard Worker // target independent and default TTI implementations handle the rest. 14*9880d681SAndroid Build Coastguard Worker // 15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H 18*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker #include "Lanai.h" 21*9880d681SAndroid Build Coastguard Worker #include "LanaiSubtarget.h" 22*9880d681SAndroid Build Coastguard Worker #include "LanaiTargetMachine.h" 23*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/TargetTransformInfo.h" 24*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/BasicTTIImpl.h" 25*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetLowering.h" 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker namespace llvm { 28*9880d681SAndroid Build Coastguard Worker class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> { 29*9880d681SAndroid Build Coastguard Worker typedef BasicTTIImplBase<LanaiTTIImpl> BaseT; 30*9880d681SAndroid Build Coastguard Worker typedef TargetTransformInfo TTI; 31*9880d681SAndroid Build Coastguard Worker friend BaseT; 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker const LanaiSubtarget *ST; 34*9880d681SAndroid Build Coastguard Worker const LanaiTargetLowering *TLI; 35*9880d681SAndroid Build Coastguard Worker getST()36*9880d681SAndroid Build Coastguard Worker const LanaiSubtarget *getST() const { return ST; } getTLI()37*9880d681SAndroid Build Coastguard Worker const LanaiTargetLowering *getTLI() const { return TLI; } 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker public: LanaiTTIImpl(const LanaiTargetMachine * TM,const Function & F)40*9880d681SAndroid Build Coastguard Worker explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F) 41*9880d681SAndroid Build Coastguard Worker : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), 42*9880d681SAndroid Build Coastguard Worker TLI(ST->getTargetLowering()) {} 43*9880d681SAndroid Build Coastguard Worker LanaiTTIImpl(const LanaiTTIImpl & Arg)44*9880d681SAndroid Build Coastguard Worker LanaiTTIImpl(const LanaiTTIImpl &Arg) 45*9880d681SAndroid Build Coastguard Worker : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {} LanaiTTIImpl(LanaiTTIImpl && Arg)46*9880d681SAndroid Build Coastguard Worker LanaiTTIImpl(LanaiTTIImpl &&Arg) 47*9880d681SAndroid Build Coastguard Worker : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)), 48*9880d681SAndroid Build Coastguard Worker TLI(std::move(Arg.TLI)) {} 49*9880d681SAndroid Build Coastguard Worker shouldBuildLookupTables()50*9880d681SAndroid Build Coastguard Worker bool shouldBuildLookupTables() const { return false; } 51*9880d681SAndroid Build Coastguard Worker getPopcntSupport(unsigned TyWidth)52*9880d681SAndroid Build Coastguard Worker TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) { 53*9880d681SAndroid Build Coastguard Worker if (TyWidth == 32) 54*9880d681SAndroid Build Coastguard Worker return TTI::PSK_FastHardware; 55*9880d681SAndroid Build Coastguard Worker return TTI::PSK_Software; 56*9880d681SAndroid Build Coastguard Worker } 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker unsigned getArithmeticInstrCost( 59*9880d681SAndroid Build Coastguard Worker unsigned Opcode, Type *Ty, 60*9880d681SAndroid Build Coastguard Worker TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue, 61*9880d681SAndroid Build Coastguard Worker TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue, 62*9880d681SAndroid Build Coastguard Worker TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None, 63*9880d681SAndroid Build Coastguard Worker TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None) { 64*9880d681SAndroid Build Coastguard Worker int ISD = TLI->InstructionOpcodeToISD(Opcode); 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker switch (ISD) { 67*9880d681SAndroid Build Coastguard Worker default: 68*9880d681SAndroid Build Coastguard Worker return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 69*9880d681SAndroid Build Coastguard Worker Opd1PropInfo, Opd2PropInfo); 70*9880d681SAndroid Build Coastguard Worker case ISD::MUL: 71*9880d681SAndroid Build Coastguard Worker case ISD::SDIV: 72*9880d681SAndroid Build Coastguard Worker case ISD::UDIV: 73*9880d681SAndroid Build Coastguard Worker case ISD::UREM: 74*9880d681SAndroid Build Coastguard Worker // This increases the cost associated with multiplication and division 75*9880d681SAndroid Build Coastguard Worker // to 64 times what the baseline arithmetic cost is. The arithmetic 76*9880d681SAndroid Build Coastguard Worker // instruction cost was arbitrarily chosen to reduce the desirability 77*9880d681SAndroid Build Coastguard Worker // of emitting arithmetic instructions that are emulated in software. 78*9880d681SAndroid Build Coastguard Worker // TODO: Investigate the performance impact given specialized lowerings. 79*9880d681SAndroid Build Coastguard Worker return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 80*9880d681SAndroid Build Coastguard Worker Opd1PropInfo, Opd2PropInfo); 81*9880d681SAndroid Build Coastguard Worker } 82*9880d681SAndroid Build Coastguard Worker } 83*9880d681SAndroid Build Coastguard Worker }; 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker } // end namespace llvm 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker #endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H 88