Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Fix bug in GCT Taps XMRs #3415

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions lib/Dialect/FIRRTL/Transforms/GrandCentralTaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,14 @@ void GrandCentralTapsPass::runOnOperation() {
<< " - Shortest prefix " << *shortestPrefix << "\n");

// Determine the module at which the hierarchical name should start.
Operation *opInRootModule =
shortestPrefix->empty() ? path.front() : shortestPrefix->front();
auto rootModule = opInRootModule->getParentOfType<FModuleLike>();
FModuleLike rootModule;
if (shortestPrefix->empty()) {
if (port.target.hasPort())
rootModule = cast<FModuleLike>(port.target.getOp());
else
rootModule = port.target.getOp()->getParentOfType<FModuleLike>();
} else
rootModule = shortestPrefix->front()->getParentOfType<FModuleLike>();

SmallVector<Attribute> symbols;
SmallString<128> hname;
Expand All @@ -847,36 +852,18 @@ void GrandCentralTapsPass::runOnOperation() {
// Concatenate the prefix into a proper full hierarchical name.
addSymbol(
FlatSymbolRefAttr::get(SymbolTable::getSymbolName(rootModule)));
if (port.nla && shortestPrefix->empty() &&
port.nla.root() != rootModule.moduleNameAttr()) {
// This handles the case when nla is not considered for common prefix
// stripping.
auto rootMod = port.nla.root();
for (auto p : path) {
if (rootMod == p->getParentOfType<FModuleOp>().getNameAttr())
break;
addSymbol(getInnerRefTo(p));
}
}
Comment on lines -850 to -860
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code was surprisingly not covered by existing tests after 43035e7. The logic that merged NLA path with the computed instance paths made this unreachable (for the tests we had).

for (auto inst : shortestPrefix.getValue())
addSymbol(getInnerRefTo(inst));
if (port.nla) {
auto namepath = port.nla.namepath();
Attribute leaf = namepath.getValue().back();
if (!leaf.isa<InnerRefAttr>()) {
if (port.target.hasPort())
leaf = getInnerRefTo(port.target.getOp(), port.target.getPort());
else
leaf = getInnerRefTo(port.target.getOp());
}
addSymbol(leaf);
} else if (port.target.getOp()) {

if (port.target.getOp()) {
Attribute leaf;
if (port.target.hasPort())
addSymbol(
getInnerRefTo(port.target.getOp(), port.target.getPort()));
leaf = getInnerRefTo(port.target.getOp(), port.target.getPort());
else
addSymbol(getInnerRefTo(port.target.getOp()));
leaf = getInnerRefTo(port.target.getOp());
addSymbol(leaf);
}

if (!port.suffix.empty()) {
hname += '.';
hname += port.suffix;
Expand Down
121 changes: 121 additions & 0 deletions test/Dialect/FIRRTL/SFCTests/data-taps-nlas.fir
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,124 @@ circuit TestHarness : %[[
; CHECK: module DataTap
; CHECK-NOT: endmodule
; CHECK: assign _0 = Top.test.signal;

; // -----

circuit Top : %[[
{
"class":"sifive.enterprise.grandcentral.DataTapsAnnotation",
"blackBox":"~Top|DataTap_Submodule",
"keys":[
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT/submodule:Submodule>wire_Submodule",
"portName":"~Top|DataTap_Submodule>_0"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT>wire_DUT",
"portName":"~Top|DataTap_Submodule>_1"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top>wire_Top",
"portName":"~Top|DataTap_Submodule>_2"
}
]
},
{
"class":"sifive.enterprise.grandcentral.DataTapsAnnotation",
"blackBox":"~Top|DataTap_DUT",
"keys":[
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT/submodule:Submodule>wire_Submodule",
"portName":"~Top|DataTap_DUT>_0"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT>wire_DUT",
"portName":"~Top|DataTap_DUT>_1"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top>wire_Top",
"portName":"~Top|DataTap_DUT>_2"
}
]
},
{
"class":"sifive.enterprise.grandcentral.DataTapsAnnotation",
"blackBox":"~Top|DataTap_Top",
"keys":[
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT/submodule:Submodule>wire_Submodule",
"portName":"~Top|DataTap_Top>_0"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top/dut:DUT>wire_DUT",
"portName":"~Top|DataTap_Top>_1"
},
{
"class":"sifive.enterprise.grandcentral.ReferenceDataTapKey",
"source":"~Top|Top>wire_Top",
"portName":"~Top|DataTap_Top>_2"
}
]
}
]]
extmodule DataTap_Submodule :
output _0 : UInt<1>
output _1 : UInt<1>
output _2 : UInt<1>

extmodule DataTap_DUT :
output _0 : UInt<1>
output _1 : UInt<1>
output _2 : UInt<1>

extmodule DataTap_Top :
output _0 : UInt<1>
output _1 : UInt<1>
output _2 : UInt<1>

module Submodule :

wire wire_Submodule: UInt<1>
wire_Submodule is invalid

inst tap of DataTap_Submodule

module DUT :

wire wire_DUT: UInt<1>
wire_DUT is invalid

inst submodule of Submodule

inst tap of DataTap_DUT

module Top :

wire wire_Top: UInt<1>
wire_Top is invalid

inst dut of DUT
inst tap of DataTap_Top

; CHECK: module DataTap_Submodule
; CHECK: assign _0 = Submodule.wire_Submodule
; CHECK-NEXT: assign _1 = DUT.wire_DUT
; CHECK-NEXT: assign _2 = Top.wire_Top

; CHECK: module DataTap_DUT
; CHECK: assign _0 = DUT.submodule.wire_Submodule
; CHECK-NEXT: assign _1 = DUT.wire_DUT
; CHECK-NEXT: assign _2 = Top.wire_Top

; CHECK: module DataTap_Top
; CHECK: assign _0 = Top.dut.submodule.wire_Submodule
; CHECK-NEXT: assign _1 = Top.dut.wire_DUT
; CHECK-NEXT: assign _2 = Top.wire_Top