Skip to content
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
13 changes: 10 additions & 3 deletions xls/ir/nodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,16 @@ bool StateRead::IsDefinitelyEqualTo(const Node* other) const {

std::vector<Next*> StateRead::GetNextValues() const {
std::vector<Next*> next_values;
for (Node* user : users()) {
if (user->Is<Next>() && user->As<Next>()->state_read() == this) {
next_values.push_back(user->As<Next>());
if (function_base()->AsProcOrDie()->uses_decoupled_next()) {
const auto& next_values_se =
function_base()->AsProcOrDie()->next_values(state_element_);
next_values.insert(next_values.end(), next_values_se.begin(),
next_values_se.end());
} else {
for (Node* user : users()) {
if (user->Is<Next>() && user->As<Next>()->state_read() == this) {
next_values.push_back(user->As<Next>());
}
}
}
return next_values;
Expand Down
35 changes: 35 additions & 0 deletions xls/ir/proc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,41 @@ TEST_F(ProcTest, RemoveStateThatStillHasUse) {
HasSubstr("state read st has uses")));
}

TEST_F(ProcTest, GetNextStateReadDecoupled) {
auto p = CreatePackage();
TokenlessProcBuilder pb(TestName(), "tkn", p.get());
XLS_ASSERT_OK_AND_ASSIGN(StateElement * state_elem,
pb.UnreadStateElement("x", Value(UBits(42, 32)),
/*non_synthesizable=*/false));
BValue read = pb.StateRead(state_elem);
BValue next_val = pb.Add(read, pb.Literal(Value(UBits(1, 32))));
XLS_ASSERT_OK_AND_ASSIGN(Proc * proc, pb.Build({}));

StateRead* state_read = proc->GetStateReadByStateElement(state_elem);
EXPECT_EQ(state_read->GetNextValues().size(), 0);

XLS_ASSERT_OK(proc->MakeNodeWithName<Next>(SourceInfo(), state_elem,
next_val.node(),
/*predicate=*/std::nullopt,
/*label=*/std::nullopt, "x_next")
.status());
EXPECT_EQ(state_read->GetNextValues().size(), 1);

XLS_ASSERT_OK_AND_ASSIGN(
Literal * next_value,
proc->MakeNode<Literal>(SourceInfo(), Value(UBits(43, 32))));
XLS_ASSERT_OK(
proc->MakeNodeWithName<Next>(SourceInfo(), state_elem, next_value,
/*predicate=*/std::nullopt,
/*label=*/std::nullopt, "second_next")
.status());
EXPECT_EQ(state_read->GetNextValues().size(), 2);
EXPECT_THAT(state_read->GetNextValues(),
UnorderedElementsAre(
m::NextWithStateElement(state_elem, m::Add()),
m::NextWithStateElement(state_elem, m::Literal(43))));
}

TEST_F(ProcTest, InsertStateElementDecoupled) {
auto p = CreatePackage();
ProcBuilder pb("p", p.get());
Expand Down
Loading