[llvm] [RISCV]Add support for resolving encoding conflicts among vendor specific CSRs (PR #96174)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 05:23:48 PDT 2024


================
@@ -478,25 +500,34 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
   OS << "      return false;\n";
   OS << "    });\n\n";
 
-  OS << "  if (Idx == Table.end()";
-
-  for (const auto &Field : Index.Fields)
-    OS << " ||\n      Key." << Field.Name << " != Idx->" << Field.Name;
-  OS << ")\n    return nullptr;\n";
+  if (!ShouldReturnRange) {
+    OS << "  if (Idx == Table.end()";
+    for (const auto &Field : Index.Fields)
+      OS << " ||\n      Key." << Field.Name << " != Idx->" << Field.Name;
+  }
 
-  if (IsPrimary)
+  if (ShouldReturnRange)
+    OS << "  return llvm::make_range(It.first, It.second);\n";
+  else if (IsPrimary) {
+    OS << ")\n    return nullptr;\n\n";
     OS << "  return &*Idx;\n";
-  else
+  } else {
+    OS << ")\n    return nullptr;\n\n";
     OS << "  return &" << Table.Name << "[Idx->_index];\n";
+  }
 
   OS << "}\n";
 }
 
 void SearchableTableEmitter::emitLookupDeclaration(const GenericTable &Table,
                                                    const SearchIndex &Index,
+                                                   bool ShouldReturnRange,
                                                    raw_ostream &OS) {
-  OS << "const " << Table.CppTypeName << " *" << Index.Name << "(";
-
+  if (ShouldReturnRange)
+    OS << "llvm::iterator_range<const " << Table.CppTypeName << " *>";
----------------
jrtc27 wrote:

```suggestion
    OS << "llvm::iterator_range<const " << Table.CppTypeName << " *> ";
```

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


More information about the llvm-commits mailing list