Skip to content

Commit

Permalink
[PrepareForEmission] Hoist registers in a procedural region with `dis…
Browse files Browse the repository at this point in the history
…allowLocalVariables` (#7404)

Fix #7399
  • Loading branch information
uenoku authored Jul 30, 2024
1 parent 15417e8 commit 68b568b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Conversion/ExportVerilog/PrepareForEmission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ static LogicalResult legalizeHWModule(Block &block,
if (auto call = dyn_cast<mlir::CallOpInterface>(op))
lowerFunctionCallResults(call);

// If logic op is located in a procedural region, we have to move the logic
// If a reg or logic is located in a procedural region, we have to move the
// op declaration to a valid program point.
if (isProceduralRegion && isa<LogicOp>(op)) {
if (isProceduralRegion && isa<LogicOp, RegOp>(op)) {
if (options.disallowLocalVariables) {
// When `disallowLocalVariables` is enabled, "automatic logic" is
// prohibited so hoist the op to a non-procedural region.
Expand Down
21 changes: 21 additions & 0 deletions test/Conversion/ExportVerilog/disallow-local-vars.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,24 @@ hw.module @AggregateInline(in %clock: i1) {
// CHECK: assign [[GEN]] = register.a[15:0]
hw.output
}

// CHECK-LABEL: module hoist_reg
// DISALLOW-LABEL: module hoist_reg
hw.module @hoist_reg(in %dummy : i32, out out : i17) {
%res_reg = sv.reg : !hw.inout<i17>
// CHECK: initial
// CHECK: reg [31:0] tmp;
// CHECK end // initial
// DISALLOW: reg [31:0] tmp;
// DISALLOW: initial
sv.initial {
%tmp = sv.reg : !hw.inout<i32>
%17 = sv.read_inout %tmp : !hw.inout<i32>
%29 = comb.xor %dummy, %17 : i32
%32 = comb.extract %29 from 3 : (i32) -> i17
sv.passign %res_reg, %32 : i17
}

%res_reg_data = sv.read_inout %res_reg : !hw.inout<i17>
hw.output %res_reg_data : i17
}

0 comments on commit 68b568b

Please sign in to comment.