LLVM 24.0.0git
RISCVISAInfo.cpp
Go to the documentation of this file.
1//===-- RISCVISAInfo.cpp - RISC-V Arch String Parser ----------------------===//
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
10#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Errc.h"
15#include "llvm/Support/Error.h"
18
19#include <atomic>
20#include <optional>
21#include <string>
22#include <vector>
23
24using namespace llvm;
25
26#define GET_EXTENSION_STRTAB
27#include "llvm/TargetParser/RISCVTargetParserDef.inc"
28
29namespace {
30
31struct RISCVSupportedExtension {
32 StringTable::Offset NameOff;
33 /// Supported version.
35
36 StringRef name() const { return ExtensionStrings[NameOff]; }
37
38 bool operator<(const RISCVSupportedExtension &RHS) const {
39 return name() < RHS.name();
40 }
41};
42
43struct RISCVProfile {
44 StringLiteral Name;
45 StringLiteral MArch;
46
47 bool operator<(const RISCVProfile &RHS) const {
48 return StringRef(Name) < StringRef(RHS.Name);
49 }
50};
51
52} // end anonymous namespace
53
54static const char *RISCVGImplications[] = {"i", "m", "a", "f", "d"};
55static const char *RISCVGImplicationsZi[] = {"zicsr", "zifencei"};
56
57#define GET_SUPPORTED_EXTENSIONS
58#include "llvm/TargetParser/RISCVTargetParserDef.inc"
59
60#define GET_SUPPORTED_PROFILES
61#include "llvm/TargetParser/RISCVTargetParserDef.inc"
62
63static void verifyTables() {
64#ifndef NDEBUG
65 static std::atomic<bool> TableChecked(false);
66 if (!TableChecked.load(std::memory_order_relaxed)) {
67 assert(llvm::is_sorted(SupportedExtensions) &&
68 "Extensions are not sorted by name");
69 assert(llvm::is_sorted(SupportedExperimentalExtensions) &&
70 "Experimental extensions are not sorted by name");
71 assert(llvm::is_sorted(SupportedProfiles) &&
72 "Profiles are not sorted by name");
73 assert(llvm::is_sorted(SupportedExperimentalProfiles) &&
74 "Experimental profiles are not sorted by name");
75 TableChecked.store(true, std::memory_order_relaxed);
76 }
77#endif
78}
79
80static void PrintExtension(StringRef Name, StringRef Version,
81 StringRef Description) {
82 outs().indent(4);
83 unsigned VersionWidth = Description.empty() ? 0 : 10;
84 outs() << left_justify(Name, 21) << left_justify(Version, VersionWidth)
85 << Description << "\n";
86}
87
89 outs() << "All available -march extensions for RISC-V\n\n";
90 PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description"));
91
93 for (const auto &E : SupportedExtensions)
94 ExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
95 for (const auto &E : ExtMap) {
96 std::string Version =
97 std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
98 PrintExtension(E.first, Version, DescMap[E.first]);
99 }
100
101 outs() << "\nExperimental extensions\n";
102 ExtMap.clear();
103 for (const auto &E : SupportedExperimentalExtensions)
104 ExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
105 for (const auto &E : ExtMap) {
106 std::string Version =
107 std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
108 PrintExtension(E.first, Version, DescMap["experimental-" + E.first]);
109 }
110
111 outs() << "\nSupported Profiles\n";
112 for (const auto &P : SupportedProfiles)
113 outs().indent(4) << P.Name << "\n";
114
115 outs() << "\nExperimental Profiles\n";
116 for (const auto &P : SupportedExperimentalProfiles)
117 outs().indent(4) << P.Name << "\n";
118
119 outs() << "\nUse -march to specify the target's extension.\n"
120 "For example, clang -march=rv32i_v1p0\n";
121}
122
124 bool IsRV64, std::set<StringRef> &EnabledFeatureNames,
125 StringMap<StringRef> &DescMap) {
126 outs() << "Extensions enabled for the given RISC-V target\n\n";
127 PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description"));
128
131 for (const auto &E : SupportedExtensions)
132 if (EnabledFeatureNames.count(E.name()) != 0) {
133 FullExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
134 ExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
135 }
136 for (const auto &E : ExtMap) {
137 std::string Version =
138 std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
139 PrintExtension(E.first, Version, DescMap[E.first]);
140 }
141
142 outs() << "\nExperimental extensions\n";
143 ExtMap.clear();
144 for (const auto &E : SupportedExperimentalExtensions) {
145 if (EnabledFeatureNames.count("experimental-" + E.name().str()) != 0) {
146 FullExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
147 ExtMap[E.name().str()] = {E.Version.Major, E.Version.Minor};
148 }
149 }
150 for (const auto &E : ExtMap) {
151 std::string Version =
152 std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
153 PrintExtension(E.first, Version, DescMap["experimental-" + E.first]);
154 }
155
156 unsigned XLen = IsRV64 ? 64 : 32;
157 if (auto ISAString = RISCVISAInfo::createFromExtMap(XLen, FullExtMap))
158 outs() << "\nISA String: " << ISAString.get()->toString() << "\n";
159}
160
162 return Ext.consume_front("experimental-");
163}
164
165// This function finds the last character that doesn't belong to a version
166// (e.g. zba1p0 is extension 'zba' of version '1p0'). So the function will
167// consume [0-9]*p[0-9]* starting from the backward. An extension name will not
168// end with a digit or the letter 'p', so this function will parse correctly.
169// NOTE: This function is NOT able to take empty strings or strings that only
170// have version numbers and no extension name. It assumes the extension name
171// will be at least more than one character.
173 assert(!Ext.empty() &&
174 "Already guarded by if-statement in ::parseArchString");
175
176 int Pos = Ext.size() - 1;
177 while (Pos > 0 && isDigit(Ext[Pos]))
178 Pos--;
179 if (Pos > 0 && Ext[Pos] == 'p' && isDigit(Ext[Pos - 1])) {
180 Pos--;
181 while (Pos > 0 && isDigit(Ext[Pos]))
182 Pos--;
183 }
184 return Pos;
185}
186
187namespace {
188struct LessExtName {
189 bool operator()(const RISCVSupportedExtension &LHS, StringRef RHS) {
190 return LHS.name() < RHS;
191 }
192 bool operator()(StringRef LHS, const RISCVSupportedExtension &RHS) {
193 return LHS < RHS.name();
194 }
195};
196} // namespace
197
198static std::optional<RISCVISAUtils::ExtensionVersion>
200 // Find default version of an extension.
201 // TODO: We might set default version based on profile or ISA spec.
202 for (auto &ExtInfo : {ArrayRef(SupportedExtensions),
203 ArrayRef(SupportedExperimentalExtensions)}) {
204 auto I = llvm::lower_bound(ExtInfo, ExtName, LessExtName());
205
206 if (I == ExtInfo.end() || I->name() != ExtName)
207 continue;
208
209 return I->Version;
210 }
211 return std::nullopt;
212}
213
215 if (Ext.starts_with('s'))
216 return "standard supervisor-level extension";
217 if (Ext.starts_with('x'))
218 return "non-standard user-level extension";
219 if (Ext.starts_with('z'))
220 return "standard user-level extension";
221 return StringRef();
222}
223
225 if (Ext.starts_with('s'))
226 return "s";
227 if (Ext.starts_with('x'))
228 return "x";
229 if (Ext.starts_with('z'))
230 return "z";
231 return StringRef();
232}
233
234static std::optional<RISCVISAUtils::ExtensionVersion>
236 auto I =
237 llvm::lower_bound(SupportedExperimentalExtensions, Ext, LessExtName());
238 if (I == std::end(SupportedExperimentalExtensions) || I->name() != Ext)
239 return std::nullopt;
240
241 return I->Version;
242}
243
245 bool IsExperimental = stripExperimentalPrefix(Ext);
246
248 IsExperimental ? ArrayRef(SupportedExperimentalExtensions)
249 : ArrayRef(SupportedExtensions);
250
251 auto I = llvm::lower_bound(ExtInfo, Ext, LessExtName());
252 return I != ExtInfo.end() && I->name() == Ext;
253}
254
256 verifyTables();
257
258 for (auto ExtInfo : {ArrayRef(SupportedExtensions),
259 ArrayRef(SupportedExperimentalExtensions)}) {
260 auto I = llvm::lower_bound(ExtInfo, Ext, LessExtName());
261 if (I != ExtInfo.end() && I->name() == Ext)
262 return true;
263 }
264
265 return false;
266}
267
268bool RISCVISAInfo::isSupportedExtension(StringRef Ext, unsigned MajorVersion,
269 unsigned MinorVersion) {
270 for (auto ExtInfo : {ArrayRef(SupportedExtensions),
271 ArrayRef(SupportedExperimentalExtensions)}) {
272 auto Range =
273 std::equal_range(ExtInfo.begin(), ExtInfo.end(), Ext, LessExtName());
274 for (auto I = Range.first, E = Range.second; I != E; ++I)
275 if (I->Version.Major == MajorVersion && I->Version.Minor == MinorVersion)
276 return true;
277 }
278
279 return false;
280}
281
284
285 if (!isSupportedExtension(Ext))
286 return false;
287
288 return Exts.count(Ext) != 0;
289}
290
291std::vector<std::string> RISCVISAInfo::toFeatures(bool AddAllExtensions,
292 bool IgnoreUnknown) const {
293 std::vector<std::string> Features;
294 for (const auto &[ExtName, _] : Exts) {
295 if (IgnoreUnknown && !isSupportedExtension(ExtName))
296 continue;
297
298 if (isExperimentalExtension(ExtName)) {
299 Features.push_back((llvm::Twine("+experimental-") + ExtName).str());
300 } else {
301 Features.push_back((llvm::Twine("+") + ExtName).str());
302 }
303 }
304 if (AddAllExtensions) {
305 for (const RISCVSupportedExtension &Ext : SupportedExtensions) {
306 if (Exts.count(Ext.name()))
307 continue;
308 Features.push_back((llvm::Twine("-") + Ext.name()).str());
309 }
310
311 for (const RISCVSupportedExtension &Ext : SupportedExperimentalExtensions) {
312 if (Exts.count(Ext.name()))
313 continue;
314 Features.push_back((llvm::Twine("-experimental-") + Ext.name()).str());
315 }
316 }
317 return Features;
318}
319
320static Error getError(const Twine &Message) {
322}
323
325 if (ExtName.size() == 1) {
326 return getError("unsupported standard user-level extension '" + ExtName +
327 "'");
328 }
329 return getError("unsupported " + getExtensionTypeDesc(ExtName) + " '" +
330 ExtName + "'");
331}
332
333// Extensions may have a version number, and may be separated by
334// an underscore '_' e.g.: rv32i2_m2.
335// Version number is divided into major and minor version numbers,
336// separated by a 'p'. If the minor version is 0 then 'p0' can be
337// omitted from the version string. E.g., rv32i2p0, rv32i2, rv32i2p1.
338static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
339 unsigned &Minor, unsigned &ConsumeLength,
340 bool EnableExperimentalExtension,
341 bool ExperimentalExtensionVersionCheck) {
342 StringRef MajorStr, MinorStr;
343 Major = 0;
344 Minor = 0;
345 ConsumeLength = 0;
346 MajorStr = In.take_while(isDigit);
347 In = In.substr(MajorStr.size());
348
349 if (!MajorStr.empty() && In.consume_front("p")) {
350 MinorStr = In.take_while(isDigit);
351 In = In.substr(MajorStr.size() + MinorStr.size() - 1);
352
353 // Expected 'p' to be followed by minor version number.
354 if (MinorStr.empty()) {
355 return getError("minor version number missing after 'p' for extension '" +
356 Ext + "'");
357 }
358 }
359
360 if (!MajorStr.empty() && MajorStr.getAsInteger(10, Major))
361 return getError("Failed to parse major version number for extension '" +
362 Ext + "'");
363
364 if (!MinorStr.empty() && MinorStr.getAsInteger(10, Minor))
365 return getError("Failed to parse minor version number for extension '" +
366 Ext + "'");
367
368 ConsumeLength = MajorStr.size();
369
370 if (!MinorStr.empty())
371 ConsumeLength += MinorStr.size() + 1 /*'p'*/;
372
373 // Expected multi-character extension with version number to have no
374 // subsequent characters (i.e. must either end string or be followed by
375 // an underscore).
376 if (Ext.size() > 1 && In.size())
377 return getError(
378 "multi-character extensions must be separated by underscores");
379
380 // If experimental extension, require use of current version number
381 if (auto ExperimentalExtension = isExperimentalExtension(Ext)) {
382 if (!EnableExperimentalExtension)
383 return getError("requires '-menable-experimental-extensions' "
384 "for experimental extension '" +
385 Ext + "'");
386
387 if (ExperimentalExtensionVersionCheck &&
388 (MajorStr.empty() && MinorStr.empty()))
389 return getError(
390 "experimental extension requires explicit version number `" + Ext +
391 "`");
392
393 auto SupportedVers = *ExperimentalExtension;
394 if (ExperimentalExtensionVersionCheck &&
395 (Major != SupportedVers.Major || Minor != SupportedVers.Minor)) {
396 std::string Error = "unsupported version number " + MajorStr.str();
397 if (!MinorStr.empty())
398 Error += "." + MinorStr.str();
399 Error += " for experimental extension '" + Ext.str() +
400 "' (this compiler supports " + utostr(SupportedVers.Major) +
401 "." + utostr(SupportedVers.Minor) + ")";
402 return getError(Error);
403 }
404 return Error::success();
405 }
406
407 // Exception rule for `g`, we don't have clear version scheme for that on
408 // ISA spec.
409 if (Ext == "g")
410 return Error::success();
411
412 if (MajorStr.empty() && MinorStr.empty()) {
413 if (auto DefaultVersion = findDefaultVersion(Ext)) {
414 Major = DefaultVersion->Major;
415 Minor = DefaultVersion->Minor;
416 }
417 // No matter found or not, return success, assume other place will
418 // verify.
419 return Error::success();
420 }
421
422 if (RISCVISAInfo::isSupportedExtension(Ext, Major, Minor))
423 return Error::success();
424
426 return getErrorForInvalidExt(Ext);
427
428 std::string Error = "unsupported version number " + MajorStr.str();
429 if (!MinorStr.empty())
430 Error += "." + MinorStr.str();
431 Error += " for extension '" + Ext.str() + "'";
432 return getError(Error);
433}
434
438 assert(XLen == 32 || XLen == 64);
439 std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
440
441 ISAInfo->Exts = Exts;
442
443 return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
444}
445
448 const std::vector<std::string> &Features) {
449 assert(XLen == 32 || XLen == 64);
450 std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
451
452 for (StringRef ExtName : Features) {
453 assert(ExtName.size() > 1 && (ExtName[0] == '+' || ExtName[0] == '-'));
454 bool Add = ExtName[0] == '+';
455 ExtName = ExtName.drop_front(1); // Drop '+' or '-'
456 bool Experimental = stripExperimentalPrefix(ExtName);
457 auto ExtensionInfos = Experimental
458 ? ArrayRef(SupportedExperimentalExtensions)
459 : ArrayRef(SupportedExtensions);
460 auto ExtensionInfoIterator =
461 llvm::lower_bound(ExtensionInfos, ExtName, LessExtName());
462
463 // Not all features is related to ISA extension, like `relax` or
464 // `save-restore`, skip those feature.
465 if (ExtensionInfoIterator == ExtensionInfos.end() ||
466 ExtensionInfoIterator->name() != ExtName)
467 continue;
468
469 if (Add)
470 ISAInfo->Exts[ExtName.str()] = ExtensionInfoIterator->Version;
471 else
472 ISAInfo->Exts.erase(ExtName.str());
473 }
474
475 return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
476}
477
480 // RISC-V ISA strings must be [a-z0-9_]
481 if (!llvm::all_of(
482 Arch, [](char C) { return isDigit(C) || isLower(C) || C == '_'; }))
483 return getError("string may only contain [a-z0-9_]");
484
485 // Must start with a valid base ISA name.
486 unsigned XLen = 0;
487 if (Arch.consume_front("rv32"))
488 XLen = 32;
489 else if (Arch.consume_front("rv64"))
490 XLen = 64;
491
492 auto IsBaseISA = [](char C) { return C == 'i' || C == 'e' || C == 'y'; };
493 if (XLen == 0 || Arch.empty() || !IsBaseISA(Arch[0]))
494 return getError("arch string must begin with valid base ISA");
495 char BaseISA = Arch[0];
496
497 std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
498
499 // Each extension is of the form ${name}${major_version}p${minor_version}
500 // and separated by _. Split by _ and then extract the name and version
501 // information for each extension.
502 while (!Arch.empty()) {
503 if (Arch[0] == '_') {
504 if (Arch.size() == 1 || Arch[1] == '_')
505 return getError("extension name missing after separator '_'");
506 Arch = Arch.drop_front();
507 }
508
509 size_t Idx = Arch.find('_');
510 StringRef Ext = Arch.slice(0, Idx);
511 Arch = Arch.substr(Idx);
512
513 StringRef Prefix, MinorVersionStr;
514 std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
515 if (MinorVersionStr.empty())
516 return getError("extension lacks version in expected format");
517 unsigned MajorVersion, MinorVersion;
518 if (MinorVersionStr.getAsInteger(10, MinorVersion))
519 return getError("failed to parse minor version number");
520
521 // Split Prefix into the extension name and the major version number
522 // (the trailing digits of Prefix).
523 size_t VersionStart = Prefix.size();
524 while (VersionStart != 0) {
525 if (!isDigit(Prefix[VersionStart - 1]))
526 break;
527 --VersionStart;
528 }
529 if (VersionStart == Prefix.size())
530 return getError("extension lacks version in expected format");
531
532 if (VersionStart == 0)
533 return getError("missing extension name");
534
535 StringRef ExtName = Prefix.slice(0, VersionStart);
536 StringRef MajorVersionStr = Prefix.substr(VersionStart);
537 if (MajorVersionStr.getAsInteger(10, MajorVersion))
538 return getError("failed to parse major version number");
539
540 if (IsBaseISA(ExtName[0])) {
541 if (ExtName.size() > 1)
542 return getError("base ISA '" + Twine(ExtName[0]) +
543 "' is missing version number");
544 if (ExtName[0] != BaseISA)
545 return getError("conflicting base ISAs '" + Twine(BaseISA) + "' and '" +
546 ExtName + "'");
547 } else if (RISCVISAUtils::AllStdExts.contains(ExtName[0]) &&
548 ExtName.size() > 1) {
549 return getError("extension '" + Twine(ExtName[0]) +
550 "' is missing version number");
551 }
552
553 if ((ExtName[0] == 'z' || ExtName[0] == 's' || ExtName[0] == 'x') &&
554 (ExtName.size() == 1 || isDigit(ExtName[1])))
555 return getError("'" + Twine(ExtName[0]) +
556 "' must be followed by a letter");
557
558 if (!ISAInfo->Exts
559 .emplace(
560 ExtName.str(),
561 RISCVISAUtils::ExtensionVersion{MajorVersion, MinorVersion})
562 .second)
563 return getError("duplicate extension '" + ExtName + "'");
564 }
565 // Plain 'y' always implies 'i' (which is omitted in the normalized arch
566 // string). Y+E requires a long base name arch string.
567 if (BaseISA == 'y')
568 ISAInfo->Exts["i"] = *findDefaultVersion("i");
569 ISAInfo->updateImpliedLengths();
570 return std::move(ISAInfo);
571}
572
574RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
575 bool ExperimentalExtensionVersionCheck) {
576 // RISC-V ISA strings must be [a-z0-9_]
577 if (!llvm::all_of(
578 Arch, [](char C) { return isDigit(C) || isLower(C) || C == '_'; }))
579 return getError("string may only contain [a-z0-9_]");
580
581 // ISA string must begin with rv32, rv64, or a profile.
582 unsigned XLen = 0;
583 if (Arch.consume_front("rv32")) {
584 XLen = 32;
585 } else if (Arch.consume_front("rv64")) {
586 XLen = 64;
587 } else {
588 // Try parsing as a profile.
589 auto ProfileCmp = [](StringRef Arch, const RISCVProfile &Profile) {
590 return Arch < Profile.Name;
591 };
592 auto I = llvm::upper_bound(SupportedProfiles, Arch, ProfileCmp);
593 bool FoundProfile = I != std::begin(SupportedProfiles) &&
594 Arch.starts_with(std::prev(I)->Name);
595 if (!FoundProfile) {
596 I = llvm::upper_bound(SupportedExperimentalProfiles, Arch, ProfileCmp);
597 FoundProfile = (I != std::begin(SupportedExperimentalProfiles) &&
598 Arch.starts_with(std::prev(I)->Name));
599 if (FoundProfile && !EnableExperimentalExtension) {
600 return getError("requires '-menable-experimental-extensions' "
601 "for profile '" +
602 std::prev(I)->Name + "'");
603 }
604 }
605 if (FoundProfile) {
606 --I;
607 std::string NewArch = I->MArch.str();
608 StringRef ArchWithoutProfile = Arch.drop_front(I->Name.size());
609 if (!ArchWithoutProfile.empty()) {
610 if (ArchWithoutProfile.front() != '_')
611 return getError("additional extensions must be after separator '_'");
612 NewArch += ArchWithoutProfile.str();
613 }
614 return parseArchString(NewArch, EnableExperimentalExtension,
615 ExperimentalExtensionVersionCheck);
616 }
617 }
618
619 if (XLen == 0 || Arch.empty())
620 return getError(
621 "string must begin with rv32{i,e,g,y}, rv64{i,e,g,y}, or a supported "
622 "profile name");
623
624 std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
625
626 // The canonical order specified in ISA manual.
627 // Ref: Table 22.1 in RISC-V User-Level ISA V2.2
628 char Baseline = Arch.front();
629 // Skip the baseline.
630 Arch = Arch.drop_front();
631
632 unsigned Major, Minor, ConsumeLength;
633
634 // First letter should be 'e', 'i', 'g' or 'y'.
635 switch (Baseline) {
636 default:
637 return getError("first letter after \'rv" + Twine(XLen) +
638 "\' should be 'e', 'i', 'g' or 'y'");
639 case 'e':
640 case 'i':
641 case 'y':
642 // Baseline is 'i', 'e', or 'y' (which implies 'i' in updateImplication).
643 // TODO: arch string syntax for RVE+RVY (and y in non-first position) will
644 // be included following conclusion of "long base name" syntax
645 // https://lists.riscv.org/g/tech-unprivileged/message/1134
646 if (auto E = getExtensionVersion(
647 StringRef(&Baseline, 1), Arch, Major, Minor, ConsumeLength,
648 EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
649 return std::move(E);
650
651 ISAInfo->Exts[std::string(1, Baseline)] = {Major, Minor};
652 break;
653 case 'g':
654 // g expands to extensions in RISCVGImplications.
655 if (!Arch.empty() && isDigit(Arch.front()))
656 return getError("version not supported for 'g'");
657
658 // Versions for g are disallowed, and this was checked for previously.
659 ConsumeLength = 0;
660
661 // No matter which version is given to `g`, we always set imafd to default
662 // version since the we don't have clear version scheme for that on
663 // ISA spec.
664 for (const char *Ext : RISCVGImplications) {
665 auto Version = findDefaultVersion(Ext);
666 assert(Version && "Default extension version not found?");
667 ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
668 }
669 break;
670 }
671
672 // Consume the base ISA version number and any '_' between rvxxx and the
673 // first extension
674 Arch = Arch.drop_front(ConsumeLength);
675
676 while (!Arch.empty()) {
677 if (Arch.front() == '_') {
678 if (Arch.size() == 1 || Arch[1] == '_')
679 return getError("extension name missing after separator '_'");
680 Arch = Arch.drop_front();
681 }
682
683 size_t Idx = Arch.find('_');
684 StringRef Ext = Arch.slice(0, Idx);
685 Arch = Arch.substr(Idx);
686
687 do {
688 StringRef Name, Vers, Desc;
690 Name = Ext.take_front(1);
691 Ext = Ext.drop_front();
692 Vers = Ext;
693 Desc = "standard user-level extension";
694 } else if (Ext.front() == 'z' || Ext.front() == 's' ||
695 Ext.front() == 'x') {
696 // Handle other types of extensions other than the standard
697 // general purpose and standard user-level extensions.
698 // Parse the ISA string containing non-standard user-level
699 // extensions, standard supervisor-level extensions and
700 // non-standard supervisor-level extensions.
701 // These extensions start with 'z', 's', 'x' prefixes, might have a
702 // version number (major, minor) and are separated by a single
703 // underscore '_'. We do not enforce a canonical order for them.
706 auto Pos = findLastNonVersionCharacter(Ext) + 1;
707 Name = Ext.substr(0, Pos);
708 Vers = Ext.substr(Pos);
709 Ext = StringRef();
710
711 assert(!Type.empty() && "Empty type?");
712 if (Name.size() == Type.size())
713 return getError(Desc + " name missing after '" + Type + "'");
714 } else {
715 return getError("invalid standard user-level extension '" +
716 Twine(Ext.front()) + "'");
717 }
718
719 unsigned Major, Minor, ConsumeLength;
720 if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
721 EnableExperimentalExtension,
722 ExperimentalExtensionVersionCheck))
723 return E;
724
725 if (Name.size() == 1)
726 Ext = Ext.substr(ConsumeLength);
727
729 return getErrorForInvalidExt(Name);
730
731 // Insert and error for duplicates.
732 if (!ISAInfo->Exts
733 .emplace(Name.str(),
735 .second)
736 return getError("duplicated " + Desc + " '" + Name + "'");
737
738 } while (!Ext.empty());
739 }
740
741 // We add Zicsr/Zifenci as final to allow duplicated "zicsr"/"zifencei" like
742 // "rv64g_zicsr_zifencei".
743 if (Baseline == 'g') {
744 for (const char *Ext : RISCVGImplicationsZi) {
745 if (ISAInfo->Exts.count(Ext))
746 continue;
747
748 auto Version = findDefaultVersion(Ext);
749 assert(Version && "Default extension version not found?");
750 ISAInfo->Exts[std::string(Ext)] = {Version->Major, Version->Minor};
751 }
752 }
753
754 return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
755}
756
758 return getError("'" + Ext1 + "' and '" + Ext2 +
759 "' extensions are incompatible");
760}
761
763 return getError("'" + Ext + "' is incompatible with " + Base + " base");
764}
765
767 return getError("'" + Ext + "' requires '" + ReqExt +
768 "' extension to also be specified");
769}
770
771Error RISCVISAInfo::checkDependency() {
772 bool HasE = Exts.count("e") != 0;
773 bool HasI = Exts.count("i") != 0;
774 bool HasF = Exts.count("f") != 0;
775 bool HasD = Exts.count("d") != 0;
776 bool HasZfinx = Exts.count("zfinx") != 0;
777 bool HasVector = Exts.count("zve32x") != 0;
778 bool HasZvl = MinVLen != 0;
779 bool HasZcmp = Exts.count("zcmp") != 0;
780 bool HasXqccmp = Exts.count("xqccmp") != 0;
781 bool HasZcmt = Exts.count("zcmt") != 0;
782 bool HasXqccmt = Exts.count("xqccmt") != 0;
783
784 static constexpr StringLiteral ZcdOverlaps[] = {
785 {"zcmt"}, {"zcmp"}, {"xqccmi"}, {"xqccmp"},
786 {"xqccmt"}, {"xqciac"}, {"xqcicm"},
787 };
788 static constexpr StringLiteral RV32Only[] = {
789 {"zcf"}, {"zclsd"}, {"zilsd"}, {"xwchc"}, {"xqccmi"},
790 {"xqci"}, {"xqcia"}, {"xqciac"}, {"xqcibi"}, {"xqcibm"},
791 {"xqcicli"}, {"xqcicm"}, {"xqcics"}, {"xqcicsr"}, {"xqciint"},
792 {"xqciio"}, {"xqcilb"}, {"xqcili"}, {"xqcilia"}, {"xqcilo"},
793 {"xqcilsm"}, {"xqcisim"}, {"xqcisls"}, {"xqcisync"},
794 };
795
796 if (HasI && HasE)
797 return getIncompatibleError("i", "e");
798
799 if (HasF && HasZfinx)
800 return getIncompatibleError("f", "zfinx");
801
802 if (HasZvl && !HasVector)
803 return getExtensionRequiresError("zvl*b", "v' or 'zve*");
804
805 if (Exts.count("xsfvfbfexp16e") &&
806 !(Exts.count("zvfbfmin") || Exts.count("zvfbfa")))
808 "'xsfvfbfexp16e' requires 'zvfbfmin' or "
809 "'zvfbfa' extension to also be specified");
810
811 if (Exts.count("zcd"))
812 for (auto Ext : ZcdOverlaps)
813 if (Exts.count(Ext))
814 return getIncompatibleError(Ext, "zcd");
815
816 if (XLen != 32)
817 for (auto Ext : RV32Only)
818 if (Exts.count(Ext))
819 return getError(Twine("'") + Ext + "' is only supported for 'rv32'");
820
821 if (Exts.count("xwchc") != 0) {
822 if (HasD)
823 return getIncompatibleError("d", "xwchc");
824
825 if (Exts.count("zcb") != 0)
826 return getIncompatibleError("xwchc", "zcb");
827 }
828
829 if (Exts.count("zclsd") != 0 && Exts.count("zcf") != 0)
830 return getIncompatibleError("zclsd", "zcf");
831
832 if (Exts.count("y") != 0) {
833 if (XLen == 32) {
834 // On RV32Y systems the zclsd/zcf encodings are used for y load/stores.
835 if (Exts.count("zclsd") != 0)
836 return getBaseIncompatibleError("zclsd", "rv32y");
837 if (Exts.count("zcf") != 0)
838 return getBaseIncompatibleError("zcf", "rv32y");
839 } else {
840 // On RV64Y systems the zcd encodings are used for y load/stores.
841 if (Exts.count("zcd") != 0)
842 return getBaseIncompatibleError("zcd", "rv64y");
843 for (auto Ext : ZcdOverlaps)
844 if (Exts.count(Ext))
845 return getBaseIncompatibleError(Ext, "rv64y");
846 }
847 }
848
849 if (HasZcmp && HasXqccmp)
850 return getIncompatibleError("zcmp", "xqccmp");
851
852 if (HasZcmt && HasXqccmt)
853 return getIncompatibleError("zcmt", "xqccmt");
854
855 return Error::success();
856}
857
861
862 StringRef name() const { return ExtensionStrings[NameOff]; }
863 StringRef impliedExt() const { return ExtensionStrings[ImpliedOff]; }
864
865 bool operator<(const ImpliedExtsEntry &Other) const {
866 return name() < Other.name();
867 }
868};
869
871 return LHS.name() < RHS;
872}
873
875 return LHS < RHS.name();
876}
877
878#define GET_IMPLIED_EXTENSIONS
879#include "llvm/TargetParser/RISCVTargetParserDef.inc"
880
881void RISCVISAInfo::updateImplication() {
882 assert(llvm::is_sorted(ImpliedExts) && "Table not sorted by Name");
883
884 // This loop may execute over 1 iteration since implication can be layered
885 // Exits loop if no more implication is applied
887 for (auto const &Ext : Exts)
888 WorkList.push_back(Ext.first);
889
890 while (!WorkList.empty()) {
891 StringRef ExtName = WorkList.pop_back_val();
892 auto Range = std::equal_range(std::begin(ImpliedExts),
893 std::end(ImpliedExts), ExtName);
894 for (const ImpliedExtsEntry &Implied : llvm::make_range(Range)) {
895 StringRef ImpliedExt = Implied.impliedExt();
896 auto [It, Inserted] = Exts.try_emplace(ImpliedExt.str());
897 if (!Inserted)
898 continue;
899 auto Version = findDefaultVersion(ImpliedExt);
900 It->second = *Version;
901 WorkList.push_back(ImpliedExt);
902 }
903 }
904
905 // Add Zcd if C and D are enabled and we aren't targeting 64-bit RVY.
906 if (Exts.count("c") && Exts.count("d") && !Exts.count("zcd") &&
907 (XLen == 32 || !Exts.count("y"))) {
908 auto Version = findDefaultVersion("zcd");
909 Exts["zcd"] = *Version;
910 }
911
912 // Add Zcf if C and F are enabled on RV32 and Y is not enabled.
913 if (XLen == 32 && Exts.count("c") && Exts.count("f") && !Exts.count("zcf") &&
914 !Exts.count("y")) {
915 auto Version = findDefaultVersion("zcf");
916 Exts["zcf"] = *Version;
917 }
918
919 // Add Zcf if Zce and F are enabled on RV32 and Y is not enabled.
920 if (XLen == 32 && Exts.count("zce") && Exts.count("f") &&
921 !Exts.count("zcf") && !Exts.count("y")) {
922 auto Version = findDefaultVersion("zcf");
923 Exts["zcf"] = *Version;
924 }
925
926 // Add C if Zca is enabled and the conditions are met.
927 // This follows the RISC-V spec rules for MISA.C and matches GCC behavior
928 // (PR119122). The rule is:
929 // For RV32:
930 // - No F and no D: Zca alone implies C
931 // - F but no D: Zca + Zcf implies C
932 // - F and D: Zca + Zcf + Zcd implies C
933 // For RV64:
934 // - No D: Zca alone implies C
935 // - D: Zca + Zcd implies C
936 // For RV32Y (Zcf incompatible):
937 // - No D (but maybe F): Zca alone implies C
938 // - F and D: Zca + Zcd implies C
939 // For RV64Y (Zcf and Zcd incompatible):
940 // - Zca alone implies C
941 if (Exts.count("zca") && !Exts.count("c")) {
942 bool ShouldAddC = false;
943 if (XLen == 32) {
944 if (Exts.count("d"))
945 ShouldAddC =
946 Exts.count("zcd") && (Exts.count("y") || Exts.count("zcf"));
947 else if (Exts.count("f"))
948 ShouldAddC = Exts.count("y") || Exts.count("zcf");
949 else
950 ShouldAddC = true;
951 } else if (XLen == 64) {
952 if (Exts.count("d"))
953 ShouldAddC = Exts.count("y") || Exts.count("zcd");
954 else
955 ShouldAddC = true;
956 }
957 if (ShouldAddC) {
958 auto Version = findDefaultVersion("c");
959 Exts["c"] = *Version;
960 }
961 }
962
963 if (!Exts.count("zce") && Exts.count("zca") && Exts.count("zcb") &&
964 Exts.count("zcmp") && Exts.count("zcmt")) {
965 bool ShouldAddZce = false;
966 if (XLen == 32) {
967 ShouldAddZce = !Exts.count("f") || Exts.count("zcf") || Exts.count("y");
968 } else if (XLen == 64) {
969 // Zce is incompatible with RV64Y, only add it if Y is not enabled.
970 ShouldAddZce = !Exts.count("y");
971 }
972 if (ShouldAddZce)
973 Exts["zce"] = *findDefaultVersion("zce");
974 }
975
976 // Handle I/E after implications have been resolved, in case either
977 // of them was implied by another extension.
978 bool HasE = Exts.count("e") != 0;
979 bool HasI = Exts.count("i") != 0;
980
981 // If not in e extension and i extension does not exist, i extension is
982 // implied
983 if (!HasE && !HasI) {
984 auto Version = findDefaultVersion("i");
985 Exts["i"] = *Version;
986 }
987
988 if (HasE && HasI)
989 Exts.erase("i");
990}
991
992static constexpr StringLiteral CombineIntoExts[] = {
993 {"a"}, {"b"}, {"zk"}, {"zkn"}, {"zks"},
994 {"zvkn"}, {"zvknc"}, {"zvkng"}, {"zvks"}, {"zvksc"},
995 {"zvksg"}, {"xqci"}, {"xsfmm32a"},
996};
997
998void RISCVISAInfo::updateCombination() {
999 bool MadeChange = false;
1000 do {
1001 MadeChange = false;
1002 for (StringRef CombineExt : CombineIntoExts) {
1003 if (Exts.count(CombineExt))
1004 continue;
1005
1006 // Look up the extension in the ImpliesExt table to find everything it
1007 // depends on.
1008 auto Range = std::equal_range(std::begin(ImpliedExts),
1009 std::end(ImpliedExts), CombineExt);
1010 bool HasAllRequiredFeatures = std::all_of(
1011 Range.first, Range.second, [&](const ImpliedExtsEntry &Implied) {
1012 return Exts.count(Implied.impliedExt());
1013 });
1014 if (HasAllRequiredFeatures) {
1015 auto Version = findDefaultVersion(CombineExt);
1016 Exts[CombineExt.str()] = *Version;
1017 MadeChange = true;
1018 }
1019 }
1020 } while (MadeChange);
1021}
1022
1023void RISCVISAInfo::updateImpliedLengths() {
1024 assert(FLen == 0 && MaxELenFp == 0 && MaxELen == 0 && MinVLen == 0 &&
1025 "Expected lengths to be initialied to zero");
1026
1027 if (Exts.count("q"))
1028 FLen = 128;
1029 else if (Exts.count("d"))
1030 FLen = 64;
1031 else if (Exts.count("f"))
1032 FLen = 32;
1033
1034 if (Exts.count("v")) {
1035 MaxELenFp = std::max(MaxELenFp, 64u);
1036 MaxELen = std::max(MaxELen, 64u);
1037 }
1038
1039 for (auto const &Ext : Exts) {
1040 StringRef ExtName = Ext.first;
1041 // Infer MaxELen and MaxELenFp from Zve(32/64)(x/f/d)
1042 if (ExtName.consume_front("zve")) {
1043 unsigned ZveELen;
1044 if (ExtName.consumeInteger(10, ZveELen))
1045 continue;
1046
1047 if (ExtName == "f")
1048 MaxELenFp = std::max(MaxELenFp, 32u);
1049 else if (ExtName == "d")
1050 MaxELenFp = std::max(MaxELenFp, 64u);
1051 else if (ExtName != "x")
1052 continue;
1053
1054 MaxELen = std::max(MaxELen, ZveELen);
1055 continue;
1056 }
1057
1058 // Infer MinVLen from zvl*b.
1059 if (ExtName.consume_front("zvl")) {
1060 unsigned ZvlLen;
1061 if (ExtName.consumeInteger(10, ZvlLen))
1062 continue;
1063
1064 if (ExtName != "b")
1065 continue;
1066
1067 MinVLen = std::max(MinVLen, ZvlLen);
1068 continue;
1069 }
1070 }
1071}
1072
1073std::string RISCVISAInfo::toString() const {
1074 std::string Buffer;
1075 raw_string_ostream Arch(Buffer);
1076
1077 Arch << "rv" << XLen;
1078
1079 bool HasY = Exts.count("y") != 0;
1080 ListSeparator LS("_");
1081 for (auto const &Ext : Exts) {
1082 StringRef ExtName = Ext.first;
1083 if (HasY) {
1084 // Plain 'y' always implies 'i' (which is omitted in the normalized arch
1085 // string). Y+E requires a long base name arch string.
1086 if (ExtName == "i")
1087 continue;
1088 if (ExtName == "e")
1089 reportFatalUsageError("Y+E is not supported yet");
1090 }
1091 auto ExtInfo = Ext.second;
1092 Arch << LS << ExtName;
1093 Arch << ExtInfo.Major << "p" << ExtInfo.Minor;
1094 }
1095
1096 return Arch.str();
1097}
1098
1100RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
1101 ISAInfo->updateImplication();
1102 ISAInfo->updateCombination();
1103 ISAInfo->updateImpliedLengths();
1104
1105 if (Error Result = ISAInfo->checkDependency())
1106 return std::move(Result);
1107 return std::move(ISAInfo);
1108}
1109
1111 bool HasY = Exts.count("y") != 0;
1112 if (XLen == 32) {
1113 if (Exts.count("xcheriot"))
1114 return "cheriot";
1115 if (Exts.count("e"))
1116 return HasY ? "il32pc64e" : "ilp32e";
1117 if (Exts.count("d"))
1118 return HasY ? "il32pc64d" : "ilp32d";
1119 if (Exts.count("f"))
1120 return HasY ? "il32pc64f" : "ilp32f";
1121 return HasY ? "il32pc64" : "ilp32";
1122 } else if (XLen == 64) {
1123 // RV64E has no capability ABI (yet).
1124 if (Exts.count("e"))
1125 return "lp64e";
1126 if (Exts.count("d"))
1127 return HasY ? "l64pc128d" : "lp64d";
1128 if (Exts.count("f"))
1129 return HasY ? "l64pc128f" : "lp64f";
1130 return HasY ? "l64pc128" : "lp64";
1131 }
1132 llvm_unreachable("Invalid XLEN");
1133}
1134
1136 if (Ext.empty())
1137 return false;
1138
1139 auto Pos = findLastNonVersionCharacter(Ext) + 1;
1140 StringRef Name = Ext.substr(0, Pos);
1141 StringRef Vers = Ext.substr(Pos);
1142 if (Vers.empty())
1143 return false;
1144
1145 unsigned Major, Minor, ConsumeLength;
1146 if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
1147 true, true)) {
1148 consumeError(std::move(E));
1149 return false;
1150 }
1151
1152 return true;
1153}
1154
1156 if (Ext.empty())
1157 return std::string();
1158
1159 auto Pos = findLastNonVersionCharacter(Ext) + 1;
1160 StringRef Name = Ext.substr(0, Pos);
1161
1162 if (Pos != Ext.size() && !isSupportedExtensionWithVersion(Ext))
1163 return std::string();
1164
1165 if (!isSupportedExtension(Name))
1166 return std::string();
1167
1168 return isExperimentalExtension(Name) ? "experimental-" + Name.str()
1169 : Name.str();
1170}
1171
1177
1178#define GET_RISCVExtensionBitmaskTable_IMPL
1179#include "llvm/TargetParser/RISCVTargetParserDef.inc"
1180
1182 // Note that this code currently accepts mixed case extension names, but
1183 // does not handle extension versions at all. That's probably fine because
1184 // there's only one extension version in the __riscv_feature_bits vector.
1185 for (auto E : ExtensionBitmask)
1186 if (Ext.equals_insensitive(ExtensionStrings[E.NameOff]))
1187 return std::make_pair(E.GroupID, E.BitPosition);
1188 return std::make_pair(-1, -1);
1189}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define _
#define I(x, y, z)
Definition MD5.cpp:57
Load MIR Sample Profile
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define P(N)
static void verifyTables()
static StringRef getExtensionTypeDesc(StringRef Ext)
static const char * RISCVGImplicationsZi[]
static std::optional< RISCVISAUtils::ExtensionVersion > findDefaultVersion(StringRef ExtName)
static size_t findLastNonVersionCharacter(StringRef Ext)
static Error getExtensionRequiresError(StringRef Ext, StringRef ReqExt)
static StringRef getExtensionType(StringRef Ext)
static Error getErrorForInvalidExt(StringRef ExtName)
static constexpr StringLiteral CombineIntoExts[]
static bool stripExperimentalPrefix(StringRef &Ext)
static std::optional< RISCVISAUtils::ExtensionVersion > isExperimentalExtension(StringRef Ext)
static void PrintExtension(StringRef Name, StringRef Version, StringRef Description)
static Error getBaseIncompatibleError(StringRef Ext, StringRef Base)
static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major, unsigned &Minor, unsigned &ConsumeLength, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck)
static Error getIncompatibleError(StringRef Ext1, StringRef Ext2)
static Error getError(const Twine &Message)
static const char * RISCVGImplications[]
This file contains some templates that are useful if you are working with the STL at all.
static const char * name
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file contains some functions that are useful when dealing with strings.
static void verifyTables()
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
A helper class to return the specified delimiter string after the first invocation of operator String...
static LLVM_ABI bool isSupportedExtensionFeature(StringRef Ext)
static LLVM_ABI std::string getTargetFeatureForExtension(StringRef Ext)
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseNormalizedArchString(StringRef Arch)
Parse RISC-V ISA info from an arch string that is already in normalized form (as defined in the psABI...
LLVM_ABI bool hasExtension(StringRef Ext) const
RISCVISAInfo(const RISCVISAInfo &)=delete
LLVM_ABI std::string toString() const
LLVM_ABI StringRef computeDefaultABI() const
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.
static LLVM_ABI bool isSupportedExtension(StringRef Ext)
static LLVM_ABI void printEnabledExtensions(bool IsRV64, std::set< StringRef > &EnabledFeatureNames, StringMap< StringRef > &DescMap)
static LLVM_ABI void printSupportedExtensions(StringMap< StringRef > &DescMap)
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatures(unsigned XLen, const std::vector< std::string > &Features)
Parse RISC-V ISA info from feature vector.
static LLVM_ABI std::pair< int, int > getRISCVFeaturesBitsInfo(StringRef Ext)
Return the group id and bit position of __riscv_feature_bits.
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > createFromExtMap(unsigned XLen, const RISCVISAUtils::OrderedExtensionMap &Exts)
LLVM_ABI std::vector< std::string > toFeatures(bool AddAllExtensions=false, bool IgnoreUnknown=true) const
Convert RISC-V ISA info to a feature vector.
static LLVM_ABI bool isSupportedExtensionWithVersion(StringRef Ext)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:880
bool empty() const
Definition StringMap.h:103
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
Definition StringRef.h:511
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition StringRef.h:482
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:627
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition StringRef.h:712
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
char front() const
Get the first character in the string.
Definition StringRef.h:147
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition StringRef.h:598
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
size_t count(char C) const
Return the number of occurrences of C in the string.
Definition StringRef.h:463
std::pair< StringRef, StringRef > rsplit(StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.
Definition StringRef.h:761
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:653
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Definition StringRef.h:170
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr StringLiteral AllStdExts
std::map< std::string, ExtensionVersion, ExtensionComparator > OrderedExtensionMap
OrderedExtensionMap is std::map, it's specialized to keep entries in canonical order of extension.
static constexpr uint64_t DefaultVersion
Definition SampleProf.h:127
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
bool isLower(char C)
Checks if character C is a lowercase letter as classified by "C" locale.
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::string utostr(uint64_t X, bool isNeg=false)
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2081
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
Op::Description Desc
@ invalid_argument
Definition Errc.h:56
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1986
@ Other
Any other memory.
Definition ModRef.h:68
FormattedString left_justify(StringRef Str, unsigned Width)
left_justify - append spaces after string so total output is Width characters.
Definition Format.h:123
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2068
@ Add
Sum of integers.
ArrayRef(const T &OneElt) -> ArrayRef< T >
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
StringTable::Offset ImpliedOff
StringTable::Offset NameOff
bool operator<(const ImpliedExtsEntry &Other) const
StringRef name() const
StringRef impliedExt() const
StringTable::Offset NameOff
Represents the major and version number components of a RISC-V extension.