-
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: ``` 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); } ``` NOTE: Emitting a different signature for returning a range of results is only supported by primary key.
- Loading branch information
1 parent
e258bb3
commit f19b276
Showing
3 changed files
with
194 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s | ||
// RUN: not llvm-tblgen -DERROR -gen-searchable-tables -I %p/../../include %s 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=ERROR %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", 0x7C0>; | ||
} | ||
|
||
let FeaturesRequired = [{ {Feature2} }] in { | ||
def : SysReg<"csr2", 0x7C0>; | ||
} | ||
|
||
def lookupSysRegByName : SearchIndex { | ||
let Table = List1; | ||
let Key = [ "Name" ]; | ||
#ifdef ERROR | ||
// ERROR: Emitting different signature for returning a range of results is only supported for Primary Key. | ||
let ReturnRange = true; | ||
#endif | ||
} | ||
|
||
// CHECK: #ifdef GET_List1_DECL | ||
// CHECK-NEXT: llvm::iterator_range<const SysReg *> lookupSysRegByEncoding(uint16_t Encoding); | ||
// CHECK-NEXT: onst SysReg *lookupSysRegByName(StringRef Name); | ||
// CHECK-NEXT: #endif | ||
|
||
// CHECK: #ifdef GET_List1_IMPL | ||
// CHECK-NEXT: constexpr SysReg List1[] = { | ||
// CHECK-NEXT: { "csr1", 0x7C0, {Feature1} }, // 0 | ||
// CHECK-NEXT: { "csr2", 0x7C0, {Feature2} }, // 1 | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: llvm::iterator_range<const SysReg *> lookupSysRegByEncoding(uint16_t Encoding) { | ||
// CHECK-NEXT: struct KeyType { | ||
// CHECK-NEXT: uint16_t Encoding; | ||
// CHECK-NEXT: }; | ||
// CHECK-NEXT: KeyType Key = {Encoding}; | ||
// CHECK-NEXT: struct Comp { | ||
// CHECK-NEXT: bool operator()(const SysReg &LHS, const KeyType &RHS) const { | ||
// 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-NEXT: bool operator()(const KeyType &LHS, const SysReg &RHS) const { | ||
// 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-NEXT: }; | ||
// CHECK-NEXT: auto Table = ArrayRef(List1); | ||
// CHECK-NEXT: auto It = std::equal_range(Table.begin(), Table.end(), Key, Comp()); | ||
// CHECK-NEXT: return llvm::make_range(It.first, It.second); | ||
// CHECK-NEXT: } | ||
|
||
// CHECK: 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: struct KeyType { | ||
// CHECK-NEXT: std::string Name; | ||
// CHECK-NEXT: }; | ||
// CHECK-NEXT: KeyType Key = {Name.upper()}; | ||
// CHECK-NEXT: struct Comp { | ||
// CHECK-NEXT: bool operator()(const IndexType &LHS, const KeyType &RHS) const { | ||
// 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-NEXT: }; | ||
// CHECK-NEXT: auto Table = ArrayRef(Index); | ||
// CHECK-NEXT: auto Idx = std::lower_bound(Table.begin(), Table.end(), Key, Comp()); | ||
// CHECK-NEXT: if (Idx == Table.end() || | ||
// CHECK-NEXT: Key.Name != Idx->Name) | ||
// CHECK-NEXT: return nullptr; | ||
|
||
// CHECK: return &List1[Idx->_index]; | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: #endif |
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