Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
R600TargetTransformInfo.cpp
Go to the documentation of this file.
1//===- R600TargetTransformInfo.cpp - AMDGPU specific TTI pass -----------===//
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// \file
10// This file implements a TargetTransformInfo analysis pass specific to the
11// R600 target machine. It uses the target's detailed information to provide
12// more precise answers to certain TTI queries, while letting the target
13// independent and default TTI implementations handle the rest.
14//
15//===----------------------------------------------------------------------===//
16
18#include "AMDGPU.h"
19#include "AMDGPUTargetMachine.h"
20#include "R600Subtarget.h"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "R600tti"
25
27 : BaseT(TM, F.getDataLayout()),
28 ST(static_cast<const R600Subtarget *>(TM->getSubtargetImpl(F))),
29 TLI(ST->getTargetLowering()), CommonTTI(TM, F) {}
30
32 return 4 * 128; // XXX - 4 channels. Should these count as vector instead?
33}
34
35unsigned R600TTIImpl::getNumberOfRegisters(unsigned ClassID) const {
36 bool Vec = ClassID == 1;
38}
39
44
45unsigned R600TTIImpl::getMinVectorRegisterBitWidth() const { return 32; }
46
47unsigned R600TTIImpl::getLoadStoreVecRegBitWidth(unsigned AddrSpace) const {
48 if (AddrSpace == AMDGPUAS::GLOBAL_ADDRESS ||
49 AddrSpace == AMDGPUAS::CONSTANT_ADDRESS)
50 return 128;
51 if (AddrSpace == AMDGPUAS::LOCAL_ADDRESS ||
52 AddrSpace == AMDGPUAS::REGION_ADDRESS)
53 return 64;
54 if (AddrSpace == AMDGPUAS::PRIVATE_ADDRESS)
55 return 32;
56
57 if ((AddrSpace == AMDGPUAS::PARAM_D_ADDRESS ||
58 AddrSpace == AMDGPUAS::PARAM_I_ADDRESS ||
59 (AddrSpace >= AMDGPUAS::CONSTANT_BUFFER_0 &&
60 AddrSpace <= AMDGPUAS::CONSTANT_BUFFER_15)))
61 return 128;
62 llvm_unreachable("unhandled address space");
63}
64
65bool R600TTIImpl::isLegalToVectorizeMemChain(unsigned ChainSizeInBytes,
66 Align Alignment,
67 unsigned AddrSpace) const {
68 // We allow vectorization of flat stores, even though we may need to decompose
69 // them later if they may access private memory. We don't have enough context
70 // here, and legalization can handle it.
71 return (AddrSpace != AMDGPUAS::PRIVATE_ADDRESS);
72}
73
74bool R600TTIImpl::isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes,
75 Align Alignment,
76 unsigned AddrSpace) const {
77 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
78}
79
80bool R600TTIImpl::isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
81 Align Alignment,
82 unsigned AddrSpace) const {
83 return isLegalToVectorizeMemChain(ChainSizeInBytes, Alignment, AddrSpace);
84}
85
87 // Disable unrolling if the loop is not vectorized.
88 // TODO: Enable this again.
89 if (VF.isScalar())
90 return 1;
91
92 return 8;
93}
94
97 const Instruction *I) const {
99 return Opcode == Instruction::PHI ? 0 : 1;
100
101 // XXX - For some reason this isn't called for switch.
102 switch (Opcode) {
103 case Instruction::Br:
104 case Instruction::Ret:
105 return 10;
106 default:
107 return BaseT::getCFInstrCost(Opcode, CostKind, I);
108 }
109}
110
113 unsigned Index,
114 const Value *Op0,
115 const Value *Op1) const {
116 switch (Opcode) {
117 case Instruction::ExtractElement:
118 case Instruction::InsertElement: {
119 unsigned EltSize =
120 DL.getTypeSizeInBits(cast<VectorType>(ValTy)->getElementType());
121 if (EltSize < 32) {
122 return BaseT::getVectorInstrCost(Opcode, ValTy, CostKind, Index, Op0,
123 Op1);
124 }
125
126 // Extracts are just reads of a subregister, so are free. Inserts are
127 // considered free because we don't want to have any cost for scalarizing
128 // operations, and we don't have to copy into a different register class.
129
130 // Dynamic indexing isn't free and is best avoided.
131 return Index == ~0u ? 2 : 0;
132 }
133 default:
134 return BaseT::getVectorInstrCost(Opcode, ValTy, CostKind, Index, Op0, Op1);
135 }
136}
137
140 OptimizationRemarkEmitter *ORE) const {
141 CommonTTI.getUnrollingPreferences(L, SE, UP, ORE);
142}
143
145 TTI::PeelingPreferences &PP) const {
146 CommonTTI.getPeelingPreferences(L, SE, PP);
147}
aarch64 promote const
The AMDGPU TargetMachine interface definition for hw codegen targets.
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")))
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
AMDGPU R600 specific subclass of TargetSubtarget.
This file a TargetTransformInfoImplBase conforming object specific to the R600 target machine.
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1) const override
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
constexpr bool isScalar() const
Exactly one element.
Definition TypeSize.h:320
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
The optimization diagnostic interface.
InstructionCost getVectorInstrCost(unsigned Opcode, Type *ValTy, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1) const override
bool isLegalToVectorizeMemChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const override
unsigned getMinVectorRegisterBitWidth() const override
unsigned getMaxInterleaveFactor(ElementCount VF) const override
unsigned getLoadStoreVecRegBitWidth(unsigned AddrSpace) const override
R600TTIImpl(const AMDGPUTargetMachine *TM, const Function &F)
unsigned getHardwareNumberOfRegisters(bool Vec) const
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool isLegalToVectorizeLoadChain(unsigned ChainSizeInBytes, Align Alignment, unsigned AddrSpace) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind Vector) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
The main scalar evolution driver.
virtual const DataLayout & getDataLayout() const
TargetCostKind
The kind of cost model.
@ TCK_CodeSize
Instruction code size.
@ TCK_SizeAndLatency
The weighted sum of size and latency.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ PARAM_D_ADDRESS
end Internal address spaces.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ PARAM_I_ADDRESS
Address space for indirect addressable parameter memory (VTX1).
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Parameters that control the generic loop unrolling transformation.