LLVM 22.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 TargetTransformInfoImplBase 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 final : 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 override { return false; }
45
47 getPopcntSupport(unsigned TyWidth) const override {
48 if (TyWidth == 32)
50 return TTI::PSK_Software;
51 }
52
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. Return
58 // 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 implemented
62 // 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
82 getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty,
84 Instruction *Inst = nullptr) const override {
85 return getIntImmCost(Imm, Ty, CostKind);
86 }
87
89 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
95 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
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 division
111 // to 64 times what the baseline arithmetic cost is. The arithmetic
112 // instruction cost was arbitrarily chosen to reduce the desirability
113 // 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 llvm
122
123#endif // LLVM_LIB_TARGET_LANAI_LANAITARGETTRANSFORMINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
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
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:82
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) const override
LanaiTTIImpl(const LanaiTargetMachine *TM, const Function &F)
InstructionCost getIntImmCostInst(unsigned Opc, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const override
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
bool shouldBuildLookupTables() const override
TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
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) const override
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
virtual 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
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:240
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18