Path: blob/main/contrib/llvm-project/llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h
35271 views
//===-- LanaiTargetTransformInfo.h - Lanai specific TTI ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file a TargetTransformInfo::Concept conforming object specific to the9// Lanai target machine. It uses the target's detailed information to10// provide more precise answers to certain TTI queries, while letting the11// target independent and default TTI implementations handle the rest.12//13//===----------------------------------------------------------------------===//1415#ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H16#define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H1718#include "Lanai.h"19#include "LanaiSubtarget.h"20#include "LanaiTargetMachine.h"21#include "llvm/Analysis/TargetTransformInfo.h"22#include "llvm/CodeGen/BasicTTIImpl.h"23#include "llvm/CodeGen/TargetLowering.h"24#include "llvm/Support/MathExtras.h"2526namespace llvm {27class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {28typedef BasicTTIImplBase<LanaiTTIImpl> BaseT;29typedef TargetTransformInfo TTI;30friend BaseT;3132const LanaiSubtarget *ST;33const LanaiTargetLowering *TLI;3435const LanaiSubtarget *getST() const { return ST; }36const LanaiTargetLowering *getTLI() const { return TLI; }3738public:39explicit LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)40: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),41TLI(ST->getTargetLowering()) {}4243bool shouldBuildLookupTables() const { return false; }4445TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) {46if (TyWidth == 32)47return TTI::PSK_FastHardware;48return TTI::PSK_Software;49}5051InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,52TTI::TargetCostKind CostKind) {53assert(Ty->isIntegerTy());54unsigned BitSize = Ty->getPrimitiveSizeInBits();55// There is no cost model for constants with a bit size of 0. Return56// TCC_Free here, so that constant hoisting will ignore this constant.57if (BitSize == 0)58return TTI::TCC_Free;59// No cost model for operations on integers larger than 64 bit implemented60// yet.61if (BitSize > 64)62return TTI::TCC_Free;6364if (Imm == 0)65return TTI::TCC_Free;66if (isInt<16>(Imm.getSExtValue()))67return TTI::TCC_Basic;68if (isInt<21>(Imm.getZExtValue()))69return TTI::TCC_Basic;70if (isInt<32>(Imm.getSExtValue())) {71if ((Imm.getSExtValue() & 0xFFFF) == 0)72return TTI::TCC_Basic;73return 2 * TTI::TCC_Basic;74}7576return 4 * TTI::TCC_Basic;77}7879InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,80const APInt &Imm, Type *Ty,81TTI::TargetCostKind CostKind,82Instruction *Inst = nullptr) {83return getIntImmCost(Imm, Ty, CostKind);84}8586InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx,87const APInt &Imm, Type *Ty,88TTI::TargetCostKind CostKind) {89return getIntImmCost(Imm, Ty, CostKind);90}9192InstructionCost getArithmeticInstrCost(93unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,94TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},95TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},96ArrayRef<const Value *> Args = std::nullopt,97const Instruction *CxtI = nullptr) {98int ISD = TLI->InstructionOpcodeToISD(Opcode);99100switch (ISD) {101default:102return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,103Op2Info);104case ISD::MUL:105case ISD::SDIV:106case ISD::UDIV:107case ISD::UREM:108// This increases the cost associated with multiplication and division109// to 64 times what the baseline arithmetic cost is. The arithmetic110// instruction cost was arbitrarily chosen to reduce the desirability111// of emitting arithmetic instructions that are emulated in software.112// TODO: Investigate the performance impact given specialized lowerings.113return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,114Op2Info);115}116}117};118119} // end namespace llvm120121#endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H122123124