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][SFCCompat] Fix tests and handling of fullasyncreset on non-port. #6984

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions lib/Dialect/FIRRTL/Transforms/SFCCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@ void SFCCompatPass::runOnOperation() {
bool madeModifications = false;
SmallVector<InvalidValueOp> invalidOps;

bool fullAsyncResetExists = false;
AnnotationSet::removePortAnnotations(
auto fullAsyncResetAttr =
StringAttr::get(&getContext(), fullAsyncResetAnnoClass);
auto isFullAsyncResetAnno = [fullAsyncResetAttr](Annotation anno) {
return anno.getClassAttr() == fullAsyncResetAttr;
};
bool fullAsyncResetExists = AnnotationSet::removePortAnnotations(
getOperation(), [&](unsigned argNum, Annotation anno) {
if (!anno.isClass(fullAsyncResetAnnoClass))
return false;
return fullAsyncResetExists = true;
return isFullAsyncResetAnno(anno);
});
getOperation()->walk(
[isFullAsyncResetAnno, &fullAsyncResetExists](Operation *op) {
fullAsyncResetExists |=
AnnotationSet::removeAnnotations(op, isFullAsyncResetAnno);
});
madeModifications |= fullAsyncResetExists;

auto result = getOperation()->walk([&](Operation *op) {
// Populate invalidOps for later handling.
Expand Down
27 changes: 21 additions & 6 deletions test/firtool/async-reset-anno.fir
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
; RUN: firtool %s -parse-only | circt-opt -firrtl-infer-resets | FileCheck %s --check-prefix POST-INFER-RESETS
; RUN: firtool %s -parse-only | circt-opt -firrtl-infer-resets -firrtl-sfc-compat | FileCheck %s --implicit-check-not POST-SFC-COMPAT-NOT
; RUN: firtool %s -parse-only | circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-infer-resets))' | FileCheck %s --check-prefixes COMMON,POST-INFER-RESETS
; RUN: firtool %s -parse-only | circt-opt -pass-pipeline='builtin.module(firrtl.circuit(firrtl-infer-resets,firrtl.module(firrtl-sfc-compat)))' | FileCheck %s --check-prefixes COMMON,POST-SFC-COMPAT

; Check that FullAsyncResetAnnotation exists after infer-resets pass
; but is deleted after sfc-compat

FIRRTL version 3.3.0
circuit test :%[[{
"class":"sifive.enterprise.firrtl.FullAsyncResetAnnotation",
"target":"~test|test>reset"
}]]
circuit test :%[[
{ "class":"sifive.enterprise.firrtl.FullAsyncResetAnnotation",
"target":"~test|test>reset" },
{ "class":"sifive.enterprise.firrtl.FullAsyncResetAnnotation",
"target":"~test|foo>r" }
]]
; COMMON-LABEL: module @test
module test :
input clock : Clock
input reset : AsyncReset
Expand All @@ -17,3 +20,15 @@ circuit test :%[[{
input in : { foo : UInt<8>, bar : UInt<8>}
output out : { foo : UInt<8>, bar : UInt<8>}
connect out, in

; COMMON-LABEL: module private @foo
module foo :
input clock : Clock
input reset : AsyncReset
input in : { foo : UInt<8>, bar : UInt<8>}
output out : { foo : UInt<8>, bar : UInt<8>}

; POST-INFER-RESETS: [{class = "sifive.enterprise.firrtl.FullAsyncResetAnnotation"}]
; POST-SFC-COMPAT-NOT: [{class = "sifive.enterprise.firrtl.FullAsyncResetAnnotation"}]
wire r : AsyncReset
connect out, in
33 changes: 32 additions & 1 deletion test/firtool/async-reset.fir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; RUN: firtool %s | FileCheck %s
; RUN: firtool --split-input-file %s | FileCheck %s

FIRRTL version 3.3.0
; CHECK-LABEL: module test(
circuit test :%[[{
"class":"sifive.enterprise.firrtl.FullAsyncResetAnnotation",
"target":"~test|test>reset"
Expand All @@ -25,3 +26,33 @@ circuit test :%[[{
connect reg1, in
connect reg2, reg1
connect out, reg2

;// -----
; CHECK-LABEL: module test_wire(
FIRRTL version 3.3.0
circuit test_wire :%[[{
"class":"sifive.enterprise.firrtl.FullAsyncResetAnnotation",
"target":"~test_wire|test_wire>reset"
}]]
module test_wire :
input clock : Clock
input r : AsyncReset
input in : { foo : UInt<8>, bar : UInt<8>}
output out : { foo : UInt<8>, bar : UInt<8>}

node reset = r

wire reg1_w : { foo : UInt<8>, bar : UInt<8>}
invalidate reg1_w.bar
invalidate reg1_w.foo
; CHECK: reg1_foo <= 8'hC;
; CHECK: reg1_bar <= 8'h0;
connect reg1_w.foo, UInt<8>(0hc)
invalidate reg1_w.bar
; CHECK: reg1_foo = 8'hC;
; CHECK: reg1_bar = 8'h0;
regreset reg1 : { foo : UInt<8>, bar : UInt<8>}, clock, reset, reg1_w
wire reg2 : { foo : UInt<8>, bar : UInt<8>}
connect reg1, in
connect reg2, reg1
connect out, reg2
Loading