-
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.
[MLIR] Add support for sync_read_mem (#1203)
Co-authored-by: rsetaluri <[email protected]>
- Loading branch information
Showing
6 changed files
with
158 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from magma.backend.mlir.hw import hw | ||
from magma.backend.mlir.mlir import push_block | ||
from magma.backend.mlir.sv import sv | ||
|
||
|
||
def make_mem_reg(ctx, name, N, T): | ||
mem_type = hw.InOutType(hw.ArrayType((N,), T)) | ||
mem = ctx.new_value(mem_type) | ||
sv.RegOp(name=name, results=[mem]) | ||
return mem | ||
|
||
|
||
def make_mem_read(ctx, target, value, has_enable, name="read_reg"): | ||
if not has_enable: | ||
sv.ReadInOutOp(operands=[target], results=[value]) | ||
return None, None | ||
reg_out = ctx.new_value(target.type.T) | ||
sv.ReadInOutOp(operands=[target], results=[reg_out]) | ||
reg = ctx.new_value(target.type) | ||
sv.RegOp(name=name, results=[reg]) | ||
sv.ReadInOutOp(operands=[reg], results=[value]) | ||
return reg, reg_out | ||
|
||
|
||
def emit_conditional_assign(target, value, en): | ||
with push_block(sv.IfOp(operands=[en]).then_block): | ||
sv.PAssignOp(operands=[target, value]) | ||
|
||
|
||
def make_index_op(ctx, value, idx): | ||
result = ctx.new_value(hw.InOutType(value.type.T.T)) | ||
sv.ArrayIndexInOutOp(operands=[value, idx], results=[result]) | ||
return result |
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
24 changes: 24 additions & 0 deletions
24
tests/test_backend/test_mlir/golds/sync_memory_wrapper.mlir
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,24 @@ | ||
module attributes {circt.loweringOptions = "locationInfoStyle=none"} { | ||
hw.module @Memory(%RADDR: i7, %CLK: i1, %WADDR: i7, %WDATA: i12, %WE: i1) -> (RDATA: i12) { | ||
%0 = hw.constant 1 : i1 | ||
%2 = sv.reg name "coreir_mem128x12_inst0" : !hw.inout<!hw.array<128xi12>> | ||
%3 = sv.array_index_inout %2[%RADDR] : !hw.inout<!hw.array<128xi12>>, i7 | ||
%4 = sv.read_inout %3 : !hw.inout<i12> | ||
%5 = sv.reg name "read_reg" : !hw.inout<i12> | ||
%1 = sv.read_inout %5 : !hw.inout<i12> | ||
%6 = sv.array_index_inout %2[%WADDR] : !hw.inout<!hw.array<128xi12>>, i7 | ||
sv.alwaysff(posedge %CLK) { | ||
sv.if %WE { | ||
sv.passign %6, %WDATA : i12 | ||
} | ||
sv.if %0 { | ||
sv.passign %5, %4 : i12 | ||
} | ||
} | ||
hw.output %1 : i12 | ||
} | ||
hw.module @sync_memory_wrapper(%RADDR: i7, %CLK: i1, %WADDR: i7, %WDATA: i12, %WE: i1) -> (RDATA: i12) { | ||
%0 = hw.instance "Memory_inst0" @Memory(RADDR: %RADDR: i7, CLK: %CLK: i1, WADDR: %WADDR: i7, WDATA: %WDATA: i12, WE: %WE: i1) -> (RDATA: i12) | ||
hw.output %0 : i12 | ||
} | ||
} |
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,39 @@ | ||
// Generated by CIRCT circtorg-0.0.0-1773-g7abbc4313 | ||
module Memory( | ||
input [6:0] RADDR, | ||
input CLK, | ||
input [6:0] WADDR, | ||
input [11:0] WDATA, | ||
input WE, | ||
output [11:0] RDATA | ||
); | ||
|
||
reg [127:0][11:0] coreir_mem128x12_inst0; | ||
reg [11:0] read_reg; | ||
always_ff @(posedge CLK) begin | ||
if (WE) | ||
coreir_mem128x12_inst0[WADDR] <= WDATA; | ||
read_reg <= coreir_mem128x12_inst0[RADDR]; | ||
end // always_ff @(posedge) | ||
assign RDATA = read_reg; | ||
endmodule | ||
|
||
module sync_memory_wrapper( | ||
input [6:0] RADDR, | ||
input CLK, | ||
input [6:0] WADDR, | ||
input [11:0] WDATA, | ||
input WE, | ||
output [11:0] RDATA | ||
); | ||
|
||
Memory Memory_inst0 ( | ||
.RADDR (RADDR), | ||
.CLK (CLK), | ||
.WADDR (WADDR), | ||
.WDATA (WDATA), | ||
.WE (WE), | ||
.RDATA (RDATA) | ||
); | ||
endmodule | ||
|
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