-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bind2] Add support for compile guard around bind (#1315)
* [Bind2] Separate return statements * [Bind2] Remove compile_guard argument * [CompileGuard] Store compile guard info directly * [CompileGuard] Expose active compile guards * [Bind2] Stash active compile guards Attaches active compile guard info's to bound instance metadata. * [Bind2] Add tests for compile guarded bind2() * [MLIR] Print attr_dict for sv.IfDefOp * [MLIR] Add MlirOp.parent_op() function * [MLIR] Add support for bind2 wrapped in compile guard * Emit sv.IfDefOp around sv.BindOp * Attach hw.OutputFileAttr for entire sub-tree of op's surrounding sv.BindOp (all enclosing sv.IfDefOp, and including sv.BindOp). * Add generic MlirOpPass infrastructure * [CompileGuard] Fix test * [MLIR] Update golds * [MLIR] Use := in MlirOp.parent_op() * [MLIR] Make MlirOpPass callable interface * [CompileGuard] Use Stack iterable interface * [Bind2] Use getattr to get bound inst info
- Loading branch information
Showing
13 changed files
with
224 additions
and
36 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
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,29 @@ | ||
import abc | ||
from typing import Any | ||
|
||
from magma.backend.mlir.mlir import MlirOp | ||
|
||
|
||
class MlirOpPass(abc.ABC): | ||
def __init__(self, root: MlirOp): | ||
self._root = root | ||
self._callable = callable(self) | ||
|
||
def _run_on_op(self, op: MlirOp): | ||
for region in op.regions: | ||
for block in region.blocks: | ||
for op in block.operations: | ||
yield from self._run_on_op(op) | ||
yield self(op) | ||
|
||
@abc.abstractmethod | ||
def __call__(self, op: MlirOp) -> Any: | ||
raise NotImplementedError() | ||
|
||
def run(self): | ||
yield from self._run_on_op(self._root) | ||
|
||
|
||
class CollectMlirOpsPass(MlirOpPass): | ||
def __call__(self, op: MlirOp): | ||
return op |
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
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
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,13 @@ | ||
module attributes {circt.loweringOptions = "locationInfoStyle=none,omitVersionComment"} { | ||
hw.module @TopCompileGuardAsserts_mlir(%I: i1, %O: i1, %other: i1) -> () attributes {output_filelist = #hw.output_filelist<"$cwd/build/test_bind2_compile_guard_bind_files.list">} { | ||
} | ||
hw.module @Top(%I: i1) -> (O: i1) { | ||
%1 = hw.constant -1 : i1 | ||
%0 = comb.xor %1, %I : i1 | ||
hw.instance "TopCompileGuardAsserts_mlir_inst0" sym @Top.TopCompileGuardAsserts_mlir_inst0 @TopCompileGuardAsserts_mlir(I: %I: i1, O: %0: i1, other: %I: i1) -> () {doNotPrint = true} | ||
hw.output %0 : i1 | ||
} | ||
sv.ifdef "ASSERT_ON" { | ||
sv.bind #hw.innerNameRef<@Top::@Top.TopCompileGuardAsserts_mlir_inst0> | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/gold/test_bind2_compile_guard_split_verilog.mlir.tpl
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,13 @@ | ||
module attributes {circt.loweringOptions = "locationInfoStyle=none,omitVersionComment"} { | ||
hw.module @TopCompileGuardAsserts_mlir(%I: i1, %O: i1, %other: i1) -> () attributes {output_file = #hw.output_file<"$cwd/build/TopCompileGuardAsserts_mlir.v">, output_filelist = #hw.output_filelist<"$cwd/build/test_bind2_compile_guard_split_verilog_bind_files.list">} { | ||
} | ||
hw.module @Top(%I: i1) -> (O: i1) attributes {output_file = #hw.output_file<"$cwd/build/test_bind2_compile_guard_split_verilog.v">} { | ||
%1 = hw.constant -1 : i1 | ||
%0 = comb.xor %1, %I : i1 | ||
hw.instance "TopCompileGuardAsserts_mlir_inst0" sym @Top.TopCompileGuardAsserts_mlir_inst0 @TopCompileGuardAsserts_mlir(I: %I: i1, O: %0: i1, other: %I: i1) -> () {doNotPrint = true} | ||
hw.output %0 : i1 | ||
} | ||
sv.ifdef "ASSERT_ON" { | ||
sv.bind #hw.innerNameRef<@Top::@Top.TopCompileGuardAsserts_mlir_inst0> {output_file = #hw.output_file<"$cwd/build/TopCompileGuardAsserts_mlir.v">} | ||
} {output_file = #hw.output_file<"$cwd/build/TopCompileGuardAsserts_mlir.v">} | ||
} |
Oops, something went wrong.