Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
RISCVSubtarget.cpp
Go to the documentation of this file.
1//===-- RISCVSubtarget.cpp - RISC-V Subtarget Information -----------------===//
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 implements the RISC-V specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "RISCVSubtarget.h"
14#include "GISel/RISCVCallLowering.h"
15#include "GISel/RISCVLegalizerInfo.h"
16#include "RISCV.h"
17#include "RISCVFrameLowering.h"
18#include "RISCVSelectionDAGInfo.h"
19#include "RISCVTargetMachine.h"
20#include "llvm/CodeGen/MacroFusion.h"
21#include "llvm/CodeGen/ScheduleDAGMutation.h"
22#include "llvm/MC/TargetRegistry.h"
23#include "llvm/Support/ErrorHandling.h"
24
25using namespacellvm;
26
27#define DEBUG_TYPE "riscv-subtarget"
28
29#define GET_SUBTARGETINFO_TARGET_DESC
30#define GET_SUBTARGETINFO_CTOR
31#include "RISCVGenSubtargetInfo.inc"
32
33#define GET_RISCV_MACRO_FUSION_PRED_IMPL
34#include "RISCVGenMacroFusion.inc"
35
36namespacellvm::RISCVTuneInfoTable {
37
38#define GET_RISCVTuneInfoTable_IMPL
39#include "RISCVGenSearchableTables.inc"
40}// namespace llvm::RISCVTuneInfoTable
41
42staticcl::opt<unsigned>RVVVectorLMULMax(
43"riscv-v-fixed-length-vector-lmul-max",
44cl::desc("The maximum LMUL value to use for fixed length vectors. "
45"Fractional LMUL values are not supported."),
46cl::init(8),cl::Hidden);
47
48staticcl::opt<bool>RISCVDisableUsingConstantPoolForLargeInts(
49"riscv-disable-using-constant-pool-for-large-ints",
50cl::desc("Disable using constant pool for large integers."),
51cl::init(false),cl::Hidden);
52
53staticcl::opt<unsigned>RISCVMaxBuildIntsCost(
54"riscv-max-build-ints-cost",
55cl::desc("The maximum cost used for building integers."),cl::init(0),
56cl::Hidden);
57
58staticcl::opt<bool>UseAA("riscv-use-aa",cl::init(true),
59cl::desc("Enable the use of AA during codegen."));
60
61staticcl::opt<unsigned>RISCVMinimumJumpTableEntries(
62"riscv-min-jump-table-entries",cl::Hidden,
63cl::desc("Set minimum number of entries to use a jump table on RISCV"));
64
65staticcl::opt<bool>
66UseMIPSLoadStorePairsOpt("mips-riscv-load-store-pairs",
67cl::desc("RISCV: Optimize for load-store bonding"),
68cl::init(false),cl::Hidden);
69
70staticcl::opt<bool>
71UseCCMovInsn("riscv-ccmov",cl::desc("RISCV: Use 'mips.ccmov' instruction"),
72cl::init(true),cl::Hidden);
73
74void RISCVSubtarget::anchor() {}
75
76RISCVSubtarget &
77RISCVSubtarget::initializeSubtargetDependencies(constTriple &TT,StringRef CPU,
78StringRef TuneCPU,StringRef FS,
79StringRef ABIName) {
80// Determine default and user-specified characteristics
81bool Is64Bit =TT.isArch64Bit();
82if (CPU.empty() || CPU =="generic")
83 CPU = Is64Bit ?"generic-rv64" :"generic-rv32";
84
85if (TuneCPU.empty())
86 TuneCPU = CPU;
87
88 TuneInfo = RISCVTuneInfoTable::getRISCVTuneInfo(TuneCPU);
89// If there is no TuneInfo for this CPU, we fail back to generic.
90if (!TuneInfo)
91 TuneInfo = RISCVTuneInfoTable::getRISCVTuneInfo("generic");
92assert(TuneInfo &&"TuneInfo shouldn't be nullptr!");
93
94ParseSubtargetFeatures(CPU, TuneCPU, FS);
95 TargetABI =RISCVABI::computeTargetABI(TT, getFeatureBits(), ABIName);
96RISCVFeatures::validate(TT, getFeatureBits());
97return *this;
98}
99
100RISCVSubtarget::RISCVSubtarget(constTriple &TT,StringRef CPU,
101StringRef TuneCPU,StringRef FS,
102StringRef ABIName,unsigned RVVVectorBitsMin,
103unsigned RVVVectorBitsMax,
104constTargetMachine &TM)
105 :RISCVGenSubtargetInfo(TT, CPU, TuneCPU, FS),
106 RVVVectorBitsMin(RVVVectorBitsMin), RVVVectorBitsMax(RVVVectorBitsMax),
107 FrameLowering(
108 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
109 InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
110TSInfo = std::make_unique<RISCVSelectionDAGInfo>();
111}
112
113RISCVSubtarget::~RISCVSubtarget() =default;
114
115constSelectionDAGTargetInfo *RISCVSubtarget::getSelectionDAGInfo() const{
116returnTSInfo.get();
117}
118
119constCallLowering *RISCVSubtarget::getCallLowering() const{
120if (!CallLoweringInfo)
121CallLoweringInfo.reset(newRISCVCallLowering(*getTargetLowering()));
122returnCallLoweringInfo.get();
123}
124
125InstructionSelector *RISCVSubtarget::getInstructionSelector() const{
126if (!InstSelector) {
127InstSelector.reset(createRISCVInstructionSelector(
128 *static_cast<constRISCVTargetMachine *>(&TLInfo.getTargetMachine()),
129 *this, *getRegBankInfo()));
130 }
131returnInstSelector.get();
132}
133
134constLegalizerInfo *RISCVSubtarget::getLegalizerInfo() const{
135if (!Legalizer)
136Legalizer.reset(newRISCVLegalizerInfo(*this));
137returnLegalizer.get();
138}
139
140constRISCVRegisterBankInfo *RISCVSubtarget::getRegBankInfo() const{
141if (!RegBankInfo)
142RegBankInfo.reset(newRISCVRegisterBankInfo(getHwMode()));
143returnRegBankInfo.get();
144}
145
146boolRISCVSubtarget::useConstantPoolForLargeInts() const{
147return !RISCVDisableUsingConstantPoolForLargeInts;
148}
149
150unsignedRISCVSubtarget::getMaxBuildIntsCost() const{
151// Loading integer from constant pool needs two instructions (the reason why
152// the minimum cost is 2): an address calculation instruction and a load
153// instruction. Usually, address calculation and instructions used for
154// building integers (addi, slli, etc.) can be done in one cycle, so here we
155// set the default cost to (LoadLatency + 1) if no threshold is provided.
156returnRISCVMaxBuildIntsCost == 0
157 ? getSchedModel().LoadLatency + 1
158 : std::max<unsigned>(2,RISCVMaxBuildIntsCost);
159}
160
161unsignedRISCVSubtarget::getMaxRVVVectorSizeInBits() const{
162assert(hasVInstructions() &&
163"Tried to get vector length without Zve or V extension support!");
164
165// ZvlLen specifies the minimum required vlen. The upper bound provided by
166// riscv-v-vector-bits-max should be no less than it.
167if (RVVVectorBitsMax != 0 && RVVVectorBitsMax < ZvlLen)
168report_fatal_error("riscv-v-vector-bits-max specified is lower "
169"than the Zvl*b limitation");
170
171return RVVVectorBitsMax;
172}
173
174unsignedRISCVSubtarget::getMinRVVVectorSizeInBits() const{
175assert(hasVInstructions() &&
176"Tried to get vector length without Zve or V extension support!");
177
178if (RVVVectorBitsMin == -1U)
179return ZvlLen;
180
181// ZvlLen specifies the minimum required vlen. The lower bound provided by
182// riscv-v-vector-bits-min should be no less than it.
183if (RVVVectorBitsMin != 0 && RVVVectorBitsMin < ZvlLen)
184report_fatal_error("riscv-v-vector-bits-min specified is lower "
185"than the Zvl*b limitation");
186
187return RVVVectorBitsMin;
188}
189
190unsignedRISCVSubtarget::getMaxLMULForFixedLengthVectors() const{
191assert(hasVInstructions() &&
192"Tried to get vector length without Zve or V extension support!");
193assert(RVVVectorLMULMax <= 8 &&
194 llvm::has_single_bit<uint32_t>(RVVVectorLMULMax) &&
195"V extension requires a LMUL to be at most 8 and a power of 2!");
196returnllvm::bit_floor(std::clamp<unsigned>(RVVVectorLMULMax, 1, 8));
197}
198
199boolRISCVSubtarget::useRVVForFixedLengthVectors() const{
200returnhasVInstructions() &&
201getMinRVVVectorSizeInBits() >=RISCV::RVVBitsPerBlock;
202}
203
204boolRISCVSubtarget::enableSubRegLiveness() const{returntrue; }
205
206boolRISCVSubtarget::enableMachinePipeliner() const{
207return getSchedModel().hasInstrSchedModel();
208}
209
210 /// Enable use of alias analysis during code generation (during MI
211 /// scheduling, DAGCombine, etc.).
212boolRISCVSubtarget::useAA() const{returnUseAA; }
213
214unsignedRISCVSubtarget::getMinimumJumpTableEntries() const{
215returnRISCVMinimumJumpTableEntries.getNumOccurrences() > 0
216 ?RISCVMinimumJumpTableEntries
217 : TuneInfo->MinimumJumpTableEntries;
218}
219
220voidRISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
221unsigned NumRegionInstrs) const{
222// Do bidirectional scheduling since it provides a more balanced scheduling
223// leading to better performance. This will increase compile time.
224 Policy.OnlyTopDown =false;
225 Policy.OnlyBottomUp =false;
226
227// Disabling the latency heuristic can reduce the number of spills/reloads but
228// will cause some regressions on some cores.
229 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic;
230
231// Spilling is generally expensive on all RISC-V cores, so always enable
232// register-pressure tracking. This will increase compile time.
233 Policy.ShouldTrackPressure =true;
234}
235
236voidRISCVSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
237unsigned NumRegionInstrs) const{
238MISched::Direction PostRASchedDirection =getPostRASchedDirection();
239if (PostRASchedDirection ==MISched::TopDown) {
240 Policy.OnlyTopDown =true;
241 Policy.OnlyBottomUp =false;
242 }elseif (PostRASchedDirection ==MISched::BottomUp) {
243 Policy.OnlyTopDown =false;
244 Policy.OnlyBottomUp =true;
245 }elseif (PostRASchedDirection ==MISched::Bidirectional) {
246 Policy.OnlyTopDown =false;
247 Policy.OnlyBottomUp =false;
248 }
249}
250
251boolRISCVSubtarget::useCCMovInsn() const{
252returnUseCCMovInsn && HasVendorXMIPSCMove;
253}
UseAA
static cl::opt< bool > UseAA("aarch64-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
MacroFusion.h
RISCVCallLowering.h
This file describes how to lower LLVM calls to machine code calls.
RISCVFrameLowering.h
RISCVLegalizerInfo.h
This file declares the targeting of the Machinelegalizer class for RISC-V.
RISCVSelectionDAGInfo.h
RVVVectorLMULMax
static cl::opt< unsigned > RVVVectorLMULMax("riscv-v-fixed-length-vector-lmul-max", cl::desc("The maximum LMUL value to use for fixed length vectors. " "Fractional LMUL values are not supported."), cl::init(8), cl::Hidden)
UseAA
static cl::opt< bool > UseAA("riscv-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
RISCVMinimumJumpTableEntries
static cl::opt< unsigned > RISCVMinimumJumpTableEntries("riscv-min-jump-table-entries", cl::Hidden, cl::desc("Set minimum number of entries to use a jump table on RISCV"))
UseMIPSLoadStorePairsOpt
static cl::opt< bool > UseMIPSLoadStorePairsOpt("mips-riscv-load-store-pairs", cl::desc("RISCV: Optimize for load-store bonding"), cl::init(false), cl::Hidden)
UseCCMovInsn
static cl::opt< bool > UseCCMovInsn("riscv-ccmov", cl::desc("RISCV: Use 'mips.ccmov' instruction"), cl::init(true), cl::Hidden)
RISCVDisableUsingConstantPoolForLargeInts
static cl::opt< bool > RISCVDisableUsingConstantPoolForLargeInts("riscv-disable-using-constant-pool-for-large-ints", cl::desc("Disable using constant pool for large integers."), cl::init(false), cl::Hidden)
RISCVMaxBuildIntsCost
static cl::opt< unsigned > RISCVMaxBuildIntsCost("riscv-max-build-ints-cost", cl::desc("The maximum cost used for building integers."), cl::init(0), cl::Hidden)
RISCVSubtarget.h
RISCVTargetMachine.h
RISCV.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ScheduleDAGMutation.h
TargetRegistry.h
RISCVGenSubtargetInfo
llvm::CallLowering
Definition:CallLowering.h:44
llvm::InstructionSelector
Definition:InstructionSelector.h:21
llvm::LegalizerInfo
Definition:LegalizerInfo.h:1311
llvm::Legalizer
Definition:Legalizer.h:37
llvm::RISCVCallLowering
Definition:RISCVCallLowering.h:26
llvm::RISCVLegalizerInfo
Definition:RISCVLegalizerInfo.h:26
llvm::RISCVRegisterBankInfo
This class provides the information for the target register banks.
Definition:RISCVRegisterBankInfo.h:32
llvm::RISCVSubtarget
Definition:RISCVSubtarget.h:78
llvm::RISCVSubtarget::getMinimumJumpTableEntries
unsigned getMinimumJumpTableEntries() const
Definition:RISCVSubtarget.cpp:214
llvm::RISCVSubtarget::getLegalizerInfo
const LegalizerInfo * getLegalizerInfo() const override
Definition:RISCVSubtarget.cpp:134
llvm::RISCVSubtarget::getMaxLMULForFixedLengthVectors
unsigned getMaxLMULForFixedLengthVectors() const
Definition:RISCVSubtarget.cpp:190
llvm::RISCVSubtarget::useRVVForFixedLengthVectors
bool useRVVForFixedLengthVectors() const
Definition:RISCVSubtarget.cpp:199
llvm::RISCVSubtarget::getPostRASchedDirection
MISched::Direction getPostRASchedDirection() const
Definition:RISCVSubtarget.h:381
llvm::RISCVSubtarget::getMinRVVVectorSizeInBits
unsigned getMinRVVVectorSizeInBits() const
Definition:RISCVSubtarget.cpp:174
llvm::RISCVSubtarget::InstSelector
std::unique_ptr< InstructionSelector > InstSelector
Definition:RISCVSubtarget.h:297
llvm::RISCVSubtarget::RISCVSubtarget
RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName, unsigned RVVVectorBitsMin, unsigned RVVVectorLMULMax, const TargetMachine &TM)
Definition:RISCVSubtarget.cpp:100
llvm::RISCVSubtarget::getRegBankInfo
const RISCVRegisterBankInfo * getRegBankInfo() const override
Definition:RISCVSubtarget.cpp:140
llvm::RISCVSubtarget::overridePostRASchedPolicy
void overridePostRASchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
Definition:RISCVSubtarget.cpp:236
llvm::RISCVSubtarget::getCallLowering
const CallLowering * getCallLowering() const override
Definition:RISCVSubtarget.cpp:119
llvm::RISCVSubtarget::getInstructionSelector
InstructionSelector * getInstructionSelector() const override
Definition:RISCVSubtarget.cpp:125
llvm::RISCVSubtarget::getMaxBuildIntsCost
unsigned getMaxBuildIntsCost() const
Definition:RISCVSubtarget.cpp:150
llvm::RISCVSubtarget::useCCMovInsn
bool useCCMovInsn() const
Definition:RISCVSubtarget.cpp:251
llvm::RISCVSubtarget::overrideSchedPolicy
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
Definition:RISCVSubtarget.cpp:220
llvm::RISCVSubtarget::TSInfo
std::unique_ptr< const SelectionDAGTargetInfo > TSInfo
Definition:RISCVSubtarget.h:293
llvm::RISCVSubtarget::hasVInstructions
bool hasVInstructions() const
Definition:RISCVSubtarget.h:248
llvm::RISCVSubtarget::useAA
bool useAA() const override
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine,...
Definition:RISCVSubtarget.cpp:212
llvm::RISCVSubtarget::enableMachinePipeliner
bool enableMachinePipeliner() const override
Definition:RISCVSubtarget.cpp:206
llvm::RISCVSubtarget::useConstantPoolForLargeInts
bool useConstantPoolForLargeInts() const
Definition:RISCVSubtarget.cpp:146
llvm::RISCVSubtarget::~RISCVSubtarget
~RISCVSubtarget() override
llvm::RISCVSubtarget::getMaxRVVVectorSizeInBits
unsigned getMaxRVVVectorSizeInBits() const
Definition:RISCVSubtarget.cpp:161
llvm::RISCVSubtarget::ParseSubtargetFeatures
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
llvm::RISCVSubtarget::RegBankInfo
std::unique_ptr< RISCVRegisterBankInfo > RegBankInfo
Definition:RISCVSubtarget.h:299
llvm::RISCVSubtarget::CallLoweringInfo
std::unique_ptr< CallLowering > CallLoweringInfo
Definition:RISCVSubtarget.h:296
llvm::RISCVSubtarget::getTargetLowering
const RISCVTargetLowering * getTargetLowering() const override
Definition:RISCVSubtarget.h:137
llvm::RISCVSubtarget::enableSubRegLiveness
bool enableSubRegLiveness() const override
Definition:RISCVSubtarget.cpp:204
llvm::RISCVSubtarget::getSelectionDAGInfo
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
Definition:RISCVSubtarget.cpp:115
llvm::RISCVTargetMachine
Definition:RISCVTargetMachine.h:23
llvm::SelectionDAGTargetInfo
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Definition:SelectionDAGTargetInfo.h:31
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::TargetLoweringBase::getTargetMachine
const TargetMachine & getTargetMachine() const
Definition:TargetLowering.h:364
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition:TargetMachine.h:77
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::cl::opt
Definition:CommandLine.h:1423
ErrorHandling.h
llvm::ARM::PredBlockMask::TT
@ TT
llvm::MISched::Direction
Direction
Definition:MachineScheduler.h:103
llvm::MISched::Bidirectional
@ Bidirectional
Definition:MachineScheduler.h:107
llvm::MISched::BottomUp
@ BottomUp
Definition:MachineScheduler.h:106
llvm::MISched::TopDown
@ TopDown
Definition:MachineScheduler.h:105
llvm::RISCVABI::computeTargetABI
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
Definition:RISCVBaseInfo.cpp:37
llvm::RISCVFeatures::validate
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Definition:RISCVBaseInfo.cpp:110
llvm::RISCVTuneInfoTable
Definition:RISCVSubtarget.cpp:36
llvm::RISCV::RVVBitsPerBlock
static constexpr unsigned RVVBitsPerBlock
Definition:RISCVTargetParser.h:51
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::createRISCVInstructionSelector
InstructionSelector * createRISCVInstructionSelector(const RISCVTargetMachine &TM, const RISCVSubtarget &Subtarget, const RISCVRegisterBankInfo &RBI)
Definition:RISCVInstructionSelector.cpp:1347
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::bit_floor
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition:bit.h:327
llvm::MachineSchedPolicy
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
Definition:MachineScheduler.h:192
llvm::MachineSchedPolicy::OnlyTopDown
bool OnlyTopDown
Definition:MachineScheduler.h:201
llvm::MachineSchedPolicy::DisableLatencyHeuristic
bool DisableLatencyHeuristic
Definition:MachineScheduler.h:206
llvm::MachineSchedPolicy::OnlyBottomUp
bool OnlyBottomUp
Definition:MachineScheduler.h:202
llvm::MachineSchedPolicy::ShouldTrackPressure
bool ShouldTrackPressure
Definition:MachineScheduler.h:194
llvm::RISCVTuneInfoTable::RISCVTuneInfo::MinimumJumpTableEntries
unsigned MinimumJumpTableEntries
Definition:RISCVSubtarget.h:52
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Thu Jul 17 2025 15:28:18 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp