LLVM 19.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"
17#include "RISCV.h"
18#include "RISCVFrameLowering.h"
19#include "RISCVTargetMachine.h"
24
25using namespace llvm;
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
37
38#define GET_RISCVTuneInfoTable_IMPL
39#include "RISCVGenSearchableTables.inc"
40} // namespace llvm::RISCVTuneInfoTable
41
43 "riscv-v-fixed-length-vector-lmul-max",
44 cl::desc("The maximum LMUL value to use for fixed length vectors. "
45 "Fractional LMUL values are not supported."),
47
49 "riscv-disable-using-constant-pool-for-large-ints",
50 cl::desc("Disable using constant pool for large integers."),
51 cl::init(false), cl::Hidden);
52
54 "riscv-max-build-ints-cost",
55 cl::desc("The maximum cost used for building integers."), cl::init(0),
57
58static cl::opt<bool> UseAA("riscv-use-aa", cl::init(true),
59 cl::desc("Enable the use of AA during codegen."));
60
62 "riscv-min-jump-table-entries", cl::Hidden,
63 cl::desc("Set minimum number of entries to use a jump table on RISCV"));
64
65void RISCVSubtarget::anchor() {}
66
68RISCVSubtarget::initializeSubtargetDependencies(const Triple &TT, StringRef CPU,
69 StringRef TuneCPU, StringRef FS,
70 StringRef ABIName) {
71 // Determine default and user-specified characteristics
72 bool Is64Bit = TT.isArch64Bit();
73 if (CPU.empty() || CPU == "generic")
74 CPU = Is64Bit ? "generic-rv64" : "generic-rv32";
75
76 if (TuneCPU.empty())
77 TuneCPU = CPU;
78
79 TuneInfo = RISCVTuneInfoTable::getRISCVTuneInfo(TuneCPU);
80 // If there is no TuneInfo for this CPU, we fail back to generic.
81 if (!TuneInfo)
82 TuneInfo = RISCVTuneInfoTable::getRISCVTuneInfo("generic");
83 assert(TuneInfo && "TuneInfo shouldn't be nullptr!");
84
85 ParseSubtargetFeatures(CPU, TuneCPU, FS);
86 TargetABI = RISCVABI::computeTargetABI(TT, getFeatureBits(), ABIName);
87 RISCVFeatures::validate(TT, getFeatureBits());
88 return *this;
89}
90
92 StringRef TuneCPU, StringRef FS,
93 StringRef ABIName, unsigned RVVVectorBitsMin,
94 unsigned RVVVectorBitsMax,
95 const TargetMachine &TM)
96 : RISCVGenSubtargetInfo(TT, CPU, TuneCPU, FS),
97 RVVVectorBitsMin(RVVVectorBitsMin), RVVVectorBitsMax(RVVVectorBitsMax),
98 FrameLowering(
99 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
100 InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
102 Legalizer.reset(new RISCVLegalizerInfo(*this));
103
104 auto *RBI = new RISCVRegisterBankInfo(getHwMode());
105 RegBankInfo.reset(RBI);
107 *static_cast<const RISCVTargetMachine *>(&TM), *this, *RBI));
108}
109
111 return CallLoweringInfo.get();
112}
113
115 return InstSelector.get();
116}
117
119 return Legalizer.get();
120}
121
123 return RegBankInfo.get();
124}
125
128}
129
131 // Loading integer from constant pool needs two instructions (the reason why
132 // the minimum cost is 2): an address calculation instruction and a load
133 // instruction. Usually, address calculation and instructions used for
134 // building integers (addi, slli, etc.) can be done in one cycle, so here we
135 // set the default cost to (LoadLatency + 1) if no threshold is provided.
136 return RISCVMaxBuildIntsCost == 0
137 ? getSchedModel().LoadLatency + 1
138 : std::max<unsigned>(2, RISCVMaxBuildIntsCost);
139}
140
143 "Tried to get vector length without Zve or V extension support!");
144
145 // ZvlLen specifies the minimum required vlen. The upper bound provided by
146 // riscv-v-vector-bits-max should be no less than it.
147 if (RVVVectorBitsMax != 0 && RVVVectorBitsMax < ZvlLen)
148 report_fatal_error("riscv-v-vector-bits-max specified is lower "
149 "than the Zvl*b limitation");
150
151 return RVVVectorBitsMax;
152}
153
156 "Tried to get vector length without Zve or V extension support!");
157
158 if (RVVVectorBitsMin == -1U)
159 return ZvlLen;
160
161 // ZvlLen specifies the minimum required vlen. The lower bound provided by
162 // riscv-v-vector-bits-min should be no less than it.
163 if (RVVVectorBitsMin != 0 && RVVVectorBitsMin < ZvlLen)
164 report_fatal_error("riscv-v-vector-bits-min specified is lower "
165 "than the Zvl*b limitation");
166
167 return RVVVectorBitsMin;
168}
169
172 "Tried to get vector length without Zve or V extension support!");
174 llvm::has_single_bit<uint32_t>(RVVVectorLMULMax) &&
175 "V extension requires a LMUL to be at most 8 and a power of 2!");
176 return llvm::bit_floor(std::clamp<unsigned>(RVVVectorLMULMax, 1, 8));
177}
178
181}
182
183bool RISCVSubtarget::enableSubRegLiveness() const { return true; }
184
186 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
187 Mutations.push_back(createMacroFusionDAGMutation(getMacroFusions()));
188}
189
190 /// Enable use of alias analysis during code generation (during MI
191 /// scheduling, DAGCombine, etc.).
192bool RISCVSubtarget::useAA() const { return UseAA; }
193
195 return RISCVMinimumJumpTableEntries.getNumOccurrences() > 0
197 : TuneInfo->MinimumJumpTableEntries;
198}
static cl::opt< bool > UseAA("aarch64-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
const char LLVMTargetMachineRef TM
This file describes how to lower LLVM calls to machine code calls.
This file declares the targeting of the Machinelegalizer class for RISC-V.
This file declares the targeting of the RegisterBankInfo class for RISC-V.
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)
static cl::opt< bool > UseAA("riscv-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
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"))
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)
static cl::opt< unsigned > RISCVMaxBuildIntsCost("riscv-max-build-ints-cost", cl::desc("The maximum cost used for building integers."), cl::init(0), cl::Hidden)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class provides the information for the target register banks.
unsigned getMinimumJumpTableEntries() const
void getPostRAMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const override
const LegalizerInfo * getLegalizerInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
unsigned getMaxLMULForFixedLengthVectors() const
bool useRVVForFixedLengthVectors() const
std::unique_ptr< RegisterBankInfo > RegBankInfo
unsigned getMinRVVVectorSizeInBits() const
std::unique_ptr< InstructionSelector > InstSelector
RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName, unsigned RVVVectorBitsMin, unsigned RVVVectorLMULMax, const TargetMachine &TM)
const CallLowering * getCallLowering() const override
InstructionSelector * getInstructionSelector() const override
unsigned getMaxBuildIntsCost() const
bool hasVInstructions() const
bool useAA() const override
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine,...
bool useConstantPoolForLargeInts() const
unsigned getMaxRVVVectorSizeInBits() const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
std::unique_ptr< CallLowering > CallLoweringInfo
const RISCVTargetLowering * getTargetLowering() const override
bool enableSubRegLiveness() const override
Holds all the information related to register banks.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::unique_ptr< ScheduleDAGMutation > createMacroFusionDAGMutation(ArrayRef< MacroFusionPredTy > Predicates, bool BranchOnly=false)
Create a DAG scheduling mutation to pair instructions back to back for instructions that benefit acco...
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition: bit.h:327
InstructionSelector * createRISCVInstructionSelector(const RISCVTargetMachine &TM, RISCVSubtarget &Subtarget, RISCVRegisterBankInfo &RBI)