Skip to content

Commit

Permalink
[DSLX] Convert next-state instructions to next-value nodes
Browse files Browse the repository at this point in the history
Progress on #1520

PiperOrigin-RevId: 710051978
  • Loading branch information
ericastor authored and copybara-github committed Dec 27, 2024
1 parent 1e83aa1 commit 7769c85
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 277 deletions.
4 changes: 2 additions & 2 deletions xls/dslx/ir_convert/function_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2788,9 +2788,9 @@ absl::Status FunctionConverter::HandleProcNextFunction(

XLS_RETURN_IF_ERROR(Visit(f->body()));

BValue result = std::get<BValue>(node_to_ir_[f->body()]);
builder_ptr->Next(state, std::get<BValue>(node_to_ir_[f->body()]));

XLS_ASSIGN_OR_RETURN(xls::Proc * p, builder_ptr->Build({result}));
XLS_ASSIGN_OR_RETURN(xls::Proc * p, builder_ptr->Build());
package_data_.ir_to_dslx[p] = f;
return absl::OkStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ top proc __test_module__foo_0_next(__state: (), init={()}) {
b: bits[32] = tuple_index(receive.9, index=1, id=12)
tok__1: token = tuple_index(receive.9, index=0, id=11)
add.13: bits[32] = add(a, b, id=13)
__token: token = literal(value=token, id=1)
__state: () = state_read(state_element=__state, id=2)
tuple.15: () = tuple(id=15)
__token: token = literal(value=token, id=1)
tuple_index.6: token = tuple_index(receive.5, index=0, id=6)
tuple_index.10: token = tuple_index(receive.9, index=0, id=10)
tok__2: token = send(tok__1, add.13, predicate=literal.3, channel=test_module__output, id=14)
tuple.15: () = tuple(id=15)
next (tuple.15)
next_value.16: () = next_value(param=__state, value=tuple.15, id=16)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,50 @@ fn __test_module__B.init() -> () {
}

top proc __test_module__A_0_next(__state: (), init={()}) {
__token: token = literal(value=token, id=2)
__state: () = state_read(state_element=__state, id=3)
__token: token = literal(value=token, id=2)
literal.4: bits[1] = literal(value=1, id=4)
next (__state)
next_value.5: () = next_value(param=__state, value=__state, id=5)
}

proc __test_module__A__B_0_next(__state: (), init={()}) {
tok: token = after_all(id=8)
literal.9: bits[32] = literal(value=0, id=9)
literal.7: bits[1] = literal(value=1, id=7)
tok__1: token = send(tok, literal.9, predicate=literal.7, channel=test_module__the_channel__0_0, id=10)
receive.11: (token, bits[32]) = receive(tok__1, predicate=literal.7, channel=test_module__the_channel__0_0, id=11)
tok__3: token = tuple_index(receive.11, index=0, id=13)
literal.15: bits[32] = literal(value=1, id=15)
tok__4: token = send(tok__3, literal.15, predicate=literal.7, channel=test_module__the_channel__0_1, id=16)
receive.17: (token, bits[32]) = receive(tok__4, predicate=literal.7, channel=test_module__the_channel__0_1, id=17)
__token: token = literal(value=token, id=5)
__state: () = state_read(state_element=__state, id=6)
tuple_index.12: token = tuple_index(receive.11, index=0, id=12)
tuple_index.14: bits[32] = tuple_index(receive.11, index=1, id=14)
tuple_index.18: token = tuple_index(receive.17, index=0, id=18)
tok__5: token = tuple_index(receive.17, index=0, id=19)
tuple_index.20: bits[32] = tuple_index(receive.17, index=1, id=20)
tuple.21: () = tuple(id=21)
next (tuple.21)
tok: token = after_all(id=9)
literal.10: bits[32] = literal(value=0, id=10)
literal.8: bits[1] = literal(value=1, id=8)
tok__1: token = send(tok, literal.10, predicate=literal.8, channel=test_module__the_channel__0_0, id=11)
receive.12: (token, bits[32]) = receive(tok__1, predicate=literal.8, channel=test_module__the_channel__0_0, id=12)
tok__3: token = tuple_index(receive.12, index=0, id=14)
literal.16: bits[32] = literal(value=1, id=16)
tok__4: token = send(tok__3, literal.16, predicate=literal.8, channel=test_module__the_channel__0_1, id=17)
receive.18: (token, bits[32]) = receive(tok__4, predicate=literal.8, channel=test_module__the_channel__0_1, id=18)
__state: () = state_read(state_element=__state, id=7)
tuple.22: () = tuple(id=22)
__token: token = literal(value=token, id=6)
tuple_index.13: token = tuple_index(receive.12, index=0, id=13)
tuple_index.15: bits[32] = tuple_index(receive.12, index=1, id=15)
tuple_index.19: token = tuple_index(receive.18, index=0, id=19)
tok__5: token = tuple_index(receive.18, index=0, id=20)
tuple_index.21: bits[32] = tuple_index(receive.18, index=1, id=21)
next_value.23: () = next_value(param=__state, value=tuple.22, id=23)
}

proc __test_module__A__B_1_next(__state: (), init={()}) {
tok: token = after_all(id=25)
literal.26: bits[32] = literal(value=0, id=26)
literal.24: bits[1] = literal(value=1, id=24)
tok__1: token = send(tok, literal.26, predicate=literal.24, channel=test_module__the_channel__1_0, id=27)
receive.28: (token, bits[32]) = receive(tok__1, predicate=literal.24, channel=test_module__the_channel__1_0, id=28)
tok__3: token = tuple_index(receive.28, index=0, id=30)
literal.32: bits[32] = literal(value=1, id=32)
tok__4: token = send(tok__3, literal.32, predicate=literal.24, channel=test_module__the_channel__1_1, id=33)
receive.34: (token, bits[32]) = receive(tok__4, predicate=literal.24, channel=test_module__the_channel__1_1, id=34)
__token: token = literal(value=token, id=22)
__state: () = state_read(state_element=__state, id=23)
tuple_index.29: token = tuple_index(receive.28, index=0, id=29)
tuple_index.31: bits[32] = tuple_index(receive.28, index=1, id=31)
tuple_index.35: token = tuple_index(receive.34, index=0, id=35)
tok__5: token = tuple_index(receive.34, index=0, id=36)
tuple_index.37: bits[32] = tuple_index(receive.34, index=1, id=37)
tuple.38: () = tuple(id=38)
next (tuple.38)
tok: token = after_all(id=27)
literal.28: bits[32] = literal(value=0, id=28)
literal.26: bits[1] = literal(value=1, id=26)
tok__1: token = send(tok, literal.28, predicate=literal.26, channel=test_module__the_channel__1_0, id=29)
receive.30: (token, bits[32]) = receive(tok__1, predicate=literal.26, channel=test_module__the_channel__1_0, id=30)
tok__3: token = tuple_index(receive.30, index=0, id=32)
literal.34: bits[32] = literal(value=1, id=34)
tok__4: token = send(tok__3, literal.34, predicate=literal.26, channel=test_module__the_channel__1_1, id=35)
receive.36: (token, bits[32]) = receive(tok__4, predicate=literal.26, channel=test_module__the_channel__1_1, id=36)
__state: () = state_read(state_element=__state, id=25)
tuple.40: () = tuple(id=40)
__token: token = literal(value=token, id=24)
tuple_index.31: token = tuple_index(receive.30, index=0, id=31)
tuple_index.33: bits[32] = tuple_index(receive.30, index=1, id=33)
tuple_index.37: token = tuple_index(receive.36, index=0, id=37)
tok__5: token = tuple_index(receive.36, index=0, id=38)
tuple_index.39: bits[32] = tuple_index(receive.36, index=1, id=39)
next_value.41: () = next_value(param=__state, value=tuple.40, id=41)
}
42 changes: 21 additions & 21 deletions xls/dslx/ir_convert/testdata/ir_converter_test_HandlesBasicProc.ir
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ fn __test_module__consumer.init() -> bits[32] {
}

top proc __test_module__main_0_next(__state: (), init={()}) {
__token: token = literal(value=token, id=3)
__state: () = state_read(state_element=__state, id=4)
literal.5: bits[1] = literal(value=1, id=5)
tuple.6: () = tuple(id=6)
next (tuple.6)
__token: token = literal(value=token, id=3)
literal.5: bits[1] = literal(value=1, id=5)
next_value.7: () = next_value(param=__state, value=tuple.6, id=7)
}

proc __test_module__main__producer_0_next(__state: bits[32], init={0}) {
after_all.10: token = after_all(id=10)
__state: bits[32] = state_read(state_element=__state, id=8)
literal.9: bits[1] = literal(value=1, id=9)
literal.12: bits[32] = literal(value=1, id=12)
__token: token = literal(value=token, id=7)
tok: token = send(after_all.10, __state, predicate=literal.9, channel=test_module__my_chan, id=11)
add.13: bits[32] = add(__state, literal.12, id=13)
next (add.13)
__state: bits[32] = state_read(state_element=__state, id=9)
literal.13: bits[32] = literal(value=1, id=13)
after_all.11: token = after_all(id=11)
literal.10: bits[1] = literal(value=1, id=10)
add.14: bits[32] = add(__state, literal.13, id=14)
__token: token = literal(value=token, id=8)
tok: token = send(after_all.11, __state, predicate=literal.10, channel=test_module__my_chan, id=12)
next_value.15: () = next_value(param=__state, value=add.14, id=15)
}

proc __test_module__main__consumer_0_next(__state: bits[32], init={0}) {
after_all.17: token = after_all(id=17)
literal.16: bits[1] = literal(value=1, id=16)
receive.18: (token, bits[32]) = receive(after_all.17, predicate=literal.16, channel=test_module__my_chan, id=18)
i: bits[32] = tuple_index(receive.18, index=1, id=21)
__token: token = literal(value=token, id=14)
__state: bits[32] = state_read(state_element=__state, id=15)
tuple_index.19: token = tuple_index(receive.18, index=0, id=19)
tok: token = tuple_index(receive.18, index=0, id=20)
add.22: bits[32] = add(i, i, id=22)
next (add.22)
after_all.19: token = after_all(id=19)
literal.18: bits[1] = literal(value=1, id=18)
receive.20: (token, bits[32]) = receive(after_all.19, predicate=literal.18, channel=test_module__my_chan, id=20)
i: bits[32] = tuple_index(receive.20, index=1, id=23)
__state: bits[32] = state_read(state_element=__state, id=17)
add.24: bits[32] = add(i, i, id=24)
__token: token = literal(value=token, id=16)
tuple_index.21: token = tuple_index(receive.20, index=0, id=21)
tok: token = tuple_index(receive.20, index=0, id=22)
next_value.25: () = next_value(param=__state, value=add.24, id=25)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ chan test_module__tuple_chan((bits[64], (bits[64], (bits[64]))), id=2, kind=stre
chan test_module__tuple_with_array_chan((bits[64], (bits[64], bits[64][4])), id=3, kind=streaming, ops=send_receive, flow_control=ready_valid, strictness=proven_mutually_exclusive, metadata="""""")

top proc __test_module__main_0_next(__state: (), init={()}) {
__token: token = literal(value=token, id=1)
__state: () = state_read(state_element=__state, id=2)
literal.3: bits[1] = literal(value=1, id=3)
tuple.4: () = tuple(id=4)
next (tuple.4)
__token: token = literal(value=token, id=1)
literal.3: bits[1] = literal(value=1, id=3)
next_value.5: () = next_value(param=__state, value=tuple.4, id=5)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,65 @@ top proc __test_module__A_0_next(__state: (), init={()}) {
receive.7: (token, bits[32]) = receive(after_all.6, predicate=literal.5, channel=test_module__s, id=7)
tok: token = tuple_index(receive.7, index=0, id=9)
data: bits[32] = tuple_index(receive.7, index=1, id=10)
__token: token = literal(value=token, id=3)
__state: () = state_read(state_element=__state, id=4)
tuple.13: () = tuple(id=13)
__token: token = literal(value=token, id=3)
tuple_index.8: token = tuple_index(receive.7, index=0, id=8)
send.11: token = send(tok, data, predicate=literal.5, channel=test_module__s0, id=11)
send.12: token = send(tok, data, predicate=literal.5, channel=test_module__s1, id=12)
tuple.13: () = tuple(id=13)
next (tuple.13)
next_value.14: () = next_value(param=__state, value=tuple.13, id=14)
}

proc __test_module__A__B_0__C_0_next(__state: bits[32], init={0}) {
after_all.17: token = after_all(id=17)
literal.16: bits[1] = literal(value=1, id=16)
receive.18: (token, bits[32]) = receive(after_all.17, predicate=literal.16, channel=test_module__s0__2, id=18)
__state: bits[32] = state_read(state_element=__state, id=15)
data: bits[32] = tuple_index(receive.18, index=1, id=21)
__token: token = literal(value=token, id=14)
tuple_index.19: token = tuple_index(receive.18, index=0, id=19)
tok: token = tuple_index(receive.18, index=0, id=20)
add.22: bits[32] = add(__state, data, id=22)
next (add.22)
after_all.18: token = after_all(id=18)
literal.17: bits[1] = literal(value=1, id=17)
receive.19: (token, bits[32]) = receive(after_all.18, predicate=literal.17, channel=test_module__s0__2, id=19)
__state: bits[32] = state_read(state_element=__state, id=16)
data: bits[32] = tuple_index(receive.19, index=1, id=22)
add.23: bits[32] = add(__state, data, id=23)
__token: token = literal(value=token, id=15)
tuple_index.20: token = tuple_index(receive.19, index=0, id=20)
tok: token = tuple_index(receive.19, index=0, id=21)
next_value.24: () = next_value(param=__state, value=add.23, id=24)
}

proc __test_module__A__B_0_next(__state: bits[32], init={0}) {
after_all.26: token = after_all(id=26)
literal.25: bits[1] = literal(value=1, id=25)
receive.27: (token, bits[32]) = receive(after_all.26, predicate=literal.25, channel=test_module__s0, id=27)
tok: token = tuple_index(receive.27, index=0, id=29)
data: bits[32] = tuple_index(receive.27, index=1, id=30)
__state: bits[32] = state_read(state_element=__state, id=24)
__token: token = literal(value=token, id=23)
tuple_index.28: token = tuple_index(receive.27, index=0, id=28)
send.31: token = send(tok, data, predicate=literal.25, channel=test_module__s0__2, id=31)
add.32: bits[32] = add(__state, data, id=32)
next (add.32)
after_all.28: token = after_all(id=28)
literal.27: bits[1] = literal(value=1, id=27)
receive.29: (token, bits[32]) = receive(after_all.28, predicate=literal.27, channel=test_module__s0, id=29)
__state: bits[32] = state_read(state_element=__state, id=26)
data: bits[32] = tuple_index(receive.29, index=1, id=32)
tok: token = tuple_index(receive.29, index=0, id=31)
add.34: bits[32] = add(__state, data, id=34)
__token: token = literal(value=token, id=25)
tuple_index.30: token = tuple_index(receive.29, index=0, id=30)
send.33: token = send(tok, data, predicate=literal.27, channel=test_module__s0__2, id=33)
next_value.35: () = next_value(param=__state, value=add.34, id=35)
}

proc __test_module__A__B_1__C_0_next(__state: bits[32], init={0}) {
after_all.36: token = after_all(id=36)
literal.35: bits[1] = literal(value=1, id=35)
receive.37: (token, bits[32]) = receive(after_all.36, predicate=literal.35, channel=test_module__s0__1, id=37)
__state: bits[32] = state_read(state_element=__state, id=34)
data: bits[32] = tuple_index(receive.37, index=1, id=40)
__token: token = literal(value=token, id=33)
tuple_index.38: token = tuple_index(receive.37, index=0, id=38)
tok: token = tuple_index(receive.37, index=0, id=39)
add.41: bits[32] = add(__state, data, id=41)
next (add.41)
after_all.39: token = after_all(id=39)
literal.38: bits[1] = literal(value=1, id=38)
receive.40: (token, bits[32]) = receive(after_all.39, predicate=literal.38, channel=test_module__s0__1, id=40)
__state: bits[32] = state_read(state_element=__state, id=37)
data: bits[32] = tuple_index(receive.40, index=1, id=43)
add.44: bits[32] = add(__state, data, id=44)
__token: token = literal(value=token, id=36)
tuple_index.41: token = tuple_index(receive.40, index=0, id=41)
tok: token = tuple_index(receive.40, index=0, id=42)
next_value.45: () = next_value(param=__state, value=add.44, id=45)
}

proc __test_module__A__B_1_next(__state: bits[32], init={0}) {
after_all.45: token = after_all(id=45)
literal.44: bits[1] = literal(value=1, id=44)
receive.46: (token, bits[32]) = receive(after_all.45, predicate=literal.44, channel=test_module__s1, id=46)
tok: token = tuple_index(receive.46, index=0, id=48)
data: bits[32] = tuple_index(receive.46, index=1, id=49)
__state: bits[32] = state_read(state_element=__state, id=43)
__token: token = literal(value=token, id=42)
tuple_index.47: token = tuple_index(receive.46, index=0, id=47)
send.50: token = send(tok, data, predicate=literal.44, channel=test_module__s0__1, id=50)
add.51: bits[32] = add(__state, data, id=51)
next (add.51)
after_all.49: token = after_all(id=49)
literal.48: bits[1] = literal(value=1, id=48)
receive.50: (token, bits[32]) = receive(after_all.49, predicate=literal.48, channel=test_module__s1, id=50)
__state: bits[32] = state_read(state_element=__state, id=47)
data: bits[32] = tuple_index(receive.50, index=1, id=53)
tok: token = tuple_index(receive.50, index=0, id=52)
add.55: bits[32] = add(__state, data, id=55)
__token: token = literal(value=token, id=46)
tuple_index.51: token = tuple_index(receive.50, index=0, id=51)
send.54: token = send(tok, data, predicate=literal.48, channel=test_module__s0__1, id=54)
next_value.56: () = next_value(param=__state, value=add.55, id=56)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ file_number 0 "test_module.x"
chan test_module__s(bits[32], id=0, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=proven_mutually_exclusive, metadata="""""")

top proc __test_module__P_0_next(__state: bits[32], init={42}) {
after_all.4: token = after_all(id=4)
__state: bits[32] = state_read(state_element=__state, id=2)
literal.3: bits[1] = literal(value=1, id=3)
literal.6: bits[32] = literal(value=1, id=6)
after_all.4: token = after_all(id=4)
literal.3: bits[1] = literal(value=1, id=3)
new_state: bits[32] = add(__state, literal.6, id=7)
__token: token = literal(value=token, id=1)
send.5: token = send(after_all.4, __state, predicate=literal.3, channel=test_module__s, id=5)
new_state: bits[32] = add(__state, literal.6, id=7)
next (new_state)
next_value.8: () = next_value(param=__state, value=new_state, id=8)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ proc __test_module__Counter_0_next(__state: bits[32], init={0}) {
__token: token = literal(value=token, id=6)
tuple_index.11: token = tuple_index(receive.10, index=0, id=11)
tok__1: token = send(tok, next_state, predicate=literal.8, channel=test_module__out_ch, id=16)
next (next_state)
next_value.17: () = next_value(param=__state, value=next_state, id=17)
}
Loading

0 comments on commit 7769c85

Please sign in to comment.