You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[RISCV]Add support for resolving encoding conflicts among vendor specific CSRs
This patch adds the framework for resolving encoding conflicts among CSRs.
Specifically, this patch adds a support for emitting a second lookup function
for the primary key which takes an additional arguemnt `List` of type `std::vector`
and inside the function definition, will populate the `List` with all sysreg
that matches primary key.
While printing the CSR name during objdump, iterate over the `List` and print the
name of only that CSR which satisifes the feature requirement of subtarget.
Below are the signatures of the functions that are generated for primary key:
```
`const SysReg *lookupSysRegByEncoding(uint16_t Encoding);`
`void lookupSysRegByEncoding(uint16_t Encoding, std::vector<const SysReg*> &List);`
```
Below is the definition for the second primary function:
```
void lookupSysRegByEncoding(uint16_t Encoding, std::vector<const SysReg*> &List) {
struct KeyType {
uint16_t Encoding;
};
KeyType Key = {Encoding};
auto Table = ArrayRef(SysRegsList);
auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
[](const SysReg &LHS, const KeyType &RHS) {
if (LHS.Encoding < RHS.Encoding)
return true;
if (LHS.Encoding > RHS.Encoding)
return false;
return false;
});
if (Idx == Table.end() ||
Key.Encoding != Idx->Encoding)
return;
auto UpperBound = std::upper_bound(Table.begin(), Table.end(), Key,
[](const KeyType &LHS, const SysReg &RHS) {
if (LHS.Encoding < RHS.Encoding)
return true;
if (LHS.Encoding > RHS.Encoding)
return false;
return false;
});
while(Idx != UpperBound){
List.push_back(&SysRegsList[Idx - Table.begin()]);
Idx++;
}
}
```
Usage: CSRs with same encodings need to be under separate features.
Below is example illustrating the same-
```
let FeaturesRequired = [{ {Feature1} }] in {
def : SysReg<"csr1", 0x123>;
}
let FeaturesRequired = [{ {Feature2} }] in {
def : SysReg<"csr2", 0x123>;
}
```
0 commit comments