Skip to content

Commit

Permalink
[SV] Mark sv.xmr.ref op as pure (#6260)
Browse files Browse the repository at this point in the history
Having an `sv.xmr.ref` op inside a procedural block such as
`sv.alwayscomb` triggers an assertion in `PrepareForEmission`. The pass
would identify the ref op as having side-effects and then go ahead and
try to pull it outside the procedural block. Doing so would create a
`sv.reg` op with multiple nested inout types, which breaks.

Fix the issue by marking the `sv.xmr.ref` op as pure. Taking a reference
to something does not have a side-effect. It's accessing what's behind
the reference that has side-effects.
  • Loading branch information
fabianschuiki authored Oct 5, 2023
1 parent 5508c1e commit 71a78d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/circt/Dialect/SV/SVInOutOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def XMROp : SVOp<"xmr", []> {
let assemblyFormat = "(`isRooted` $isRooted^)? custom<XMRPath>($path, $terminal) attr-dict `:` qualified(type($result))";
}

def XMRRefOp : SVOp<"xmr.ref", [DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
def XMRRefOp : SVOp<"xmr.ref", [
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
Pure
]> {
let summary = "Encode a reference to something with a hw.hierpath.";
let description = [{
This represents a hierarchical path, but using something which the compiler
Expand Down
20 changes: 20 additions & 0 deletions test/Conversion/ExportVerilog/prepare-for-emission.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,23 @@ hw.module @Issue5605(in %a: i1, in %b: i1, in %clock: i1, in %reset: i1) {
sv.assert.concurrent posedge %clock, %reset label "assert_1" message "bar"(%1) : i2
hw.output
}

// -----

// The following use of `sv.xmr.ref` inside a procedural block would trigger an
// assertion in `PrepareForEmission`, since the op was not marked as side-effect
// free.
//
// CHECK-LABEL: hw.module @Foo
module attributes {circt.loweringOptions = "disallowLocalVariables"} {
hw.module @Foo(in %a: i1) {
hw.wire %a sym @a : i1
// CHECK: sv.alwayscomb
sv.alwayscomb {
// CHECK-NEXT: sv.xmr.ref
%0 = sv.xmr.ref @xmr : !hw.inout<i1>
sv.verbatim "{{0}}" (%0) : !hw.inout<i1>
}
}
hw.hierpath @xmr [@Foo::@a]
}

0 comments on commit 71a78d6

Please sign in to comment.