[llvm] df44aaa - [RISCV] Add a table for extension implications.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 14 09:30:18 PST 2021


Author: Craig Topper
Date: 2021-12-14T09:30:13-08:00
New Revision: df44aaa50e3632f3528850278bdec1c4a45890b1

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

LOG: [RISCV] Add a table for extension implications.

This a proof of concept for a suggestion I proposed in D108694.

Reviewed By: eopXD

Differential Revision: https://reviews.llvm.org/D115668

Added: 
    

Modified: 
    llvm/lib/Support/RISCVISAInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index 378e6644d0d72..bce6ea63870de 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -695,11 +695,28 @@ Error RISCVISAInfo::checkDependency() {
   return Error::success();
 }
 
+static const char *ImpliedExtsV[] = {"zvlsseg"};
+static const char *ImpliedExtsZfh[] = {"zfhmin"};
+
+struct ImpliedExtsEntry {
+  StringLiteral Name;
+  ArrayRef<const char *> Exts;
+
+  bool operator<(const ImpliedExtsEntry &Other) const {
+    return Name < Other.Name;
+  }
+
+  bool operator<(StringRef Other) const { return Name < Other; }
+};
+
+static constexpr ImpliedExtsEntry ImpliedExts[] = {
+    {"v", ImpliedExtsV},
+    {"zfh", ImpliedExtsZfh},
+};
+
 void RISCVISAInfo::updateImplication() {
   bool HasE = Exts.count("e") == 1;
   bool HasI = Exts.count("i") == 1;
-  bool HasV = Exts.count("v") == 1;
-  bool HasZfh = Exts.count("zfh") == 1;
 
   // If not in e extension and i extension does not exist, i extension is
   // implied
@@ -708,14 +725,15 @@ void RISCVISAInfo::updateImplication() {
     addExtension("i", Version->Major, Version->Minor);
   }
 
-  if (HasV) {
-    auto Version = findDefaultVersion("zvlsseg");
-    addExtension("zvlsseg", Version->Major, Version->Minor);
-  }
-
-  if (HasZfh) {
-    auto Version = findDefaultVersion("zfhmin");
-    addExtension("zfhmin", Version->Major, Version->Minor);
+  assert(llvm::is_sorted(ImpliedExts) && "Table not sorted by Name");
+  for (auto &Ext : Exts) {
+    auto I = llvm::lower_bound(ImpliedExts, Ext.first);
+    if (I != std::end(ImpliedExts) && I->Name == Ext.first) {
+      for (auto &ImpliedExt : I->Exts) {
+        auto Version = findDefaultVersion(ImpliedExt);
+        addExtension(ImpliedExt, Version->Major, Version->Minor);
+      }
+    }
   }
 }
 


        


More information about the llvm-commits mailing list