LLVM 20.0.0git
LanaiTargetTransformInfo.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
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.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
17#define LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
18
19#include "Lanai.h"
20#include "LanaiSubtarget.h"
21#include "LanaiTargetMachine.h"
26
27namespace llvm {
28class LanaiTTIImpl : public BasicTTIImplBase<LanaiTTIImpl> {
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 { return false; }
45
47 if (TyWidth == 32)
49 return TTI::PSK_Software;
50 }
51
54 assert(Ty->isIntegerTy());
55 unsigned BitSize = Ty->getPrimitiveSizeInBits();
56 // There is no cost model for constants with a bit size of 0. Return
57 // TCC_Free here, so that constant hoisting will ignore this constant.
58 if (BitSize == 0)
59 return TTI::TCC_Free;
60 // No cost model for operations on integers larger than 64 bit implemented
61 // yet.
62 if (BitSize > 64)
63 return TTI::TCC_Free;
64
65 if (Imm == 0)
66 return TTI::TCC_Free;
67 if (isInt<16>(Imm.getSExtValue()))
68 return TTI::TCC_Basic;
69 if (isInt<21>(Imm.getZExtValue()))
70 return TTI::TCC_Basic;
71 if (isInt<32>(Imm.getSExtValue())) {
72 if ((Imm.getSExtValue() & 0xFFFF) == 0)
73 return TTI::TCC_Basic;
74 return 2 * TTI::TCC_Basic;
75 }
76
77 return 4 * TTI::TCC_Basic;
78 }
79
80 InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx,
81 const APInt &Imm, Type *Ty,
83 Instruction *Inst = nullptr) {
84 return getIntImmCost(Imm, Ty, CostKind);
85 }
86
88 const APInt &Imm, Type *Ty,
90 return getIntImmCost(Imm, Ty, CostKind);
91 }
92
94 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
97 ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr) {
98 int ISD = TLI->InstructionOpcodeToISD(Opcode);
99
100 switch (ISD) {
101 default:
102 return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
103 Op2Info);
104 case ISD::MUL:
105 case ISD::SDIV:
106 case ISD::UDIV:
107 case ISD::UREM:
108 // This increases the cost associated with multiplication and division
109 // to 64 times what the baseline arithmetic cost is. The arithmetic
110 // instruction cost was arbitrarily chosen to reduce the desirability
111 // of emitting arithmetic instructions that are emulated in software.
112 // TODO: Investigate the performance impact given specialized lowerings.
113 return 64 * BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
114 Op2Info);
115 }
116 }
117};
118
119} // end namespace llvm
120
121#endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size"), clEnumValN(TargetTransformInfo::TCK_SizeAndLatency, "size-latency", "Code size and latency")))
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file describes how to lower LLVM code to machine code.
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition: APInt.h:78
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:80
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:932
InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr)
TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
bool shouldBuildLookupTables() const
LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind)
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind)
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr)
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
const DataLayout & getDataLayout() const
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
PopcntSupportKind
Flags indicating the kind of support for population count.
@ TCC_Free
Expected to fold away in lowering.
@ TCC_Basic
The cost of a typical 'add' instruction.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:237
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18