diff --git a/xls/codegen/block_conversion.cc b/xls/codegen/block_conversion.cc index c76c606856..5bd697d797 100644 --- a/xls/codegen/block_conversion.cc +++ b/xls/codegen/block_conversion.cc @@ -1921,11 +1921,11 @@ static absl::Status RemoveDeadTokenNodes(Block* block) { // chan y_ch(bits[32], kind=streaming, flow_control=single_value, id=1, ...) // // proc foo(tkn: token, st: (), init=42) { -// rcv_x: (token, bits[32]) = receive(tkn, channel_id=0) +// rcv_x: (token, bits[32]) = receive(tkn, channel=x_ch) // rcv_x_token: token = tuple_index(rcv_x, index=0) // x: bits[32] = tuple_index(rcv_x, index=1) // not_x: bits[32] = not(x) -// snd_y: token = send(rcv_x_token, not_x, channel_id=1) +// snd_y: token = send(rcv_x_token, not_x, channel=y_ch) // next (tkn, snd_y) // } // @@ -2050,7 +2050,7 @@ class CloneNodesIntoBlockHandler { inst_name, std::make_unique( inst_name, *streaming_channel->fifo_config(), - streaming_channel->type(), streaming_channel->id(), + streaming_channel->type(), streaming_channel->name(), block_->package()))); itr->second = instantiation; } else { @@ -2402,8 +2402,8 @@ class CloneNodesIntoBlockHandler { XLS_ASSIGN_OR_RETURN(Node * valid, block_->MakeNode( receive->loc(), fifo_instantiation, "pop_valid")); - XLS_ASSIGN_OR_RETURN(Channel * channel, - block_->package()->GetChannel(receive->channel_id())); + XLS_ASSIGN_OR_RETURN(Channel * channel, block_->package()->GetChannel( + receive->channel_name())); Node* signal_valid; if (receive->is_blocking()) { signal_valid = valid; @@ -2492,7 +2492,7 @@ class CloneNodesIntoBlockHandler { block_->MakeNode( send->loc(), fifo_instantiation, "push_ready")); XLS_ASSIGN_OR_RETURN(Channel * channel, - block_->package()->GetChannel(send->channel_id())); + block_->package()->GetChannel(send->channel_name())); Node* data = node_map_.at(send->data()); XLS_ASSIGN_OR_RETURN( Node * port, block_->MakeNode( diff --git a/xls/codegen/block_conversion_test.cc b/xls/codegen/block_conversion_test.cc index 9e2f860013..db7be8217d 100644 --- a/xls/codegen/block_conversion_test.cc +++ b/xls/codegen/block_conversion_test.cc @@ -612,11 +612,11 @@ chan out(bits[32], id=1, kind=single_value, ops=send_only, metadata="""module_port { flopped: false, port_order: 0 }""") proc my_proc(my_token: token, my_state: (), init={()}) { - rcv: (token, bits[32]) = receive(my_token, channel_id=0) + rcv: (token, bits[32]) = receive(my_token, channel=in) data: bits[32] = tuple_index(rcv, index=1) negate: bits[32] = neg(data) rcv_token: token = tuple_index(rcv, index=0) - send: token = send(rcv_token, negate, channel_id=1) + send: token = send(rcv_token, negate, channel=out) next (send, my_state) } )"; @@ -807,8 +807,8 @@ chan in2(bits[32], id=2, kind=single_value, ops=receive_only, metadata="") chan out2(bits[32], id=3, kind=single_value, ops=send_only, metadata="") proc my_proc(my_token: token, my_state: (), init={()}) { - rcv: (token, bits[32]) = receive(my_token, channel_id=0) - rcv2: (token, bits[32]) = receive(my_token, channel_id=2) + rcv: (token, bits[32]) = receive(my_token, channel=in) + rcv2: (token, bits[32]) = receive(my_token, channel=in2) data: bits[32] = tuple_index(rcv, index=1) rcv_token: token = tuple_index(rcv, index=0) @@ -818,8 +818,8 @@ proc my_proc(my_token: token, my_state: (), init={()}) { rcv2_token: token = tuple_index(rcv2, index=0) negate2: bits[32] = neg(data2) - send: token = send(rcv_token, negate, channel_id=1) - send2: token = send(rcv2_token, negate2, channel_id=3) + send: token = send(rcv_token, negate, channel=out) + send2: token = send(rcv2_token, negate2, channel=out2) fin : token = after_all(send, send2) next (fin, my_state) } @@ -892,11 +892,11 @@ chan out(bits[32], id=3, kind=single_value, ops=send_only, metadata="""module_port { flopped: false, port_order: 0 }""") proc my_proc(my_token: token, my_state: (), init={()}) { - rcv0: (token, bits[32]) = receive(my_token, channel_id=0) + rcv0: (token, bits[32]) = receive(my_token, channel=in0) rcv0_token: token = tuple_index(rcv0, index=0) - rcv1: (token, bits[32]) = receive(rcv0_token, channel_id=1) + rcv1: (token, bits[32]) = receive(rcv0_token, channel=in1) rcv1_token: token = tuple_index(rcv1, index=0) - rcv2: (token, bits[32]) = receive(rcv1_token, channel_id=2) + rcv2: (token, bits[32]) = receive(rcv1_token, channel=in2) rcv2_token: token = tuple_index(rcv2, index=0) data0: bits[32] = tuple_index(rcv0, index=1) data1: bits[32] = tuple_index(rcv1, index=1) @@ -906,7 +906,7 @@ proc my_proc(my_token: token, my_state: (), init={()}) { data2_times_two: bits[32] = umul(data2, two) tmp: bits[32] = add(neg_data1, data2_times_two) sum: bits[32] = add(tmp, data0) - send: token = send(rcv2_token, sum, channel_id=3) + send: token = send(rcv2_token, sum, channel=out) next (send, my_state) } )"; @@ -930,11 +930,11 @@ chan in(bits[32], id=0, kind=single_value, ops=receive_only, metadata="") chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") proc my_proc(tkn: token, st: (), init={()}) { - receive.13: (token, bits[32]) = receive(tkn, channel_id=0, id=13) + receive.13: (token, bits[32]) = receive(tkn, channel=in, id=13) tuple_index.14: token = tuple_index(receive.13, index=0, id=14) literal.21: bits[1] = literal(value=1, id=21, pos=[(1,8,3)]) tuple_index.15: bits[32] = tuple_index(receive.13, index=1, id=15) - send.20: token = send(tuple_index.14, tuple_index.15, predicate=literal.21, channel_id=1, id=20, pos=[(1,5,1)]) + send.20: token = send(tuple_index.14, tuple_index.15, predicate=literal.21, channel=out, id=20, pos=[(1,5,1)]) next (send.20, st) } @@ -956,16 +956,17 @@ TEST_F(BlockConversionTest, OnlyFIFOInProcGateRecvsTrue) { const std::string ir_text = R"(package test chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_valid, metadata="""module_port { flopped: false -port_order: 0 }""") chan out(bits[32], id=1, kind=single_value, +port_order: 0 }""") +chan out(bits[32], id=1, kind=single_value, ops=send_only, metadata="""module_port { flopped: false port_order: 1 }""") proc my_proc(tkn: token, st: (), init={()}) { literal.21: bits[1] = literal(value=1, id=21, pos=[(1,8,3)]) - receive.13: (token, bits[32]) = receive(tkn, predicate=literal.21, channel_id=0, id=13) + receive.13: (token, bits[32]) = receive(tkn, predicate=literal.21, channel=in, id=13) tuple_index.14: token = tuple_index(receive.13, index=0, id=14) tuple_index.15: bits[32] = tuple_index(receive.13, index=1, id=15) send.20: token = send(tuple_index.14, tuple_index.15, - channel_id=1, id=20, pos=[(1,5,1)]) + channel=out, id=20, pos=[(1,5,1)]) next (send.20, st) } )"; @@ -991,16 +992,17 @@ TEST_F(BlockConversionTest, OnlyFIFOInProcGateRecvsFalse) { const std::string ir_text = R"(package test chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_valid, metadata="""module_port { flopped: false -port_order: 0 }""") chan out(bits[32], id=1, kind=single_value, +port_order: 0 }""") +chan out(bits[32], id=1, kind=single_value, ops=send_only, metadata="""module_port { flopped: false port_order: 1 }""") proc my_proc(tkn: token, st: (), init={()}) { literal.21: bits[1] = literal(value=1, id=21, pos=[(1,8,3)]) - receive.13: (token, bits[32]) = receive(tkn, predicate=literal.21, channel_id=0, id=13) + receive.13: (token, bits[32]) = receive(tkn, predicate=literal.21, channel=in, id=13) tuple_index.14: token = tuple_index(receive.13, index=0, id=14) tuple_index.15: bits[32] = tuple_index(receive.13, index=1, id=15) send.20: token = send(tuple_index.14, tuple_index.15, - channel_id=1, id=20, pos=[(1,5,1)]) + channel=out, id=20, pos=[(1,5,1)]) next (send.20, st) } )"; @@ -1027,10 +1029,10 @@ chan in(bits[32], id=0, kind=single_value, ops=receive_only, metadata="") chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") proc my_proc(tkn: token, st: (), init={()}) { - receive.13: (token, bits[32]) = receive(tkn, channel_id=0, id=13) + receive.13: (token, bits[32]) = receive(tkn, channel=in, id=13) tuple_index.14: token = tuple_index(receive.13, index=0, id=14) tuple_index.15: bits[32] = tuple_index(receive.13, index=1, id=15) - send.20: token = send(tuple_index.14, tuple_index.15, channel_id=1, id=20) next (send.20, st) + send.20: token = send(tuple_index.14, tuple_index.15, channel=out, id=20) next (send.20, st) } )"; @@ -1449,10 +1451,10 @@ chan in(bits[32], id=0, kind=single_value, ops=receive_only, metadata="") chan out(bits[32], id=1, kind=single_value, ops=send_only, metadata="") proc my_proc(tkn: token, st: (), init={()}) { - receive.13: (token, bits[32]) = receive(tkn, channel_id=0, id=13) + receive.13: (token, bits[32]) = receive(tkn, channel=in, id=13) tuple_index.14: token = tuple_index(receive.13, index=0, id=14) tuple_index.15: bits[32] = tuple_index(receive.13, index=1, id=15) - send.20: token = send(tuple_index.14, tuple_index.15, channel_id=1, id=20) next (send.20, st) + send.20: token = send(tuple_index.14, tuple_index.15, channel=out, id=20) next (send.20, st) } )"; @@ -3362,7 +3364,7 @@ TEST_F(ProcConversionTestFixture, ProcSendDuringReset) { chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") proc pipelined_proc(tkn: token, st: bits[32], init={1}) { - send.1: token = send(tkn, st, channel_id=1, id=1) + send.1: token = send(tkn, st, channel=out, id=1) next (send.1, st) } )"; @@ -3423,12 +3425,12 @@ chan in_out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_va #[initiation_interval(2)] proc pipelined_proc(tkn: token, st: bits[32], init={0}) { - send.1: token = send(tkn, st, channel_id=1, id=1) + send.1: token = send(tkn, st, channel=out, id=1) min_delay.2: token = min_delay(send.1, delay=1, id=2) - receive.3: (token, bits[32]) = receive(min_delay.2, channel_id=0, id=3) + receive.3: (token, bits[32]) = receive(min_delay.2, channel=in, id=3) tuple_index.4: token = tuple_index(receive.3, index=0, id=4) tuple_index.5: bits[32] = tuple_index(receive.3, index=1, id=5) - send.6: token = send(tuple_index.4, tuple_index.5, channel_id=2, id=6) + send.6: token = send(tuple_index.4, tuple_index.5, channel=in_out, id=6) next (send.6, tuple_index.5) } )"; @@ -3502,12 +3504,12 @@ chan in_out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_va #[initiation_interval(2)] proc pipelined_proc(tkn: token, st: bits[32], init={0}) { - send.1: token = send(tkn, st, channel_id=1, id=1) + send.1: token = send(tkn, st, channel=out, id=1) min_delay.2: token = min_delay(send.1, delay=1, id=2) - receive.3: (token, bits[32]) = receive(min_delay.2, channel_id=0, id=3) + receive.3: (token, bits[32]) = receive(min_delay.2, channel=in, id=3) tuple_index.4: token = tuple_index(receive.3, index=0, id=4) tuple_index.5: bits[32] = tuple_index(receive.3, index=1, id=5) - send.6: token = send(tuple_index.4, tuple_index.5, channel_id=2, id=6) + send.6: token = send(tuple_index.4, tuple_index.5, channel=in_out, id=6) next (send.6, tuple_index.5) } )"; @@ -4155,15 +4157,15 @@ class ProcWithStateTest : public BlockConversionTest { chan c_out(bits[32], id=5, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc test_proc(tkn: token, st_0: bits[32], st_1: bits[32], st_2: bits[32], init={3, 5, 9}) { - receive.107: (token, bits[32]) = receive(tkn, channel_id=0, id=107) - receive.108: (token, bits[32]) = receive(tkn, channel_id=2, id=108) - receive.109: (token, bits[32]) = receive(tkn, channel_id=4, id=109) + receive.107: (token, bits[32]) = receive(tkn, channel=a_in, id=107) + receive.108: (token, bits[32]) = receive(tkn, channel=b_in, id=108) + receive.109: (token, bits[32]) = receive(tkn, channel=c_in, id=109) tuple_index.34: token = tuple_index(receive.107, index=0, id=34) - send.110: token = send(tkn, st_0, channel_id=1, id=110) + send.110: token = send(tkn, st_0, channel=a_out, id=110) tuple_index.43: token = tuple_index(receive.108, index=0, id=43) - send.111: token = send(tkn, st_1, channel_id=3, id=111) + send.111: token = send(tkn, st_1, channel=b_out, id=111) tuple_index.52: token = tuple_index(receive.109, index=0, id=52) - send.112: token = send(tkn, st_2, channel_id=5, id=112) + send.112: token = send(tkn, st_2, channel=c_out, id=112) tuple_index.35: bits[32] = tuple_index(receive.107, index=1, id=35) tuple_index.44: bits[32] = tuple_index(receive.108, index=1, id=44) tuple_index.53: bits[32] = tuple_index(receive.109, index=1, id=53) @@ -4430,12 +4432,12 @@ chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid proc loopback_proc(tkn: token, st: bits[32], init={1}) { lit1: bits[32] = literal(value=1) not_first_cycle: bits[1] = ne(st, lit1) - loopback_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel_id=0) + loopback_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel=loopback) loopback_tkn: token = tuple_index(loopback_recv, index=0) loopback_data: bits[32] = tuple_index(loopback_recv, index=1) sum: bits[32] = add(loopback_data, st) - out_send: token = send(loopback_tkn, sum, channel_id=1) - loopback_send: token = send(out_send, sum, channel_id=0) + out_send: token = send(loopback_tkn, sum, channel=out) + loopback_send: token = send(out_send, sum, channel=loopback) next (loopback_send, sum) } )"; @@ -4478,17 +4480,17 @@ chan out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid proc loopback_proc(tkn: token, st: bits[32], init={1}) { lit1: bits[32] = literal(value=1) not_first_cycle: bits[1] = ne(st, lit1) - loopback0_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel_id=0) + loopback0_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel=loopback0) loopback0_tkn: token = tuple_index(loopback0_recv, index=0) loopback0_data: bits[32] = tuple_index(loopback0_recv, index=1) - loopback1_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel_id=1) + loopback1_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel=loopback1) loopback1_tkn: token = tuple_index(loopback1_recv, index=0) loopback1_data: bits[32] = tuple_index(loopback1_recv, index=1) sum: bits[32] = add(loopback0_data, loopback1_data) loopback_tkn: token = after_all(loopback0_tkn, loopback1_tkn) - out_send: token = send(loopback_tkn, sum, channel_id=2) - loopback0_send: token = send(out_send, sum, channel_id=0) - loopback1_send: token = send(out_send, sum, channel_id=1) + out_send: token = send(loopback_tkn, sum, channel=out) + loopback0_send: token = send(out_send, sum, channel=loopback0) + loopback1_send: token = send(out_send, sum, channel=loopback1) loopback_send: token = after_all(loopback0_send, loopback1_send) next (loopback_send, sum) } diff --git a/xls/codegen/block_generator_test.cc b/xls/codegen/block_generator_test.cc index 2c7b5a5b47..218a92100b 100644 --- a/xls/codegen/block_generator_test.cc +++ b/xls/codegen/block_generator_test.cc @@ -1063,18 +1063,18 @@ chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid chan loopback(bits[32], id=2, kind=streaming, ops=send_receive, flow_control=ready_valid, fifo_depth=1, bypass=false, metadata="") proc running_sum(tkn: token, first_cycle: bits[1], init={1}) { - in_recv: (token, bits[32]) = receive(tkn, channel_id=0) + in_recv: (token, bits[32]) = receive(tkn, channel=in) in_tkn: token = tuple_index(in_recv, index=0) in_data: bits[32] = tuple_index(in_recv, index=1) lit1: bits[32] = literal(value=1) not_first_cycle: bits[1] = not(first_cycle) - loopback_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel_id=2) + loopback_recv: (token, bits[32]) = receive(tkn, predicate=not_first_cycle, channel=loopback) loopback_tkn: token = tuple_index(loopback_recv, index=0) loopback_data: bits[32] = tuple_index(loopback_recv, index=1) sum: bits[32] = add(loopback_data, in_data) all_recv_tkn: token = after_all(in_tkn, loopback_tkn) - out_send: token = send(all_recv_tkn, sum, channel_id=1) - loopback_send: token = send(out_send, sum, channel_id=2) + out_send: token = send(all_recv_tkn, sum, channel=out) + loopback_send: token = send(out_send, sum, channel=loopback) lit0: bits[1] = literal(value=0) next (loopback_send, lit0) } diff --git a/xls/codegen/pipeline_generator_test.cc b/xls/codegen/pipeline_generator_test.cc index 12d97c3550..b09f045e4c 100644 --- a/xls/codegen/pipeline_generator_test.cc +++ b/xls/codegen/pipeline_generator_test.cc @@ -1112,12 +1112,12 @@ chan in_out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_va #[initiation_interval(2)] proc ii_greater_than_one(tkn: token, st: bits[32], init={0}) { - send.1: token = send(tkn, st, channel_id=1, id=1) + send.1: token = send(tkn, st, channel=out, id=1) min_delay.2: token = min_delay(send.1, delay=1, id=2) - receive.3: (token, bits[32]) = receive(min_delay.2, channel_id=0, id=3) + receive.3: (token, bits[32]) = receive(min_delay.2, channel=in, id=3) tuple_index.4: token = tuple_index(receive.3, index=0, id=4) tuple_index.5: bits[32] = tuple_index(receive.3, index=1, id=5) - send.6: token = send(tuple_index.4, tuple_index.5, channel_id=2, id=6) + send.6: token = send(tuple_index.4, tuple_index.5, channel=in_out, id=6) next (send.6, tuple_index.5) } )", diff --git a/xls/codegen/ram_rewrite_pass_test.cc b/xls/codegen/ram_rewrite_pass_test.cc index f7d580f13a..21f0c1c7af 100644 --- a/xls/codegen/ram_rewrite_pass_test.cc +++ b/xls/codegen/ram_rewrite_pass_test.cc @@ -634,10 +634,10 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { true_lit: bits[1] = literal(value=1) false_lit: bits[1] = literal(value=0) to_send: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(__state, __state, empty_tuple, empty_tuple, true_lit, false_lit) - send_token: token = send(__token, to_send, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token, channel_id=1) + send_token: token = send(__token, to_send, channel=req) + rcv: (token, (bits[32])) = receive(send_token, channel=resp) rcv_token: token = tuple_index(rcv, index=0) - wr_comp_rcv: (token, ()) = receive(rcv_token, channel_id=2) + wr_comp_rcv: (token, ()) = receive(rcv_token, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -660,10 +660,10 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { false_lit: bits[1] = literal(value=0) all_mask: bits[4] = literal(value=0xf) to_send: (bits[32], bits[32], bits[4], bits[4], bits[1], bits[1]) = tuple(__state, __state, all_mask, all_mask, true_lit, false_lit) - send_token: token = send(__token, to_send, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token, channel_id=1) + send_token: token = send(__token, to_send, channel=req) + rcv: (token, (bits[32])) = receive(send_token, channel=resp) rcv_token: token = tuple_index(rcv, index=0) - wr_comp_rcv: (token, ()) = receive(rcv_token, channel_id=2) + wr_comp_rcv: (token, ()) = receive(rcv_token, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -689,15 +689,15 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { false_lit: bits[1] = literal(value=0) empty_tuple: () = literal(value=()) to_send: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(__state, __state, empty_tuple, empty_tuple, true_lit, false_lit) - send_token: token = send(__token, to_send, channel_id=3) - rcv: (token, (bits[32])) = receive(send_token, channel_id=1) + send_token: token = send(__token, to_send, channel=req) + rcv: (token, (bits[32])) = receive(send_token, channel=resp) rcv_token: token = tuple_index(rcv, index=0) one_lit: bits[32] = literal(value=1) - extra0_rcv: (token, bits[1]) = receive(rcv_token, channel_id=0) + extra0_rcv: (token, bits[1]) = receive(rcv_token, channel=extra0) extra0_token: token = tuple_index(extra0_rcv, index=0) - extra1_rcv: (token, bits[1]) = receive(extra0_token, channel_id=2) + extra1_rcv: (token, bits[1]) = receive(extra0_token, channel=extra1) extra1_token: token = tuple_index(extra1_rcv, index=0) - wr_comp_rcv: (token, ()) = receive(extra1_token, channel_id=4) + wr_comp_rcv: (token, ()) = receive(extra1_token, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) next_state: bits[32] = add(__state, one_lit) next (wr_comp_token, next_state) @@ -725,28 +725,28 @@ proc my_proc(__token: token, __state: (), init={()}) { empty_lit: bits[32] = literal(value=0) empty_tuple: () = literal(value=()) to_send0: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(empty_lit, empty_lit, empty_tuple, empty_tuple, false_lit, true_lit) - send0_token: token = send(__token, to_send0, channel_id=0) - rcv0: (token, (bits[32])) = receive(send0_token, channel_id=1) + send0_token: token = send(__token, to_send0, channel=req0) + rcv0: (token, (bits[32])) = receive(send0_token, channel=resp0) rcv0_token: token = tuple_index(rcv0, index=0) rcv0_tuple: (bits[32]) = tuple_index(rcv0, index=1) rcv0_data: bits[32] = tuple_index(rcv0_tuple, index=0) to_send1: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(rcv0_data, empty_lit, empty_tuple, empty_tuple, false_lit, true_lit) - send1_token: token = send(__token, to_send1, channel_id=2) - rcv1: (token, (bits[32])) = receive(send1_token, channel_id=3) + send1_token: token = send(__token, to_send1, channel=req1) + rcv1: (token, (bits[32])) = receive(send1_token, channel=resp1) rcv1_token: token = tuple_index(rcv1, index=0) rcv1_tuple: (bits[32]) = tuple_index(rcv1, index=1) rcv1_data: bits[32] = tuple_index(rcv1_tuple, index=0) to_send2: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(rcv1_data, empty_lit, empty_tuple, empty_tuple, false_lit, true_lit) - send2_token: token = send(__token, to_send2, channel_id=4) - rcv2: (token, (bits[32])) = receive(send2_token, channel_id=5) + send2_token: token = send(__token, to_send2, channel=req2) + rcv2: (token, (bits[32])) = receive(send2_token, channel=resp2) rcv2_token: token = tuple_index(rcv2, index=0) rcv2_tuple: (bits[32]) = tuple_index(rcv2, index=1) rcv2_data: bits[32] = tuple_index(rcv2_tuple, index=0) - wr_comp0_rcv: (token, ()) = receive(send0_token, channel_id=6) + wr_comp0_rcv: (token, ()) = receive(send0_token, channel=wr_comp0) wr_comp0_token: token = tuple_index(wr_comp0_rcv, index=0) - wr_comp1_rcv: (token, ()) = receive(send1_token, channel_id=7) + wr_comp1_rcv: (token, ()) = receive(send1_token, channel=wr_comp1) wr_comp1_token: token = tuple_index(wr_comp1_rcv, index=0) - wr_comp2_rcv: (token, ()) = receive(send2_token, channel_id=8) + wr_comp2_rcv: (token, ()) = receive(send2_token, channel=wr_comp2) wr_comp2_token: token = tuple_index(wr_comp2_rcv, index=0) after_all_token: token = after_all(rcv0_token, rcv1_token, rcv2_token, wr_comp0_token, wr_comp1_token, wr_comp2_token) next_state: () = tuple() @@ -767,12 +767,12 @@ chan wr_comp((), id=3, kind=streaming, ops=receive_only, flow_control=ready_vali proc my_proc(__token: token, __state: bits[32], init={0}) { empty_tuple: () = literal(value=()) to_send0: (bits[32], ()) = tuple(__state, empty_tuple) - send_token0: token = send(__token, to_send0, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=rd_req) + rcv: (token, (bits[32])) = receive(send_token0, channel=rd_resp) rcv_token: token = tuple_index(rcv, index=0) to_send1: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token1: token = send(rcv_token, to_send1, channel_id=2) - wr_comp_rcv: (token, ()) = receive(send_token1, channel_id=3) + send_token1: token = send(rcv_token, to_send1, channel=wr_req) + wr_comp_rcv: (token, ()) = receive(send_token1, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -794,12 +794,12 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { all_mask: bits[4] = literal(value=0xf) empty_tuple: () = literal(value=()) to_send0: (bits[32], bits[4]) = tuple(__state, all_mask) - send_token0: token = send(__token, to_send0, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=rd_req) + rcv: (token, (bits[32])) = receive(send_token0, channel=rd_resp) rcv_token: token = tuple_index(rcv, index=0) to_send1: (bits[32], bits[32], bits[4]) = tuple(__state, __state, all_mask) - send_token1: token = send(rcv_token, to_send1, channel_id=2) - wr_comp_rcv: (token, ()) = receive(send_token1, channel_id=3) + send_token1: token = send(rcv_token, to_send1, channel=wr_req) + wr_comp_rcv: (token, ()) = receive(send_token1, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -824,16 +824,16 @@ chan extra1(bits[1], id=4, kind=streaming, ops=receive_only, flow_control=ready_ proc my_proc(__token: token, __state: bits[32], init={0}) { empty_tuple: () = literal(value=()) to_send0: (bits[32], ()) = tuple(__state, empty_tuple) - send_token0: token = send(__token, to_send0, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=rd_req) + rcv: (token, (bits[32])) = receive(send_token0, channel=rd_resp) rcv_token: token = tuple_index(rcv, index=0) to_send1: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token1: token = send(rcv_token, to_send1, channel_id=2) - extra0_rcv: (token, bits[1]) = receive(send_token1, channel_id=3) + send_token1: token = send(rcv_token, to_send1, channel=wr_req) + extra0_rcv: (token, bits[1]) = receive(send_token1, channel=extra0) extra0_token: token = tuple_index(extra0_rcv, index=0) - extra1_rcv: (token, bits[1]) = receive(extra0_token, channel_id=4) + extra1_rcv: (token, bits[1]) = receive(extra0_token, channel=extra1) extra1_token: token = tuple_index(extra1_rcv, index=0) - wr_comp_rcv: (token, ()) = receive(extra1_token, channel_id=5) + wr_comp_rcv: (token, ()) = receive(extra1_token, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -862,26 +862,26 @@ chan wr_comp2((), id=11, kind=streaming, ops=receive_only, flow_control=ready_va proc my_proc(__token: token, __state: bits[32], init={0}) { empty_tuple: () = literal(value=()) to_send0: (bits[32], ()) = tuple(__state, empty_tuple) - send_token0: token = send(__token, to_send0, channel_id=0) - rcv: (token, (bits[32])) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=rd_req0) + rcv: (token, (bits[32])) = receive(send_token0, channel=rd_resp0) rcv_token: token = tuple_index(rcv, index=0) to_send1: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token1: token = send(rcv_token, to_send1, channel_id=2) - send_token2: token = send(send_token1, to_send0, channel_id=3) - rcv1: (token, (bits[32])) = receive(send_token2, channel_id=4) + send_token1: token = send(rcv_token, to_send1, channel=wr_req0) + send_token2: token = send(send_token1, to_send0, channel=rd_req1) + rcv1: (token, (bits[32])) = receive(send_token2, channel=rd_resp1) rcv_token1: token = tuple_index(rcv1, index=0) to_send2: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token3: token = send(rcv_token1, to_send2, channel_id=5) - send_token4: token = send(send_token3, to_send0, channel_id=6) - rcv2: (token, (bits[32])) = receive(send_token4, channel_id=7) + send_token3: token = send(rcv_token1, to_send2, channel=wr_req1) + send_token4: token = send(send_token3, to_send0, channel=rd_req2) + rcv2: (token, (bits[32])) = receive(send_token4, channel=rd_resp2) rcv_token2: token = tuple_index(rcv2, index=0) to_send3: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token5: token = send(rcv_token2, to_send2, channel_id=8) - wr_comp0_rcv: (token, ()) = receive(send_token1, channel_id=9) + send_token5: token = send(rcv_token2, to_send2, channel=wr_req2) + wr_comp0_rcv: (token, ()) = receive(send_token1, channel=wr_comp0) wr_comp0_token: token = tuple_index(wr_comp0_rcv, index=0) - wr_comp1_rcv: (token, ()) = receive(send_token3, channel_id=10) + wr_comp1_rcv: (token, ()) = receive(send_token3, channel=wr_comp1) wr_comp1_token: token = tuple_index(wr_comp1_rcv, index=0) - wr_comp2_rcv: (token, ()) = receive(send_token5, channel_id=11) + wr_comp2_rcv: (token, ()) = receive(send_token5, channel=wr_comp2) wr_comp2_token: token = tuple_index(wr_comp2_rcv, index=0) next_token: token = after_all(rcv_token2, wr_comp0_token, wr_comp1_token, wr_comp2_token) one_lit: bits[32] = literal(value=1) @@ -909,19 +909,19 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { true_lit: bits[1] = literal(value=1) false_lit: bits[1] = literal(value=0) to_send0: (bits[32], bits[32], (), (), bits[1], bits[1]) = tuple(__state, __state, empty_tuple, empty_tuple, true_lit, false_lit) - send_token0: token = send(__token, to_send0, channel_id=0) - rcv0: (token, (bits[32])) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=req0) + rcv0: (token, (bits[32])) = receive(send_token0, channel=resp0) rcv_token0: token = tuple_index(rcv0, index=0) one_lit: bits[32] = literal(value=1) to_send1: (bits[32], ()) = tuple(__state, empty_tuple) - send_token1: token = send(rcv_token0, to_send1, channel_id=2) - rcv1: (token, (bits[32])) = receive(send_token1, channel_id=3) + send_token1: token = send(rcv_token0, to_send1, channel=rd_req1) + rcv1: (token, (bits[32])) = receive(send_token1, channel=rd_resp1) rcv_token1: token = tuple_index(rcv1, index=0) to_send2: (bits[32], bits[32], ()) = tuple(__state, __state, empty_tuple) - send_token2: token = send(rcv_token1, to_send2, channel_id=4) - wr_comp0_rcv: (token, ()) = receive(send_token0, channel_id=5) + send_token2: token = send(rcv_token1, to_send2, channel=wr_req1) + wr_comp0_rcv: (token, ()) = receive(send_token0, channel=wr_comp0) wr_comp0_token: token = tuple_index(wr_comp0_rcv, index=0) - wr_comp1_rcv: (token, ()) = receive(send_token2, channel_id=6) + wr_comp1_rcv: (token, ()) = receive(send_token2, channel=wr_comp1) wr_comp1_token: token = tuple_index(wr_comp1_rcv, index=0) next_token: token = after_all(send_token2, wr_comp0_token, wr_comp1_token) next_state: bits[32] = add(__state, one_lit) @@ -1029,10 +1029,10 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { false_lit: bits[1] = literal(value=0) empty_tuple: () = literal(value=()) to_send: $req_type = $send_value - send_token: token = send(__token, to_send, channel_id=0) - rcv: (token, $resp_type) = receive(send_token, channel_id=1) + send_token: token = send(__token, to_send, channel=req) + rcv: (token, $resp_type) = receive(send_token, channel=resp) rcv_token: token = tuple_index(rcv, index=0) - wr_comp_rcv: (token, $wr_comp_type) = receive(rcv_token, channel_id=2) + wr_comp_rcv: (token, $wr_comp_type) = receive(rcv_token, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_rcv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) @@ -1088,12 +1088,12 @@ proc my_proc(__token: token, __state: bits[32], init={0}) { all_mask: bits[4] = literal(value=0xf) empty_tuple: () = literal(value=()) to_send0: $rd_req_type = $rd_send_value - send_token0: token = send(__token, to_send0, channel_id=0) - rcv: (token, $rd_resp_type) = receive(send_token0, channel_id=1) + send_token0: token = send(__token, to_send0, channel=rd_req) + rcv: (token, $rd_resp_type) = receive(send_token0, channel=rd_resp) rcv_token: token = tuple_index(rcv, index=0) to_send1: $wr_req_type = $wr_send_value - send_token1: token = send(rcv_token, to_send1, channel_id=2) - wr_comp_recv: (token, $wr_comp_type) = receive(send_token1, channel_id=3) + send_token1: token = send(rcv_token, to_send1, channel=wr_req) + wr_comp_recv: (token, $wr_comp_type) = receive(send_token1, channel=wr_comp) wr_comp_token: token = tuple_index(wr_comp_recv, index=0) one_lit: bits[32] = literal(value=1) next_state: bits[32] = add(__state, one_lit) diff --git a/xls/codegen/side_effect_condition_pass_test.cc b/xls/codegen/side_effect_condition_pass_test.cc index 36f9ec366a..d0800708b4 100644 --- a/xls/codegen/side_effect_condition_pass_test.cc +++ b/xls/codegen/side_effect_condition_pass_test.cc @@ -206,13 +206,13 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") top proc g(tok: token, x: (), init={()}) { - recv_tuple: (token, bits[32]) = receive(tok, channel_id=0) + recv_tuple: (token, bits[32]) = receive(tok, channel=in) recv_token: token = tuple_index(recv_tuple, index=0) recv_data: bits[32] = tuple_index(recv_tuple, index=1) xy: bits[32] = umul(recv_data, recv_data) literal1: bits[32] = literal(value=1) xy_plus_1: bits[32] = add(xy, literal1) - send: token = send(recv_token, xy_plus_1, channel_id=1) + send: token = send(recv_token, xy_plus_1, channel=out) literal4: bits[32] = literal(value=4) xy_plus_1_gt_4: bits[1] = ugt(xy_plus_1, literal4) assertion: token = assert(send, xy_plus_1_gt_4, label="foo", message="bar") @@ -432,13 +432,13 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") top proc f(tkn: token, x: bits[32], init={0}) { - y_recv: (token, bits[32]) = receive(tkn, channel_id=0) + y_recv: (token, bits[32]) = receive(tkn, channel=in) y_token: token = tuple_index(y_recv, index=0) y: bits[32] = tuple_index(y_recv, index=1) x_lt_y: bits[1] = ult(x, y) assertion: token = assert(y_token, x_lt_y, label="foo", message="bar") sum: bits[32] = add(x, y) - send_tok: token = send(assertion, sum, channel_id=1) + send_tok: token = send(assertion, sum, channel=out) next (send_tok, sum) } )"; @@ -556,13 +556,13 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") proc g(tok: token, x: bits[32], init={4}) { - recv_tuple: (token, bits[32]) = receive(tok, channel_id=0) + recv_tuple: (token, bits[32]) = receive(tok, channel=in) recv_token: token = tuple_index(recv_tuple, index=0) recv_data: bits[32] = tuple_index(recv_tuple, index=1) xy: bits[32] = umul(x, recv_data) literal1: bits[32] = literal(value=1) xy_plus_1: bits[32] = add(xy, literal1) - send: token = send(recv_token, xy_plus_1, channel_id=1) + send: token = send(recv_token, xy_plus_1, channel=out) literal4: bits[32] = literal(value=4) xy_plus_1_gt_4: bits[1] = ugt(xy_plus_1, literal4) assertion: token = assert(send, xy_plus_1_gt_4, label="foo", message="bar") @@ -621,15 +621,15 @@ chan in_out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_va #[initiation_interval(2)] top proc ii_greater_than_one(tkn: token, st: bits[32], init={0}) { - send0_token: token = send(tkn, st, channel_id=1) + send0_token: token = send(tkn, st, channel=out) min_delay_token: token = min_delay(send0_token, delay=1) - receive_tuple: (token, bits[32]) = receive(min_delay_token, channel_id=0) + receive_tuple: (token, bits[32]) = receive(min_delay_token, channel=in) receive_token: token = tuple_index(receive_tuple, index=0) receive_data: bits[32] = tuple_index(receive_tuple, index=1) literal5: bits[32] = literal(value=5) receive_data_lt_5: bits[1] = ult(receive_data, literal5) assertion: token = assert(receive_token, receive_data_lt_5, label="foo", message="bar") - send1_token: token = send(assertion, receive_data, channel_id=2) + send1_token: token = send(assertion, receive_data, channel=in_out) next (send1_token, receive_data) } )"; diff --git a/xls/codegen/signature_generator.cc b/xls/codegen/signature_generator.cc index 2c161ffe6e..97f0d2f84e 100644 --- a/xls/codegen/signature_generator.cc +++ b/xls/codegen/signature_generator.cc @@ -144,9 +144,9 @@ absl::StatusOr GenerateSignature( const FifoInstantiation* fifo = down_cast(instantiation); std::optional channel_name; - if (fifo->channel_id().has_value()) { + if (fifo->channel_name().has_value()) { XLS_ASSIGN_OR_RETURN(Channel * ch, - p->GetChannel(*fifo->channel_id())); + p->GetChannel(*fifo->channel_name())); channel_name = ch->name(); } b.AddFifoInstantiation(p, fifo->name(), channel_name, fifo->data_type(), diff --git a/xls/codegen/signature_generator_test.cc b/xls/codegen/signature_generator_test.cc index 94f54621a5..4ca09cf930 100644 --- a/xls/codegen/signature_generator_test.cc +++ b/xls/codegen/signature_generator_test.cc @@ -348,18 +348,18 @@ block my_block(in: bits[32], out: (bits[32])) { } TEST(SignatureGeneratorTest, BlockWithFifoInstantiationWithChannel) { - constexpr std::string_view ir_text =R"(package test + constexpr std::string_view ir_text = R"(package test chan a(bits[32], id=0, ops=send_only, fifo_depth=3, bypass=false, kind=streaming, flow_control=ready_valid, metadata="") proc needed_to_verify(tok: token, state: (), init={()}) { literal0: bits[32] = literal(value=32) - send_tok: token = send(tok, literal0, channel_id=0) + send_tok: token = send(tok, literal0, channel=a) next(send_tok, state) } block my_block(in: bits[32], out: (bits[32])) { in: bits[32] = input_port(name=in) - instantiation my_inst(data_type=(bits[32]), depth=3, bypass=false, channel_id=0, kind=fifo) + instantiation my_inst(data_type=(bits[32]), depth=3, bypass=false, channel=a, kind=fifo) in_inst_input: () = instantiation_input(in, instantiation=my_inst, port_name=push_data) pop_data_inst_output: (bits[32]) = instantiation_output(instantiation=my_inst, port_name=pop_data) out_output_port: () = output_port(pop_data_inst_output, name=out) diff --git a/xls/contrib/xlscc/unit_tests/translator_memory_test.cc b/xls/contrib/xlscc/unit_tests/translator_memory_test.cc index d24a460d3f..60de0cd5d8 100644 --- a/xls/contrib/xlscc/unit_tests/translator_memory_test.cc +++ b/xls/contrib/xlscc/unit_tests/translator_memory_test.cc @@ -1023,21 +1023,21 @@ TEST_F(TranslatorMemoryTest, MemoryUnused) { XLS_ASSERT_OK_AND_ASSIGN(xls::Channel * channel, package_->GetChannel("foo_unused__read_request")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } { XLS_ASSERT_OK_AND_ASSIGN(xls::Channel * channel, package_->GetChannel("foo_unused__read_response")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } { XLS_ASSERT_OK_AND_ASSIGN(xls::Channel * channel, package_->GetChannel("foo_unused__write_request")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } { @@ -1045,7 +1045,7 @@ TEST_F(TranslatorMemoryTest, MemoryUnused) { xls::Channel * channel, package_->GetChannel("foo_unused__write_response")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } @@ -1186,33 +1186,33 @@ TEST_F(TranslatorMemoryTest, MemoryTokenNetwork) { xls::Proc * ret, translator_->GenerateIR_BlockFromClass(package_.get(), &block_spec)); - int64_t memory_read_request_id = -1, memory_read_response_id = -1; + std::string_view memory_read_request, memory_read_response; for (xls::Channel* channel : package_->channels()) { const std::string ch_name = channel->name(); if (ch_name == "memory__read_request") { - memory_read_request_id = channel->id(); + memory_read_request = channel->name(); } else if (ch_name == "memory__read_response") { - memory_read_response_id = channel->id(); + memory_read_response = channel->name(); } } - ASSERT_GE(memory_read_request_id, 0); - ASSERT_GE(memory_read_response_id, 0); + ASSERT_FALSE(memory_read_request.empty()); + ASSERT_FALSE(memory_read_response.empty()); XLS_ASSERT_OK_AND_ASSIGN( - std::vector nodes_for_memory_read_response_id, - GetIOOpsForChannel(ret, memory_read_response_id)); - ASSERT_EQ(nodes_for_memory_read_response_id.size(), 1); + std::vector nodes_for_memory_read_response, + GetIOOpsForChannel(ret, memory_read_response)); + ASSERT_EQ(nodes_for_memory_read_response.size(), 1); XLS_ASSERT_OK_AND_ASSIGN( - std::vector nodes_for_memory_read_request_id, - GetIOOpsForChannel(ret, memory_read_request_id)); - ASSERT_EQ(nodes_for_memory_read_request_id.size(), 1); + std::vector nodes_for_memory_read_request, + GetIOOpsForChannel(ret, memory_read_request)); + ASSERT_EQ(nodes_for_memory_read_request.size(), 1); XLS_ASSERT_OK_AND_ASSIGN( bool request_before_response, - NodeIsAfterTokenWise(ret, /*before=*/nodes_for_memory_read_request_id[0], - /*after=*/nodes_for_memory_read_response_id[0])); + NodeIsAfterTokenWise(ret, /*before=*/nodes_for_memory_read_request[0], + /*after=*/nodes_for_memory_read_response[0])); EXPECT_TRUE(request_before_response); } @@ -1240,33 +1240,33 @@ TEST_F(TranslatorMemoryTest, MemoryTokenNetworkReadAfterWrite) { xls::Proc * ret, translator_->GenerateIR_BlockFromClass(package_.get(), &block_spec)); - int64_t memory_read_request_id = -1, memory_write_request_id = -1; + std::string_view memory_read_request, memory_write_request; for (xls::Channel* channel : package_->channels()) { const std::string ch_name = channel->name(); if (ch_name == "memory__read_request") { - memory_read_request_id = channel->id(); + memory_read_request = channel->name(); } else if (ch_name == "memory__write_request") { - memory_write_request_id = channel->id(); + memory_write_request = channel->name(); } } - ASSERT_GE(memory_read_request_id, 0); - ASSERT_GE(memory_write_request_id, 0); + ASSERT_FALSE(memory_read_request.empty()); + ASSERT_FALSE(memory_write_request.empty()); XLS_ASSERT_OK_AND_ASSIGN( - std::vector nodes_for_memory_read_request_id, - GetIOOpsForChannel(ret, memory_read_request_id)); - ASSERT_EQ(nodes_for_memory_read_request_id.size(), 1); + std::vector nodes_for_memory_read_request, + GetIOOpsForChannel(ret, memory_read_request)); + ASSERT_EQ(nodes_for_memory_read_request.size(), 1); XLS_ASSERT_OK_AND_ASSIGN( - std::vector nodes_for_memory_write_request_id, - GetIOOpsForChannel(ret, memory_write_request_id)); - ASSERT_EQ(nodes_for_memory_write_request_id.size(), 1); + std::vector nodes_for_memory_write_request, + GetIOOpsForChannel(ret, memory_write_request)); + ASSERT_EQ(nodes_for_memory_write_request.size(), 1); XLS_ASSERT_OK_AND_ASSIGN( bool write_before_read, - NodeIsAfterTokenWise(ret, /*before=*/nodes_for_memory_write_request_id[0], - /*after=*/nodes_for_memory_read_request_id[0])); + NodeIsAfterTokenWise(ret, /*before=*/nodes_for_memory_write_request[0], + /*after=*/nodes_for_memory_read_request[0])); EXPECT_TRUE(write_before_read); } diff --git a/xls/contrib/xlscc/unit_tests/translator_proc_test.cc b/xls/contrib/xlscc/unit_tests/translator_proc_test.cc index cedfb81daf..4e9ac679cc 100644 --- a/xls/contrib/xlscc/unit_tests/translator_proc_test.cc +++ b/xls/contrib/xlscc/unit_tests/translator_proc_test.cc @@ -191,14 +191,14 @@ TEST_F(TranslatorProcTest, IOProcUnusedChannels) { XLS_ASSERT_OK_AND_ASSIGN(xls::Channel * channel, package_->GetChannel("in_unused1")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } { XLS_ASSERT_OK_AND_ASSIGN(xls::Channel * channel, package_->GetChannel("in_unused2")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); } @@ -262,7 +262,7 @@ TEST_F(TranslatorProcTest, IOProcUnusedDirectIn) { package_->GetChannel("dir_unused")); XLS_ASSERT_OK_AND_ASSIGN(std::vector ops, - GetOpsForChannel(channel->id())); + GetOpsForChannel(channel->name())); EXPECT_FALSE(ops.empty()); diff --git a/xls/contrib/xlscc/unit_tests/unit_test.cc b/xls/contrib/xlscc/unit_tests/unit_test.cc index 088d767f17..95bf0bd634 100644 --- a/xls/contrib/xlscc/unit_tests/unit_test.cc +++ b/xls/contrib/xlscc/unit_tests/unit_test.cc @@ -533,16 +533,16 @@ absl::StatusOr XlsccTestBase::GetBlockSpec() { } absl::StatusOr> XlsccTestBase::GetIOOpsForChannel( - xls::FunctionBase* proc, int64_t channel_id) { + xls::FunctionBase* proc, std::string_view channel) { std::vector ret; for (xls::Node* node : proc->nodes()) { if (node->Is()) { - if (node->As()->channel_id() == channel_id) { + if (node->As()->channel_name() == channel) { ret.push_back(node); } } if (node->Is()) { - if (node->As()->channel_id() == channel_id) { + if (node->As()->channel_name() == channel) { ret.push_back(node); } } @@ -596,17 +596,17 @@ absl::StatusOr XlsccTestBase::NodeIsAfterTokenWise(xls::Proc* proc, } absl::StatusOr> XlsccTestBase::GetOpsForChannel( - int64_t channel_id) { + std::string_view channel) { std::vector ret; XLS_CHECK_NE(package_.get(), nullptr); for (const std::unique_ptr& proc : package_->procs()) { for (xls::Node* node : proc->nodes()) { if (node->Is() && - node->As()->channel_id() == channel_id) { + node->As()->channel_name() == channel) { ret.push_back(node); } if (node->Is() && - node->As()->channel_id() == channel_id) { + node->As()->channel_name() == channel) { ret.push_back(node); } } diff --git a/xls/contrib/xlscc/unit_tests/unit_test.h b/xls/contrib/xlscc/unit_tests/unit_test.h index ce35698378..af8d10a4ba 100644 --- a/xls/contrib/xlscc/unit_tests/unit_test.h +++ b/xls/contrib/xlscc/unit_tests/unit_test.h @@ -173,14 +173,15 @@ class XlsccTestBase : public xls::IrTestBase, public ::xls::LogSink { absl::StatusOr GetBlockSpec(); absl::StatusOr> GetIOOpsForChannel( - xls::FunctionBase* proc, int64_t channel_id); + xls::FunctionBase* proc, std::string_view channel); static absl::Status TokensForNode( xls::Node* node, absl::flat_hash_set& predecessors); absl::StatusOr NodeIsAfterTokenWise(xls::Proc* proc, xls::Node* before, xls::Node* after); - absl::StatusOr> GetOpsForChannel(int64_t channel_id); + absl::StatusOr> GetOpsForChannel( + std::string_view channel); std::unique_ptr package_; std::unique_ptr translator_; diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_BoundaryChannels.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_BoundaryChannels.ir index 52ffaeb2f0..47173bed4e 100644 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_BoundaryChannels.ir +++ b/xls/dslx/ir_convert/testdata/ir_converter_test_BoundaryChannels.ir @@ -7,16 +7,16 @@ chan test_module__in_1(bits[32], id=1, kind=streaming, ops=receive_only, flow_co chan test_module__output(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=proven_mutually_exclusive, metadata="""""") top proc __test_module__foo_0_next(__token: token, __state: (), init={()}) { - receive.4: (token, bits[32]) = receive(__token, channel_id=0, id=4) + receive.4: (token, bits[32]) = receive(__token, channel=test_module__in_0, id=4) tok: token = tuple_index(receive.4, index=0, id=6) - receive.8: (token, bits[32]) = receive(tok, channel_id=1, id=8) + receive.8: (token, bits[32]) = receive(tok, channel=test_module__in_1, id=8) a: bits[32] = tuple_index(receive.4, index=1, id=7) b: bits[32] = tuple_index(receive.8, index=1, id=11) tok__1: token = tuple_index(receive.8, index=0, id=10) add.12: bits[32] = add(a, b, id=12) tuple_index.5: token = tuple_index(receive.4, index=0, id=5) tuple_index.9: token = tuple_index(receive.8, index=0, id=9) - tok__2: token = send(tok__1, add.12, channel_id=2, id=13) + tok__2: token = send(tok__1, add.12, channel=test_module__output, id=13) literal.3: bits[1] = literal(value=1, id=3) tuple.14: () = tuple(id=14) after_all.15: token = after_all(__token, tuple_index.5, tuple_index.9, tok__2, id=15) diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_HandlesBasicProc.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_HandlesBasicProc.ir index 239ba03d59..bc284360eb 100644 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_HandlesBasicProc.ir +++ b/xls/dslx/ir_convert/testdata/ir_converter_test_HandlesBasicProc.ir @@ -21,7 +21,7 @@ top proc __test_module__main_0_next(__token: token, __state: (), init={()}) { proc __test_module__main__producer_0_next(__token: token, __state: bits[32], init={0}) { literal.12: bits[32] = literal(value=1, id=12) - tok: token = send(__token, __state, channel_id=0, id=11) + tok: token = send(__token, __state, channel=main_chandecl_test_module_x_33_18_33_26, id=11) literal.10: bits[1] = literal(value=1, id=10) add.13: bits[32] = add(__state, literal.12, id=13) after_all.14: token = after_all(__token, tok, id=14) @@ -29,7 +29,7 @@ proc __test_module__main__producer_0_next(__token: token, __state: bits[32], ini } proc __test_module__main__consumer_0_next(__token: token, __state: bits[32], init={0}) { - receive.18: (token, bits[32]) = receive(__token, channel_id=0, id=18) + receive.18: (token, bits[32]) = receive(__token, channel=main_chandecl_test_module_x_33_18_33_26, id=18) i: bits[32] = tuple_index(receive.18, index=1, id=21) tuple_index.19: token = tuple_index(receive.18, index=0, id=19) literal.17: bits[1] = literal(value=1, id=17) diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_Join.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_Join.ir index fb659a190d..d95c23b491 100644 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_Join.ir +++ b/xls/dslx/ir_convert/testdata/ir_converter_test_Join.ir @@ -21,16 +21,16 @@ top proc __test_module__main_0_next(__token: token, __state: (), init={()}) { proc __test_module__main__foo_0_next(__token: token, __state: bits[32], init={0}) { zero_ext.10: bits[32] = zero_ext(__state, new_bit_count=32, id=10) - tok0: token = send(__token, zero_ext.10, channel_id=1, id=11) + tok0: token = send(__token, zero_ext.10, channel=main__foo_chandecl_test_module_x_12_20_12_28, id=11) zero_ext.16: bits[32] = zero_ext(__state, new_bit_count=32, id=16) zero_ext.12: bits[32] = zero_ext(__state, new_bit_count=32, id=12) zero_ext.14: bits[32] = zero_ext(__state, new_bit_count=32, id=14) zero_ext.18: bits[32] = zero_ext(__state, new_bit_count=32, id=18) - tok3: token = send(tok0, zero_ext.16, channel_id=1, id=17) - tok1: token = send(__token, zero_ext.12, channel_id=2, id=13) - tok2: token = send(__token, zero_ext.14, channel_id=3, id=15) - send.19: token = send(tok0, zero_ext.18, channel_id=1, id=19) - receive.21: (token, bits[32]) = receive(tok3, channel_id=4, id=21) + tok3: token = send(tok0, zero_ext.16, channel=main__foo_chandecl_test_module_x_12_20_12_28, id=17) + tok1: token = send(__token, zero_ext.12, channel=main__foo_chandecl_test_module_x_13_20_13_28, id=13) + tok2: token = send(__token, zero_ext.14, channel=main__foo_chandecl_test_module_x_14_20_14_28, id=15) + send.19: token = send(tok0, zero_ext.18, channel=main__foo_chandecl_test_module_x_12_20_12_28, id=19) + receive.21: (token, bits[32]) = receive(tok3, channel=main__foo_chandecl_test_module_x_15_20_15_28, id=21) literal.25: bits[32] = literal(value=1, id=25) tok: token = after_all(tok0, tok1, tok2, send.19, id=20) tuple_index.22: token = tuple_index(receive.21, index=0, id=22) diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_SendIfRecvIf.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_SendIfRecvIf.ir index a7832ce2b2..b02489c69e 100644 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_SendIfRecvIf.ir +++ b/xls/dslx/ir_convert/testdata/ir_converter_test_SendIfRecvIf.ir @@ -21,7 +21,7 @@ top proc __test_module__main_0_next(__token: token, __state: (), init={()}) { proc __test_module__main__producer_0_next(__token: token, __state: bits[1], init={0}) { zero_ext.11: bits[32] = zero_ext(__state, new_bit_count=32, id=11) - send.12: token = send(__token, zero_ext.11, predicate=__state, channel_id=0, id=12) + send.12: token = send(__token, zero_ext.11, predicate=__state, channel=main_chandecl_test_module_x_38_18_38_26, id=12) literal.10: bits[1] = literal(value=1, id=10) not.13: bits[1] = not(__state, id=13) after_all.14: token = after_all(__token, send.12, id=14) @@ -29,7 +29,7 @@ proc __test_module__main__producer_0_next(__token: token, __state: bits[1], init } proc __test_module__main__consumer_0_next(__token: token, __state: bits[1], init={0}) { - receive.19: (token, bits[32]) = receive(__token, predicate=__state, channel_id=0, id=19) + receive.19: (token, bits[32]) = receive(__token, predicate=__state, channel=main_chandecl_test_module_x_38_18_38_26, id=19) literal.18: bits[32] = literal(value=42, id=18) tuple_index.21: bits[32] = tuple_index(receive.19, index=1, id=21) tuple_index.20: token = tuple_index(receive.19, index=0, id=20) diff --git a/xls/dslx/ir_convert/testdata/ir_converter_test_TraceFmt.ir b/xls/dslx/ir_convert/testdata/ir_converter_test_TraceFmt.ir index cdd21221be..4b8f18ffd6 100644 --- a/xls/dslx/ir_convert/testdata/ir_converter_test_TraceFmt.ir +++ b/xls/dslx/ir_convert/testdata/ir_converter_test_TraceFmt.ir @@ -33,7 +33,7 @@ fn __itok__test_module__assert_trace_and_add(__token: token, __activated: bits[1 top proc __test_module__main_0_next(__token: token, __state: bits[32], init={0}) { literal.29: bits[1] = literal(value=1, id=29) invoke.31: (token, bits[32]) = invoke(__token, literal.29, __state, to_apply=__itok__test_module__assert_trace_and_add, id=31) - tok: token = send(__token, __state, channel_id=0, id=30) + tok: token = send(__token, __state, channel=test_module__input_c, id=30) tuple_index.32: token = tuple_index(invoke.31, index=0, id=32) tuple_index.33: bits[32] = tuple_index(invoke.31, index=1, id=33) after_all.34: token = after_all(__token, tok, tuple_index.32, id=34) diff --git a/xls/examples/matmul_4x4.ir b/xls/examples/matmul_4x4.ir index 2ba0fc073a..967258ff30 100644 --- a/xls/examples/matmul_4x4.ir +++ b/xls/examples/matmul_4x4.ir @@ -83,7 +83,7 @@ proc tile_0_0(my_token: token, state: (), init={()}) { literal.1: bits[32] = literal(value=2) // Receive an activation from the left. - receive.2: (token, bits[32]) = receive(my_token, channel_id=0) + receive.2: (token, bits[32]) = receive(my_token, channel=c_0_0_x) // Compute our partial sum. tuple_index.3: token = tuple_index(receive.2, index=0) @@ -91,223 +91,223 @@ proc tile_0_0(my_token: token, state: (), init={()}) { umul.5: bits[32] = umul(literal.1, tuple_index.4) // Send our partial sum south. - send.6: token = send(tuple_index.3, umul.5, channel_id=14) + send.6: token = send(tuple_index.3, umul.5, channel=c_1_0_y) // Send our activation east. - send.7: token = send(send.6, tuple_index.4, channel_id=1) + send.7: token = send(send.6, tuple_index.4, channel=c_0_1_x) next (send.7, state) } proc tile_0_1(my_token: token, state: (), init={()}) { literal.101: bits[32] = literal(value=0) - receive.102: (token, bits[32]) = receive(my_token, channel_id=1) + receive.102: (token, bits[32]) = receive(my_token, channel=c_0_1_x) tuple_index.103: token = tuple_index(receive.102, index=0) tuple_index.104: bits[32] = tuple_index(receive.102, index=1) umul.105: bits[32] = umul(literal.101, tuple_index.104) - send.106: token = send(tuple_index.103, umul.105, channel_id=15) - send.107: token = send(send.106, tuple_index.104, channel_id=2) + send.106: token = send(tuple_index.103, umul.105, channel=c_1_1_y) + send.107: token = send(send.106, tuple_index.104, channel=c_0_2_x) next (send.107, state) } proc tile_0_2(my_token: token, state: (), init={()}) { literal.201: bits[32] = literal(value=0) - receive.202: (token, bits[32]) = receive(my_token, channel_id=2) + receive.202: (token, bits[32]) = receive(my_token, channel=c_0_2_x) tuple_index.203: token = tuple_index(receive.202, index=0) tuple_index.204: bits[32] = tuple_index(receive.202, index=1) umul.205: bits[32] = umul(literal.201, tuple_index.204) - send.206: token = send(tuple_index.203, umul.205, channel_id=16) - send.207: token = send(send.206, tuple_index.204, channel_id=3) + send.206: token = send(tuple_index.203, umul.205, channel=c_1_2_y) + send.207: token = send(send.206, tuple_index.204, channel=c_0_3_x) next (send.207, state) } proc tile_0_3(my_token: token, state: (), init={()}) { literal.301: bits[32] = literal(value=0) - receive.302: (token, bits[32]) = receive(my_token, channel_id=3) + receive.302: (token, bits[32]) = receive(my_token, channel=c_0_3_x) tuple_index.303: token = tuple_index(receive.302, index=0) tuple_index.304: bits[32] = tuple_index(receive.302, index=1) umul.305: bits[32] = umul(literal.301, tuple_index.304) - send.306: token = send(tuple_index.303, umul.305, channel_id=17) + send.306: token = send(tuple_index.303, umul.305, channel=c_1_3_y) // Eastern-most tiles don't send activations any further. next (send.306, state) } proc tile_1_0(my_token: token, state: (), init={()}) { literal.1001: bits[32] = literal(value=0) - receive.1002: (token, bits[32]) = receive(my_token, channel_id=10) + receive.1002: (token, bits[32]) = receive(my_token, channel=c_1_0_x) tuple_index.1003: token = tuple_index(receive.1002, index=0) tuple_index.1004: bits[32] = tuple_index(receive.1002, index=1) - receive.1005: (token, bits[32]) = receive(tuple_index.1003, channel_id=14) + receive.1005: (token, bits[32]) = receive(tuple_index.1003, channel=c_1_0_y) tuple_index.1006: token = tuple_index(receive.1005, index=0) tuple_index.1007: bits[32] = tuple_index(receive.1005, index=1) umul.1008: bits[32] = umul(literal.1001, tuple_index.1004) add.1009: bits[32] = add(umul.1008, tuple_index.1007) - send.1010: token = send(tuple_index.1006, add.1009, channel_id=24) - send.1011: token = send(send.1010, tuple_index.1004, channel_id=11) + send.1010: token = send(tuple_index.1006, add.1009, channel=c_2_0_y) + send.1011: token = send(send.1010, tuple_index.1004, channel=c_1_1_x) next (send.1011, state) } proc tile_1_1(my_token: token, state: (), init={()}) { literal.1101: bits[32] = literal(value=2) - receive.1102: (token, bits[32]) = receive(my_token, channel_id=11) + receive.1102: (token, bits[32]) = receive(my_token, channel=c_1_1_x) tuple_index.1103: token = tuple_index(receive.1102, index=0) tuple_index.1104: bits[32] = tuple_index(receive.1102, index=1) - receive.1105: (token, bits[32]) = receive(tuple_index.1103, channel_id=15) + receive.1105: (token, bits[32]) = receive(tuple_index.1103, channel=c_1_1_y) tuple_index.1106: token = tuple_index(receive.1105, index=0) tuple_index.1107: bits[32] = tuple_index(receive.1105, index=1) umul.1108: bits[32] = umul(literal.1101, tuple_index.1104) add.1109: bits[32] = add(umul.1108, tuple_index.1107) - send.1110: token = send(tuple_index.1106, add.1109, channel_id=25) - send.1111: token = send(send.1110, tuple_index.1104, channel_id=12) + send.1110: token = send(tuple_index.1106, add.1109, channel=c_2_1_y) + send.1111: token = send(send.1110, tuple_index.1104, channel=c_1_2_x) next (send.1111, state) } proc tile_1_2(my_token: token, state: (), init={()}) { literal.1201: bits[32] = literal(value=0) - receive.1202: (token, bits[32]) = receive(my_token, channel_id=12) + receive.1202: (token, bits[32]) = receive(my_token, channel=c_1_2_x) tuple_index.1203: token = tuple_index(receive.1202, index=0) tuple_index.1204: bits[32] = tuple_index(receive.1202, index=1) - receive.1205: (token, bits[32]) = receive(tuple_index.1203, channel_id=16) + receive.1205: (token, bits[32]) = receive(tuple_index.1203, channel=c_1_2_y) tuple_index.1206: token = tuple_index(receive.1205, index=0) tuple_index.1207: bits[32] = tuple_index(receive.1205, index=1) umul.1208: bits[32] = umul(literal.1201, tuple_index.1204) add.1209: bits[32] = add(umul.1208, tuple_index.1207) - send.1210: token = send(tuple_index.1206, add.1209, channel_id=26) - send.1211: token = send(send.1210, tuple_index.1204, channel_id=13) + send.1210: token = send(tuple_index.1206, add.1209, channel=c_2_2_y) + send.1211: token = send(send.1210, tuple_index.1204, channel=c_1_3_x) next (send.1211, state) } proc tile_1_3(my_token: token, state: (), init={()}) { literal.1301: bits[32] = literal(value=0) - receive.1302: (token, bits[32]) = receive(my_token, channel_id=13) + receive.1302: (token, bits[32]) = receive(my_token, channel=c_1_3_x) tuple_index.1303: token = tuple_index(receive.1302, index=0) tuple_index.1304: bits[32] = tuple_index(receive.1302, index=1) - receive.1305: (token, bits[32]) = receive(tuple_index.1303, channel_id=17) + receive.1305: (token, bits[32]) = receive(tuple_index.1303, channel=c_1_3_y) tuple_index.1306: token = tuple_index(receive.1305, index=0) tuple_index.1307: bits[32] = tuple_index(receive.1305, index=1) umul.1308: bits[32] = umul(literal.1301, tuple_index.1304) add.1309: bits[32] = add(umul.1308, tuple_index.1307) - send.1310: token = send(tuple_index.1306, add.1309, channel_id=27) + send.1310: token = send(tuple_index.1306, add.1309, channel=c_2_3_y) // Eastern-most tiles don't send activations any further. next (send.1310, state) } proc tile_2_0(my_token: token, state: (), init={()}) { literal.2001: bits[32] = literal(value=0) - receive.2002: (token, bits[32]) = receive(my_token, channel_id=20) + receive.2002: (token, bits[32]) = receive(my_token, channel=c_2_0_x) tuple_index.2003: token = tuple_index(receive.2002, index=0) tuple_index.2004: bits[32] = tuple_index(receive.2002, index=1) - receive.2005: (token, bits[32]) = receive(tuple_index.2003, channel_id=24) + receive.2005: (token, bits[32]) = receive(tuple_index.2003, channel=c_2_0_y) tuple_index.2006: token = tuple_index(receive.2005, index=0) tuple_index.2007: bits[32] = tuple_index(receive.2005, index=1) umul.2008: bits[32] = umul(literal.2001, tuple_index.2004) add.2009: bits[32] = add(umul.2008, tuple_index.2007) - send.2010: token = send(tuple_index.2006, add.2009, channel_id=34) - send.2011: token = send(send.2010, tuple_index.2004, channel_id=21) + send.2010: token = send(tuple_index.2006, add.2009, channel=c_3_0_y) + send.2011: token = send(send.2010, tuple_index.2004, channel=c_2_1_x) next (send.2011, state) } proc tile_2_1(my_token: token, state: (), init={()}) { literal.2101: bits[32] = literal(value=0) - receive.2102: (token, bits[32]) = receive(my_token, channel_id=21) + receive.2102: (token, bits[32]) = receive(my_token, channel=c_2_1_x) tuple_index.2103: token = tuple_index(receive.2102, index=0) tuple_index.2104: bits[32] = tuple_index(receive.2102, index=1) - receive.2105: (token, bits[32]) = receive(tuple_index.2103, channel_id=25) + receive.2105: (token, bits[32]) = receive(tuple_index.2103, channel=c_2_1_y) tuple_index.2106: token = tuple_index(receive.2105, index=0) tuple_index.2107: bits[32] = tuple_index(receive.2105, index=1) umul.2108: bits[32] = umul(literal.2101, tuple_index.2104) add.2109: bits[32] = add(umul.2108, tuple_index.2107) - send.2110: token = send(tuple_index.2106, add.2109, channel_id=35) - send.2111: token = send(send.2110, tuple_index.2104, channel_id=22) + send.2110: token = send(tuple_index.2106, add.2109, channel=c_3_1_y) + send.2111: token = send(send.2110, tuple_index.2104, channel=c_2_2_x) next (send.2111, state) } proc tile_2_2(my_token: token, state: (), init={()}) { literal.2201: bits[32] = literal(value=2) - receive.2202: (token, bits[32]) = receive(my_token, channel_id=22) + receive.2202: (token, bits[32]) = receive(my_token, channel=c_2_2_x) tuple_index.2203: token = tuple_index(receive.2202, index=0) tuple_index.2204: bits[32] = tuple_index(receive.2202, index=1) - receive.2205: (token, bits[32]) = receive(tuple_index.2203, channel_id=26) + receive.2205: (token, bits[32]) = receive(tuple_index.2203, channel=c_2_2_y) tuple_index.2206: token = tuple_index(receive.2205, index=0) tuple_index.2207: bits[32] = tuple_index(receive.2205, index=1) umul.2208: bits[32] = umul(literal.2201, tuple_index.2204) add.2209: bits[32] = add(umul.2208, tuple_index.2207) - send.2210: token = send(tuple_index.2206, add.2209, channel_id=36) - send.2211: token = send(send.2210, tuple_index.2204, channel_id=23) + send.2210: token = send(tuple_index.2206, add.2209, channel=c_3_2_y) + send.2211: token = send(send.2210, tuple_index.2204, channel=c_2_3_x) next (send.2211, state) } proc tile_2_3(my_token: token, state: (), init={()}) { literal.2301: bits[32] = literal(value=0) - receive.2302: (token, bits[32]) = receive(my_token, channel_id=23) + receive.2302: (token, bits[32]) = receive(my_token, channel=c_2_3_x) tuple_index.2303: token = tuple_index(receive.2302, index=0) tuple_index.2304: bits[32] = tuple_index(receive.2302, index=1) - receive.2305: (token, bits[32]) = receive(tuple_index.2303, channel_id=27) + receive.2305: (token, bits[32]) = receive(tuple_index.2303, channel=c_2_3_y) tuple_index.2306: token = tuple_index(receive.2305, index=0) tuple_index.2307: bits[32] = tuple_index(receive.2305, index=1) umul.2308: bits[32] = umul(literal.2301, tuple_index.2304) add.2309: bits[32] = add(umul.2308, tuple_index.2307) - send.2310: token = send(tuple_index.2306, add.2309, channel_id=37) + send.2310: token = send(tuple_index.2306, add.2309, channel=c_3_3_y) // Eastern-most tiles don't send activations any further. next (send.2310, state) } proc tile_3_0(my_token: token, state: (), init={()}) { literal.3001: bits[32] = literal(value=0) - receive.3002: (token, bits[32]) = receive(my_token, channel_id=30) + receive.3002: (token, bits[32]) = receive(my_token, channel=c_3_0_x) tuple_index.3003: token = tuple_index(receive.3002, index=0) tuple_index.3004: bits[32] = tuple_index(receive.3002, index=1) - receive.3005: (token, bits[32]) = receive(tuple_index.3003, channel_id=34) + receive.3005: (token, bits[32]) = receive(tuple_index.3003, channel=c_3_0_y) tuple_index.3006: token = tuple_index(receive.3005, index=0) tuple_index.3007: bits[32] = tuple_index(receive.3005, index=1) umul.3008: bits[32] = umul(literal.3001, tuple_index.3004) add.3009: bits[32] = add(umul.3008, tuple_index.3007) - send.3010: token = send(tuple_index.3006, add.3009, channel_id=44) - send.3011: token = send(send.3010, tuple_index.3004, channel_id=31) + send.3010: token = send(tuple_index.3006, add.3009, channel=c_3_0_o) + send.3011: token = send(send.3010, tuple_index.3004, channel=c_3_1_x) next (send.3011, state) } proc tile_3_1(my_token: token, state: (), init={()}) { literal.3101: bits[32] = literal(value=0) - receive.3102: (token, bits[32]) = receive(my_token, channel_id=31) + receive.3102: (token, bits[32]) = receive(my_token, channel=c_3_1_x) tuple_index.3103: token = tuple_index(receive.3102, index=0) tuple_index.3104: bits[32] = tuple_index(receive.3102, index=1) - receive.3105: (token, bits[32]) = receive(tuple_index.3103, channel_id=35) + receive.3105: (token, bits[32]) = receive(tuple_index.3103, channel=c_3_1_y) tuple_index.3106: token = tuple_index(receive.3105, index=0) tuple_index.3107: bits[32] = tuple_index(receive.3105, index=1) umul.3108: bits[32] = umul(literal.3101, tuple_index.3104) add.3109: bits[32] = add(umul.3108, tuple_index.3107) - send.3110: token = send(tuple_index.3106, add.3109, channel_id=45) - send.3111: token = send(send.3110, tuple_index.3104, channel_id=32) + send.3110: token = send(tuple_index.3106, add.3109, channel=c_3_1_o) + send.3111: token = send(send.3110, tuple_index.3104, channel=c_3_2_x) next (send.3111, state) } proc tile_3_2(my_token: token, state: (), init={()}) { literal.3201: bits[32] = literal(value=0) - receive.3202: (token, bits[32]) = receive(my_token, channel_id=32) + receive.3202: (token, bits[32]) = receive(my_token, channel=c_3_2_x) tuple_index.3203: token = tuple_index(receive.3202, index=0) tuple_index.3204: bits[32] = tuple_index(receive.3202, index=1) - receive.3205: (token, bits[32]) = receive(tuple_index.3203, channel_id=36) + receive.3205: (token, bits[32]) = receive(tuple_index.3203, channel=c_3_2_y) tuple_index.3206: token = tuple_index(receive.3205, index=0) tuple_index.3207: bits[32] = tuple_index(receive.3205, index=1) umul.3208: bits[32] = umul(literal.3201, tuple_index.3204) add.3209: bits[32] = add(umul.3208, tuple_index.3207) - send.3210: token = send(tuple_index.3206, add.3209, channel_id=46) - send.3211: token = send(send.3210, tuple_index.3204, channel_id=33) + send.3210: token = send(tuple_index.3206, add.3209, channel=c_3_2_o) + send.3211: token = send(send.3210, tuple_index.3204, channel=c_3_3_x) next (send.3211, state) } proc tile_3_3(my_token: token, state: (), init={()}) { literal.3301: bits[32] = literal(value=2) - receive.3302: (token, bits[32]) = receive(my_token, channel_id=33) + receive.3302: (token, bits[32]) = receive(my_token, channel=c_3_3_x) tuple_index.3303: token = tuple_index(receive.3302, index=0) tuple_index.3304: bits[32] = tuple_index(receive.3302, index=1) - receive.3305: (token, bits[32]) = receive(tuple_index.3303, channel_id=37) + receive.3305: (token, bits[32]) = receive(tuple_index.3303, channel=c_3_3_y) tuple_index.3306: token = tuple_index(receive.3305, index=0) tuple_index.3307: bits[32] = tuple_index(receive.3305, index=1) umul.3308: bits[32] = umul(literal.3301, tuple_index.3304) add.3309: bits[32] = add(umul.3308, tuple_index.3307) - send.3310: token = send(tuple_index.3306, add.3309, channel_id=47) + send.3310: token = send(tuple_index.3306, add.3309, channel=c_3_3_o) // Eastern-most tiles don't send activations any further. next (send.3310, state) } diff --git a/xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOk.ir b/xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOk.ir index e758dfc1c9..fe7203e836 100644 --- a/xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOk.ir +++ b/xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOk.ir @@ -7,13 +7,13 @@ chan test_package__in_1(bits[32], id=1, kind=streaming, ops=receive_only, flow_c chan test_package__output(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=proven_mutually_exclusive, metadata="""""") proc __top__foo_0_next(__token: token, init={}) { - receive.4: (token, bits[32]) = receive(__token, channel_id=0, id=4) + receive.4: (token, bits[32]) = receive(__token, channel=test_package__in_0, id=4) tok: token = tuple_index(receive.4, index=0, id=6, pos=[(0,11,13)]) - receive.8: (token, bits[32]) = receive(tok, channel_id=1, id=8) + receive.8: (token, bits[32]) = receive(tok, channel=test_package__in_1, id=8) a: bits[32] = tuple_index(receive.4, index=1, id=7, pos=[(0,11,18)]) b: bits[32] = tuple_index(receive.8, index=1, id=11, pos=[(0,12,18)]) tok__1: token = tuple_index(receive.8, index=0, id=10, pos=[(0,12,13)]) add.12: bits[32] = add(a, b, id=12, pos=[(0,13,38)]) - tok__2: token = send(tok__1, add.12, channel_id=2, id=13) + tok__2: token = send(tok__1, add.12, channel=test_package__output, id=13) next (tok__2) } diff --git a/xls/interpreter/BUILD b/xls/interpreter/BUILD index 4826a9c2d3..7a5436cf8f 100644 --- a/xls/interpreter/BUILD +++ b/xls/interpreter/BUILD @@ -109,10 +109,11 @@ cc_library( ":channel_queue", ":ir_interpreter", ":proc_evaluator", - ":serial_proc_runtime", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", + "//xls/common/status:ret_check", + "//xls/common/status:status_macros", "//xls/ir", "//xls/ir:events", "//xls/ir:value", @@ -130,7 +131,6 @@ cc_test( ":proc_interpreter", "//xls/common:xls_gunit", "//xls/common:xls_gunit_main", - "//xls/common/status:matchers", "//xls/ir", ], ) diff --git a/xls/interpreter/proc_interpreter.cc b/xls/interpreter/proc_interpreter.cc index 24e7b1cd24..f3fa09a0a8 100644 --- a/xls/interpreter/proc_interpreter.cc +++ b/xls/interpreter/proc_interpreter.cc @@ -14,22 +14,29 @@ #include "xls/interpreter/proc_interpreter.h" +#include #include #include #include #include +#include "absl/container/flat_hash_map.h" #include "absl/status/statusor.h" -#include "absl/strings/str_join.h" +#include "absl/types/span.h" +#include "xls/common/status/ret_check.h" +#include "xls/common/status/status_macros.h" +#include "xls/interpreter/channel_queue.h" #include "xls/interpreter/ir_interpreter.h" +#include "xls/ir/events.h" #include "xls/ir/node_iterator.h" +#include "xls/ir/value.h" #include "xls/ir/value_helpers.h" namespace xls { namespace { // A visitor for interpreting procs. Adds handlers for send and receive -// communcate via ChannelQueues. +// communicate via ChannelQueues. class ProcIrInterpreter : public IrInterpreter { public: // Constructor args: @@ -48,8 +55,8 @@ class ProcIrInterpreter : public IrInterpreter { queue_manager_(queue_manager) {} absl::Status HandleReceive(Receive* receive) override { - XLS_ASSIGN_OR_RETURN(ChannelQueue * queue, - queue_manager_->GetQueueById(receive->channel_id())); + XLS_ASSIGN_OR_RETURN(ChannelQueue * queue, queue_manager_->GetQueueByName( + receive->channel_name())); if (receive->predicate().has_value()) { const Bits& pred = ResolveAsBits(receive->predicate().value()); @@ -83,7 +90,7 @@ class ProcIrInterpreter : public IrInterpreter { absl::Status HandleSend(Send* send) override { XLS_ASSIGN_OR_RETURN(ChannelQueue * queue, - queue_manager_->GetQueueById(send->channel_id())); + queue_manager_->GetQueueByName(send->channel_name())); if (send->predicate().has_value()) { const Bits& pred = ResolveAsBits(send->predicate().value()); if (pred.IsZero()) { diff --git a/xls/interpreter/proc_interpreter.h b/xls/interpreter/proc_interpreter.h index 5324416940..e8b3f0ed86 100644 --- a/xls/interpreter/proc_interpreter.h +++ b/xls/interpreter/proc_interpreter.h @@ -15,17 +15,14 @@ #ifndef XLS_INTERPRETER_PROC_INTERPRETER_H_ #define XLS_INTERPRETER_PROC_INTERPRETER_H_ -#include -#include +#include #include -#include #include #include "absl/container/flat_hash_map.h" #include "absl/status/statusor.h" #include "xls/interpreter/channel_queue.h" #include "xls/interpreter/proc_evaluator.h" -#include "xls/interpreter/serial_proc_runtime.h" #include "xls/ir/events.h" #include "xls/ir/proc.h" #include "xls/ir/value.h" diff --git a/xls/interpreter/proc_interpreter_test.cc b/xls/interpreter/proc_interpreter_test.cc index 305c8f91b8..3faf5b7c10 100644 --- a/xls/interpreter/proc_interpreter_test.cc +++ b/xls/interpreter/proc_interpreter_test.cc @@ -14,12 +14,14 @@ #include "xls/interpreter/proc_interpreter.h" +#include + #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "xls/common/status/matchers.h" #include "xls/interpreter/channel_queue.h" #include "xls/interpreter/proc_evaluator.h" #include "xls/interpreter/proc_evaluator_test_base.h" +#include "xls/ir/package.h" #include "xls/ir/proc.h" namespace xls { diff --git a/xls/interpreter/proc_runtime_test_base.cc b/xls/interpreter/proc_runtime_test_base.cc index 8fc45d8848..e708bea3a9 100644 --- a/xls/interpreter/proc_runtime_test_base.cc +++ b/xls/interpreter/proc_runtime_test_base.cc @@ -582,56 +582,56 @@ chan e_o(bits[32], id=7, kind=streaming, ops=send_only, flow_control=none, metad proc a(my_token: token, state: (), init={()}) { literal.1: bits[32] = literal(value=1) - receive.2: (token, bits[32]) = receive(my_token, channel_id=0) + receive.2: (token, bits[32]) = receive(my_token, channel=i_a) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[32] = tuple_index(receive.2, index=1) umul.5: bits[32] = umul(literal.1, tuple_index.4) - send.6: token = send(tuple_index.3, umul.5, channel_id=2) + send.6: token = send(tuple_index.3, umul.5, channel=a_c) next (send.6, state) } proc b(my_token: token, state: (), init={()}) { literal.101: bits[32] = literal(value=2) - receive.102: (token, bits[32]) = receive(my_token, channel_id=1) + receive.102: (token, bits[32]) = receive(my_token, channel=i_b) tuple_index.103: token = tuple_index(receive.102, index=0) tuple_index.104: bits[32] = tuple_index(receive.102, index=1) umul.105: bits[32] = umul(literal.101, tuple_index.104) - send.106: token = send(tuple_index.103, umul.105, channel_id=3) + send.106: token = send(tuple_index.103, umul.105, channel=b_c) next (send.106, state) } proc c(my_token: token, state: (), init={()}) { literal.201: bits[32] = literal(value=3) - receive.202: (token, bits[32]) = receive(my_token, channel_id=2) + receive.202: (token, bits[32]) = receive(my_token, channel=a_c) tuple_index.203: token = tuple_index(receive.202, index=0) tuple_index.204: bits[32] = tuple_index(receive.202, index=1) - receive.205: (token, bits[32]) = receive(tuple_index.203, channel_id=3) + receive.205: (token, bits[32]) = receive(tuple_index.203, channel=b_c) tuple_index.206: token = tuple_index(receive.205, index=0) tuple_index.207: bits[32] = tuple_index(receive.205, index=1) umul.208: bits[32] = umul(literal.201, tuple_index.204) umul.209: bits[32] = umul(literal.201, tuple_index.207) - send.210: token = send(tuple_index.206, umul.208, channel_id=4) - send.211: token = send(send.210, umul.209, channel_id=5) + send.210: token = send(tuple_index.206, umul.208, channel=c_d) + send.211: token = send(send.210, umul.209, channel=c_e) next (send.211, state) } proc d(my_token: token, state: (), init={()}) { literal.301: bits[32] = literal(value=4) - receive.302: (token, bits[32]) = receive(my_token, channel_id=4) + receive.302: (token, bits[32]) = receive(my_token, channel=c_d) tuple_index.303: token = tuple_index(receive.302, index=0) tuple_index.304: bits[32] = tuple_index(receive.302, index=1) umul.305: bits[32] = umul(literal.301, tuple_index.304) - send.306: token = send(tuple_index.303, umul.305, channel_id=6) + send.306: token = send(tuple_index.303, umul.305, channel=d_o) next (send.306, state) } proc e(my_token: token, state: (), init={()}) { literal.401: bits[32] = literal(value=5) - receive.402: (token, bits[32]) = receive(my_token, channel_id=5) + receive.402: (token, bits[32]) = receive(my_token, channel=c_e) tuple_index.403: token = tuple_index(receive.402, index=0) tuple_index.404: bits[32] = tuple_index(receive.402, index=1) umul.405: bits[32] = umul(literal.401, tuple_index.404) - send.406: token = send(tuple_index.403, umul.405, channel_id=7) + send.406: token = send(tuple_index.403, umul.405, channel=e_o) next (send.406, state) } )"; diff --git a/xls/ir/block.cc b/xls/ir/block.cc index a397c5eb12..3330baf83c 100644 --- a/xls/ir/block.cc +++ b/xls/ir/block.cc @@ -599,13 +599,13 @@ absl::StatusOr Block::AddBlockInstantiation( absl::StatusOr Block::AddFifoInstantiation( std::string_view name, FifoConfig fifo_config, Type* data_type, - std::optional channel_id) { + std::optional channel) { XLS_RET_CHECK(package()->IsOwnedType(data_type)); XLS_ASSIGN_OR_RETURN( absl::StatusOr instantiation, - AddInstantiation( - name, std::make_unique( - name, fifo_config, data_type, channel_id, package()))); + AddInstantiation(name, + std::make_unique( + name, fifo_config, data_type, channel, package()))); return down_cast(instantiation.value()); } diff --git a/xls/ir/block.h b/xls/ir/block.h index 9efc8e9f4b..f009e42d6c 100644 --- a/xls/ir/block.h +++ b/xls/ir/block.h @@ -140,7 +140,7 @@ class Block : public FunctionBase { // instantiation to the data-flow graph. absl::StatusOr AddFifoInstantiation( std::string_view name, FifoConfig fifo_config, Type* data_type, - std::optional channel_id = std::nullopt); + std::optional channel = std::nullopt); absl::StatusOr AddInstantiation( std::string_view name, std::unique_ptr instantiation); diff --git a/xls/ir/function_builder.cc b/xls/ir/function_builder.cc index dac91b72bd..58e2c67afd 100644 --- a/xls/ir/function_builder.cc +++ b/xls/ir/function_builder.cc @@ -1374,7 +1374,7 @@ BValue ProcBuilder::Receive(Channel* channel, BValue token, loc); } return AddNode(loc, token.node(), /*predicate=*/std::nullopt, - channel->id(), /*is_blocking=*/true, name); + channel->name(), /*is_blocking=*/true, name); } BValue ProcBuilder::ReceiveNonBlocking(Channel* channel, BValue token, @@ -1391,7 +1391,7 @@ BValue ProcBuilder::ReceiveNonBlocking(Channel* channel, BValue token, loc); } return AddNode(loc, token.node(), /*predicate=*/std::nullopt, - channel->id(), /*is_blocking=*/false, name); + channel->name(), /*is_blocking=*/false, name); } BValue ProcBuilder::ReceiveIf(Channel* channel, BValue token, BValue pred, @@ -1414,7 +1414,7 @@ BValue ProcBuilder::ReceiveIf(Channel* channel, BValue token, BValue pred, pred.GetType()->ToString()), loc); } - return AddNode(loc, token.node(), pred.node(), channel->id(), + return AddNode(loc, token.node(), pred.node(), channel->name(), /*is_blocking=*/true, name); } @@ -1439,7 +1439,7 @@ BValue ProcBuilder::ReceiveIfNonBlocking(Channel* channel, BValue token, pred.GetType()->ToString()), loc); } - return AddNode(loc, token.node(), pred.node(), channel->id(), + return AddNode(loc, token.node(), pred.node(), channel->name(), /*is_blocking=*/false, name); } @@ -1455,7 +1455,7 @@ BValue ProcBuilder::Send(Channel* channel, BValue token, BValue data, loc); } return AddNode(loc, token.node(), data.node(), - /*predicate=*/std::nullopt, channel->id(), name); + /*predicate=*/std::nullopt, channel->name(), name); } BValue ProcBuilder::SendIf(Channel* channel, BValue token, BValue pred, @@ -1478,7 +1478,7 @@ BValue ProcBuilder::SendIf(Channel* channel, BValue token, BValue pred, loc); } return AddNode(loc, token.node(), data.node(), pred.node(), - channel->id(), name); + channel->name(), name); } BValue TokenlessProcBuilder::MinDelay(int64_t delay, const SourceInfo& loc, diff --git a/xls/ir/instantiation.cc b/xls/ir/instantiation.cc index 02ad90e505..cd4e5b9bd1 100644 --- a/xls/ir/instantiation.cc +++ b/xls/ir/instantiation.cc @@ -178,14 +178,13 @@ std::string ExternInstantiation::ToString() const { name(), function_->name()); } -FifoInstantiation::FifoInstantiation(std::string_view inst_name, - FifoConfig fifo_config, Type* data_type, - std::optional channel_id, - Package* package) +FifoInstantiation::FifoInstantiation( + std::string_view inst_name, FifoConfig fifo_config, Type* data_type, + std::optional channel_name, Package* package) : Instantiation(inst_name, InstantiationKind::kFifo), fifo_config_(fifo_config), data_type_(data_type), - channel_id_(channel_id), + channel_name_(channel_name), package_(package) { XLS_CHECK(package->IsOwnedType(data_type)); } @@ -223,8 +222,8 @@ absl::StatusOr FifoInstantiation::GetOutputPort( std::string FifoInstantiation::ToString() const { std::string channel_str; - if (channel_id_.has_value()) { - channel_str = absl::StrFormat("channel_id=%d, ", *channel_id_); + if (channel_name_.has_value()) { + channel_str = absl::StrFormat("channel=\"%s\", ", *channel_name_); } return absl::StrFormat( diff --git a/xls/ir/instantiation.h b/xls/ir/instantiation.h index 5fefb5431a..561d7a69ef 100644 --- a/xls/ir/instantiation.h +++ b/xls/ir/instantiation.h @@ -117,7 +117,8 @@ class ExternInstantiation : public Instantiation { class FifoInstantiation : public Instantiation { public: FifoInstantiation(std::string_view inst_name, FifoConfig fifo_config, - Type* data_type, std::optional channel_id, + Type* data_type, + std::optional channel_name, Package* package); absl::StatusOr GetInputPort(std::string_view name) final; @@ -125,14 +126,14 @@ class FifoInstantiation : public Instantiation { const FifoConfig& fifo_config() const { return fifo_config_; } Type* data_type() const { return data_type_; } - std::optional channel_id() const { return channel_id_; } + std::optional channel_name() const { return channel_name_; } std::string ToString() const final; private: FifoConfig fifo_config_; Type* data_type_; - std::optional channel_id_; + std::optional channel_name_; Package* package_; }; diff --git a/xls/ir/ir_matcher.cc b/xls/ir/ir_matcher.cc index 5133af1fd6..55cb6cec6a 100644 --- a/xls/ir/ir_matcher.cc +++ b/xls/ir/ir_matcher.cc @@ -377,25 +377,24 @@ bool TupleIndexMatcher::MatchAndExplain( } static bool MatchChannel( - int64_t channel_id, Package* package, + std::string_view channel, Package* package, const ::testing::Matcher& channel_matcher, ::testing::MatchResultListener* listener) { - absl::StatusOr<::xls::Channel*> channel_status = - package->GetChannel(channel_id); + absl::StatusOr<::xls::Channel*> channel_status = package->GetChannel(channel); if (!channel_status.ok()) { - *listener << " has an invalid channel id: " << channel_id; + *listener << " has an invalid channel name: " << channel; return false; } ::xls::Channel* ch = channel_status.value(); return channel_matcher.MatchAndExplain(ch, listener); } -static int64_t GetChannelId(const Node* node) { +static std::string_view GetChannelName(const Node* node) { switch (node->op()) { case Op::kReceive: - return node->As<::xls::Receive>()->channel_id(); + return node->As<::xls::Receive>()->channel_name(); case Op::kSend: - return node->As<::xls::Send>()->channel_id(); + return node->As<::xls::Send>()->channel_name(); default: XLS_LOG(FATAL) << "Node is not a channel node: " << node->ToString(); } @@ -409,7 +408,7 @@ bool ChannelNodeMatcher::MatchAndExplain( if (!channel_matcher_.has_value()) { return true; } - return MatchChannel(GetChannelId(node), node->package(), + return MatchChannel(GetChannelName(node), node->package(), channel_matcher_.value(), listener); } diff --git a/xls/ir/ir_parser.cc b/xls/ir/ir_parser.cc index 212a16d406..dc5861b92b 100644 --- a/xls/ir/ir_parser.cc +++ b/xls/ir/ir_parser.cc @@ -999,16 +999,18 @@ absl::StatusOr Parser::ParseNode( op_token.pos())); std::optional* predicate = arg_parser.AddOptionalKeywordArg("predicate"); - int64_t* channel_id = arg_parser.AddKeywordArg("channel_id"); + IdentifierString* channel_name = + arg_parser.AddKeywordArg("channel"); bool* is_blocking = arg_parser.AddOptionalKeywordArg( "blocking", /*default_value=*/true); XLS_ASSIGN_OR_RETURN(operands, arg_parser.Run(/*arity=*/1)); // Get the channel from the package. - if (!package->HasChannelWithId(*channel_id)) { + if (!package->HasChannelWithName(channel_name->value)) { return absl::InvalidArgumentError( - absl::StrFormat("No such channel with channel ID %d", *channel_id)); + absl::StrFormat("No such channel `%s`", channel_name->value)); } - XLS_ASSIGN_OR_RETURN(Channel * channel, package->GetChannel(*channel_id)); + XLS_ASSIGN_OR_RETURN(Channel * channel, + package->GetChannel(channel_name->value)); Type* expected_type = (*is_blocking) @@ -1047,14 +1049,16 @@ absl::StatusOr Parser::ParseNode( fb, "send operations only supported in procs", op_token.pos())); std::optional* predicate = arg_parser.AddOptionalKeywordArg("predicate"); - int64_t* channel_id = arg_parser.AddKeywordArg("channel_id"); + IdentifierString* channel_name = + arg_parser.AddKeywordArg("channel"); XLS_ASSIGN_OR_RETURN(operands, arg_parser.Run(/*arity=*/2)); // Get the channel from the package. - if (!package->HasChannelWithId(*channel_id)) { + if (!package->HasChannelWithName(channel_name->value)) { return absl::InvalidArgumentError( - absl::StrFormat("No such channel with channel ID %d", *channel_id)); + absl::StrFormat("No such channel `%s`", channel_name->value)); } - XLS_ASSIGN_OR_RETURN(Channel * channel, package->GetChannel(*channel_id)); + XLS_ASSIGN_OR_RETURN(Channel * channel, + package->GetChannel(channel_name->value)); if (predicate->has_value()) { bvalue = pb->SendIf(channel, operands[0], predicate->value(), operands[1], *loc, node_name); @@ -1390,11 +1394,11 @@ absl::StatusOr Parser::ParseInstantiation(Block* block) { return absl::OkStatus(); }; - std::optional channel_id; - handlers["channel_id"] = [&]() -> absl::Status { - XLS_ASSIGN_OR_RETURN(Token channel_id_token, - scanner_.PopTokenOrError(LexicalTokenType::kLiteral)); - XLS_ASSIGN_OR_RETURN(channel_id, channel_id_token.GetValueInt64()); + std::optional channel; + handlers["channel"] = [&]() -> absl::Status { + XLS_ASSIGN_OR_RETURN(Token channel_token, + scanner_.PopTokenOrError(LexicalTokenType::kIdent)); + channel = channel_token.value(); return absl::OkStatus(); }; @@ -1443,7 +1447,7 @@ absl::StatusOr Parser::ParseInstantiation(Block* block) { Field::MustNotHave(data_type.has_value(), "data_type"), Field::MustNotHave(depth.has_value(), "depth"), Field::MustNotHave(bypass.has_value(), "bypass"), - Field::MustNotHave(channel_id.has_value(), "channel_id"), + Field::MustNotHave(channel.has_value(), "channel"), Field::MustHave(instantiated_block.has_value(), "instantiated_block"), }, @@ -1464,7 +1468,7 @@ absl::StatusOr Parser::ParseInstantiation(Block* block) { return block->AddFifoInstantiation( instantiation_name.value(), FifoConfig{.depth = depth.value(), .bypass = bypass.value()}, - *data_type, channel_id); + *data_type, channel); } return absl::InvalidArgumentError( diff --git a/xls/ir/ir_parser_test.cc b/xls/ir/ir_parser_test.cc index 07ef122bb1..d72126a364 100644 --- a/xls/ir/ir_parser_test.cc +++ b/xls/ir/ir_parser_test.cc @@ -1267,9 +1267,9 @@ TEST(IrParserTest, ParseSimpleProc) { chan ch(bits[32], id=0, kind=streaming, ops=send_receive, flow_control=none, strictness=proven_mutually_exclusive, metadata="""""") proc my_proc(my_token: token, my_state: bits[32], init={42}) { - send.1: token = send(my_token, my_state, channel_id=0, id=1) + send.1: token = send(my_token, my_state, channel=ch, id=1) literal.2: bits[1] = literal(value=1, id=2) - receive.3: (token, bits[32]) = receive(send.1, predicate=literal.2, channel_id=0, id=3) + receive.3: (token, bits[32]) = receive(send.1, predicate=literal.2, channel=ch, id=3) tuple_index.4: token = tuple_index(receive.3, index=0, id=4) next (tuple_index.4, my_state) } @@ -2571,11 +2571,11 @@ chan mtv(bits[32], id=1, kind=streaming, flow_control=none, ops=send_only, metadata="module_port { flopped: true }") proc my_proc(my_token: token, my_state: bits[32], init={42}) { - receive.1: (token, bits[32]) = receive(my_token, channel_id=0) + receive.1: (token, bits[32]) = receive(my_token, channel=hbo) tuple_index.2: token = tuple_index(receive.1, index=0, id=2) tuple_index.3: bits[32] = tuple_index(receive.1, index=1, id=3) add.4: bits[32] = add(my_state, tuple_index.3, id=4) - send.5: token = send(tuple_index.2, add.4, channel_id=1) + send.5: token = send(tuple_index.2, add.4, channel=mtv) next (send.5, add.4) } )"; diff --git a/xls/ir/node.cc b/xls/ir/node.cc index 311e1bc96c..a0af0d91f5 100644 --- a/xls/ir/node.cc +++ b/xls/ir/node.cc @@ -517,7 +517,7 @@ std::string Node::ToStringInternal(bool include_operand_types) const { args.push_back(absl::StrFormat("predicate=%s", send->predicate().value()->GetName())); } - args.push_back(absl::StrFormat("channel_id=%d", send->channel_id())); + args.push_back(absl::StrFormat("channel=%s", send->channel_name())); break; } case Op::kReceive: { @@ -527,7 +527,7 @@ std::string Node::ToStringInternal(bool include_operand_types) const { args.push_back(absl::StrFormat( "predicate=%s", receive->predicate().value()->GetName())); } - args.push_back(absl::StrFormat("channel_id=%d", receive->channel_id())); + args.push_back(absl::StrFormat("channel=%s", receive->channel_name())); if (receive->is_blocking() == false) { // Default blocking=true so we only need to push is !is_blocking(). args.push_back("blocking=false"); diff --git a/xls/ir/node_test.cc b/xls/ir/node_test.cc index b17a67267c..2f9a392254 100644 --- a/xls/ir/node_test.cc +++ b/xls/ir/node_test.cc @@ -242,13 +242,13 @@ TEST_F(NodeTest, ReplaceSendChannel) { pb.Build(send1_tok, {pb.Not(send_on_c1)})); Send* send0 = send0_tok.node()->As(); Send* send1 = send1_tok.node()->As(); - EXPECT_NE(send0->channel_id(), ch1->id()); - send0->ReplaceChannel(ch1->id()); - EXPECT_EQ(send0->channel_id(), ch1->id()); + EXPECT_NE(send0->channel_name(), ch1->name()); + send0->ReplaceChannel(ch1->name()); + EXPECT_EQ(send0->channel_name(), ch1->name()); XLS_EXPECT_OK(VerifyNode(send0)); - EXPECT_NE(send1->channel_id(), ch0->id()); - send1->ReplaceChannel(ch0->id()); - EXPECT_EQ(send1->channel_id(), ch0->id()); + EXPECT_NE(send1->channel_name(), ch0->name()); + send1->ReplaceChannel(ch0->name()); + EXPECT_EQ(send1->channel_name(), ch0->name()); XLS_EXPECT_OK(VerifyNode(send1)); XLS_EXPECT_OK(VerifyProc(proc)); } @@ -286,17 +286,17 @@ TEST_F(NodeTest, ReplaceReceiveChannel) { Receive* recv0_node = recv0.node()->As(); Receive* recv1_node = recv1.node()->As(); Receive* recv2_node = recv2.node()->As(); - EXPECT_NE(recv0_node->channel_id(), ch1->id()); - recv0_node->ReplaceChannel(ch1->id()); - EXPECT_EQ(recv0_node->channel_id(), ch1->id()); + EXPECT_NE(recv0_node->channel_name(), ch1->name()); + recv0_node->ReplaceChannel(ch1->name()); + EXPECT_EQ(recv0_node->channel_name(), ch1->name()); XLS_EXPECT_OK(VerifyNode(recv0_node)); - EXPECT_NE(recv1_node->channel_id(), ch2->id()); - recv1_node->ReplaceChannel(ch2->id()); - EXPECT_EQ(recv1_node->channel_id(), ch2->id()); + EXPECT_NE(recv1_node->channel_name(), ch2->name()); + recv1_node->ReplaceChannel(ch2->name()); + EXPECT_EQ(recv1_node->channel_name(), ch2->name()); XLS_EXPECT_OK(VerifyNode(recv1_node)); - EXPECT_NE(recv2_node->channel_id(), ch0->id()); - recv2_node->ReplaceChannel(ch0->id()); - EXPECT_EQ(recv2_node->channel_id(), ch0->id()); + EXPECT_NE(recv2_node->channel_name(), ch0->name()); + recv2_node->ReplaceChannel(ch0->name()); + EXPECT_EQ(recv2_node->channel_name(), ch0->name()); XLS_EXPECT_OK(VerifyNode(recv2_node)); XLS_EXPECT_OK(VerifyProc(proc)); diff --git a/xls/ir/node_util.cc b/xls/ir/node_util.cc index 07d345e335..f298587eaf 100644 --- a/xls/ir/node_util.cc +++ b/xls/ir/node_util.cc @@ -248,25 +248,26 @@ bool IsChannelNode(Node* node) { } absl::StatusOr GetChannelUsedByNode(Node* node) { - int64_t channel_id; + std::string_view channel; if (node->Is()) { - channel_id = node->As()->channel_id(); + channel = node->As()->channel_name(); } else if (node->Is()) { - channel_id = node->As()->channel_id(); + channel = node->As()->channel_name(); } else { return absl::NotFoundError( absl::StrFormat("No channel associated with node %s", node->GetName())); } - return node->package()->GetChannel(channel_id); + return node->package()->GetChannel(channel); } -absl::Status ReplaceChannelUsedByNode(Node* node, int64_t new_channel_id) { +absl::Status ReplaceChannelUsedByNode(Node* node, + std::string_view new_channel) { switch (node->op()) { case Op::kSend: - node->As()->ReplaceChannel(new_channel_id); + node->As()->ReplaceChannel(new_channel); return absl::OkStatus(); case Op::kReceive: - node->As()->ReplaceChannel(new_channel_id); + node->As()->ReplaceChannel(new_channel); return absl::OkStatus(); default: return absl::InvalidArgumentError(absl::StrFormat( diff --git a/xls/ir/node_util.h b/xls/ir/node_util.h index f5fc43576f..280a3a5873 100644 --- a/xls/ir/node_util.h +++ b/xls/ir/node_util.h @@ -199,7 +199,7 @@ absl::StatusOr GetChannelUsedByNode(Node* node); // Replace the channel that node is operating on. If node is not a // send/sendif/receive/receiveif node then an error is returned. -absl::Status ReplaceChannelUsedByNode(Node* node, int64_t new_channel_id); +absl::Status ReplaceChannelUsedByNode(Node* node, std::string_view new_channel); // Returns the predicate used by the given node. If node is not a // send/sendif/receive/receiveif node then an error is returned. diff --git a/xls/ir/nodes_source.tmpl b/xls/ir/nodes_source.tmpl index 3562ea8a42..6b0508f8f8 100644 --- a/xls/ir/nodes_source.tmpl +++ b/xls/ir/nodes_source.tmpl @@ -53,18 +53,18 @@ Type* GetMapType(Node* operand, Function* to_apply) { to_apply->return_value()->GetType()); } -Type* GetReceivePayloadType(Package* package, int64_t channel_id) { - return package->GetChannel(channel_id).value()->type(); +Type* GetReceivePayloadType(Package* package, std::string_view channel_name) { + return package->GetChannel(channel_name).value()->type(); } -Type* GetReceiveType(Package* package, int64_t channel_id, bool is_blocking) { +Type* GetReceiveType(Package* package, std::string_view channel_name, bool is_blocking) { if(is_blocking) { return package->GetTupleType({package->GetTokenType(), - GetReceivePayloadType(package, channel_id)}); + GetReceivePayloadType(package, channel_name)}); } return package->GetTupleType({package->GetTokenType(), - GetReceivePayloadType(package, channel_id), + GetReceivePayloadType(package, channel_name), package->GetBitsType(1)}); } @@ -237,15 +237,15 @@ absl::StatusOr Trace::CloneInNewFunction( } Type* Receive::GetPayloadType() const { - return GetReceivePayloadType(function_base_->package(), channel_id_); + return GetReceivePayloadType(function_base_->package(), channel_name_); } -void Receive::ReplaceChannel(int64_t new_channel_id) { - channel_id_ = new_channel_id; +void Receive::ReplaceChannel(std::string_view new_channel_name) { + channel_name_ = new_channel_name; } -void Send::ReplaceChannel(int64_t new_channel_id) { - channel_id_ = new_channel_id; +void Send::ReplaceChannel(std::string_view new_channel_name) { + channel_name_ = new_channel_name; } absl::StatusOr Receive::CloneInNewFunction( @@ -256,7 +256,7 @@ absl::StatusOr Receive::CloneInNewFunction( loc(), new_operands[0], new_operands.size() > 1 ? std::optional(new_operands[1]) : absl::nullopt, - channel_id(), is_blocking(), name_); + channel_name(), is_blocking(), name_); } absl::StatusOr Send::CloneInNewFunction( @@ -267,7 +267,7 @@ absl::StatusOr Send::CloneInNewFunction( loc(), new_operands[0], new_operands[1], new_operands.size() > 2 ? std::optional(new_operands[2]) : absl::nullopt, - channel_id(), name_); + channel_name(), name_); } bool Select::AllCases(std::function p) const { diff --git a/xls/ir/op_specification.py b/xls/ir/op_specification.py index 2be0465edb..4fb03b2b44 100644 --- a/xls/ir/op_specification.py +++ b/xls/ir/op_specification.py @@ -708,7 +708,7 @@ def __init__( name='Receive', op='Op::kReceive', operands=[Operand('token'), OptionalOperand('predicate')], - xls_type_expression='GetReceiveType(function->package(), channel_id, is_blocking)', + xls_type_expression='GetReceiveType(function->package(), channel_name, is_blocking)', extra_methods=[Method(name='token', return_cpp_type='Node*', expression='operand(0)'), @@ -721,10 +721,10 @@ def __init__( Method(name='ReplaceChannel', return_cpp_type='void', expression=None, - params='int64_t new_channel_id', + params='std::string_view new_channel_name', is_const=False), ], - attributes=[Int64Attribute('channel_id'), BoolAttribute('is_blocking')], + attributes=[StringAttribute('channel_name'), BoolAttribute('is_blocking')], custom_clone_method=True ) @@ -733,7 +733,7 @@ def __init__( op='Op::kSend', operands=[Operand('token'), Operand('data'), OptionalOperand('predicate')], xls_type_expression='function->package()->GetTokenType()', - attributes=[Int64Attribute('channel_id')], + attributes=[StringAttribute('channel_name')], extra_methods=[Method(name='token', return_cpp_type='Node*', expression='operand(0)'), @@ -746,7 +746,7 @@ def __init__( Method(name='ReplaceChannel', return_cpp_type='void', expression=None, - params='int64_t new_channel_id', + params='std::string_view new_channel_name', is_const=False), ], custom_clone_method=True diff --git a/xls/ir/package.cc b/xls/ir/package.cc index 25d9da4218..d344dc7693 100644 --- a/xls/ir/package.cc +++ b/xls/ir/package.cc @@ -219,11 +219,11 @@ absl::flat_hash_set AllPackageNames(const Package& package) { } // Adds channels from other_package to this_package, potentially changing the -// channel id. Returns channels ID mapping from old id -> new id. -absl::StatusOr> AddChannelsFromPackage( - Package* this_package, const Package* other_package, - NameCollisionResolver* name_resolver) { - absl::flat_hash_map channel_id_updates; +// channel id. Returns channel name mapping from old name -> new name. +absl::StatusOr> +AddChannelsFromPackage(Package* this_package, const Package* other_package, + NameCollisionResolver* name_resolver) { + absl::flat_hash_map channel_updates; // Channels can collide in two ways: by name, and by id. First we resolve name // collisions, and then we call the various Create*Channel() functions, which // will give a new channel id. We keep track of this new id to update @@ -232,9 +232,9 @@ absl::StatusOr> AddChannelsFromPackage( std::string channel_name = name_resolver->ResolveName(channel->name()); XLS_ASSIGN_OR_RETURN(Channel * new_channel, this_package->CloneChannel(channel, channel_name)); - channel_id_updates[channel->id()] = new_channel->id(); + channel_updates[channel->name()] = new_channel->name(); } - return channel_id_updates; + return channel_updates; } // Add FunctionBases (function, proc, and block) from other_package to @@ -243,7 +243,7 @@ absl::StatusOr> AddFunctionBasesFromPackage( Package* this_package, const Package* other_package, NameCollisionResolver* name_resolver, - const absl::flat_hash_map& channel_remapping) { + const absl::flat_hash_map& channel_remapping) { std::vector other_function_bases = other_package->GetFunctionBases(); @@ -305,17 +305,17 @@ absl::StatusOr Package::AddPackage( NameCollisionResolver name_resolver(AllPackageNames(*this)); // First, merge channels. - // Returns a mapping of channel ids from old id -> new id - XLS_ASSIGN_OR_RETURN(auto channel_id_updates, + // Returns a mapping of channel ids from old name -> new name + XLS_ASSIGN_OR_RETURN(auto channel_updates, AddChannelsFromPackage(this, other, &name_resolver)); // Next, merge in functions, procs, and blocks. XLS_ASSIGN_OR_RETURN(auto call_mapping, AddFunctionBasesFromPackage(this, other, &name_resolver, - channel_id_updates)); + channel_updates)); return Package::PackageMergeResult{ .name_updates = name_resolver.name_updates(), - .channel_id_updates = std::move(channel_id_updates)}; + .channel_updates = std::move(channel_updates)}; } absl::StatusOr Package::GetFunction( @@ -843,9 +843,9 @@ absl::Status Package::RemoveChannel(Channel* channel) { for (const auto& proc : procs()) { for (Node* node : proc->nodes()) { if ((node->Is() && - node->As()->channel_id() == channel->id()) || + node->As()->channel_name() == channel->name()) || (node->Is() && - node->As()->channel_id() == channel->id())) { + node->As()->channel_name() == channel->name())) { return absl::InternalError(absl::StrFormat( "Channel %s (id=%d) cannot be removed because it " "is used by node %v in %v", @@ -858,26 +858,26 @@ absl::Status Package::RemoveChannel(Channel* channel) { channel_vec_.erase(it); // Remove from channel map. - XLS_RET_CHECK(channels_.contains(channel->id())); - channels_.erase(channel->id()); + XLS_RET_CHECK(channels_.contains(channel->name())); + channels_.erase(channel->name()); return absl::OkStatus(); } absl::Status Package::AddChannel(std::unique_ptr channel) { - int64_t id = channel->id(); - auto [channel_it, inserted] = channels_.insert({id, std::move(channel)}); + std::string name = channel->name(); + auto [channel_it, inserted] = channels_.insert({name, std::move(channel)}); if (!inserted) { return absl::InternalError( - absl::StrFormat("Channel already exists with id %d.", id)); + absl::StrFormat("Channel already exists with name `%s`.", name)); } Channel* channel_ptr = channel_it->second.get(); - // Verify the channel name is unique. + // Verify the channel id is unique. for (Channel* ch : channel_vec_) { - if (ch->name() == channel_ptr->name()) { - return absl::InvalidArgumentError(absl::StrFormat( - "Channel already exists with name \"%s\"", ch->name())); + if (ch->id() == channel_ptr->id()) { + return absl::InvalidArgumentError( + absl::StrFormat("Channel already exists with id %d", ch->id())); } } @@ -893,17 +893,19 @@ absl::Status Package::AddChannel(std::unique_ptr channel) { std::sort(channel_vec_.begin(), channel_vec_.end(), [](Channel* a, Channel* b) { return a->id() < b->id(); }); - next_channel_id_ = std::max(next_channel_id_, id + 1); + next_channel_id_ = std::max(next_channel_id_, channel_ptr->id() + 1); return absl::OkStatus(); } absl::StatusOr Package::GetChannel(int64_t id) const { - if (channels_.find(id) == channels_.end()) { - return absl::NotFoundError(absl::StrFormat( - "No channel with id %d (package has %d channels: %s).", id, - channels_.size(), absl::StrJoin(GetChannelNames(), ", "))); + for (Channel* ch : channels()) { + if (ch->id() == id) { + return ch; + } } - return channels_.at(id).get(); + return absl::NotFoundError(absl::StrFormat( + "No channel with id %d (package has %d channels: %s).", id, + channels().size(), absl::StrJoin(GetChannelNames(), ", "))); } std::vector Package::GetChannelNames() const { @@ -916,14 +918,13 @@ std::vector Package::GetChannelNames() const { } absl::StatusOr Package::GetChannel(std::string_view name) const { - for (Channel* ch : channels()) { - if (ch->name() == name) { - return ch; - } + auto it = channels_.find(name); + if (it == channels_.end()) { + return absl::NotFoundError(absl::StrFormat( + "No channel with name `%s` (package has %d channels: %s).", name, + channels_.size(), absl::StrJoin(GetChannelNames(), ", "))); } - return absl::NotFoundError(absl::StrFormat( - "No channel with name '%s' (package has %d channels: %s).", name, - channels().size(), absl::StrJoin(GetChannelNames(), ", "))); + return it->second.get(); } absl::StatusOr Package::CloneChannel( diff --git a/xls/ir/package.h b/xls/ir/package.h index 922ce7f5a3..a403c487c1 100644 --- a/xls/ir/package.h +++ b/xls/ir/package.h @@ -117,7 +117,7 @@ class Package { // and blocks) absl::flat_hash_map name_updates; // other package -> this package channel id mapping - absl::flat_hash_map channel_id_updates; + absl::flat_hash_map channel_updates; }; // Add another package to this package. Ownership is transferred to this // package. @@ -263,9 +263,17 @@ class Package { absl::StatusOr GetChannel(int64_t id) const; absl::StatusOr GetChannel(std::string_view name) const; - // Returns whether there exists a channel with the given ID. + // Returns whether there exists a channel with the given ID / name. bool HasChannelWithId(int64_t id) const { - return channels_.find(id) != channels_.end(); + for (Channel* channel : channel_vec_) { + if (channel->id() == id) { + return true; + } + } + return false; + } + bool HasChannelWithName(std::string_view name) const { + return channels_.find(name) != channels_.end(); } // Removes the given channel. If the channel has any associated send/receive @@ -403,9 +411,9 @@ class Package { absl::flat_hash_map fileno_to_filename_; absl::flat_hash_map filename_to_fileno_; - // Channels owned by this package. Indexed by channel id. Stored as + // Channels owned by this package. Indexed by channel name. Stored as // unique_ptrs for pointer stability. - absl::flat_hash_map> channels_; + absl::flat_hash_map> channels_; // Vector of channel pointers. Kept in sync with the channels_ map. Enables // easy, stable iteration over channels. diff --git a/xls/ir/package_test.cc b/xls/ir/package_test.cc index 60f0d3bf83..04a8eb1a4c 100644 --- a/xls/ir/package_test.cc +++ b/xls/ir/package_test.cc @@ -347,7 +347,7 @@ TEST_F(PackageTest, CreateStreamingChannel) { ChannelStrictness::kProvenMutuallyExclusive, ChannelMetadataProto(), 1) .status(), - StatusIs(absl::StatusCode::kInternal, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Channel already exists with id 1"))); // Fetching a non-existent channel ID is an error. @@ -1005,10 +1005,10 @@ chan test_channel( flow_control=ready_valid, metadata="""""") top proc main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(__token, tuple_index.3, channel_id=0) + send.4: token = send(__token, tuple_index.3, channel=test_channel) after_all.5: token = after_all(send.4, tuple_index.2) tuple.6: () = tuple() next (after_all.5, tuple.6) @@ -1023,10 +1023,10 @@ chan another_test_channel( top proc another_main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=another_test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(__token, tuple_index.3, channel_id=0) + send.4: token = send(__token, tuple_index.3, channel=another_test_channel) after_all.5: token = after_all(send.4, tuple_index.2) tuple.6: () = tuple() next (after_all.5, tuple.6) @@ -1057,11 +1057,11 @@ fn f(x: bits[32], y: bits[32]) -> bits[32] { } top proc main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) invoke.4: bits[32] = invoke(tuple_index.3, tuple_index.3, to_apply=f) - send.5: token = send(__token, invoke.4, channel_id=0) + send.5: token = send(__token, invoke.4, channel=test_channel) after_all.6: token = after_all(send.5, tuple_index.2) tuple.7: () = tuple() next (after_all.6, tuple.7) @@ -1079,11 +1079,11 @@ fn f(x: bits[32], y: bits[32]) -> bits[32] { } top proc another_main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=another_test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) invoke.4: bits[32] = invoke(tuple_index.3, tuple_index.3, to_apply=f) - send.5: token = send(__token, invoke.4, channel_id=0) + send.5: token = send(__token, invoke.4, channel=another_test_channel) after_all.6: token = after_all(send.5, tuple_index.2) tuple.7: () = tuple() next (after_all.6, tuple.7) diff --git a/xls/ir/proc.cc b/xls/ir/proc.cc index 6b021968f4..14e1174d94 100644 --- a/xls/ir/proc.cc +++ b/xls/ir/proc.cc @@ -310,7 +310,7 @@ bool Proc::HasImplicitUse(Node* node) const { absl::StatusOr Proc::Clone( std::string_view new_name, Package* target_package, - absl::flat_hash_map channel_remapping, + absl::flat_hash_map channel_remapping, absl::flat_hash_map call_remapping) const { absl::flat_hash_map original_to_clone; @@ -338,24 +338,23 @@ absl::StatusOr Proc::Clone( } case Op::kReceive: { Receive* src = node->As(); - int64_t channel_id = channel_remapping.contains(src->channel_id()) - ? channel_remapping.at(src->channel_id()) - : src->channel_id(); - XLS_ASSIGN_OR_RETURN( - original_to_clone[node], - cloned_proc->MakeNodeWithName( - src->loc(), cloned_operands[0], - cloned_operands.size() == 2 - ? std::optional(cloned_operands[1]) - : std::nullopt, - channel_id, src->is_blocking(), src->GetName())); + std::string channel = channel_remapping.contains(src->channel_name()) + ? channel_remapping.at(src->channel_name()) + : src->channel_name(); + XLS_ASSIGN_OR_RETURN(original_to_clone[node], + cloned_proc->MakeNodeWithName( + src->loc(), cloned_operands[0], + cloned_operands.size() == 2 + ? std::optional(cloned_operands[1]) + : std::nullopt, + channel, src->is_blocking(), src->GetName())); break; } case Op::kSend: { Send* src = node->As(); - int64_t channel_id = channel_remapping.contains(src->channel_id()) - ? channel_remapping.at(src->channel_id()) - : src->channel_id(); + std::string channel = channel_remapping.contains(src->channel_name()) + ? channel_remapping.at(src->channel_name()) + : src->channel_name(); XLS_ASSIGN_OR_RETURN( original_to_clone[node], cloned_proc->MakeNodeWithName( @@ -363,7 +362,7 @@ absl::StatusOr Proc::Clone( cloned_operands.size() == 3 ? std::optional(cloned_operands[2]) : std::nullopt, - channel_id, src->GetName())); + channel, src->GetName())); break; } // Remap CountedFor body. diff --git a/xls/ir/proc.h b/xls/ir/proc.h index 500133d3e0..52bc479371 100644 --- a/xls/ir/proc.h +++ b/xls/ir/proc.h @@ -150,11 +150,12 @@ class Proc : public FunctionBase { // Creates a clone of the proc with the new name `new_name`. Proc is // owned by `target_package`. `channel_remapping` dictates how to map channel - // IDs to new channel IDs in the cloned version; if a key is unavailable in - // `channel_remapping` it is assumed to be the identity mapping at that key. + // names to new channel names in the cloned version; if a key is unavailable + // in `channel_remapping` it is assumed to be the identity mapping at that + // key. absl::StatusOr Clone( std::string_view new_name, Package* target_package = nullptr, - absl::flat_hash_map channel_remapping = {}, + absl::flat_hash_map channel_remapping = {}, absl::flat_hash_map call_remapping = {}) const; diff --git a/xls/ir/proc_test.cc b/xls/ir/proc_test.cc index 6988aba022..5b3abaed9d 100644 --- a/xls/ir/proc_test.cc +++ b/xls/ir/proc_test.cc @@ -302,8 +302,8 @@ TEST_F(ProcTest, Clone) { p->GetBitsType(32))); XLS_ASSERT_OK_AND_ASSIGN( - Proc * clone, - proc->Clone("cloned", p.get(), {{channel->id(), cloned_channel->id()}})); + Proc * clone, proc->Clone("cloned", p.get(), + {{channel->name(), cloned_channel->name()}})); EXPECT_FALSE(clone->IsFunction()); EXPECT_TRUE(clone->IsProc()); @@ -311,12 +311,12 @@ TEST_F(ProcTest, Clone) { EXPECT_EQ(clone->DumpIr(), R"(proc cloned(tkn: token, st: bits[32], init={42}) { literal.12: bits[32] = literal(value=1, id=12) - receive_3: (token, bits[32]) = receive(tkn, channel_id=1, id=13) + receive_3: (token, bits[32]) = receive(tkn, channel=cloned_chan, id=13) add.14: bits[32] = add(literal.12, st, id=14) tuple_index.15: bits[32] = tuple_index(receive_3, index=1, id=15) tuple_index.16: token = tuple_index(receive_3, index=0, id=16) add.17: bits[32] = add(add.14, tuple_index.15, id=17) - send_9: token = send(tuple_index.16, add.17, channel_id=1, id=18) + send_9: token = send(tuple_index.16, add.17, channel=cloned_chan, id=18) next (send_9, add.17) } )"); diff --git a/xls/ir/testdata/node_util_test_ReplaceTupleIndicesWorksWithToken.ir b/xls/ir/testdata/node_util_test_ReplaceTupleIndicesWorksWithToken.ir index 3d43ac8b5b..d9f6ab09c9 100644 --- a/xls/ir/testdata/node_util_test_ReplaceTupleIndicesWorksWithToken.ir +++ b/xls/ir/testdata/node_util_test_ReplaceTupleIndicesWorksWithToken.ir @@ -3,7 +3,7 @@ proc ReplaceTupleIndicesWorksWithToken(tkn: token, init={}) { receive: (token, bits[32]) = tuple(tkn, literal.6, id=9) tuple_index.3: token = tuple_index(receive, index=0, id=3) tuple_index.4: bits[32] = tuple_index(receive, index=1, id=4) - receive.2: (token, bits[32]) = receive(tkn, channel_id=0, id=2) - send.5: token = send(tuple_index.3, tuple_index.4, channel_id=1, id=5) + receive.2: (token, bits[32]) = receive(tkn, channel=ch0, id=2) + send.5: token = send(tuple_index.3, tuple_index.4, channel=ch1, id=5) next (send.5) } diff --git a/xls/ir/verifier.cc b/xls/ir/verifier.cc index 0679aa83f7..672eebd762 100644 --- a/xls/ir/verifier.cc +++ b/xls/ir/verifier.cc @@ -170,13 +170,13 @@ class NodeChecker : public DfsVisitor { XLS_RETURN_IF_ERROR( ExpectOperandHasBitsType(receive, 1, /*expected_bit_count=*/1)); } - if (!receive->package()->HasChannelWithId(receive->channel_id())) { + if (!receive->package()->HasChannelWithName(receive->channel_name())) { return absl::InternalError( - StrFormat("%s refers to channel ID %d which does not exist", - receive->GetName(), receive->channel_id())); + StrFormat("%s refers to channel `%s` which does not exist", + receive->GetName(), receive->channel_name())); } - XLS_ASSIGN_OR_RETURN(Channel * channel, - receive->package()->GetChannel(receive->channel_id())); + XLS_ASSIGN_OR_RETURN(Channel * channel, receive->package()->GetChannel( + receive->channel_name())); Type* expected_type = receive->is_blocking() ? receive->package()->GetTupleType( @@ -206,13 +206,13 @@ class NodeChecker : public DfsVisitor { ExpectOperandHasBitsType(send, 2, /*expected_bit_count=*/1)); } - if (!send->package()->HasChannelWithId(send->channel_id())) { + if (!send->package()->HasChannelWithName(send->channel_name())) { return absl::InternalError( - StrFormat("%s refers to channel ID %d which does not exist", - send->GetName(), send->channel_id())); + StrFormat("%s refers to channel `%s` which does not exist", + send->GetName(), send->channel_name())); } XLS_ASSIGN_OR_RETURN(Channel * channel, - send->package()->GetChannel(send->channel_id())); + send->package()->GetChannel(send->channel_name())); if (!channel->CanSend()) { return absl::InternalError( StrFormat("Cannot send over channel %s (%d), send operation: %s", @@ -1513,10 +1513,10 @@ absl::Status VerifyFunctionBase(FunctionBase* function) { // if the given node is not a send or receive. absl::StatusOr GetSendOrReceiveChannel(Node* node) { if (node->Is()) { - return node->package()->GetChannel(node->As()->channel_id()); + return node->package()->GetChannel(node->As()->channel_name()); } if (node->Is()) { - return node->package()->GetChannel(node->As()->channel_id()); + return node->package()->GetChannel(node->As()->channel_name()); } return absl::InternalError(absl::StrFormat( "Node is not a send or receive node: %s", node->ToString())); @@ -2033,9 +2033,9 @@ static absl::Status VerifyFifoInstantiation(Package* package, absl::StrFormat("Expected fifo depth >= 0, got %d", instantiation->fifo_config().depth)); } - if (instantiation->channel_id().has_value()) { + if (instantiation->channel_name().has_value()) { XLS_ASSIGN_OR_RETURN(Channel * channel, - package->GetChannel(*instantiation->channel_id())); + package->GetChannel(*instantiation->channel_name())); if (channel->kind() != ChannelKind::kStreaming) { return absl::InvalidArgumentError( absl::StrFormat("Expected channel %s (with FIFO instantiation %s) to " diff --git a/xls/ir/verifier_test.cc b/xls/ir/verifier_test.cc index c51461ca83..d131063eb7 100644 --- a/xls/ir/verifier_test.cc +++ b/xls/ir/verifier_test.cc @@ -212,7 +212,7 @@ package test_package chan ch(bits[32], id=42, kind=streaming, ops=send_receive, flow_control=none, metadata="""module_port { flopped: true }""") proc my_proc(t: token, s: bits[32], init={45}) { - send.1: token = send(t, s, channel_id=42) + send.1: token = send(t, s, channel=ch) next (send.1, s) } @@ -232,8 +232,8 @@ package test_package chan ch(bits[32], id=42, kind=streaming, ops=send_only, flow_control=none, metadata="""module_port { flopped: true }""") proc my_proc(t: token, s: bits[32], init={45}) { - send.1: token = send(t, s, channel_id=42) - send.2: token = send(send.1, s, channel_id=42) + send.1: token = send(t, s, channel=ch) + send.2: token = send(send.1, s, channel=ch) next (send.2, s) } @@ -254,7 +254,7 @@ chan ch(bits[32], id=42, kind=streaming, ops=send_only, flow_control=none, metad proc my_proc(t: token, s: bits[32], init={45}) { after_all.1: token = after_all() - send.2: token = send(after_all.1, s, channel_id=42) + send.2: token = send(after_all.1, s, channel=ch) next (send.2, s) } @@ -275,7 +275,7 @@ package test_package chan ch(bits[32], id=42, kind=streaming, ops=receive_only, flow_control=none, metadata="""module_port { flopped: true }""") proc my_proc(t: token, s: bits[42], init={45}) { - receive.1: (token, bits[32]) = receive(t, channel_id=42) + receive.1: (token, bits[32]) = receive(t, channel=ch) next (t, s) } @@ -328,8 +328,8 @@ package test_package chan ch(bits[32], id=42, kind=streaming, ops=receive_only, flow_control=none, metadata="""module_port { flopped: true }""") proc my_proc(t: token, s: bits[42], init={45}) { - send.1: token = send(t, s, channel_id=42) - receive.2: (token, bits[32]) = receive(send.1, channel_id=42) + send.1: token = send(t, s, channel=ch) + receive.2: (token, bits[32]) = receive(send.1, channel=ch) tuple_index.3: token = tuple_index(receive.2, index=0) next (tuple_index.3, s) } diff --git a/xls/jit/BUILD b/xls/jit/BUILD index 62604772d5..2d468886ca 100644 --- a/xls/jit/BUILD +++ b/xls/jit/BUILD @@ -497,10 +497,12 @@ cc_library( "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", + "//xls/common/status:ret_check", "//xls/common/status:status_macros", "//xls/interpreter:proc_evaluator", "//xls/interpreter:serial_proc_runtime", "//xls/ir", + "//xls/ir:channel", "//xls/ir:events", "//xls/ir:type", "//xls/ir:value", diff --git a/xls/jit/ir_builder_visitor.cc b/xls/jit/ir_builder_visitor.cc index 393732f73f..5649252a29 100644 --- a/xls/jit/ir_builder_visitor.cc +++ b/xls/jit/ir_builder_visitor.cc @@ -3162,7 +3162,7 @@ absl::Status IrBuilderVisitor::HandleReceive(Receive* recv) { XLS_RET_CHECK(jit_context_.queue_manager().has_value()); XLS_ASSIGN_OR_RETURN(Channel * channel, - recv->package()->GetChannel(recv->channel_id())); + recv->package()->GetChannel(recv->channel_name())); JitChannelQueue& queue = jit_context_.queue_manager().value()->GetJitQueue(channel); @@ -3303,7 +3303,7 @@ absl::Status IrBuilderVisitor::HandleSend(Send* send) { XLS_RET_CHECK(jit_context_.queue_manager().has_value()); XLS_ASSIGN_OR_RETURN(Channel * channel, - send->package()->GetChannel(send->channel_id())); + send->package()->GetChannel(send->channel_name())); JitChannelQueue& queue = jit_context_.queue_manager().value()->GetJitQueue(channel); if (send->predicate().has_value()) { diff --git a/xls/jit/proc_jit.cc b/xls/jit/proc_jit.cc index 80ab773085..e3016d70a6 100644 --- a/xls/jit/proc_jit.cc +++ b/xls/jit/proc_jit.cc @@ -25,8 +25,12 @@ #include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "absl/types/span.h" +#include "xls/common/status/ret_check.h" #include "xls/common/status/status_macros.h" +#include "xls/interpreter/proc_evaluator.h" #include "xls/interpreter/serial_proc_runtime.h" +#include "xls/ir/channel.h" +#include "xls/ir/node.h" #include "xls/ir/proc.h" #include "xls/ir/type.h" #include "xls/ir/value.h" @@ -131,7 +135,7 @@ absl::StatusOr ProcJit::Tick(ProcContinuation& continuation) const { // Execution exited after sending data on a channel. XLS_ASSIGN_OR_RETURN(Channel * sent_channel, proc()->package()->GetChannel( - early_exit_node->As()->channel_id())); + early_exit_node->As()->channel_name())); // The send executed so some progress should have been made. XLS_RET_CHECK_NE(next_continuation_point, start_continuation_point); return TickResult{.execution_state = TickExecutionState::kSentOnChannel, @@ -141,7 +145,7 @@ absl::StatusOr ProcJit::Tick(ProcContinuation& continuation) const { XLS_RET_CHECK(early_exit_node->Is()); XLS_ASSIGN_OR_RETURN(Channel * blocked_channel, proc()->package()->GetChannel( - early_exit_node->As()->channel_id())); + early_exit_node->As()->channel_name())); return TickResult{ .execution_state = TickExecutionState::kBlockedOnReceive, .channel = blocked_channel, diff --git a/xls/passes/BUILD b/xls/passes/BUILD index 9268f2d450..fb6e155868 100644 --- a/xls/passes/BUILD +++ b/xls/passes/BUILD @@ -1197,6 +1197,7 @@ cc_library( "//xls/common/status:status_macros", "//xls/ir", "//xls/ir:bits", + "//xls/ir:channel", "//xls/ir:node_util", "//xls/ir:op", "//xls/ir:value", diff --git a/xls/passes/channel_legalization_pass.cc b/xls/passes/channel_legalization_pass.cc index 230f76458b..134e372596 100644 --- a/xls/passes/channel_legalization_pass.cc +++ b/xls/passes/channel_legalization_pass.cc @@ -70,8 +70,9 @@ absl::StatusOr TokenOperandNumberForChannelOp(Node* node) { } } struct MultipleChannelOps { - absl::flat_hash_map> multiple_sends; - absl::flat_hash_map> multiple_receives; + absl::flat_hash_map> multiple_sends; + absl::flat_hash_map> + multiple_receives; }; // Find instances of multiple sends/recvs on a channel. @@ -81,27 +82,28 @@ MultipleChannelOps FindMultipleChannelOps(Package* p) { for (Node* node : fb->nodes()) { if (node->Is()) { Send* send = node->As(); - absl::StatusOr channel = p->GetChannel(send->channel_id()); + absl::StatusOr channel = p->GetChannel(send->channel_name()); XLS_VLOG(4) << "Found send " << send->ToString(); - result.multiple_sends[send->channel_id()].insert(send); + result.multiple_sends[send->channel_name()].insert(send); } if (node->Is()) { Receive* recv = node->As(); - absl::StatusOr channel = p->GetChannel(recv->channel_id()); - result.multiple_receives[recv->channel_id()].insert(recv); + absl::StatusOr channel = p->GetChannel(recv->channel_name()); + result.multiple_receives[recv->channel_name()].insert(recv); XLS_VLOG(4) << "Found recv " << recv->ToString(); } } } // Erase cases where there's only one send or receive. - absl::erase_if(result.multiple_sends, - [](const std::pair>& elt) { - return elt.second.size() < 2; - }); + absl::erase_if( + result.multiple_sends, + [](const std::pair>& elt) { + return elt.second.size() < 2; + }); absl::erase_if( result.multiple_receives, - [](const std::pair>& elt) { + [](const std::pair>& elt) { return elt.second.size() < 2; }); @@ -378,7 +380,7 @@ absl::StatusOr MakePredicateChannel(Node* operation) { Send * send_pred, proc->MakeNodeWithName( SourceInfo(), operation->operand(operand_number), predicate.value(), - std::nullopt, pred_channel->id(), + std::nullopt, pred_channel->name(), absl::StrFormat("send_predicate_for_chan_%s", channel->name()))); // Replace the op's original input token with the predicate send's token. XLS_RETURN_IF_ERROR(operation->ReplaceOperandNumber( @@ -435,7 +437,7 @@ absl::StatusOr MakeCompletionChannel(Node* operation) { Receive * recv_completion, proc->MakeNodeWithName( SourceInfo(), proc->TokenParam(), predicate.value(), - completion_channel->id(), /*is_blocking=*/true, + completion_channel->name(), /*is_blocking=*/true, absl::StrFormat("recv_completion_for_chan_%s", channel->name()))); XLS_ASSIGN_OR_RETURN(Node * recv_completion_token, proc->MakeNodeWithName( @@ -895,7 +897,7 @@ absl::Status AddAdapterForMultipleReceives( .OverrideSupportedOps(ChannelOps::kSendReceive) .OverrideFifoDepth(1))); XLS_RETURN_IF_ERROR( - ReplaceChannelUsedByNode(node, new_data_channel->id())); + ReplaceChannelUsedByNode(node, new_data_channel->name())); BValue send_token = pb.AfterAll({activation.pred_recv_token, recv_token}); send_tokens.push_back(pb.SendIf(new_data_channel, send_token, activation.activate, recv_data)); @@ -946,7 +948,7 @@ absl::Status AddAdapterForMultipleSends(Package* p, StreamingChannel* channel, .OverrideSupportedOps(ChannelOps::kSendReceive) .OverrideFifoDepth(1))); XLS_RETURN_IF_ERROR( - ReplaceChannelUsedByNode(node, new_data_channel->id())); + ReplaceChannelUsedByNode(node, new_data_channel->name())); BValue recv = pb.ReceiveIf(new_data_channel, activation.pred_recv_token, activation.activate); recv_tokens.push_back(pb.TupleIndex(recv, 0)); @@ -989,7 +991,7 @@ absl::StatusOr ChannelLegalizationPass::RunInternal( XLS_VLOG(3) << "Running channel legalization pass."; bool changed = false; MultipleChannelOps multiple_ops = FindMultipleChannelOps(p); - for (const auto& [channel_id, ops] : multiple_ops.multiple_receives) { + for (const auto& [channel_name, ops] : multiple_ops.multiple_receives) { for (Receive* recv : ops) { if (!recv->is_blocking()) { return absl::InvalidArgumentError(absl::StrFormat( @@ -998,7 +1000,7 @@ absl::StatusOr ChannelLegalizationPass::RunInternal( recv->GetName())); } } - XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_id)); + XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_name)); if (channel->kind() != ChannelKind::kStreaming) { // Don't make adapters for non-streaming channels. continue; @@ -1011,14 +1013,14 @@ absl::StatusOr ChannelLegalizationPass::RunInternal( continue; } XLS_VLOG(3) << absl::StreamFormat( - "Making receive channel adapter for channel %d, has receives (%s).", - channel_id, absl::StrJoin(ops, ", ")); + "Making receive channel adapter for channel `%s`, has receives (%s).", + channel_name, absl::StrJoin(ops, ", ")); XLS_RETURN_IF_ERROR( AddAdapterForMultipleReceives(p, streaming_channel, ops)); changed = true; } - for (const auto& [channel_id, ops] : multiple_ops.multiple_sends) { - XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_id)); + for (const auto& [channel_name, ops] : multiple_ops.multiple_sends) { + XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_name)); if (channel->kind() != ChannelKind::kStreaming) { // Don't make adapters for non-streaming channels. continue; @@ -1031,8 +1033,8 @@ absl::StatusOr ChannelLegalizationPass::RunInternal( continue; } XLS_VLOG(3) << absl::StreamFormat( - "Making send channel adapter for channel %d, has sends (%s).", - channel_id, absl::StrJoin(ops, ", ")); + "Making send channel adapter for channel `%s`, has sends (%s).", + channel_name, absl::StrJoin(ops, ", ")); XLS_RETURN_IF_ERROR(AddAdapterForMultipleSends(p, streaming_channel, ops)); changed = true; } diff --git a/xls/passes/channel_legalization_pass_test.cc b/xls/passes/channel_legalization_pass_test.cc index b754c76d4d..5b99df88e7 100644 --- a/xls/passes/channel_legalization_pass_test.cc +++ b/xls/passes/channel_legalization_pass_test.cc @@ -150,14 +150,14 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="""""") top proc my_proc(tok: token, init={}) { - recv0: (token, bits[32]) = receive(tok, channel_id=0) + recv0: (token, bits[32]) = receive(tok, channel=in) recv0_tok: token = tuple_index(recv0, index=0) recv0_data: bits[32] = tuple_index(recv0, index=1) - recv1: (token, bits[32]) = receive(recv0_tok, channel_id=0) + recv1: (token, bits[32]) = receive(recv0_tok, channel=in) recv1_tok: token = tuple_index(recv1, index=0) recv1_data: bits[32] = tuple_index(recv1, index=1) - send0: token = send(recv1_tok, recv1_data, channel_id=1) - send1: token = send(send0, recv0_data, channel_id=1) + send0: token = send(recv1_tok, recv1_data, channel=out) + send1: token = send(send0, recv0_data, channel=out) next(send1) } )", @@ -227,19 +227,19 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="""""") top proc proc_a(tok: token, pred: bits[1], init={1}) { - recv: (token, bits[32]) = receive(tok, predicate=pred, channel_id=0) + recv: (token, bits[32]) = receive(tok, predicate=pred, channel=in) recv_tok: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send: token = send(recv_tok, recv_data, predicate=pred, channel_id=1) + send: token = send(recv_tok, recv_data, predicate=pred, channel=out) next_pred: bits[1] = not(pred) next(send, next_pred) } proc proc_b(tok: token, pred: bits[1], init={0}) { - recv: (token, bits[32]) = receive(tok, predicate=pred, channel_id=0) + recv: (token, bits[32]) = receive(tok, predicate=pred, channel=in) recv_tok: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send: token = send(recv_tok, recv_data, predicate=pred, channel_id=1) + send: token = send(recv_tok, recv_data, predicate=pred, channel=out) next_pred: bits[1] = not(pred) next(send, next_pred) } @@ -291,18 +291,18 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="""""") top proc proc_a(tok: token, init={}) { - recv: (token, bits[32]) = receive(tok, channel_id=0) + recv: (token, bits[32]) = receive(tok, channel=in) recv_tok: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send: token = send(recv_tok, recv_data, channel_id=1) + send: token = send(recv_tok, recv_data, channel=out) next(send) } proc proc_b(tok: token, init={}) { - recv: (token, bits[32]) = receive(tok, channel_id=0) + recv: (token, bits[32]) = receive(tok, channel=in) recv_tok: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send: token = send(recv_tok, recv_data, channel_id=1) + send: token = send(recv_tok, recv_data, channel=out) next(send) } )", @@ -367,24 +367,24 @@ chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid chan pred(bits[2], id=2, kind=streaming, ops=receive_only, flow_control=ready_valid, strictness=$0, metadata="""""") top proc my_proc(tok: token, init={}) { - pred_recv: (token, bits[2]) = receive(tok, channel_id=2) + pred_recv: (token, bits[2]) = receive(tok, channel=pred) pred_token: token = tuple_index(pred_recv, index=0) pred_data: bits[2] = tuple_index(pred_recv, index=1) pred0: bits[1] = bit_slice(pred_data, start=0, width=1) pred1: bits[1] = bit_slice(pred_data, start=1, width=1) - recv0: (token, bits[32]) = receive(pred_token, channel_id=0) + recv0: (token, bits[32]) = receive(pred_token, channel=in) recv0_tok: token = tuple_index(recv0, index=0) recv0_data: bits[32] = tuple_index(recv0, index=1) - recv1: (token, bits[32]) = receive(recv0_tok, channel_id=0, predicate=pred0) + recv1: (token, bits[32]) = receive(recv0_tok, channel=in, predicate=pred0) recv1_tok: token = tuple_index(recv1, index=0) recv1_data: bits[32] = tuple_index(recv1, index=1) - recv2: (token, bits[32]) = receive(recv0_tok, channel_id=0, predicate=pred1) + recv2: (token, bits[32]) = receive(recv0_tok, channel=in, predicate=pred1) recv2_tok: token = tuple_index(recv2, index=0) recv2_data: bits[32] = tuple_index(recv2, index=1) all_recv_tok: token = after_all(recv0_tok, recv1_tok, recv2_tok) - send0: token = send(all_recv_tok, recv0_data, channel_id=1) - send1: token = send(send0, recv1_data, predicate=pred0, channel_id=1) - send2: token = send(send0, recv2_data, predicate=pred1, channel_id=1) + send0: token = send(all_recv_tok, recv0_data, channel=out) + send1: token = send(send0, recv1_data, predicate=pred0, channel=out) + send2: token = send(send0, recv2_data, predicate=pred1, channel=out) all_send_tok: token = after_all(send0, send1, send2) next(all_send_tok) } @@ -527,15 +527,15 @@ chan out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid top proc test_proc(tkn: token, state:(), init={()}) { data_to_send: bits[32] = literal(value=5) - pred_recv: (token, bits[1]) = receive(tkn, channel_id=0) + pred_recv: (token, bits[1]) = receive(tkn, channel=pred_recv) pred_recv_token: token = tuple_index(pred_recv, index=0) pred_recv_data: bits[1] = tuple_index(pred_recv, index=1) - in_recv0: (token, bits[32]) = receive(pred_recv_token, predicate=pred_recv_data, channel_id=1) + in_recv0: (token, bits[32]) = receive(pred_recv_token, predicate=pred_recv_data, channel=in) in_recv0_token: token = tuple_index(in_recv0, index=0) - in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=pred_recv_data, channel_id=1) + in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=pred_recv_data, channel=in) in_recv1_token: token = tuple_index(in_recv1, index=0) - out_send0: token = send(in_recv1_token, data_to_send, channel_id=2) - out_send1: token = send(out_send0, data_to_send, channel_id=2) + out_send0: token = send(in_recv1_token, data_to_send, channel=out) + out_send1: token = send(out_send0, data_to_send, channel=out) next (out_send1, state) } )", @@ -607,17 +607,17 @@ chan in(bits[32], id=1, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="") top proc test_proc(tkn: token, state:(), init={()}) { - in_recv0: (token, bits[32]) = receive(tkn, channel_id=1) + in_recv0: (token, bits[32]) = receive(tkn, channel=in) in_recv0_token: token = tuple_index(in_recv0, index=0) in_recv0_data: bits[32] = tuple_index(in_recv0, index=1) comp_data: bits[32] = literal(value=5) in_recv1_pred: bits[1] = ugt(in_recv0_data, comp_data) - in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=in_recv1_pred, channel_id=1) + in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=in_recv1_pred, channel=in) in_recv1_token: token = tuple_index(in_recv1, index=0) in_recv1_data: bits[32] = tuple_index(in_recv1, index=1) data_to_send: bits[32] = add(in_recv0_data, in_recv1_data) - out_send0: token = send(in_recv1_token, data_to_send, channel_id=2) - out_send1: token = send(out_send0, data_to_send, predicate=in_recv1_pred, channel_id=2) + out_send0: token = send(in_recv1_token, data_to_send, channel=out) + out_send1: token = send(out_send0, data_to_send, predicate=in_recv1_pred, channel=out) next (out_send1, state) } )", @@ -699,17 +699,17 @@ chan out0(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_vali chan out1(bits[32], id=3, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="") top proc test_proc(tkn: token, state:(), init={()}) { - in_recv0: (token, bits[32]) = receive(tkn, channel_id=1) + in_recv0: (token, bits[32]) = receive(tkn, channel=in) in_recv0_token: token = tuple_index(in_recv0, index=0) in_recv0_data: bits[32] = tuple_index(in_recv0, index=1) comp_data: bits[32] = literal(value=5) in_recv1_pred: bits[1] = ugt(in_recv0_data, comp_data) - in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=in_recv1_pred, channel_id=1) + in_recv1: (token, bits[32]) = receive(in_recv0_token, predicate=in_recv1_pred, channel=in) in_recv1_token: token = tuple_index(in_recv1, index=0) in_recv1_data: bits[32] = tuple_index(in_recv1, index=1) data_to_send: bits[32] = add(in_recv0_data, in_recv1_data) - out_send0: token = send(in_recv1_token, data_to_send, channel_id=2) - out_send1: token = send(out_send0, data_to_send, predicate=in_recv1_pred, channel_id=3) + out_send0: token = send(in_recv1_token, data_to_send, channel=out0) + out_send1: token = send(out_send0, data_to_send, predicate=in_recv1_pred, channel=out1) next (out_send1, state) } )", @@ -806,17 +806,17 @@ chan pred1(bits[1], id=1, kind=streaming, ops=receive_only, flow_control=ready_v chan out(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=$0, metadata="") top proc test_proc(tkn: token, state:(), init={()}) { - pred1_recv: (token, bits[1]) = receive(tkn, channel_id=1) + pred1_recv: (token, bits[1]) = receive(tkn, channel=pred1) pred1_recv_token: token = tuple_index(pred1_recv, index=0) pred1_recv_data: bits[1] = tuple_index(pred1_recv, index=1) - pred0_recv: (token, bits[1]) = receive(pred1_recv_token, channel_id=0) + pred0_recv: (token, bits[1]) = receive(pred1_recv_token, channel=pred0) pred0_recv_token: token = tuple_index(pred0_recv, index=0) pred0_recv_data: bits[1] = tuple_index(pred0_recv, index=1) literal0: bits[32] = literal(value=0) literal1: bits[32] = literal(value=1) - out_send0: token = send(pred0_recv_token, literal0, predicate=pred0_recv_data, channel_id=2) + out_send0: token = send(pred0_recv_token, literal0, predicate=pred0_recv_data, channel=out) after_all_tok: token = after_all(out_send0, pred1_recv_token) - out_send1: token = send(after_all_tok, literal1, predicate=pred1_recv_data, channel_id=2) + out_send1: token = send(after_all_tok, literal1, predicate=pred1_recv_data, channel=out) next (out_send1, state) } )", diff --git a/xls/passes/conditional_specialization_pass_test.cc b/xls/passes/conditional_specialization_pass_test.cc index 798e41da7b..114320089b 100644 --- a/xls/passes/conditional_specialization_pass_test.cc +++ b/xls/passes/conditional_specialization_pass_test.cc @@ -560,7 +560,7 @@ TEST_F(ConditionalSpecializationPassTest, SendNoChangeLiteralPred) { literal.5: bits[32] = literal(value=400, id=5) eq.3: bits[1] = eq(value, literal.5, id=3) sel.4: bits[32] = sel(eq.3, cases=[literal.5, value], id=4) - send.1: token = send(tkn, sel.4, predicate=literal.2, channel_id=1, id=1) + send.1: token = send(tkn, sel.4, predicate=literal.2, channel=out, id=1) next (send.1, value) } )")); @@ -580,7 +580,7 @@ TEST_F(ConditionalSpecializationPassTest, SendNoChangeUnprovable) { eq.3: bits[1] = eq(value, literal.5, id=3) ugt.4: bits[1] = ugt(value, literal.6, id=4) sel.4: bits[32] = sel(eq.3, cases=[literal.5, value], id=4) - send.1: token = send(tkn, sel.4, predicate=ugt.4, channel_id=1, id=1) + send.1: token = send(tkn, sel.4, predicate=ugt.4, channel=out, id=1) next (send.1, value) } )")); @@ -598,7 +598,7 @@ TEST_F(ConditionalSpecializationPassTest, SendChange) { literal.5: bits[32] = literal(value=400, id=5) eq.3: bits[1] = eq(value, literal.5, id=3) sel.4: bits[32] = sel(eq.3, cases=[literal.5, value], id=4) - send.1: token = send(tkn, sel.4, predicate=eq.3, channel_id=1, id=1) + send.1: token = send(tkn, sel.4, predicate=eq.3, channel=out, id=1) next (send.1, value) } )")); diff --git a/xls/passes/dfe_pass.cc b/xls/passes/dfe_pass.cc index a26900ac9b..cbb5b3329f 100644 --- a/xls/passes/dfe_pass.cc +++ b/xls/passes/dfe_pass.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "absl/container/flat_hash_map.h" @@ -90,32 +91,31 @@ absl::StatusOr DeadFunctionEliminationPass::RunInternal( return false; } - // Mapping from proc->channel_id, where channel_id is a representative value - // for all the channel_ids in the UnionFind. - absl::flat_hash_map representative_channel_ids; - representative_channel_ids.reserve(p->procs().size()); + // Mapping from proc->channel, where channel is a representative value + // for all the channel names in the UnionFind. + absl::flat_hash_map representative_channels; + representative_channels.reserve(p->procs().size()); // Channels in the same proc will be union'd. - UnionFind channel_id_union; + UnionFind channel_union; for (std::unique_ptr& proc : p->procs()) { - std::optional representative_proc_channel_id; + std::optional representative_proc_channel; for (Node* node : proc->nodes()) { if (IsChannelNode(node)) { - int64_t channel_id; + std::string channel; if (node->Is()) { - channel_id = node->As()->channel_id(); + channel = node->As()->channel_name(); } else if (node->Is()) { - channel_id = node->As()->channel_id(); + channel = node->As()->channel_name(); } else { return absl::NotFoundError(absl::StrFormat( "No channel associated with node %s", node->GetName())); } - channel_id_union.Insert(channel_id); - if (representative_proc_channel_id.has_value()) { - channel_id_union.Union(representative_proc_channel_id.value(), - channel_id); + channel_union.Insert(channel); + if (representative_proc_channel.has_value()) { + channel_union.Union(representative_proc_channel.value(), channel); } else { - representative_proc_channel_id = channel_id; - representative_channel_ids.insert({proc.get(), channel_id}); + representative_proc_channel = channel; + representative_channels.insert({proc.get(), channel}); } } } @@ -123,18 +123,17 @@ absl::StatusOr DeadFunctionEliminationPass::RunInternal( absl::flat_hash_set reached; MarkReachedFunctions(top.value(), &reached); - std::optional top_proc_representative_channel_id; + std::optional top_proc_representative_channel; if ((*top)->IsProc()) { - auto itr = representative_channel_ids.find(top.value()->AsProcOrDie()); - if (itr != representative_channel_ids.end()) { - top_proc_representative_channel_id = channel_id_union.Find(itr->second); - for (auto [proc, representative_channel_id] : - representative_channel_ids) { - if (channel_id_union.Find(representative_channel_id) == - *top_proc_representative_channel_id) { + auto itr = representative_channels.find(top.value()->AsProcOrDie()); + if (itr != representative_channels.end()) { + top_proc_representative_channel = channel_union.Find(itr->second); + for (auto [proc, representative_channel] : representative_channels) { + if (channel_union.Find(representative_channel) == + *top_proc_representative_channel) { MarkReachedFunctions(proc, &reached); } - } + } } } @@ -149,19 +148,18 @@ absl::StatusOr DeadFunctionEliminationPass::RunInternal( } // Find any channels which are only used by now-removed procs. - std::vector channel_ids_to_remove; - channel_ids_to_remove.reserve(p->channels().size()); + std::vector channels_to_remove; + channels_to_remove.reserve(p->channels().size()); for (Channel* channel : p->channels()) { - int64_t channel_id = channel->id(); - if (!top_proc_representative_channel_id.has_value() || - channel_id_union.Find(channel_id) != - *top_proc_representative_channel_id) { - channel_ids_to_remove.push_back(channel_id); + if (!top_proc_representative_channel.has_value() || + channel_union.Find(channel->name()) != + *top_proc_representative_channel) { + channels_to_remove.push_back(channel->name()); } } // Now remove any channels which are only used by now-removed procs. - for (int64_t channel_id : channel_ids_to_remove) { - XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_id)); + for (const std::string& channel_name : channels_to_remove) { + XLS_ASSIGN_OR_RETURN(Channel * channel, p->GetChannel(channel_name)); XLS_VLOG(2) << "Removing channel: " << channel->name(); XLS_RETURN_IF_ERROR(p->RemoveChannel(channel)); changed = true; diff --git a/xls/passes/dfe_pass_test.cc b/xls/passes/dfe_pass_test.cc index c411bbb1e9..ff15b8278a 100644 --- a/xls/passes/dfe_pass_test.cc +++ b/xls/passes/dfe_pass_test.cc @@ -289,16 +289,16 @@ chan c(bits[32], id=2, kind=streaming, ops=receive_only, flow_control=ready_vali chan d(bits[32], id=3, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") top proc test_proc0(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0) + rcv: (token, bits[32]) = receive(tkn, channel=a) rcv_token: token = tuple_index(rcv, index=0) next (rcv_token, state) } proc test_proc1(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0) + rcv: (token, bits[32]) = receive(tkn, channel=a) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } @@ -307,17 +307,17 @@ fn negate(in: bits[32]) -> bits[32] { } proc test_proc2(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=2) + rcv: (token, bits[32]) = receive(tkn, channel=c) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) send_data: bits[32] = invoke(rcv_data, to_apply=negate) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } proc test_proc3(tkn: token, state:(), init={()}) { literal0: bits[32] = literal(value=0) - send_token: token = send(tkn, literal0, channel_id=3) + send_token: token = send(tkn, literal0, channel=d) next (send_token, state) } )"; @@ -348,10 +348,10 @@ top proc test_proc0(tkn: token, state:(), init={()}) { } proc test_proc1(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0) + rcv: (token, bits[32]) = receive(tkn, channel=a) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } @@ -360,17 +360,17 @@ fn negate(in: bits[32]) -> bits[32] { } proc test_proc2(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=2) + rcv: (token, bits[32]) = receive(tkn, channel=c) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) send_data: bits[32] = invoke(rcv_data, to_apply=negate) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } proc test_proc3(tkn: token, state:(), init={()}) { literal0: bits[32] = literal(value=0) - send_token: token = send(tkn, literal0, channel_id=3) + send_token: token = send(tkn, literal0, channel=d) next (send_token, state) } )"; @@ -395,10 +395,10 @@ proc test_proc0(tkn: token, state:(), init={()}) { } proc test_proc1(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0) + rcv: (token, bits[32]) = receive(tkn, channel=a) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } @@ -407,17 +407,17 @@ top fn negate(in: bits[32]) -> bits[32] { } proc test_proc2(tkn: token, state:(), init={()}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=2) + rcv: (token, bits[32]) = receive(tkn, channel=c) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) send_data: bits[32] = invoke(rcv_data, to_apply=negate) - send_token: token = send(rcv_token, rcv_data, channel_id=1) + send_token: token = send(rcv_token, rcv_data, channel=b) next (send_token, state) } proc test_proc3(tkn: token, state:(), init={()}) { literal0: bits[32] = literal(value=0) - send_token: token = send(tkn, literal0, channel_id=3) + send_token: token = send(tkn, literal0, channel=d) next (send_token, state) } )"; diff --git a/xls/passes/minimal_feedback_arcs_test.cc b/xls/passes/minimal_feedback_arcs_test.cc index fb8d34d630..d14cc77728 100644 --- a/xls/passes/minimal_feedback_arcs_test.cc +++ b/xls/passes/minimal_feedback_arcs_test.cc @@ -151,10 +151,10 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="") top proc foo(tkn: token, st: (), init={()}) { - recv: (token, bits[32]) = receive(tkn, channel_id=0) + recv: (token, bits[32]) = receive(tkn, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send_token: token = send(recv_token, recv_data, channel_id=1) + send_token: token = send(recv_token, recv_data, channel=out) next (send_token, st) } )"; @@ -171,16 +171,16 @@ chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid chan internal(bits[32], id=2, kind=streaming, ops=send_receive, flow_control=ready_valid, metadata="") top proc foo(tkn: token, st: (), init={()}) { - recv: (token, bits[32]) = receive(tkn, channel_id=0) + recv: (token, bits[32]) = receive(tkn, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - internal_recv: (token, bits[32]) = receive(tkn, channel_id=2) + internal_recv: (token, bits[32]) = receive(tkn, channel=internal) internal_recv_token: token = tuple_index(internal_recv, index=0) internal_recv_data: bits[32] = tuple_index(internal_recv, index=1) sum: bits[32] = add(recv_data, internal_recv_data) all_receive_token: token = after_all(recv_token, internal_recv_token) - send_token: token = send(all_receive_token, sum, channel_id=1) - internal_send_token: token = send(recv_token, recv_data, channel_id=2) + send_token: token = send(all_receive_token, sum, channel=out) + internal_send_token: token = send(recv_token, recv_data, channel=internal) all_send_token: token = after_all(send_token, internal_send_token) next (all_send_token, st) } @@ -198,16 +198,16 @@ chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid chan internal(bits[32], id=2, kind=streaming, ops=send_receive, flow_control=ready_valid, metadata="") top proc foo(tkn: token, st: (), init={()}) { - recv: (token, bits[32]) = receive(tkn, channel_id=0) + recv: (token, bits[32]) = receive(tkn, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - internal_recv: (token, bits[32]) = receive(tkn, channel_id=2) + internal_recv: (token, bits[32]) = receive(tkn, channel=internal) internal_recv_token: token = tuple_index(internal_recv, index=0) internal_recv_data: bits[32] = tuple_index(internal_recv, index=1) sum: bits[32] = add(recv_data, internal_recv_data) all_receive_token: token = after_all(recv_token, internal_recv_token) - send_token: token = send(all_receive_token, sum, channel_id=1) - internal_send_token: token = send(all_receive_token, sum, channel_id=2) + send_token: token = send(all_receive_token, sum, channel=out) + internal_send_token: token = send(all_receive_token, sum, channel=internal) all_send_token: token = after_all(send_token, internal_send_token) next (all_send_token, st) } @@ -235,30 +235,30 @@ chan internal1(bits[32], id=3, kind=streaming, ops=send_receive, flow_control=re chan internal2(bits[32], id=4, kind=streaming, ops=send_receive, flow_control=ready_valid, metadata="") top proc foo(tkn: token, st: (), init={()}) { - recv: (token, bits[32]) = receive(tkn, channel_id=0) + recv: (token, bits[32]) = receive(tkn, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - internal_recv0: (token, bits[32]) = receive(tkn, channel_id=2) + internal_recv0: (token, bits[32]) = receive(tkn, channel=internal0) internal_recv0_token: token = tuple_index(internal_recv0, index=0) internal_recv0_data: bits[32] = tuple_index(internal_recv0, index=1) - internal_recv1: (token, bits[32]) = receive(tkn, channel_id=3) + internal_recv1: (token, bits[32]) = receive(tkn, channel=internal1) internal_recv1_token: token = tuple_index(internal_recv1, index=0) internal_recv1_data: bits[32] = tuple_index(internal_recv1, index=1) partial_sum: bits[32] = add(internal_recv0_data, internal_recv1_data) sum: bits[32] = add(recv_data, partial_sum) all_receive_token: token = after_all(recv_token, internal_recv0_token, internal_recv1_token) - send_token: token = send(all_receive_token, sum, channel_id=1) - internal_send_token: token = send(all_receive_token, sum, channel_id=4) + send_token: token = send(all_receive_token, sum, channel=out) + internal_send_token: token = send(all_receive_token, sum, channel=internal2) all_send_token: token = after_all(send_token, internal_send_token) next (all_send_token, st) } proc bar(tkn: token, st: (), init={()}) { - recv: (token, bits[32]) = receive(tkn, channel_id=4) + recv: (token, bits[32]) = receive(tkn, channel=internal2) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send0_token: token = send(recv_token, recv_data, channel_id=2) - send1_token: token = send(recv_token, recv_data, channel_id=3) + send0_token: token = send(recv_token, recv_data, channel=internal0) + send1_token: token = send(recv_token, recv_data, channel=internal1) all_send_token: token = after_all(send0_token, send1_token) next(all_send_token, st) } diff --git a/xls/passes/optimization_pass.h b/xls/passes/optimization_pass.h index 93a5aa5640..23ba27e1e4 100644 --- a/xls/passes/optimization_pass.h +++ b/xls/passes/optimization_pass.h @@ -68,7 +68,8 @@ struct RamConfig { struct RamModelBuilderResult { std::unique_ptr package; - absl::flat_hash_map channel_logical_name_to_physical_id; + absl::flat_hash_map + channel_logical_name_to_physical_name; }; using ram_model_builder_t = std::function; diff --git a/xls/passes/proc_inlining_pass.cc b/xls/passes/proc_inlining_pass.cc index c86474b436..f760291a64 100644 --- a/xls/passes/proc_inlining_pass.cc +++ b/xls/passes/proc_inlining_pass.cc @@ -157,7 +157,7 @@ absl::StatusOr AddSendPredicate(Send* send, Node* predicate) { } XLS_ASSIGN_OR_RETURN(Send * new_send, send->ReplaceUsesWithNew( send->token(), send->data(), - predicate, send->channel_id())); + predicate, send->channel_name())); return new_send; } @@ -178,7 +178,7 @@ absl::StatusOr AddReceivePredicate(Receive* receive, } XLS_ASSIGN_OR_RETURN(Receive * new_receive, receive->ReplaceUsesWithNew( - receive->token(), predicate, receive->channel_id(), + receive->token(), predicate, receive->channel_name(), receive->is_blocking())); return new_receive; } diff --git a/xls/passes/proc_inlining_pass_test.cc b/xls/passes/proc_inlining_pass_test.cc index 31962b5dd4..48cabff6b3 100644 --- a/xls/passes/proc_inlining_pass_test.cc +++ b/xls/passes/proc_inlining_pass_test.cc @@ -3936,23 +3936,23 @@ top proc foo(tkn: token, count: bits[32], init={0}) { lit0: bits[32] = literal(value=0) lit1: bits[32] = literal(value=1) pred: bits[1] = eq(count, lit0) - recv: (token, bits[32]) = receive(tkn, predicate=pred, channel_id=0) + recv: (token, bits[32]) = receive(tkn, predicate=pred, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) count_minus_one: bits[32] = sub(count, lit1) next_count: bits[32] = sel(pred, cases=[count_minus_one, recv_data]) - send_token: token = send(recv_token, recv_data, predicate=pred, channel_id=1) + send_token: token = send(recv_token, recv_data, predicate=pred, channel=internal) next (send_token, next_count) } proc output_passthrough(tkn: token, state:(), init={()}) { - recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, channel_id=1) + recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, channel=internal) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) recv_valid: bits[1] = tuple_index(recv, index=2) literal1000: bits[32] = literal(value=1000) send_data: bits[32] = sel(recv_valid, cases=[literal1000, recv_data]) - send_token: token = send(recv_token, send_data, channel_id=2) + send_token: token = send(recv_token, send_data, channel=out) next(send_token, state) } )"; @@ -4002,17 +4002,17 @@ top proc foo(tkn: token, count: bits[32], init={0}) { lit0: bits[32] = literal(value=0) lit1: bits[32] = literal(value=1) pred: bits[1] = eq(count, lit0) - recv: (token, bits[32]) = receive(tkn, predicate=pred, channel_id=0) + recv: (token, bits[32]) = receive(tkn, predicate=pred, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) count_minus_one: bits[32] = sub(count, lit1) next_count: bits[32] = sel(pred, cases=[count_minus_one, recv_data]) - send_token: token = send(recv_token, recv_data, predicate=pred, channel_id=1) + send_token: token = send(recv_token, recv_data, predicate=pred, channel=internal) next (send_token, next_count) } proc output_passthrough(tkn: token, state: bits[1], init={1}) { - recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, predicate=state, channel_id=1) + recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, predicate=state, channel=internal) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) recv_valid: bits[1] = tuple_index(recv, index=2) @@ -4020,7 +4020,7 @@ proc output_passthrough(tkn: token, state: bits[1], init={1}) { literal1000: bits[32] = literal(value=1000) recv_data_or_literal: bits[32] = sel(recv_valid, cases=[literal1000, recv_data]) send_data: bits[32] = sel(state, cases=[literal500, recv_data_or_literal]) - send_token: token = send(recv_token, send_data, channel_id=2) + send_token: token = send(recv_token, send_data, channel=out) next_state: bits[1] = not(state) next(send_token, next_state) } @@ -4091,21 +4091,21 @@ top proc foo(tkn: token, count: bits[2], init={0}) { lit0: bits[2] = literal(value=0) lit1: bits[2] = literal(value=1) pred: bits[1] = eq(count, lit0) - recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, predicate=pred, channel_id=0) + recv: (token, bits[32], bits[1]) = receive(tkn, blocking=false, predicate=pred, channel=in) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) recv_valid: bits[1] = tuple_index(recv, index=2) - send0_token: token = send(recv_token, recv_data, predicate=recv_valid, channel_id=1) - send1_token: token = send(send0_token, recv_data, predicate=recv_valid, channel_id=3) + send0_token: token = send(recv_token, recv_data, predicate=recv_valid, channel=internal) + send1_token: token = send(send0_token, recv_data, predicate=recv_valid, channel=out1) next_count: bits[2] = add(count, lit1) next (send1_token, next_count) } proc output_passthrough(tkn: token, state:bits[1], init={0}) { - recv: (token, bits[32]) = receive(tkn, predicate=state, channel_id=1) + recv: (token, bits[32]) = receive(tkn, predicate=state, channel=internal) recv_token: token = tuple_index(recv, index=0) recv_data: bits[32] = tuple_index(recv, index=1) - send_token: token = send(recv_token, recv_data, predicate=state, channel_id=2) + send_token: token = send(recv_token, recv_data, predicate=state, channel=out0) next_state: bits[1] = not(state) next(send_token, next_state) } diff --git a/xls/passes/proc_loop_folding.cc b/xls/passes/proc_loop_folding.cc index 19eeedad6c..bf44fb9f0a 100644 --- a/xls/passes/proc_loop_folding.cc +++ b/xls/passes/proc_loop_folding.cc @@ -29,6 +29,7 @@ #include "xls/common/status/ret_check.h" #include "xls/common/status/status_macros.h" #include "xls/ir/bits.h" +#include "xls/ir/channel.h" #include "xls/ir/node.h" #include "xls/ir/node_iterator.h" #include "xls/ir/node_util.h" @@ -204,8 +205,8 @@ absl::StatusOr RollIntoProcPass::CreateInitialState( new_state_vals.push_back(ZeroOfType(loopbody->param(0)->GetType())); new_state_vals.push_back(ZeroOfType(loopbody->param(0)->GetType())); new_state_vals.push_back(ZeroOfType(initial_value->GetType())); - XLS_ASSIGN_OR_RETURN(Channel* recv_channel, - proc->package()->GetChannel(recv->channel_id())); + XLS_ASSIGN_OR_RETURN(Channel * recv_channel, + proc->package()->GetChannel(recv->channel_name())); new_state_vals.push_back(ZeroOfType(recv_channel->type())); // Naively push the loop invariants into the state. for (Node* invariant : loop_invariants) { @@ -285,9 +286,9 @@ absl::StatusOr RollIntoProcPass::ReplaceReceiveWithConditionalReceive( Node* on_condition_false) const { XLS_ASSIGN_OR_RETURN( auto new_receive, - proc->MakeNode(original_receive->loc(), proc->TokenParam(), - receive_condition, original_receive->channel_id(), - original_receive->is_blocking())); + proc->MakeNode( + original_receive->loc(), proc->TokenParam(), receive_condition, + original_receive->channel_name(), original_receive->is_blocking())); XLS_ASSIGN_OR_RETURN( auto new_receive_token, proc->MakeNode(original_receive->loc(), new_receive, 0)); @@ -500,12 +501,10 @@ absl::StatusOr RollIntoProcPass::RunOnProcInternal( receive_val_proc_state)); // Create the "SendIf" node. - XLS_ASSIGN_OR_RETURN(auto new_send, - proc->MakeNode(send_node->loc(), - proc->TokenParam(), - send_node->data(), - is_final_iteration, - send_node->channel_id())); + XLS_ASSIGN_OR_RETURN( + auto new_send, proc->MakeNode(send_node->loc(), proc->TokenParam(), + send_node->data(), is_final_iteration, + send_node->channel_name())); XLS_RETURN_IF_ERROR(send_node->ReplaceUsesWith(new_send)); XLS_RETURN_IF_ERROR(proc->RemoveNode(send_node)); diff --git a/xls/passes/ram_rewrite_pass.cc b/xls/passes/ram_rewrite_pass.cc index 6ee29102f0..ac3cc6b2cb 100644 --- a/xls/passes/ram_rewrite_pass.cc +++ b/xls/passes/ram_rewrite_pass.cc @@ -233,17 +233,17 @@ GetChannelsForNewRam(Package* p, std::string_view name_prefix, XLS_ASSIGN_OR_RETURN(auto linked_channel_mapping, p->AddPackage(new_package.get())); absl::flat_hash_map resolved_channel_mapping; - for (const auto& [logical_name, original_id] : new_channel_mapping) { - auto new_id = linked_channel_mapping.channel_id_updates.find(original_id); - if (new_id == linked_channel_mapping.channel_id_updates.end()) { + for (const auto& [logical_name, original_channel] : new_channel_mapping) { + auto new_channel_it = + linked_channel_mapping.channel_updates.find(original_channel); + if (new_channel_it == linked_channel_mapping.channel_updates.end()) { return absl::InternalError(absl::StrFormat( - "Could not find new channel id for linked channel %s.", - logical_name)); + "Could not find new channel for linked channel %s.", logical_name)); } XLS_ASSIGN_OR_RETURN(RamLogicalChannel logical_channel, RamLogicalChannelFromName(logical_name)); XLS_ASSIGN_OR_RETURN(Channel * new_channel, - p->GetChannel(new_id->second)); + p->GetChannel(new_channel_it->second)); resolved_channel_mapping.insert({logical_channel, new_channel}); } return resolved_channel_mapping; @@ -442,14 +442,14 @@ absl::Status ReplaceSend(Proc* proc, Send* old_send, RamLogicalChannel logical_channel, const RamConfig& from_config, const RamConfig& to_config, Type* data_type, - int64_t new_channel_id) { + std::string_view new_channel) { XLS_ASSIGN_OR_RETURN(Node * new_payload, RepackPayload(proc, old_send->data(), logical_channel, from_config, to_config, data_type)); XLS_RETURN_IF_ERROR( old_send ->ReplaceUsesWithNew(old_send->token(), new_payload, - old_send->predicate(), new_channel_id) + old_send->predicate(), new_channel) .status()); XLS_RETURN_IF_ERROR(proc->RemoveNode(old_send)); return absl::OkStatus(); @@ -466,7 +466,7 @@ absl::Status ReplaceReceive(Proc* proc, Receive* old_receive, RamLogicalChannel logical_channel, const RamConfig& from_config, const RamConfig& to_config, Type* data_type, - int64_t new_channel_id) { + std::string_view new_channel) { std::optional new_receive; if (from_config.kind == RamKind::kAbstract && (to_config.kind == RamKind::k1RW || to_config.kind == RamKind::k1R1W)) { @@ -475,7 +475,7 @@ absl::Status ReplaceReceive(Proc* proc, Receive* old_receive, XLS_ASSIGN_OR_RETURN( new_receive, proc->MakeNode(old_receive->loc(), old_receive->token(), - old_receive->predicate(), new_channel_id, + old_receive->predicate(), new_channel, old_receive->is_blocking())); break; } @@ -483,7 +483,7 @@ absl::Status ReplaceReceive(Proc* proc, Receive* old_receive, XLS_ASSIGN_OR_RETURN( new_receive, proc->MakeNode(old_receive->loc(), old_receive->token(), - old_receive->predicate(), new_channel_id, + old_receive->predicate(), new_channel, old_receive->is_blocking())); break; } @@ -554,7 +554,7 @@ absl::Status ReplaceChannelReferences( // channel and replace this send with a new send to the new channel. XLS_ASSIGN_OR_RETURN( Channel * old_channel, - proc->package()->GetChannel(old_send->channel_id())); + proc->package()->GetChannel(old_send->channel_name())); auto it = reverse_from_mapping.find(old_channel); if (it == reverse_from_mapping.end()) { continue; @@ -563,10 +563,11 @@ absl::Status ReplaceChannelReferences( XLS_ASSIGN_OR_RETURN( RamLogicalChannel new_logical_channel, MapChannel(from_config.kind, logical_channel, to_config.kind)); - int64_t new_channel_id = to_mapping.at(new_logical_channel)->id(); + std::string_view new_channel = + to_mapping.at(new_logical_channel)->name(); XLS_RETURN_IF_ERROR(ReplaceSend(proc.get(), old_send, logical_channel, from_config, to_config, data_type, - new_channel_id)); + new_channel)); } else if (node->Is()) { // If this receive operates on a channel in our mapping, find the new // channel and replace this receive with a new receive to the new @@ -574,7 +575,7 @@ absl::Status ReplaceChannelReferences( Receive* old_receive = node->As(); XLS_ASSIGN_OR_RETURN( Channel * old_channel, - proc->package()->GetChannel(old_receive->channel_id())); + proc->package()->GetChannel(old_receive->channel_name())); auto it = reverse_from_mapping.find(old_channel); if (it == reverse_from_mapping.end()) { continue; @@ -583,10 +584,11 @@ absl::Status ReplaceChannelReferences( XLS_ASSIGN_OR_RETURN( RamLogicalChannel new_logical_channel, MapChannel(from_config.kind, logical_channel, to_config.kind)); - int64_t new_channel_id = to_mapping.at(new_logical_channel)->id(); - XLS_RETURN_IF_ERROR( - ReplaceReceive(proc.get(), old_receive, logical_channel, - from_config, to_config, data_type, new_channel_id)); + std::string_view new_channel = + to_mapping.at(new_logical_channel)->name(); + XLS_RETURN_IF_ERROR(ReplaceReceive(proc.get(), old_receive, + logical_channel, from_config, + to_config, data_type, new_channel)); } } } diff --git a/xls/passes/token_dependency_pass_test.cc b/xls/passes/token_dependency_pass_test.cc index 5abb16a65e..31862c9ce2 100644 --- a/xls/passes/token_dependency_pass_test.cc +++ b/xls/passes/token_dependency_pass_test.cc @@ -55,10 +55,10 @@ TEST_F(TokenDependencyPassTest, Simple) { flow_control=ready_valid, metadata="""""") top proc main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(__token, tuple_index.3, channel_id=0) + send.4: token = send(__token, tuple_index.3, channel=test_channel) after_all.5: token = after_all(send.4, tuple_index.2) tuple.6: () = tuple() next (after_all.5, tuple.6) @@ -82,12 +82,12 @@ TEST_F(TokenDependencyPassTest, MultipleSends) { flow_control=ready_valid, metadata="""""") top proc main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(__token, tuple_index.3, channel_id=0) - send.5: token = send(__token, tuple_index.3, channel_id=0) - send.6: token = send(__token, tuple_index.3, channel_id=0) + send.4: token = send(__token, tuple_index.3, channel=test_channel) + send.5: token = send(__token, tuple_index.3, channel=test_channel) + send.6: token = send(__token, tuple_index.3, channel=test_channel) after_all.7: token = after_all(send.4, send.5, send.6, tuple_index.2) tuple.8: () = tuple() next (after_all.7, tuple.8) @@ -117,12 +117,12 @@ TEST_F(TokenDependencyPassTest, DependentSends) { flow_control=ready_valid, metadata="""""") top proc main(__token: token, __state: (), init={()}) { - receive.1: (token, bits[32]) = receive(__token, channel_id=0) + receive.1: (token, bits[32]) = receive(__token, channel=test_channel) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(__token, tuple_index.3, channel_id=0) - send.5: token = send(send.4, tuple_index.3, channel_id=0) - send.6: token = send(__token, tuple_index.3, channel_id=0) + send.4: token = send(__token, tuple_index.3, channel=test_channel) + send.5: token = send(send.4, tuple_index.3, channel=test_channel) + send.6: token = send(__token, tuple_index.3, channel=test_channel) after_all.7: token = after_all(send.4, send.5, send.6, tuple_index.2) tuple.8: () = tuple() next (after_all.7, tuple.8) @@ -151,7 +151,7 @@ TEST_F(TokenDependencyPassTest, SideEffectingNontokenOps) { flow_control=ready_valid, metadata="""""") top proc main(__token: token, init={}) { - rcv: (token, bits[32]) = receive(__token, channel_id=0) + rcv: (token, bits[32]) = receive(__token, channel=test_channel) tkn: token = tuple_index(rcv, index=0) data: bits[32] = tuple_index(rcv, index=1) one: bits[1] = literal(value=1) diff --git a/xls/passes/token_simplification_pass_test.cc b/xls/passes/token_simplification_pass_test.cc index 067ef32625..3e21d17ce9 100644 --- a/xls/passes/token_simplification_pass_test.cc +++ b/xls/passes/token_simplification_pass_test.cc @@ -151,9 +151,9 @@ TEST_F(TokenSimplificationPassTest, DuplicatedArgument2) { top proc main(tok: token, state: (), init={()}) { literal.1: bits[32] = literal(value=10) - send.2: token = send(tok, literal.1, channel_id=0) - send.3: token = send(send.2, literal.1, channel_id=0) - send.4: token = send(tok, literal.1, channel_id=0) + send.2: token = send(tok, literal.1, channel=test_channel) + send.3: token = send(send.2, literal.1, channel=test_channel) + send.4: token = send(tok, literal.1, channel=test_channel) after_all.5: token = after_all(send.2, send.3, send.4) tuple.6: () = tuple() next (after_all.5, tuple.6) @@ -177,9 +177,9 @@ TEST_F(TokenSimplificationPassTest, UnrelatedArguments) { top proc main(tok: token, state: (), init={()}) { literal.1: bits[32] = literal(value=10) - send.2: token = send(tok, literal.1, channel_id=0) - send.3: token = send(tok, literal.1, channel_id=0) - send.4: token = send(tok, literal.1, channel_id=0) + send.2: token = send(tok, literal.1, channel=test_channel) + send.3: token = send(tok, literal.1, channel=test_channel) + send.4: token = send(tok, literal.1, channel=test_channel) after_all.5: token = after_all(send.2, send.3, send.4) tuple.6: () = tuple() next (after_all.5, tuple.6) @@ -203,8 +203,8 @@ TEST_F(TokenSimplificationPassTest, ArgumentsWithDependencies) { top proc main(tok: token, state: (), init={()}) { literal.1: bits[32] = literal(value=10) - send.2: token = send(tok, literal.1, channel_id=0) - send.3: token = send(send.2, literal.1, channel_id=0) + send.2: token = send(tok, literal.1, channel=test_channel) + send.3: token = send(send.2, literal.1, channel=test_channel) after_all.4: token = after_all(tok, send.2, send.3) tuple.5: () = tuple() next (after_all.4, tuple.5) @@ -229,8 +229,8 @@ TEST_F(TokenSimplificationPassTest, DoNotRelyOnInvokeForDependencies) { top proc main(tok: token, state: (), init={()}) { literal.1: bits[32] = literal(value=10) - send.2: token = send(tok, literal.1, channel_id=0) - send.3: token = send(tok, literal.1, channel_id=0) + send.2: token = send(tok, literal.1, channel=test_channel) + send.3: token = send(tok, literal.1, channel=test_channel) invoke.4: token = invoke(send.2, send.3, to_apply=test_fn) after_all.5: token = after_all(tok, send.2, send.3, invoke.4) tuple.6: () = tuple() diff --git a/xls/passes/unroll_proc_test.cc b/xls/passes/unroll_proc_test.cc index e0ebe434c0..c4de7226a7 100644 --- a/xls/passes/unroll_proc_test.cc +++ b/xls/passes/unroll_proc_test.cc @@ -79,7 +79,7 @@ TEST_F(UnrollProcTest, UnrollWithIO) { top proc main(__token: token, __state: bits[10], init={0}) { literal.1: bits[10] = literal(value=1) add.2: bits[10] = add(literal.1, __state) - send.3: token = send(__token, add.2, channel_id=0) + send.3: token = send(__token, add.2, channel=test_channel) next (send.3, add.2) } )")); diff --git a/xls/passes/useless_io_removal_pass.cc b/xls/passes/useless_io_removal_pass.cc index 5ef8bc4ab7..70b8691a8d 100644 --- a/xls/passes/useless_io_removal_pass.cc +++ b/xls/passes/useless_io_removal_pass.cc @@ -15,6 +15,8 @@ #include "xls/passes/useless_io_removal_pass.h" #include +#include +#include #include #include "absl/container/flat_hash_map.h" @@ -34,8 +36,10 @@ namespace xls { namespace { -using ChannelToSendMap = std::vector>; -using ChannelToReceiveMap = std::vector>; +using ChannelToSendMap = + absl::flat_hash_map>; +using ChannelToReceiveMap = + absl::flat_hash_map>; struct ChannelMaps { ChannelToSendMap to_send; @@ -47,16 +51,14 @@ absl::StatusOr ComputeChannelMaps(Package* package) { if (package->channels().empty()) { return result; } - int64_t max_id = package->channels().back()->id(); - result.to_send.resize(max_id + 1); - result.to_receive.resize(max_id + 1); for (std::unique_ptr& proc : package->procs()) { for (Node* node : proc->nodes()) { if (node->Is()) { - result.to_send[node->As()->channel_id()].insert(node->As()); + result.to_send[node->As()->channel_name()].insert( + node->As()); } if (node->Is()) { - result.to_receive[node->As()->channel_id()].insert( + result.to_receive[node->As()->channel_name()].insert( node->As()); } } @@ -85,15 +87,15 @@ absl::StatusOr UselessIORemovalPass::RunInternal( } Node* predicate = send->predicate().value(); if (IsLiteralZero(predicate) && - channel_maps.to_send.at(send->channel_id()).size() >= 2) { - channel_maps.to_send.at(send->channel_id()).erase(send); + channel_maps.to_send.at(send->channel_name()).size() >= 2) { + channel_maps.to_send.at(send->channel_name()).erase(send); replacement = send->token(); } else if (IsLiteralUnsignedOne(predicate)) { XLS_ASSIGN_OR_RETURN( replacement, proc->MakeNode(node->loc(), send->token(), send->data(), /*predicate=*/std::nullopt, - send->channel_id())); + send->channel_name())); } } else if (node->Is()) { Receive* receive = node->As(); @@ -102,9 +104,9 @@ absl::StatusOr UselessIORemovalPass::RunInternal( } Node* predicate = receive->predicate().value(); if (IsLiteralZero(predicate) && - channel_maps.to_receive.at(receive->channel_id()).size() >= 2) { + channel_maps.to_receive.at(receive->channel_name()).size() >= 2) { XLS_ASSIGN_OR_RETURN(Channel * channel, GetChannelUsedByNode(node)); - channel_maps.to_receive.at(receive->channel_id()).erase(receive); + channel_maps.to_receive.at(receive->channel_name()).erase(receive); XLS_ASSIGN_OR_RETURN(Literal * zero, proc->MakeNode( node->loc(), ZeroOfType(channel->type()))); @@ -113,11 +115,11 @@ absl::StatusOr UselessIORemovalPass::RunInternal( proc->MakeNode( node->loc(), std::vector{receive->token(), zero})); } else if (IsLiteralUnsignedOne(predicate)) { - XLS_ASSIGN_OR_RETURN( - replacement, proc->MakeNode( - node->loc(), receive->token(), - /*predicate=*/std::nullopt, - receive->channel_id(), receive->is_blocking())); + XLS_ASSIGN_OR_RETURN(replacement, proc->MakeNode( + node->loc(), receive->token(), + /*predicate=*/std::nullopt, + receive->channel_name(), + receive->is_blocking())); } } if (replacement != nullptr) { diff --git a/xls/scheduling/mutual_exclusion_pass.cc b/xls/scheduling/mutual_exclusion_pass.cc index 47564c466c..2c1962708b 100644 --- a/xls/scheduling/mutual_exclusion_pass.cc +++ b/xls/scheduling/mutual_exclusion_pass.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -183,14 +184,14 @@ absl::StatusOr ComputeMergableEffects(FunctionBase* f) { } } - auto get_channel_id = [](Node* node) -> int64_t { + auto get_channel_name = [](Node* node) -> std::string_view { if (node->Is()) { - return node->As()->channel_id(); + return node->As()->channel_name(); } if (node->Is()) { - return node->As()->channel_id(); + return node->As()->channel_name(); } - return -1; + return ""; }; auto get_predicate = [](Node* node) -> std::optional { @@ -211,7 +212,7 @@ absl::StatusOr ComputeMergableEffects(FunctionBase* f) { absl::flat_hash_set subgraph = LargestConnectedSubgraph(node, token_dag, [&](Node* n) -> bool { return n->op() == node->op() && - get_channel_id(n) == get_channel_id(node); + get_channel_name(n) == get_channel_name(node); }); for (Node* x : subgraph) { for (Node* y : subgraph) { @@ -292,12 +293,12 @@ absl::StatusOr>> ComputeMergeClasses( } if ((x->op() == Op::kSend) && (!is_mergable(x, y) || - (x->As()->channel_id() != y->As()->channel_id()))) { + (x->As()->channel_name() != y->As()->channel_name()))) { continue; } if ((x->op() == Op::kReceive) && - (!is_mergable(x, y) || (x->As()->channel_id() != - y->As()->channel_id()))) { + (!is_mergable(x, y) || (x->As()->channel_name() != + y->As()->channel_name()))) { continue; } if (p->QueryMutuallyExclusive(px, py) == std::make_optional(true)) { @@ -426,9 +427,9 @@ absl::StatusOr> ComputeTokenInputs( absl::StatusOr MergeSends(Predicates* p, FunctionBase* f, absl::Span to_merge) { - int64_t channel_id = to_merge.front()->As()->channel_id(); + std::string_view channel_name = to_merge.front()->As()->channel_name(); for (Node* send : to_merge) { - XLS_CHECK_EQ(channel_id, send->As()->channel_id()); + XLS_CHECK_EQ(channel_name, send->As()->channel_name()); } XLS_ASSIGN_OR_RETURN(std::vector token_inputs, @@ -459,7 +460,7 @@ absl::StatusOr MergeSends(Predicates* p, FunctionBase* f, f->MakeNode(SourceInfo(), selector, args)); XLS_ASSIGN_OR_RETURN(Node * send, f->MakeNode(SourceInfo(), token, data, - predicate, channel_id)); + predicate, channel_name)); for (Node* node : to_merge) { XLS_RETURN_IF_ERROR(node->ReplaceUsesWith(send)); @@ -471,11 +472,12 @@ absl::StatusOr MergeSends(Predicates* p, FunctionBase* f, absl::StatusOr MergeReceives(Predicates* p, FunctionBase* f, absl::Span to_merge) { - int64_t channel_id = to_merge.front()->As()->channel_id(); + std::string_view channel_name = + to_merge.front()->As()->channel_name(); bool is_blocking = to_merge.front()->As()->is_blocking(); for (Node* send : to_merge) { - XLS_CHECK_EQ(channel_id, send->As()->channel_id()); + XLS_CHECK_EQ(channel_name, send->As()->channel_name()); XLS_CHECK_EQ(is_blocking, send->As()->is_blocking()); } @@ -493,7 +495,7 @@ absl::StatusOr MergeReceives(Predicates* p, FunctionBase* f, XLS_ASSIGN_OR_RETURN(Node * receive, f->MakeNode(SourceInfo(), token, predicate, - channel_id, is_blocking)); + channel_name, is_blocking)); XLS_ASSIGN_OR_RETURN(Node * token_output, f->MakeNode(SourceInfo(), receive, 0)); diff --git a/xls/scheduling/mutual_exclusion_pass_test.cc b/xls/scheduling/mutual_exclusion_pass_test.cc index a5986b20ba..6814080a39 100644 --- a/xls/scheduling/mutual_exclusion_pass_test.cc +++ b/xls/scheduling/mutual_exclusion_pass_test.cc @@ -104,8 +104,8 @@ TEST_F(MutualExclusionPassTest, TwoParallelSends) { not.1: bits[1] = not(__state) literal.2: bits[32] = literal(value=50) literal.3: bits[32] = literal(value=60) - send.4: token = send(__token, literal.2, predicate=__state, channel_id=0) - send.5: token = send(__token, literal.3, predicate=not.1, channel_id=0) + send.4: token = send(__token, literal.2, predicate=__state, channel=test_channel) + send.5: token = send(__token, literal.3, predicate=not.1, channel=test_channel) after_all.6: token = after_all(send.4, send.5) next (after_all.6, not.1) } @@ -134,9 +134,9 @@ TEST_F(MutualExclusionPassTest, ThreeParallelSends) { eq.7: bits[1] = eq(zero_ext.3, literal.4) eq.8: bits[1] = eq(zero_ext.3, literal.5) eq.9: bits[1] = eq(zero_ext.3, literal.6) - send.10: token = send(__token, literal.4, predicate=eq.7, channel_id=0) - send.11: token = send(__token, literal.5, predicate=eq.8, channel_id=0) - send.12: token = send(__token, literal.6, predicate=eq.9, channel_id=0) + send.10: token = send(__token, literal.4, predicate=eq.7, channel=test_channel) + send.11: token = send(__token, literal.5, predicate=eq.8, channel=test_channel) + send.12: token = send(__token, literal.6, predicate=eq.9, channel=test_channel) after_all.13: token = after_all(send.10, send.11, send.12) next (after_all.13, add.2) } @@ -169,8 +169,8 @@ TEST_F(MutualExclusionPassTest, TwoSequentialSends) { not.1: bits[1] = not(__state) literal.2: bits[32] = literal(value=50) literal.3: bits[32] = literal(value=60) - send.4: token = send(__token, literal.2, predicate=__state, channel_id=0) - send.5: token = send(send.4, literal.3, predicate=not.1, channel_id=0) + send.4: token = send(__token, literal.2, predicate=__state, channel=test_channel) + send.5: token = send(send.4, literal.3, predicate=not.1, channel=test_channel) next (send.5, not.1) } )")); @@ -195,9 +195,9 @@ TEST_F(MutualExclusionPassTest, TwoSequentialSendsWithInterveningIO) { not.1: bits[1] = not(__state) literal.2: bits[32] = literal(value=50) literal.3: bits[32] = literal(value=60) - send.4: token = send(__token, literal.2, predicate=__state, channel_id=0) - send.5: token = send(send.4, literal.2, channel_id=1) - send.6: token = send(send.5, literal.3, predicate=not.1, channel_id=0) + send.4: token = send(__token, literal.2, predicate=__state, channel=test_channel) + send.5: token = send(send.4, literal.2, channel=other_channel) + send.6: token = send(send.5, literal.3, predicate=not.1, channel=test_channel) next (send.6, not.1) } )")); @@ -227,10 +227,10 @@ TEST_F(MutualExclusionPassTest, Complex) { eq.6: bits[1] = eq(__state, literal.3) eq.7: bits[1] = eq(__state, literal.4) eq.8: bits[1] = eq(__state, literal.5) - send.9: token = send(__token, literal.3, predicate=eq.6, channel_id=0) - send.10: token = send(send.9, literal.3, channel_id=1) - send.11: token = send(send.10, literal.4, predicate=eq.7, channel_id=0) - send.12: token = send(__token, literal.5, predicate=eq.8, channel_id=0) + send.9: token = send(__token, literal.3, predicate=eq.6, channel=test_channel) + send.10: token = send(send.9, literal.3, channel=other_channel) + send.11: token = send(send.10, literal.4, predicate=eq.7, channel=test_channel) + send.12: token = send(__token, literal.5, predicate=eq.8, channel=test_channel) after_all.13: token = after_all(send.11, send.12) next (after_all.13, add.2) } @@ -250,15 +250,15 @@ TEST_F(MutualExclusionPassTest, TwoParallelReceives) { top proc main(__token: token, __state: bits[1], init={0}) { not.1: bits[1] = not(__state) - receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel_id=0) + receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel=test_channel) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[32] = tuple_index(receive.2, index=1) - receive.5: (token, bits[32]) = receive(__token, predicate=not.1, channel_id=0) + receive.5: (token, bits[32]) = receive(__token, predicate=not.1, channel=test_channel) tuple_index.6: token = tuple_index(receive.5, index=0) tuple_index.7: bits[32] = tuple_index(receive.5, index=1) add.8: bits[32] = add(tuple_index.4, tuple_index.7) after_all.9: token = after_all(tuple_index.3, tuple_index.6) - send.10: token = send(after_all.9, add.8, channel_id=0) + send.10: token = send(after_all.9, add.8, channel=test_channel) next (send.10, not.1) } )")); @@ -278,15 +278,15 @@ TEST_F(MutualExclusionPassTest, TwoSequentialReceives) { top proc main(__token: token, __state: bits[1], init={0}) { not.1: bits[1] = not(__state) - receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel_id=0) + receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel=test_channel) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[32] = tuple_index(receive.2, index=1) - receive.5: (token, bits[32]) = receive(tuple_index.3, predicate=not.1, channel_id=0) + receive.5: (token, bits[32]) = receive(tuple_index.3, predicate=not.1, channel=test_channel) tuple_index.6: token = tuple_index(receive.5, index=0) tuple_index.7: bits[32] = tuple_index(receive.5, index=1) add.8: bits[32] = add(tuple_index.4, tuple_index.7) after_all.9: token = after_all(tuple_index.3, tuple_index.6) - send.10: token = send(after_all.9, add.8, channel_id=0) + send.10: token = send(after_all.9, add.8, channel=test_channel) next (send.10, not.1) } )")); @@ -309,16 +309,16 @@ TEST_F(MutualExclusionPassTest, TwoSequentialReceivesWithInterveningIO) { top proc main(__token: token, __state: bits[1], init={0}) { not.1: bits[1] = not(__state) - receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel_id=0) + receive.2: (token, bits[32]) = receive(__token, predicate=__state, channel=test_channel) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[32] = tuple_index(receive.2, index=1) - send.5: token = send(tuple_index.3, tuple_index.4, channel_id=1) - receive.6: (token, bits[32]) = receive(send.5, predicate=not.1, channel_id=0) + send.5: token = send(tuple_index.3, tuple_index.4, channel=other_channel) + receive.6: (token, bits[32]) = receive(send.5, predicate=not.1, channel=test_channel) tuple_index.7: token = tuple_index(receive.6, index=0) tuple_index.8: bits[32] = tuple_index(receive.6, index=1) add.9: bits[32] = add(tuple_index.4, tuple_index.8) after_all.10: token = after_all(tuple_index.3, tuple_index.7) - send.11: token = send(after_all.10, add.9, channel_id=0) + send.11: token = send(after_all.10, add.9, channel=test_channel) next (send.11, not.1) } )")); @@ -337,16 +337,16 @@ TEST_F(MutualExclusionPassTest, TwoSequentialReceivesWithDataDep) { top proc main(__token: token, __state: bits[1], init={0}) { not.1: bits[1] = not(__state) - receive.2: (token, bits[1]) = receive(__token, predicate=__state, channel_id=0) + receive.2: (token, bits[1]) = receive(__token, predicate=__state, channel=test_channel) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[1] = tuple_index(receive.2, index=1) and.11: bits[1] = and(not.1, tuple_index.4) - receive.5: (token, bits[1]) = receive(tuple_index.3, predicate=and.11, channel_id=0) + receive.5: (token, bits[1]) = receive(tuple_index.3, predicate=and.11, channel=test_channel) tuple_index.6: token = tuple_index(receive.5, index=0) tuple_index.7: bits[1] = tuple_index(receive.5, index=1) add.8: bits[1] = add(tuple_index.4, tuple_index.7) after_all.9: token = after_all(tuple_index.3, tuple_index.6) - send.10: token = send(after_all.9, add.8, channel_id=0) + send.10: token = send(after_all.9, add.8, channel=test_channel) next (send.10, not.1) } )")); @@ -369,19 +369,19 @@ TEST_F(MutualExclusionPassTest, TwoReceivesDependingOnReceive) { top proc main(__token: token, __state: bits[1], init={0}) { not.1: bits[1] = not(__state) - receive.2: (token, bits[32]) = receive(__token, channel_id=1) + receive.2: (token, bits[32]) = receive(__token, channel=other_channel) tuple_index.3: token = tuple_index(receive.2, index=0) tuple_index.4: bits[32] = tuple_index(receive.2, index=1) - receive.5: (token, bits[32]) = receive(tuple_index.3, predicate=__state, channel_id=0) + receive.5: (token, bits[32]) = receive(tuple_index.3, predicate=__state, channel=test_channel) tuple_index.7: token = tuple_index(receive.5, index=0) tuple_index.8: bits[32] = tuple_index(receive.5, index=1) - receive.9: (token, bits[32]) = receive(tuple_index.3, predicate=not.1, channel_id=0) + receive.9: (token, bits[32]) = receive(tuple_index.3, predicate=not.1, channel=test_channel) tuple_index.10: token = tuple_index(receive.9, index=0) tuple_index.11: bits[32] = tuple_index(receive.9, index=1) add.12: bits[32] = add(tuple_index.4, tuple_index.8) add.13: bits[32] = add(add.12, tuple_index.11) after_all.14: token = after_all(tuple_index.7, tuple_index.10) - send.15: token = send(after_all.14, add.13, channel_id=0) + send.15: token = send(after_all.14, add.13, channel=test_channel) next (send.15, not.1) } )")); diff --git a/xls/tools/codegen_main_test.py b/xls/tools/codegen_main_test.py index 89b75350c9..4d62d07df0 100644 --- a/xls/tools/codegen_main_test.py +++ b/xls/tools/codegen_main_test.py @@ -53,11 +53,11 @@ flow_control=ready_valid, metadata="") proc neg_proc(my_token: token, my_state: (), init={()}) { - rcv: (token, bits[32]) = receive(my_token, channel_id=0) + rcv: (token, bits[32]) = receive(my_token, channel=in) data: bits[32] = tuple_index(rcv, index=1) negate: bits[32] = neg(data) rcv_token: token = tuple_index(rcv, index=0) - send: token = send(rcv_token, negate, channel_id=1) + send: token = send(rcv_token, negate, channel=out) next (send, my_state) } """ diff --git a/xls/tools/eval_proc_main_test.py b/xls/tools/eval_proc_main_test.py index fb0de2c10a..26bf6e7416 100644 --- a/xls/tools/eval_proc_main_test.py +++ b/xls/tools/eval_proc_main_test.py @@ -32,7 +32,7 @@ chan out_ch_2(bits[64], id=4, kind=streaming, ops=send_only, flow_control=ready_valid, metadata=\"\"\"\"\"\") proc test_proc(tkn: token, st: (bits[64]), init={(10)}) { - receive.1: (token, bits[64]) = receive(tkn, channel_id=1, id=1) + receive.1: (token, bits[64]) = receive(tkn, channel=in_ch, id=1) literal.21: bits[64] = literal(value=10, id=21) tuple_index.23: bits[64] = tuple_index(st, index=0, id=23) @@ -40,15 +40,15 @@ literal.3: bits[1] = literal(value=1, id=3) tuple_index.7: token = tuple_index(receive.1, index=0, id=7) tuple_index.4: bits[64] = tuple_index(receive.1, index=1, id=4) - receive.9: (token, bits[64]) = receive(tuple_index.7, channel_id=2, id=9) + receive.9: (token, bits[64]) = receive(tuple_index.7, channel=in_ch_2, id=9) tuple_index.10: bits[64] = tuple_index(receive.9, index=1, id=10) add.8: bits[64] = add(tuple_index.4, tuple_index.10, id=8) add.24: bits[64] = add(add.8, tuple_index.23, id=24) tuple_index.11: token = tuple_index(receive.9, index=0, id=11) - send.2: token = send(tuple_index.11, add.24, predicate=literal.3, channel_id=3, id=2) + send.2: token = send(tuple_index.11, add.24, predicate=literal.3, channel=out_ch, id=2) literal.14: bits[64] = literal(value=55, id=14) - send.12: token = send(send.2, literal.14, predicate=literal.3, channel_id=4, id=12) + send.12: token = send(send.2, literal.14, predicate=literal.3, channel=out_ch_2, id=12) add.20: bits[64] = add(literal.21, tuple_index.23, id=20) @@ -66,12 +66,12 @@ chan output(bits[8], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata=\"\"\"\"\"\") proc test_proc(__token: token, init={}) { - receive.4: (token, bits[8]) = receive(__token, channel_id=0, id=4) + receive.4: (token, bits[8]) = receive(__token, channel=input, id=4) recv_val: bits[8] = tuple_index(receive.4, index=1, id=7, pos=[(0,7,19)]) literal.8: bits[8] = literal(value=42, id=8, pos=[(0,8,39)]) recv_tok: token = tuple_index(receive.4, index=0, id=6, pos=[(0,7,9)]) do_send: bits[1] = ne(recv_val, literal.8, id=9, pos=[(0,8,33)]) - send_tok: token = send(recv_tok, recv_val, predicate=do_send, channel_id=1, id=10) + send_tok: token = send(recv_tok, recv_val, predicate=do_send, channel=output, id=10) after_all.12: token = after_all(__token, recv_tok, send_tok, id=12) next (after_all.12) } diff --git a/xls/tools/ir_minimizer_main_test.py b/xls/tools/ir_minimizer_main_test.py index c437409176..447ee70be3 100644 --- a/xls/tools/ir_minimizer_main_test.py +++ b/xls/tools/ir_minimizer_main_test.py @@ -191,10 +191,10 @@ def test_proc(self): chan output(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc foo(tkn: token, foo: bits[32], bar: bits[32], baz: bits[32], init={1, 2, 3}) { - receive.1: (token, bits[32]) = receive(tkn, channel_id=0) + receive.1: (token, bits[32]) = receive(tkn, channel=input) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(tkn, baz, channel_id=1) + send.4: token = send(tkn, baz, channel=output) after_all.5: token = after_all(tuple_index.2, send.4) next (after_all.5, tuple_index.3, foo, bar) } @@ -218,10 +218,10 @@ def test_proc_remove_sends(self): chan output(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc foo(tkn: token, foo: bits[32], bar: bits[32], baz: bits[32], init={1, 2, 3}) { - receive.1: (token, bits[32]) = receive(tkn, channel_id=0) + receive.1: (token, bits[32]) = receive(tkn, channel=input) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(tkn, baz, channel_id=1) + send.4: token = send(tkn, baz, channel=output) after_all.5: token = after_all(tuple_index.2, send.4) next (after_all.5, tuple_index.3, foo, bar) } @@ -247,10 +247,10 @@ def test_remove_receives(self): chan output(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc foo(tkn: token, foo: bits[32], bar: bits[32], baz: bits[32], init={1, 2, 3}) { - receive.1: (token, bits[32]) = receive(tkn, channel_id=0) + receive.1: (token, bits[32]) = receive(tkn, channel=input) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(tkn, baz, channel_id=1) + send.4: token = send(tkn, baz, channel=output) after_all.5: token = after_all(tuple_index.2, send.4) next (after_all.5, tuple_index.3, foo, bar) } @@ -276,10 +276,10 @@ def test_proc_remove_sends_and_receives(self): chan output(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc foo(tkn: token, foo: bits[32], bar: bits[32], baz: bits[32], init={1, 2, 3}) { - receive.1: (token, bits[32]) = receive(tkn, channel_id=0) + receive.1: (token, bits[32]) = receive(tkn, channel=input) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(tkn, baz, channel_id=1) + send.4: token = send(tkn, baz, channel=output) after_all.5: token = after_all(tuple_index.2, send.4) next (after_all.5, tuple_index.3, foo, bar) } @@ -306,10 +306,10 @@ def test_proc_preserve_channels(self): chan output(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc foo(tkn: token, foo: bits[32], bar: bits[32], baz: bits[32], init={1, 2, 3}) { - receive.1: (token, bits[32]) = receive(tkn, channel_id=0) + receive.1: (token, bits[32]) = receive(tkn, channel=input) tuple_index.2: token = tuple_index(receive.1, index=0) tuple_index.3: bits[32] = tuple_index(receive.1, index=1) - send.4: token = send(tkn, baz, channel_id=1) + send.4: token = send(tkn, baz, channel=output) after_all.5: token = after_all(tuple_index.2, send.4) next (after_all.5, tuple_index.3, foo, bar) } diff --git a/xls/tools/simulate_module_main_test.py b/xls/tools/simulate_module_main_test.py index 4f225f1e7e..daa55f0b62 100644 --- a/xls/tools/simulate_module_main_test.py +++ b/xls/tools/simulate_module_main_test.py @@ -38,15 +38,15 @@ chan sample__result(bits[32], id=2, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc add(__token: token, init={}) { - receive.4: (token, bits[32]) = receive(__token, channel_id=0, id=4) - receive.7: (token, bits[32]) = receive(__token, channel_id=1, id=7) + receive.4: (token, bits[32]) = receive(__token, channel=sample__operand_0, id=4) + receive.7: (token, bits[32]) = receive(__token, channel=sample__operand_1, id=7) tok_operand_0_val: token = tuple_index(receive.4, index=0, id=5, pos=[(0,14,9)]) tok_operand_1_val: token = tuple_index(receive.7, index=0, id=8, pos=[(0,15,9)]) operand_0_val: bits[32] = tuple_index(receive.4, index=1, id=6, pos=[(0,14,28)]) operand_1_val: bits[32] = tuple_index(receive.7, index=1, id=9, pos=[(0,15,28)]) tok_recv: token = after_all(tok_operand_0_val, tok_operand_1_val, id=10) result_val: bits[32] = add(operand_0_val, operand_1_val, id=11, pos=[(0,18,35)]) - tok_send: token = send(tok_recv, result_val, channel_id=2, id=12) + tok_send: token = send(tok_recv, result_val, channel=sample__result, id=12) after_all.14: token = after_all(__token, tok_operand_0_val, tok_operand_1_val, tok_recv, tok_send, id=14) next (after_all.14) } @@ -60,9 +60,9 @@ chan in1(bits[42], id=1, kind=streaming, ops=receive_only, flow_control=ready_valid, metadata="""""") top proc no_output_channels(__token: token, init={}) { - recv0: (token, bits[12]) = receive(__token, channel_id=0, id=4) + recv0: (token, bits[12]) = receive(__token, channel=in0, id=4) recv0_token: token = tuple_index(recv0, index=0, id=11, pos=[(0,15,22)]) - recv1: (token, bits[42], bits[1]) = receive(recv0_token, channel_id=1, blocking=false, id=36) + recv1: (token, bits[42], bits[1]) = receive(recv0_token, channel=in1, blocking=false, id=36) recv1_token: token = tuple_index(recv1, index=0, id=37) after_all_token: token = after_all(__token, recv0_token, recv1_token, id=45) next (after_all_token) diff --git a/xls/visualization/ir_viz/ir_to_json_test.cc b/xls/visualization/ir_viz/ir_to_json_test.cc index 7bdb973e10..8acfd492f7 100644 --- a/xls/visualization/ir_viz/ir_to_json_test.cc +++ b/xls/visualization/ir_viz/ir_to_json_test.cc @@ -154,12 +154,12 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, metadata="""""") top proc the_proc(tkn: token, x: bits[32], y: bits[64], init={0, 42}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0) + rcv: (token, bits[32]) = receive(tkn, channel=in) rcv_token: token = tuple_index(rcv, index=0) rcv_data: bits[32] = tuple_index(rcv, index=1) next_x: bits[32] = add(x, rcv_data) not_y: bits[64] = not(y) - send: token = send(rcv_token, next_x, channel_id=1) + send: token = send(rcv_token, next_x, channel=out) next (send, next_x, not_y) } )")); diff --git a/xls/visualization/ir_viz/testdata/ir_to_json_test_SimpleProc.htmltext b/xls/visualization/ir_viz/testdata/ir_to_json_test_SimpleProc.htmltext index d3f8c16c3f..431aa07399 100644 --- a/xls/visualization/ir_viz/testdata/ir_to_json_test_SimpleProc.htmltext +++ b/xls/visualization/ir_viz/testdata/ir_to_json_test_SimpleProc.htmltext @@ -4,11 +4,11 @@ chan in(bits[32], id=0, kind=streaming, ops=receive_only, flow_control=ready_val chan out(bits[32], id=1, kind=streaming, ops=send_only, flow_control=ready_valid, strictness=proven_mutually_exclusive, metadata="""""") top proc the_proc(tkn: token, x: bits[32], y: bits[64], init={0, 42}) { - rcv: (token, bits[32]) = receive(tkn, channel_id=0, id=4) + rcv: (token, bits[32]) = receive(tkn, channel=in, id=4) rcv_data: bits[32] = tuple_index(rcv, index=1, id=6) rcv_token: token = tuple_index(rcv, index=0, id=5) next_x: bits[32] = add(x, rcv_data, id=7) not_y: bits[64] = not(y, id=8) - send: token = send(rcv_token, next_x, channel_id=1, id=9) + send: token = send(rcv_token, next_x, channel=out, id=9) next (send, next_x, not_y) }