-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV]Add support for resolving encoding conflicts among vendor spec…
…ific CSRs This patch adds the framework for resolving encoding conflicts among CSRs. Specifically, this patch adds a support for emitting a new lookup function for the primary key which return a pair of iterators pointing to first and last value hence giving a range of values which satisfies the query. While printing the CSR name during objdump, iterate over the range and print the name of only that CSR which satisifes the feature requirement of subtarget. Below is the signature of the new function that will be emitted for primary key: ``` std::pair<const SysReg *, const SysReg *>lookupSysRegByEncoding(uint16_t Encoding) { SysReg Key; Key.Encoding = Encoding; auto Table = ArrayRef(SysRegsList); auto It = std::equal_range(Table.begin(), Table.end(), Key, [](const SysReg &LHS, const SysReg &RHS) { if (LHS.Encoding < RHS.Encoding) return true; if (LHS.Encoding > RHS.Encoding) return false; return false; }); auto Idx = It.first; if (Idx == Table.end() || Key.Encoding != Idx->Encoding) return {nullptr, nullptr}; return It; ```
- Loading branch information
1 parent
e258bb3
commit bc106a0
Showing
4 changed files
with
229 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s | ||
|
||
include "llvm/TableGen/SearchableTable.td" | ||
|
||
class SysReg<string name, bits<12> op> { | ||
string Name = name; | ||
bits<12> Encoding = op; | ||
code FeaturesRequired = [{ {} }]; | ||
} | ||
|
||
def List1 : GenericTable { | ||
let FilterClass = "SysReg"; | ||
let Fields = [ | ||
"Name", "Encoding", "FeaturesRequired", | ||
]; | ||
|
||
let PrimaryKey = [ "Encoding" ]; | ||
let PrimaryKeyName = "lookupSysRegByEncoding"; | ||
let PrimaryKeyReturnRange = true; | ||
} | ||
|
||
|
||
let FeaturesRequired = [{ {Feature1} }] in { | ||
def : SysReg<"csr1", 0x7C9>; | ||
} | ||
|
||
let FeaturesRequired = [{ {Feature2} }] in { | ||
def : SysReg<"csr2", 0x7C9>; | ||
} | ||
|
||
// CHECK: #ifdef GET_List1_DECL | ||
// CHECK-NEXT: std::pair<const SysReg *, const SysReg *>lookupSysRegByEncoding(uint16_t Encoding); | ||
// CHECK-NEXT: #endif | ||
|
||
// CHECK: #ifdef GET_List1_IMPL | ||
// CHECK-NEXT: constexpr SysReg List1[] = { | ||
// CHECK-NEXT: { "csr1", 0x7C9, {Feature1} }, // 0 | ||
// CHECK-NEXT: { "csr2", 0x7C9, {Feature2} }, // 1 | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: std::pair<const SysReg *, const SysReg *>lookupSysRegByEncoding(uint16_t Encoding) { | ||
// CHECK-NEXT: SysReg Key; | ||
// CHECK-NEXT: Key.Encoding = Encoding; | ||
// CHECK-NEXT: auto Table = ArrayRef(List1); | ||
// CHECK-NEXT: auto It = std::equal_range(Table.begin(), Table.end(), Key, | ||
// CHECK-NEXT: [](const SysReg &LHS, const SysReg &RHS) { | ||
// CHECK-NEXT: if (LHS.Encoding < RHS.Encoding) | ||
// CHECK-NEXT: return true; | ||
// CHECK-NEXT: if (LHS.Encoding > RHS.Encoding) | ||
// CHECK-NEXT: return false; | ||
// CHECK-NEXT: return false; | ||
// CHECK-NEXT: }); | ||
// CHECK: auto Idx = It.first; | ||
// CHECK-NEXT: if (Idx == Table.end() || | ||
// CHECK-NEXT: Key.Encoding != Idx->Encoding) | ||
// CHECK-NEXT: return {nullptr, nullptr}; | ||
|
||
// CHECK: return It; | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: #endif | ||
|
||
def List2 : GenericTable { | ||
let FilterClass = "SysReg"; | ||
let Fields = [ | ||
"Name", "Encoding", "FeaturesRequired", | ||
]; | ||
} | ||
|
||
def lookupSysRegByName : SearchIndex { | ||
let Table = List2; | ||
let Key = [ "Name" ]; | ||
let ReturnRange = true; | ||
} | ||
|
||
// CHECK: #ifdef GET_List2_DECL | ||
// CHECK-NEXT: std::pair<const SysReg *, const SysReg *>lookupSysRegByName(StringRef Name); | ||
// CHECK-NEXT: #endif | ||
|
||
// CHECK: #ifdef GET_List2_IMPL | ||
// CHECK-NEXT: constexpr SysReg List2[] = { | ||
// CHECK-NEXT: { "csr1", 0x7C9, {Feature1} }, // 0 | ||
// CHECK-NEXT: { "csr2", 0x7C9, {Feature2} }, // 1 | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: std::pair<const SysReg *, const SysReg *>lookupSysRegByName(StringRef Name) { | ||
// CHECK-NEXT: struct IndexType { | ||
// CHECK-NEXT: const char * Name; | ||
// CHECK-NEXT: unsigned _index; | ||
// CHECK-NEXT: }; | ||
// CHECK-NEXT: static const struct IndexType Index[] = { | ||
// CHECK-NEXT: { "CSR1", 0 }, | ||
// CHECK-NEXT: { "CSR2", 1 }, | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: IndexType Key; | ||
// CHECK-NEXT: Key.Name = Name.upper(); | ||
// CHECK-NEXT: auto Table = ArrayRef(Index); | ||
// CHECK-NEXT: auto It = std::equal_range(Table.begin(), Table.end(), Key, | ||
// CHECK-NEXT: [](const IndexType &LHS, const IndexType &RHS) { | ||
// CHECK-NEXT: int CmpName = StringRef(LHS.Name).compare(RHS.Name); | ||
// CHECK-NEXT: if (CmpName < 0) return true; | ||
// CHECK-NEXT: if (CmpName > 0) return false; | ||
// CHECK-NEXT: return false; | ||
// CHECK-NEXT: }); | ||
|
||
// CHECK: auto Idx = It.first; | ||
// CHECK-NEXT: if (Idx == Table.end() || | ||
// CHECK-NEXT: Key.Name != Idx->Name) | ||
// CHECK-NEXT: return {nullptr, nullptr}; | ||
|
||
// CHECK: return It; | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: #endif | ||
|
||
// CHECK: #undef GET_List1_DECL | ||
// CHECK-NEXT: #undef GET_List1_IMPL | ||
// CHECK-NEXT: #undef GET_List2_DECL | ||
// CHECK-NEXT: #undef GET_List2_IMPL |
Oops, something went wrong.