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

Garvit Gupta via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 12:18:31 PDT 2024


================
@@ -426,16 +428,25 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
     OS << "    return nullptr;\n\n";
   }
 
-  OS << "  struct KeyType {\n";
-  for (const auto &Field : Index.Fields) {
-    OS << "    " << searchableFieldType(Table, Index, Field, TypeInTempStruct)
-       << " " << Field.Name << ";\n";
+  bool ShouldReturnRange = Index.ReturnRange;
+  if (ShouldReturnRange)
----------------
quic-garvgupt wrote:

I understand that this will simplify the code changes for generating the key, however we would still need to use equal_range instead of lower_bound to return a range of answers like below. Do let me know if this is what you were expecting
```
llvm::iterator_range<const SysReg *> lookupSysRegByEncoding(uint16_t Encoding) {
  struct KeyType {
    uint16_t Encoding;
  };
  KeyType Key = {Encoding};
  struct Comp {
    bool operator()(const SysReg &LHS, const KeyType &RHS) const {
      if (LHS.Encoding < RHS.Encoding)
        return true;
      if (LHS.Encoding > RHS.Encoding)
        return false;
      return false;
    }
    bool operator()(const KeyType &LHS, const SysReg &RHS) const {
      if (LHS.Encoding < RHS.Encoding)
        return true;
      if (LHS.Encoding > RHS.Encoding)
        return false;
      return false;
    }
  };
  auto Table = ArrayRef(SysRegsList);
  auto It = std::equal_range(Table.begin(), Table.end(), Key, Comp());
  return llvm::make_range(It.first, It.second);
}
```


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


More information about the llvm-commits mailing list