[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

Brandon Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 13 18:59:51 PDT 2024


================
@@ -854,6 +895,30 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
                              "string must be lowercase");
   }
 
+  bool IsProfile = Arch.starts_with("rvi") || Arch.starts_with("rva") ||
+                   Arch.starts_with("rvb") || Arch.starts_with("rvm");
+  std::string NewArch;
+  if (IsProfile) {
+    const auto *FoundProfile =
+        llvm::find_if(SupportedProfiles, [&](const RISCVProfile &Profile) {
+          return Arch.starts_with(Profile.Name);
+        });
+
+    if (FoundProfile == std::end(SupportedProfiles))
+      return createStringError(errc::invalid_argument, "unsupported profile");
+
+    NewArch = FoundProfile->MArch;
+    StringRef ArchWithoutProfile = Arch.substr(strlen(FoundProfile->Name));
+    if (!ArchWithoutProfile.empty()) {
+      if (!ArchWithoutProfile.starts_with("_"))
+        return createStringError(
+            errc::invalid_argument,
+            "additional extensions must be after separator '_'");
+      NewArch = NewArch + ArchWithoutProfile.str();
----------------
4vtomat wrote:

Maybe `NewArch += ArchWithoutProfile.str()` to reduce 1 redundant copy?

https://github.com/llvm/llvm-project/pull/76357


More information about the cfe-commits mailing list