Skip to content

Commit 7c5dcfe

Browse files
dplassgitcopybara-github
authored andcommitted
Update more tests in proc lowering block eval PSC test to work.
PiperOrigin-RevId: 866099089
1 parent 08c941a commit 7c5dcfe

File tree

2 files changed

+43
-50
lines changed

2 files changed

+43
-50
lines changed

xls/codegen_v_1_5/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ cc_test(
838838
"//xls/ir:ir_matcher",
839839
"//xls/ir:ir_test_base",
840840
"//xls/ir:op",
841+
"//xls/ir:proc_conversion",
841842
"//xls/ir:proc_elaboration",
842843
"//xls/ir:source_location",
843844
"//xls/ir:type",

xls/codegen_v_1_5/proc_lowering_block_eval_psc_test.cc

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "xls/ir/nodes.h"
7676
#include "xls/ir/op.h"
7777
#include "xls/ir/package.h"
78+
#include "xls/ir/proc_conversion.h"
7879
#include "xls/ir/proc_elaboration.h"
7980
#include "xls/ir/source_location.h"
8081
#include "xls/ir/type.h"
@@ -230,29 +231,33 @@ absl::StatusOr<bool> RunBlockStitchingPass(
230231
return changed;
231232
}
232233

233-
TEST_F(ProcLoweringBlockEvalTest, DISABLED_SingleBlockIsNoop) {
234+
TEST_F(ProcLoweringBlockEvalTest, SingleBlockIsNoop) {
234235
auto p = CreatePackage();
235236
Type* u32 = p->GetBitsType(32);
237+
ProcBuilder pb(NewStyleProc{}, TestName(), p.get());
236238
XLS_ASSERT_OK_AND_ASSIGN(
237-
StreamingChannel * ch0,
238-
p->CreateStreamingChannel("ch0", ChannelOps::kReceiveOnly, u32));
239+
ReceiveChannelInterface * ch0,
240+
pb.AddInputChannel("ch0", u32, ChannelKind::kStreaming, std::nullopt,
241+
std::nullopt));
239242
XLS_ASSERT_OK_AND_ASSIGN(
240-
StreamingChannel * ch1,
241-
p->CreateStreamingChannel("ch1", ChannelOps::kSendOnly, u32));
242-
ProcBuilder pb(TestName(), p.get());
243+
SendChannelInterface * ch1,
244+
pb.AddOutputChannel("ch1", u32, ChannelKind::kStreaming, std::nullopt,
245+
std::nullopt));
243246
BValue rcv = pb.Receive(ch0, pb.AfterAll({}));
244247
pb.Send(ch1, pb.TupleIndex(rcv, 0), pb.TupleIndex(rcv, 1));
245-
XLS_ASSERT_OK_AND_ASSIGN(Proc * proc, pb.Build());
246-
XLS_ASSERT_OK(p->SetTop(proc));
248+
XLS_ASSERT_OK(pb.SetAsTop());
249+
XLS_ASSERT_OK(pb.Build());
247250

251+
// Unlike GlobalChannelBlockStitchingPass, this will return true because it
252+
// will have lowered the proc instantiations and removed them from the IR.
248253
EXPECT_THAT(
249-
RunBlockStitchingPass(p.get(), /*top_name=*/"top_proc",
254+
RunBlockStitchingPass(p.get(), /*top_name=*/TestName(),
250255
/*scheduling_options=*/DefaultSchedulingOptions(),
251256
/*codegen_options=*/DefaultCodegenOptions()),
252-
IsOkAndHolds(false));
257+
IsOkAndHolds(true));
253258
}
254259

255-
TEST_F(ProcLoweringBlockEvalTest, DISABLED_StitchNetworkWithFifos) {
260+
TEST_F(ProcLoweringBlockEvalTest, StitchNetworkWithFifos) {
256261
auto p = CreatePackage();
257262
Type* u32 = p->GetBitsType(32);
258263
XLS_ASSERT_OK_AND_ASSIGN(
@@ -282,37 +287,22 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_StitchNetworkWithFifos) {
282287
XLS_ASSERT_OK(p->SetTop(proc0));
283288
std::string proc1_name = proc1->name();
284289

290+
XLS_ASSERT_OK(xls::ConvertPackageToNewStyleProcs(p.get()));
291+
285292
EXPECT_THAT(RunBlockStitchingPass(p.get()), IsOkAndHolds(true));
286293
EXPECT_THAT(p->blocks(),
287-
UnorderedElementsAre(m::Block("top_proc__1"),
288-
m::Block("top_proc"), m::Block(proc1_name)));
294+
UnorderedElementsAre(m::Block("top_proc"), m::Block(proc1_name)));
289295
EXPECT_THAT(
290296
p->GetBlock("top_proc").value()->GetInstantiations(),
291297
UnorderedElementsAre(
292-
m::Instantiation(proc1_name + "_inst0", InstantiationKind::kBlock),
293-
m::Instantiation("top_proc__1_inst1", InstantiationKind::kBlock),
298+
m::Instantiation(proc1_name + "_inst", InstantiationKind::kBlock),
294299
m::Instantiation(HasSubstr("fifo"), InstantiationKind::kFifo)));
295-
XLS_ASSERT_OK_AND_ASSIGN(
296-
xls::Instantiation * inst1,
297-
p->GetBlock("top_proc").value()->GetInstantiation("top_proc__1_inst1"));
298300
XLS_ASSERT_OK_AND_ASSIGN(
299301
xls::Instantiation * inst0,
300-
p->GetBlock("top_proc").value()->GetInstantiation(proc1_name + "_inst0"));
302+
p->GetBlock("top_proc").value()->GetInstantiation(proc1_name + "_inst"));
301303
EXPECT_THAT(
302304
p->GetBlock("top_proc").value()->nodes(),
303305
IsSupersetOf({
304-
m::InstantiationInput(m::InputPort("ch0_valid"), "ch0_valid",
305-
Eq(inst1)),
306-
m::InstantiationInput(m::InputPort("ch0_data"), "ch0_data",
307-
Eq(inst1)),
308-
m::InstantiationInput(
309-
m::InstantiationOutput(
310-
"push_ready", m::Instantiation(HasSubstr("fifo"),
311-
InstantiationKind::kFifo)),
312-
"ch1_ready", Eq(inst1)),
313-
m::InstantiationOutput("ch1_data", Eq(inst1)),
314-
m::InstantiationOutput("ch1_valid", Eq(inst1)),
315-
m::InstantiationOutput("ch0_ready", Eq(inst1)),
316306
m::InstantiationInput(
317307
m::InstantiationOutput(
318308
"pop_valid", m::Instantiation(HasSubstr("fifo"),
@@ -352,23 +342,23 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_StitchNetworkWithFifos) {
352342
EXPECT_THAT(top_block->GetReadyPortForChannel("ch2", ChannelDirection::kSend),
353343
IsOkAndHolds(Optional(m::InputPort("ch2_ready"))));
354344

355-
XLS_ASSERT_OK_AND_ASSIGN(Block * block0, p->GetBlock("top_proc__1"));
345+
XLS_ASSERT_OK_AND_ASSIGN(Block * block0, p->GetBlock("top_proc"));
356346
EXPECT_THAT(block0->GetChannelsWithMappedPorts(),
357347
UnorderedElementsAre(Pair("ch0", ChannelDirection::kReceive),
358-
Pair("ch1", ChannelDirection::kSend)));
348+
Pair("ch2", ChannelDirection::kSend)));
359349
EXPECT_THAT(block0->GetDataPortForChannel("ch0", ChannelDirection::kReceive),
360350
IsOkAndHolds(Optional(m::InputPort("ch0_data"))));
361351
EXPECT_THAT(block0->GetValidPortForChannel("ch0", ChannelDirection::kReceive),
362352
IsOkAndHolds(Optional(m::InputPort("ch0_valid"))));
363353
EXPECT_THAT(block0->GetReadyPortForChannel("ch0", ChannelDirection::kReceive),
364354
IsOkAndHolds(Optional(m::OutputPort("ch0_ready"))));
365355

366-
EXPECT_THAT(block0->GetDataPortForChannel("ch1", ChannelDirection::kSend),
367-
IsOkAndHolds(Optional(m::OutputPort("ch1_data"))));
368-
EXPECT_THAT(block0->GetValidPortForChannel("ch1", ChannelDirection::kSend),
369-
IsOkAndHolds(Optional(m::OutputPort("ch1_valid"))));
370-
EXPECT_THAT(block0->GetReadyPortForChannel("ch1", ChannelDirection::kSend),
371-
IsOkAndHolds(Optional(m::InputPort("ch1_ready"))));
356+
EXPECT_THAT(block0->GetDataPortForChannel("ch2", ChannelDirection::kSend),
357+
IsOkAndHolds(Optional(m::OutputPort("ch2_data"))));
358+
EXPECT_THAT(block0->GetValidPortForChannel("ch2", ChannelDirection::kSend),
359+
IsOkAndHolds(Optional(m::OutputPort("ch2_valid"))));
360+
EXPECT_THAT(block0->GetReadyPortForChannel("ch2", ChannelDirection::kSend),
361+
IsOkAndHolds(Optional(m::InputPort("ch2_ready"))));
372362

373363
XLS_ASSERT_OK_AND_ASSIGN(Block * block1, p->GetBlock(proc1_name));
374364
EXPECT_THAT(block1->GetChannelsWithMappedPorts(),
@@ -5074,7 +5064,7 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithGate) {
50745064
IsOkAndHolds(BlockOutputsEq({{"out", {0, 1, 2, 99, 100, 0, 0, 0}}})));
50755065
}
50765066

5077-
TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithTrace) {
5067+
TEST_F(ProcLoweringBlockEvalTest, ProcWithTrace) {
50785068
auto p = CreatePackage();
50795069
Type* u32 = p->GetBitsType(32);
50805070

@@ -5093,6 +5083,7 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithTrace) {
50935083
MakeDelayedLoopbackProc("loopback", 4, in, middle, p.get()).status());
50945084
{
50955085
ProcBuilder b("trace_not_zero", p.get());
5086+
XLS_ASSERT_OK(b.SetAsTop());
50965087
BValue recv = b.Receive(middle, b.Literal(Value::Token()));
50975088
BValue recv_token = b.TupleIndex(recv, 0);
50985089
BValue recv_data = b.TupleIndex(recv, 1);
@@ -5105,6 +5096,7 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithTrace) {
51055096
XLS_ASSERT_OK(b.Build());
51065097
}
51075098

5099+
XLS_ASSERT_OK(xls::ConvertPackageToNewStyleProcs(p.get()));
51085100
EXPECT_EQ(p->procs().size(), 2);
51095101
// Every number except for the zeros should appear in the trace output.
51105102
XLS_ASSERT_OK_AND_ASSIGN(
@@ -5119,10 +5111,10 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithTrace) {
51195111
HasSubstr("data: 300"), HasSubstr("data: 400"),
51205112
HasSubstr("data: 500")));
51215113

5122-
ASSERT_THAT(RunBlockStitchingPass(p.get(), /*top_name=*/"trace_nont_zero"),
5114+
ASSERT_THAT(RunBlockStitchingPass(p.get(), /*top_name=*/"trace_not_zero"),
51235115
IsOkAndHolds(true));
51245116

5125-
EXPECT_EQ(p->blocks().size(), 3);
5117+
EXPECT_EQ(p->blocks().size(), 2);
51265118

51275119
XLS_ASSERT_OK_AND_ASSIGN(Block * top_block, p->GetBlock("trace_not_zero"));
51285120
EXPECT_THAT(
@@ -5139,8 +5131,7 @@ TEST_F(ProcLoweringBlockEvalTest, DISABLED_ProcWithTrace) {
51395131
HasSubstr("data: 500")))))));
51405132
}
51415133

5142-
TEST_F(ProcLoweringBlockEvalTest,
5143-
DISABLED_ProcWithNonblockingReceivesWithPassthrough) {
5134+
TEST_F(ProcLoweringBlockEvalTest, ProcWithNonblockingReceivesWithPassthrough) {
51445135
// Constructs two procs:
51455136
// foo: a counter that counts down to zero and then receives on 'in',
51465137
// sending the value to 'internal' and counting down from that value.
@@ -5207,6 +5198,7 @@ proc output_passthrough(state:(), init={()}) {
52075198
ParsePackage(absl::Substitute(ir_text, fifo_depth, bypass,
52085199
register_push_outputs,
52095200
register_pop_outputs)));
5201+
XLS_ASSERT_OK(xls::ConvertPackageToNewStyleProcs(p.get()));
52105202
EXPECT_THAT(p->GetFunctionBases(),
52115203
UnorderedElementsAre(m::Proc("foo"),
52125204
m::Proc("output_passthrough")));
@@ -5221,7 +5213,7 @@ proc output_passthrough(state:(), init={()}) {
52215213
ASSERT_THAT(RunBlockStitchingPass(p.get(), /*top_name=*/"foo"),
52225214
IsOkAndHolds(true));
52235215
EXPECT_THAT(p->blocks(),
5224-
UnorderedElementsAre(m::Block("foo"), m::Block("foo__1"),
5216+
UnorderedElementsAre(m::Block("foo"),
52255217
m::Block("output_passthrough")));
52265218
XLS_ASSERT_OK_AND_ASSIGN(Block * top_block, p->GetBlock("foo"));
52275219
EXPECT_THAT(
@@ -5239,8 +5231,7 @@ proc output_passthrough(state:(), init={()}) {
52395231
}
52405232
}
52415233

5242-
TEST_F(ProcLoweringBlockEvalTest,
5243-
DISABLED_ProcWithConditionalNonblockingReceives) {
5234+
TEST_F(ProcLoweringBlockEvalTest, ProcWithConditionalNonblockingReceives) {
52445235
// Similar to ProcWithNonblockingReceivesWithPassthrough, except the
52455236
// passthrough proc has a state bit which alternates between 0 and 1. When the
52465237
// state is 0, it does not perform the non-blocking receive and instead sends
@@ -5289,6 +5280,7 @@ proc output_passthrough(state: bits[1], init={1}) {
52895280
std::unique_ptr<Package> p,
52905281
ParsePackage(absl::Substitute(ir_text, fifo_depth,
52915282
fifo_depth == 0 ? "true" : "false")));
5283+
XLS_ASSERT_OK(xls::ConvertPackageToNewStyleProcs(p.get()));
52925284
EXPECT_THAT(
52935285
p->GetFunctionBases(),
52945286
UnorderedElementsAre(m::Proc("foo"), m::Proc("output_passthrough")));
@@ -5310,9 +5302,9 @@ proc output_passthrough(state: bits[1], init={1}) {
53105302

53115303
ASSERT_THAT(RunBlockStitchingPass(p.get(), /*top_name=*/"foo"),
53125304
IsOkAndHolds(true));
5313-
EXPECT_THAT(p->blocks(),
5314-
UnorderedElementsAre(m::Block("foo"), m::Block("foo__1"),
5315-
m::Block("output_passthrough")));
5305+
EXPECT_THAT(
5306+
p->blocks(),
5307+
UnorderedElementsAre(m::Block("foo"), m::Block("output_passthrough")));
53165308

53175309
XLS_ASSERT_OK_AND_ASSIGN(Block * top_block, p->GetBlock("foo"));
53185310
// This test is latency sensitive, so the output can (and does) differ from

0 commit comments

Comments
 (0)