30#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN, \
31 FAST_VECTOR_UNALIGN, MVENDORID, MARCHID, MIMPID) \
33#define TUNE_PROC(ENUM, NAME) CK_##ENUM,
34#include "llvm/TargetParser/RISCVTargetParserDef.inc"
38#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN, \
39 FAST_VECTOR_UNALIGN, MVENDORID, MARCHID, MIMPID) \
43 FAST_SCALAR_UNALIGN, \
44 FAST_VECTOR_UNALIGN, \
45 {MVENDORID, MARCHID, MIMPID}, \
47#include "llvm/TargetParser/RISCVTargetParserDef.inc"
59 return Info && Info->FastScalarUnalignedAccess;
64 return Info && Info->FastVectorUnalignedAccess;
91 return Info->is64Bit() == IsRV64;
95 std::optional<CPUKind> Kind =
98 #include "llvm/TargetParser/RISCVTargetParserDef.inc"
101 if (Kind.has_value())
112 return Info->DefaultMarch;
117 if (IsRV64 ==
C.is64Bit())
124 if (IsRV64 ==
C.is64Bit())
127#define TUNE_PROC(ENUM, NAME) Values.emplace_back(StringRef(NAME));
128#include "llvm/TargetParser/RISCVTargetParserDef.inc"
136 if (MarchFromCPU ==
"")
139 EnabledFeatures.
clear();
146 std::vector<std::string> FeatStrings =
147 (*RII)->toFeatures(
false);
148 for (
const auto &
F : FeatStrings)
156class RISCVTuneFeatureLookupTable {
157 struct RISCVTuneFeature {
163 struct RISCVImpliedTuneFeature {
165 unsigned ImpliedFeatureIdx;
168 struct RISCVConfigurableTuneFeatures {
170 unsigned DirectiveIdx;
172 bool operator<(
const RISCVConfigurableTuneFeatures &
RHS)
const {
173 return Processor <
RHS.Processor;
177#define GET_TUNE_FEATURES
178#define GET_CONFIGURABLE_TUNE_FEATURES
179#include "llvm/TargetParser/RISCVTargetParserDef.inc"
182 StringMap<StringRef> PositiveMap;
184 StringMap<StringRef> NegativeMap;
186 StringMap<SmallVector<StringRef>> ImpliedFeatureMap;
187 StringMap<SmallVector<StringRef>> InvImpliedFeatureMap;
190 using SmallStringSet = SmallSet<StringRef, 4>;
193 for (
const auto &TuneFeature : TuneFeatures)
194 Features.push_back(TuneFeatureStrings[TuneFeature.FeatureIdx]);
197 static void getConfigurableFeatures(StringRef ProcName,
198 SmallStringSet &Directives) {
200 auto [ItFirst, ItEnd] =
201 std::equal_range(std::begin(ConfigurableTuneFeatures),
202 std::end(ConfigurableTuneFeatures),
203 RISCVConfigurableTuneFeatures{ProcName, 0});
204 for (; ItFirst != ItEnd; ++ItFirst)
205 Directives.insert(TuneFeatureStrings[ItFirst->DirectiveIdx]);
208 RISCVTuneFeatureLookupTable() {
209 for (
const auto &TuneFeature : TuneFeatures) {
210 StringRef PosDirective = TuneFeatureStrings[TuneFeature.PosIdx];
211 StringRef NegDirective = TuneFeatureStrings[TuneFeature.NegIdx];
212 StringRef FeatureName = TuneFeatureStrings[TuneFeature.FeatureIdx];
213 PositiveMap[PosDirective] = FeatureName;
214 NegativeMap[NegDirective] = FeatureName;
217 for (
const auto &Imp : ImpliedTuneFeatures) {
218 StringRef Feature = TuneFeatureStrings[Imp.FeatureIdx];
219 StringRef ImpliedFeature = TuneFeatureStrings[Imp.ImpliedFeatureIdx];
220 ImpliedFeatureMap[Feature].push_back(ImpliedFeature);
221 InvImpliedFeatureMap[ImpliedFeature].push_back(Feature);
227 std::pair<StringRef, bool> getFeature(StringRef DirectiveName)
const {
228 auto It = PositiveMap.find(DirectiveName);
229 if (It != PositiveMap.end())
230 return {It->getValue(),
true};
232 return {NegativeMap.lookup(DirectiveName),
false};
239 bool Inverse =
false)
const {
240 const auto &
Map = Inverse ? InvImpliedFeatureMap : ImpliedFeatureMap;
241 auto It =
Map.find(FeatureName);
250 RISCVTuneFeatureLookupTable::getAllTuneFeatures(Features);
255 RISCVTuneFeatureLookupTable TFLookup;
256 using SmallStringSet = RISCVTuneFeatureLookupTable::SmallStringSet;
260 std::string WarningMsg;
262 TFString = TFString.
trim();
263 if (TFString.
empty())
267 SmallStringSet PositiveFeatures;
268 SmallStringSet NegativeFeatures;
269 SmallStringSet PerProcDirectives;
270 RISCVTuneFeatureLookupTable::getConfigurableFeatures(ProcName,
272 if (PerProcDirectives.empty() && !ProcName.
empty())
275 "configurable tuning features");
280 std::tie(DirectiveStr, TFString) = TFString.
split(
",");
281 auto [FeatureName, IsPositive] = TFLookup.getFeature(DirectiveStr);
282 if (FeatureName.empty()) {
284 SS <<
"unrecognized tune feature directive '" << DirectiveStr <<
"'";
288 auto &Features = IsPositive ? PositiveFeatures : NegativeFeatures;
289 if (!Features.insert(FeatureName).second)
291 "cannot specify more than one instance of '" +
Twine(DirectiveStr) +
294 if (!PerProcDirectives.count(DirectiveStr) && !ProcName.
empty())
297 "allowed to be used with processor '" +
298 Twine(ProcName) +
"'");
299 }
while (!TFString.
empty());
303 if (!Intersection.empty()) {
304 std::string IntersectedStr =
join(Intersection,
"', '");
306 "' cannot appear in both "
307 "positive and negative directives");
311 SmallStringSet DerivedPosFeatures;
312 SmallStringSet DerivedNegFeatures;
314 if (
auto FeatureList = TFLookup.featureImplies(PF); !FeatureList.empty())
315 DerivedPosFeatures.insert_range(FeatureList);
318 if (
auto FeatureList = TFLookup.featureImplies(NF,
true);
319 !FeatureList.empty())
320 DerivedNegFeatures.insert_range(FeatureList);
322 PositiveFeatures.insert_range(DerivedPosFeatures);
323 NegativeFeatures.insert_range(DerivedNegFeatures);
326 if (!Intersection.empty()) {
327 std::string IntersectedStr =
join(Intersection,
"', '");
329 "' were implied by both "
330 "positive and negative directives");
334 const std::string PosPrefix(
"+");
335 const std::string NegPrefix(
"-");
341 if (WarningMsg.empty())
349 RISCVTuneFeatureLookupTable::SmallStringSet DirectiveSet;
350 RISCVTuneFeatureLookupTable::getConfigurableFeatures(CPU, DirectiveSet);
355namespace RISCVVType {
367 bool MaskAgnostic,
bool AltFmt) {
369 unsigned VLMulBits =
static_cast<unsigned>(VLMul);
371 unsigned VTypeI = (VSEWBits << 3) | (VLMulBits & 0x7);
387 unsigned VTypeI = (VSEWBits << 3) | AltFmt << 8 | TWiden << 9;
399 return std::make_pair(1 <<
static_cast<unsigned>(VLMul),
false);
403 return std::make_pair(1 << (8 -
static_cast<unsigned>(VLMul)),
true);
408 unsigned Sew =
getSEW(VType);
446 LMul = Fractional ? (8 / LMul) : (LMul * 8);
448 assert(SEW >= 8 &&
"Unexpected SEW value");
449 return (SEW * 8) / LMul;
453 unsigned EMULFixedPoint = (EEW * 8) / Ratio;
454 bool Fractional = EMULFixedPoint < 8;
455 unsigned EMUL = Fractional ? 8 / EMULFixedPoint : EMULFixedPoint / 8;
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define TUNE_PROC(ENUM, NAME)
This file defines generic set operations that may be used on set's of different types,...
This file defines the SmallSet class.
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISC-V ISA info from arch string.
const_iterator begin() const
const_iterator end() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
static bool isTailAgnostic(unsigned VType)
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI void printXSfmmVType(unsigned VType, raw_ostream &OS)
LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt)
static unsigned getXSfmmWiden(unsigned VType)
static bool isValidLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI std::optional< VLMUL > getSameRatioLMUL(unsigned Ratio, unsigned EEW)
static bool isMaskAgnostic(unsigned VType)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
static unsigned encodeSEW(unsigned SEW)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
static bool isValidSEW(unsigned SEW)
LLVM_ABI void printVType(unsigned VType, raw_ostream &OS)
static bool isAltFmt(unsigned VType)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
static unsigned getSEW(unsigned VType)
static VLMUL getVLMUL(unsigned VType)
LLVM_ABI bool hasFastVectorUnalignedAccess(StringRef CPU)
LLVM_ABI void getFeaturesForCPU(StringRef CPU, SmallVectorImpl< std::string > &EnabledFeatures, bool NeedPlus=false)
LLVM_ABI void fillValidTuneCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
static const CPUInfo * getCPUInfoByName(StringRef CPU)
constexpr CPUInfo RISCVCPUInfo[]
LLVM_ABI CPUModel getCPUModel(StringRef CPU)
LLVM_ABI Error parseTuneFeatureString(StringRef ProcName, StringRef TFString, SmallVectorImpl< std::string > &TuneFeatures)
Parse the tune feature string with the respective processor.
LLVM_ABI void getAllTuneFeatures(SmallVectorImpl< StringRef > &TuneFeatures)
LLVM_ABI StringRef getMArchFromMcpu(StringRef CPU)
LLVM_ABI bool parseCPU(StringRef CPU, bool IsRV64)
LLVM_ABI bool hasFastScalarUnalignedAccess(StringRef CPU)
LLVM_ABI bool hasValidCPUModel(StringRef CPU)
LLVM_ABI StringRef getCPUNameFromCPUModel(const CPUModel &Model)
LLVM_ABI bool parseTuneCPU(StringRef CPU, bool IsRV64)
LLVM_ABI void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values, bool IsRV64)
LLVM_ABI void getCPUConfigurableTuneFeatures(StringRef CPU, SmallVectorImpl< StringRef > &Directives)
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
bool operator<(int64_t V1, const APSInt &V2)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
S1Ty set_intersection(const S1Ty &S1, const S2Ty &S2)
set_intersection(A, B) - Return A ^ B
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
ArrayRef(const T &OneElt) -> ArrayRef< T >