[llvm] d489b7c - [RISCV] Merge some ISA error reporting together and make some errors more precise.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 00:22:40 PDT 2024


Author: Craig Topper
Date: 2024-08-19T00:22:28-07:00
New Revision: d489b7ccb7b43fe54dfb4b2884d7f1eb2cb5806e

URL: https://github.com/llvm/llvm-project/commit/d489b7ccb7b43fe54dfb4b2884d7f1eb2cb5806e
DIFF: https://github.com/llvm/llvm-project/commit/d489b7ccb7b43fe54dfb4b2884d7f1eb2cb5806e.diff

LOG: [RISCV] Merge some ISA error reporting together and make some errors more precise.

Loop over the extension names that have the same error message.

Print the name of Zvk* extensions instead of 'zvk*'.

Added: 
    

Modified: 
    llvm/lib/TargetParser/RISCVISAInfo.cpp
    llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 156ee0debab87b..e8d912486efc6b 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -739,31 +739,23 @@ Error RISCVISAInfo::checkDependency() {
     return getError("'f' and 'zfinx' extensions are incompatible");
 
   if (HasZvl && !HasVector)
-    return getError(
-        "'zvl*b' requires 'v' or 'zve*' extension to also be specified");
-
-  if (Exts.count("zvbb") && !HasVector)
-    return getError(
-        "'zvbb' requires 'v' or 'zve*' extension to also be specified");
-
-  if (Exts.count("zvbc") && !Exts.count("zve64x"))
-    return getError(
-        "'zvbc' requires 'v' or 'zve64*' extension to also be specified");
-
-  if (Exts.count("zvbc32e") && !Exts.count("zve32x"))
-    return getError(
-        "'zvbc32e' requires 'v' or 'zve*' extension to also be specified");
-
-  if ((Exts.count("zvkb") || Exts.count("zvkg") || Exts.count("zvkgs") ||
-       Exts.count("zvkned") || Exts.count("zvknha") || Exts.count("zvksed") ||
-       Exts.count("zvksh")) &&
-      !HasVector)
-    return getError(
-        "'zvk*' requires 'v' or 'zve*' extension to also be specified");
-
-  if (Exts.count("zvknhb") && !Exts.count("zve64x"))
-    return getError(
-        "'zvknhb' requires 'v' or 'zve64*' extension to also be specified");
+    return getError(Twine("'") + "zvl*b" +
+                    "' requires 'v' or 'zve*' extension to also be specified");
+
+  if (!HasVector)
+    for (auto Ext :
+         {"zvbb", "zvbc32e", "zvkb", "zvkg", "zvkgs", "zvkned", "zvknha", "zvksed", "zvksh"})
+      if (Exts.count(Ext))
+        return getError(
+            Twine("'") + Ext +
+            "' requires 'v' or 'zve*' extension to also be specified");
+
+  if (!Exts.count("zve64x"))
+    for (auto Ext : {"zvknhb", "zvbc"})
+      if (Exts.count(Ext))
+        return getError(
+            Twine("'") + Ext +
+            "' requires 'v' or 'zve64*' extension to also be specified");
 
   if ((HasZcmt || Exts.count("zcmp")) && HasD && (HasC || Exts.count("zcd")))
     return getError(Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
@@ -774,13 +766,12 @@ Error RISCVISAInfo::checkDependency() {
   if (XLen != 32 && Exts.count("zcf"))
     return getError("'zcf' is only supported for 'rv32'");
 
-  if (Exts.count("zacas") && !(Exts.count("a") || Exts.count("zaamo")))
-    return getError(
-        "'zacas' requires 'a' or 'zaamo' extension to also be specified");
-
-  if (Exts.count("zabha") && !(Exts.count("a") || Exts.count("zaamo")))
-    return getError(
-        "'zabha' requires 'a' or 'zaamo' extension to also be specified");
+  if (!(Exts.count("a") || Exts.count("zaamo")))
+    for (auto Ext : {"zacas", "zabha"})
+      if (Exts.count(Ext))
+        return getError(
+            Twine("'") + Ext +
+            "' requires 'a' or 'zaamo' extension to also be specified");
 
   if (Exts.count("xwchc") != 0) {
     if (XLen != 32)

diff  --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 4c5087b570fc93..0d6a354101a345 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -660,37 +660,37 @@ TEST(ParseArchString, MissingDepency) {
 
   for (StringRef Input : {"rv32i_zvkb"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvkb' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvkg"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvkg' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvkgs0p7"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvkg' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvkned"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvkned' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvknha"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvknha' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvksed"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvksed' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvksh"}) {
     EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-              "'zvk*' requires 'v' or 'zve*' extension to also be specified");
+              "'zvksh' requires 'v' or 'zve*' extension to also be specified");
   }
 
   for (StringRef Input : {"rv32i_zvknhb"}) {


        


More information about the llvm-commits mailing list