brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 0342af6 Raw
124 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file a TargetTransformInfoImplBase conforming object specific to the10// Lanai target machine. It uses the target's detailed information to11// provide more precise answers to certain TTI queries, while letting the12// target independent and default TTI implementations handle the rest.13//14//===----------------------------------------------------------------------===//15 16#ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H17#define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H18 19#include "Lanai.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"26 27namespace llvm {28class LanaiTTIImpl final : public BasicTTIImplBase<LanaiTTIImpl> {29  typedef BasicTTIImplBase<LanaiTTIImpl> BaseT;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 39public:40  explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)41      : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),42        TLI(ST->getTargetLowering()) {}43 44  bool shouldBuildLookupTables() const override { return false; }45 46  TargetTransformInfo::PopcntSupportKind47  getPopcntSupport(unsigned TyWidth) const override {48    if (TyWidth == 32)49      return TTI::PSK_FastHardware;50    return TTI::PSK_Software;51  }52 53  InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,54                                TTI::TargetCostKind CostKind) const override {55    assert(Ty->isIntegerTy());56    unsigned BitSize = Ty->getPrimitiveSizeInBits();57    // There is no cost model for constants with a bit size of 0. Return58    // TCC_Free here, so that constant hoisting will ignore this constant.59    if (BitSize == 0)60      return TTI::TCC_Free;61    // No cost model for operations on integers larger than 64 bit implemented62    // yet.63    if (BitSize > 64)64      return TTI::TCC_Free;65 66    if (Imm == 0)67      return TTI::TCC_Free;68    if (isInt<16>(Imm.getSExtValue()))69      return TTI::TCC_Basic;70    if (isInt<21>(Imm.getZExtValue()))71      return TTI::TCC_Basic;72    if (isInt<32>(Imm.getSExtValue())) {73      if ((Imm.getSExtValue() & 0xFFFF) == 0)74        return TTI::TCC_Basic;75      return 2 * TTI::TCC_Basic;76    }77 78    return 4 * TTI::TCC_Basic;79  }80 81  InstructionCost82  getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty,83                    TTI::TargetCostKind CostKind,84                    Instruction *Inst = nullptr) const override {85    return getIntImmCost(Imm, Ty, CostKind);86  }87 88  InstructionCost89  getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,90                      Type *Ty, TTI::TargetCostKind CostKind) const override {91    return getIntImmCost(Imm, Ty, CostKind);92  }93 94  InstructionCost getArithmeticInstrCost(95      unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,96      TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},97      TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},98      ArrayRef<const Value *> Args = {},99      const Instruction *CxtI = nullptr) const override {100    int ISD = TLI->InstructionOpcodeToISD(Opcode);101 102    switch (ISD) {103    default:104      return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,105                                           Op2Info);106    case ISD::MUL:107    case ISD::SDIV:108    case ISD::UDIV:109    case ISD::UREM:110      // This increases the cost associated with multiplication and division111      // to 64 times what the baseline arithmetic cost is. The arithmetic112      // instruction cost was arbitrarily chosen to reduce the desirability113      // of emitting arithmetic instructions that are emulated in software.114      // TODO: Investigate the performance impact given specialized lowerings.115      return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,116                                                Op2Info);117    }118  }119};120 121} // end namespace llvm122 123#endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H124