Skip to content

Properly set flow control when adding channels to procs in the IR. #2256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package test_module
file_number 0 "test_module.x"

top proc __test_module__passthrough_0_next<test_module__c_in: bits[32] in, test_module__c_out: bits[32] out>(__state: (), init={()}) {
chan_interface test_module__c_in(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
chan_interface test_module__c_out(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=none, flop_kind=none)
chan_interface test_module__c_in(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
chan_interface test_module__c_out(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
after_all.4: token = after_all(id=4)
literal.3: bits[1] = literal(value=1, id=3)
receive.5: (token, bits[32]) = receive(after_all.4, predicate=literal.3, channel=test_module__c_in, id=5)
Expand Down
13 changes: 8 additions & 5 deletions xls/ir/proc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -734,33 +734,36 @@ absl::StatusOr<ChannelInterface*> Proc::AddChannelInterface(

absl::StatusOr<ReceiveChannelInterface*> Proc::AddInputChannel(
std::string_view name, Type* type, ChannelKind kind,
std::optional<ChannelStrictness> strictness) {
FlowControl flow_control, std::optional<ChannelStrictness> strictness) {
XLS_ASSIGN_OR_RETURN(
ReceiveChannelInterface * interface,
AddInputChannelInterface(
std::make_unique<ReceiveChannelInterface>(name, type, kind)));
interface->SetStrictness(strictness);
interface->SetFlowControl(flow_control);
return interface;
}

absl::StatusOr<SendChannelInterface*> Proc::AddOutputChannel(
std::string_view name, Type* type, ChannelKind kind,
std::optional<ChannelStrictness> strictness) {
FlowControl flow_control, std::optional<ChannelStrictness> strictness) {
XLS_ASSIGN_OR_RETURN(
SendChannelInterface * interface,
AddOutputChannelInterface(
std::make_unique<SendChannelInterface>(name, type, kind)));
interface->SetStrictness(strictness);
interface->SetFlowControl(flow_control);
return interface;
}

absl::StatusOr<ChannelInterface*> Proc::AddInterfaceChannel(
std::string_view name, ChannelDirection direction, Type* type,
ChannelKind kind, std::optional<ChannelStrictness> strictness) {
ChannelKind kind, FlowControl flow_control,
std::optional<ChannelStrictness> strictness) {
if (direction == ChannelDirection::kSend) {
return AddOutputChannel(name, type, kind, strictness);
return AddOutputChannel(name, type, kind, flow_control, strictness);
}
return AddInputChannel(name, type, kind, strictness);
return AddInputChannel(name, type, kind, flow_control, strictness);
}

absl::Status Proc::RemoveChannelInterface(ChannelInterface* channel_interface) {
Expand Down
4 changes: 3 additions & 1 deletion xls/ir/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ class Proc : public FunctionBase {
// Add input/output channels to the interface of the proc.
absl::StatusOr<ReceiveChannelInterface*> AddInputChannel(
std::string_view name, Type* type, ChannelKind kind,
FlowControl flow_control,
std::optional<ChannelStrictness> strictness = std::nullopt);
absl::StatusOr<SendChannelInterface*> AddOutputChannel(
std::string_view name, Type* type, ChannelKind kind,
FlowControl flow_control,
std::optional<ChannelStrictness> strictness = std::nullopt);
absl::StatusOr<ChannelInterface*> AddInterfaceChannel(
std::string_view name, ChannelDirection direction, Type* type,
ChannelKind kind,
ChannelKind kind, FlowControl flow_control,
std::optional<ChannelStrictness> strictness = std::nullopt);

// Remove a channel from the interface of the proc. ChannelInterfaceslater
Expand Down
6 changes: 4 additions & 2 deletions xls/ir/proc_conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,22 @@ absl::Status DeclareChannelInProc(Proc* proc, Channel* channel) {
absl::Status AddInterfaceChannel(Proc* proc, Channel* channel,
ChannelDirection direction) {
std::optional<ChannelStrictness> strictness;
FlowControl flow_control = FlowControl::kNone;
if (StreamingChannel* streaming_channel =
dynamic_cast<StreamingChannel*>(channel)) {
strictness = streaming_channel->GetStrictness();
flow_control = streaming_channel->GetFlowControl();
}
std::unique_ptr<ChannelInterface> channel_interface;
if (direction == ChannelDirection::kSend) {
return proc
->AddOutputChannel(channel->name(), channel->type(), channel->kind(),
strictness)
flow_control, strictness)
.status();
}
return proc
->AddInputChannel(channel->name(), channel->type(), channel->kind(),
strictness)
flow_control, strictness)
.status();
}

Expand Down
8 changes: 4 additions & 4 deletions xls/passes/ram_rewrite_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ absl::StatusOr<RamChannel> CreateRamChannel(
ChannelDirection direction = GetRamLogicalChannelDirection(logical_channel);
if (metadata.proc_scope.has_value()) {
XLS_RET_CHECK(p->ChannelsAreProcScoped());
XLS_ASSIGN_OR_RETURN(
ChannelInterface * channel_ref,
metadata.proc_scope.value()->AddInterfaceChannel(
name, direction, type, ChannelKind::kStreaming, strictness));
XLS_ASSIGN_OR_RETURN(ChannelInterface * channel_ref,
metadata.proc_scope.value()->AddInterfaceChannel(
name, direction, type, ChannelKind::kStreaming,
flow_control, strictness));

return RamChannel{
.logical_channel = logical_channel,
Expand Down
9 changes: 5 additions & 4 deletions xls/passes/ram_rewrite_pass_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,21 @@ class RamRewritePassTest : public IrTestBase {
Package* p, std::optional<Proc*> proc_scope) {
if (proc_scope.has_value()) {
return proc_scope.value()->AddOutputChannel(
name, type, ChannelKind::kStreaming, strictness);
name, type, ChannelKind::kStreaming, FlowControl::kReadyValid,
strictness);
}
return p->CreateStreamingChannel(
name, ChannelOps::kSendOnly, type, /*initial_values=*/{},
/*channel_config=*/{}, /*flow_control=*/FlowControl::kReadyValid,
/*strictness=*/strictness);
/*channel_config=*/{}, FlowControl::kReadyValid, strictness);
}

absl::StatusOr<ReceiveChannelRef> CreateInputFromRam(
std::string_view name, Type* type, ChannelStrictness strictness,
Package* p, std::optional<Proc*> proc_scope) {
if (proc_scope.has_value()) {
return proc_scope.value()->AddInputChannel(
name, type, ChannelKind::kStreaming, strictness);
name, type, ChannelKind::kStreaming, FlowControl::kReadyValid,
strictness);
}
return p->CreateStreamingChannel(
name, ChannelOps::kReceiveOnly, type, /*initial_values=*/{},
Expand Down