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
3 changes: 2 additions & 1 deletion xls/scheduling/pipeline_schedule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ bool PipelineSchedule::IsLiveOutOfCycle(Node* node, int64_t c) const {
}
if (user->Is<Next>()) {
Next* user_next = user->As<Next>();
if (user_next->predicate() != node && user_next->value() != node) {
if (user_next->predicate() != node && user_next->value() != node &&
user_next->has_state_read()) {
CHECK_EQ(user_next->state_read(), node);
// This Next node only uses this StateRead node to target the state
// register it needs to write to; it doesn't actually need the value
Expand Down
29 changes: 29 additions & 0 deletions xls/scheduling/pipeline_schedule_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,36 @@ TEST_F(PipelineScheduleTest,
EXPECT_EQ(schedule.cycle(next.node()), 1);
EXPECT_EQ(schedule.cycle(read_mutually_exclusive.node()), 2);
}
TEST_F(PipelineScheduleTest, DecoupledNextIsOutOfCycle) {
Package p(TestName());
ProcBuilder pb("the_proc", &p);
XLS_ASSERT_OK_AND_ASSIGN(StateElement * se,
pb.UnreadStateElement("state", Value(UBits(0, 32)),
/*non_synthesizable=*/false));
BValue read = pb.StateRead(se);
BValue next = pb.Next(se, read);
XLS_ASSERT_OK_AND_ASSIGN(Proc * proc, pb.Build());

// Run scheduler to get a valid base schedule first.
SchedulingOptions options;
options.clock_period_ps(1);
options.pipeline_stages(2);
XLS_ASSERT_OK_AND_ASSIGN(
PipelineSchedule schedule,
RunPipelineSchedule(proc, TestDelayEstimator(), options));

ScheduleCycleMap cycle_map = schedule.GetCycleMap();
cycle_map[read.node()] = 0;
cycle_map[next.node()] = 1;
XLS_ASSERT_OK_AND_ASSIGN(schedule, PipelineSchedule::Create(proc, cycle_map));
EXPECT_EQ(schedule.cycle(read.node()), 0);
EXPECT_EQ(schedule.cycle(next.node()), 1);
// Read is consumed by Next in cycle 1, so read IS live out of cycle 0
EXPECT_TRUE(schedule.IsLiveOutOfCycle(read.node(), 0));
// By cycle 1 (where Next is), read no longer requires a pipeline register
// and isn't live out of cycle 1.
EXPECT_FALSE(schedule.IsLiveOutOfCycle(read.node(), 1));
}
TEST_F(PipelineScheduleTest, ProcWriteBeforeReadFailsVerification) {
Package p(TestName());
ProcBuilder pb("the_proc", &p);
Expand Down
Loading