Skip to content
Draft
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
91 changes: 86 additions & 5 deletions docs_src/passes_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ value.

- [simplify-and-inline](#simplify-and-inline)
- [post-inlining](#post-inlining)
- [prepare-for-scheduling](#prepare-for-scheduling)



Expand Down Expand Up @@ -178,6 +179,39 @@ class CanonicalizationPass iterates over nodes and tries to canonicalize the exp



## canonicalize_proc_state - canonicalize proc state representation {#canonicalize_proc_state}


Bring proc-state representation to the canonical 'flat' representationother passes expect.


[Text-proto](http://github.com/google/xls/tree/main/xls/passes/optimization_pass_pipeline.txtpb)


### Options Set


Run to a fixedpoint.








### Invoked Passes


- [fixedpoint_proc_state_flattening](#fixedpoint_proc_state_flattening)
- [proc_state_bits_shatter](#proc_state_bits_shatter)
- [proc_state_tuple_flat](#proc_state_tuple_flat)
- [ident_remove](#ident_remove)
- [dataflow](#dataflow)
- [dce](#dce)



## channel_legalization - Legalize multiple send/recvs per channel {#channel_legalization}


Expand Down Expand Up @@ -772,6 +806,12 @@ Passes performed after inlining

- [fixedpoint_simp(2)](#fixedpoint_simp2)
- [cond_spec(noBdd)](#cond_specnoBdd)
- [canonicalize_proc_state](#canonicalize_proc_state)
- [non_synth_separation](#non_synth_separation)
- [dce](#dce)
- [next_value_opt](#next_value_opt)
- [dce](#dce)
- [fixedpoint_simp(2)](#fixedpoint_simp2)
- [dce](#dce)
- [bdd_simp(2)](#bdd_simp2)
- [dce](#dce)
Expand Down Expand Up @@ -799,13 +839,13 @@ Passes performed after inlining
- [channel_legalization](#channel_legalization)
- [token_dependency](#token_dependency)
- [fixedpoint_simp(2)](#fixedpoint_simp2)
- [fixedpoint_proc_state_flattening](#fixedpoint_proc_state_flattening)
- [proc_state_bits_shatter](#proc_state_bits_shatter)
- [proc_state_tuple_flat](#proc_state_tuple_flat)
- [ident_remove](#ident_remove)
- [dataflow](#dataflow)
- [canonicalize_proc_state](#canonicalize_proc_state)
- [non_synth_separation](#non_synth_separation)
- [dce](#dce)
- [next_value_opt](#next_value_opt)
- [dce](#dce)
- [fixedpoint_simp(2)](#fixedpoint_simp2)
- [dce](#dce)
- [proc_state_narrow](#proc_state_narrow)
- [dce](#dce)
- [proc_state_opt](#proc_state_opt)
Expand Down Expand Up @@ -899,6 +939,42 @@ Passes performed before each inlining.



## prepare-for-scheduling - Prepare for scheduling optimization passes {#prepare-for-scheduling}


Passes performed at the very end of optimization.

TODO(allight): We might want to move resource sharing into here fororganizational reasons.

TODO(allight): The duplication between this and [scheduling-opt](#scheduling-opt) is a massive code-smell. Significant adjustments to codegen/sched pass pipelines are likely required.


[Text-proto](http://github.com/google/xls/tree/main/xls/passes/optimization_pass_pipeline.txtpb)


### Options Set




Min opt level: 1






### Invoked Passes


- [full-inlining](#full-inlining)
- [dce](#dce)
- [dfe](#dfe)
- [fixedpoint_simp](#fixedpoint_simp)
- [dce](#dce)



## proc_state_array_flat - Proc State Array Flattening {#proc_state_array_flat}


Expand Down Expand Up @@ -1059,6 +1135,11 @@ Min opt level: 1

- [fixedpoint_simp](#fixedpoint_simp)
- [dce](#dce)
- [full-inlining](#full-inlining)
- [dce](#dce)
- [dfe](#dfe)
- [useless_assert_remove](#useless_assert_remove)
- [dce](#dce)



Expand Down
32 changes: 16 additions & 16 deletions xls/codegen/testdata/assertions_comb_multiple_ifdef_guards.svtxt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ module assertions_top(
input wire [31:0] y,
output wire [31:0] out
);
wire [30:0] add_195;
wire ult_202;
wire [30:0] add_209;
wire ult_206;
wire nand_211;
wire nand_212;
assign add_195 = y[31:1] + 31'h7fff_fffb;
assign ult_202 = y < 32'h0000_0014;
assign add_209 = y[31:1] + 31'h0000_000f;
assign ult_206 = y < 32'h0000_000a;
assign nand_211 = ~(y > 32'h0000_0009 & ult_202 & {add_195, y[0]} > 32'h0000_0004);
assign nand_212 = ~(ult_206 & y > 32'h0000_0004);
assign out = ult_206 ? {add_209, y[0]} : y & {32{ult_202}};
wire [30:0] add_270;
wire ult_277;
wire [30:0] add_284;
wire ult_281;
wire nand_286;
wire nand_287;
assign add_270 = y[31:1] + 31'h7fff_fffb;
assign ult_277 = y < 32'h0000_0014;
assign add_284 = y[31:1] + 31'h0000_000f;
assign ult_281 = y < 32'h0000_000a;
assign nand_286 = ~(y > 32'h0000_0009 & ult_277 & {add_270, y[0]} > 32'h0000_0004);
assign nand_287 = ~(ult_281 & y > 32'h0000_0004);
assign out = ult_281 ? {add_284, y[0]} : y & {32{ult_277}};
`ifdef ASSERT_ON
`ifndef SYNTHESIS
y_ge_than_21: assert final ($isunknown(ult_202) || ult_202) else $fatal(0, "Assertion failure via fail! @ xls/examples/assertions/assertions.x:32:14-32:37");
__assertions__main_0___itok__assertions__main___itok__assertions__main_0___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_211) || nand_211) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
__assertions__main_0___itok__assertions__main___itok__assertions__main_1___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_212) || nand_212) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main_y_ge_than_21: assert final ($isunknown(ult_277) || ult_277) else $fatal(0, "Assertion failure via fail! @ xls/examples/assertions/assertions.x:32:14-32:37");
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main___assertions__main_0___itok__assertions__main___itok__assertions__main_0___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_286) || nand_286) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main___assertions__main_0___itok__assertions__main___itok__assertions__main_1___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_287) || nand_287) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
`endif // SYNTHESIS
`endif // ASSERT_ON
endmodule
32 changes: 16 additions & 16 deletions xls/codegen/testdata/assertions_comb_no_ifdef_guards.svtxt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ module assertions_top(
input wire [31:0] y,
output wire [31:0] out
);
wire [30:0] add_195;
wire ult_202;
wire [30:0] add_209;
wire ult_206;
wire nand_211;
wire nand_212;
assign add_195 = y[31:1] + 31'h7fff_fffb;
assign ult_202 = y < 32'h0000_0014;
assign add_209 = y[31:1] + 31'h0000_000f;
assign ult_206 = y < 32'h0000_000a;
assign nand_211 = ~(y > 32'h0000_0009 & ult_202 & {add_195, y[0]} > 32'h0000_0004);
assign nand_212 = ~(ult_206 & y > 32'h0000_0004);
assign out = ult_206 ? {add_209, y[0]} : y & {32{ult_202}};
y_ge_than_21: assert final ($isunknown(ult_202) || ult_202) else $fatal(0, "Assertion failure via fail! @ xls/examples/assertions/assertions.x:32:14-32:37");
__assertions__main_0___itok__assertions__main___itok__assertions__main_0___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_211) || nand_211) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
__assertions__main_0___itok__assertions__main___itok__assertions__main_1___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_212) || nand_212) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
wire [30:0] add_270;
wire ult_277;
wire [30:0] add_284;
wire ult_281;
wire nand_286;
wire nand_287;
assign add_270 = y[31:1] + 31'h7fff_fffb;
assign ult_277 = y < 32'h0000_0014;
assign add_284 = y[31:1] + 31'h0000_000f;
assign ult_281 = y < 32'h0000_000a;
assign nand_286 = ~(y > 32'h0000_0009 & ult_277 & {add_270, y[0]} > 32'h0000_0004);
assign nand_287 = ~(ult_281 & y > 32'h0000_0004);
assign out = ult_281 ? {add_284, y[0]} : y & {32{ult_277}};
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main_y_ge_than_21: assert final ($isunknown(ult_277) || ult_277) else $fatal(0, "Assertion failure via fail! @ xls/examples/assertions/assertions.x:32:14-32:37");
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main___assertions__main_0___itok__assertions__main___itok__assertions__main_0___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_286) || nand_286) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
__assertions__main_1_non_synth___assertions__main_non_synth___assertions__main_0_non_synth_non_synth___assertions__main___assertions__main_0___itok__assertions__main___itok__assertions__main_1___itok__assertions__func_0__32_x_less_than_5: assert final ($isunknown(nand_287) || nand_287) else $fatal(0, "Assertion failure via assert! @ xls/examples/assertions/assertions.x:21:12-21:40");
endmodule
2 changes: 2 additions & 0 deletions xls/dslx/run_routines/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ cc_library(
"//xls/ir:value_utils",
"//xls/passes",
"//xls/passes:dce_pass",
"//xls/passes:dfe_pass",
"//xls/passes:inlining_pass",
"//xls/passes:optimization_pass",
"//xls/passes:optimization_pass_pipeline",
"//xls/passes:pass_base",
Expand Down
8 changes: 7 additions & 1 deletion xls/dslx/run_routines/run_routines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
#include "xls/ir/value.h"
#include "xls/ir/value_utils.h"
#include "xls/passes/dce_pass.h"
#include "xls/passes/dfe_pass.h"
#include "xls/passes/inlining_pass.h"
#include "xls/passes/optimization_pass.h"
#include "xls/passes/optimization_pass_pipeline.h"
#include "xls/passes/pass_base.h"
Expand Down Expand Up @@ -805,9 +807,13 @@ absl::StatusOr<ParseAndProveResult> ParseAndProve(
// non-inlined function calls.
auto pipeline = CreateOptimizationPassPipeline();

// By the time this pass executes only the single top function is left.
// By the time this pass executes only the single top function is left (and
// non-synth function).
// Strip any remaining asserts from it and 'and' them to the quickcheck
// goal.
pipeline->Add<InliningPass>();
pipeline->Add<DeadFunctionEliminationPass>();
pipeline->Add<DeadCodeEliminationPass>();
pipeline->Add<QuickCheckProveAssertsNotFiredPass>();
pipeline->Add<DeadCodeEliminationPass>();
PassResults results;
Expand Down
1 change: 1 addition & 0 deletions xls/flows/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cc_test(
"//xls/common:xls_gunit_main",
"//xls/common/logging:log_lines",
"//xls/common/status:matchers",
"//xls/dev_tools:remove_identifiers",
"//xls/dslx:create_import_data",
"//xls/dslx:default_dslx_stdlib_path",
"//xls/dslx:import_data",
Expand Down
35 changes: 28 additions & 7 deletions xls/flows/ir_wrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "xls/common/golden_files.h"
#include "xls/common/logging/log_lines.h"
#include "xls/common/status/matchers.h"
#include "xls/dev_tools/remove_identifiers.h"
#include "xls/dslx/create_import_data.h"
#include "xls/dslx/default_dslx_stdlib_path.h"
#include "xls/dslx/frontend/module.h"
Expand All @@ -50,19 +51,39 @@
namespace xls {
namespace {

void ExpectVersionSpecificIr(std::string_view got, std::string_view test_name,
void ExpectVersionSpecificIr(Package* got, std::string_view test_name,
bool proc_scoped_channels) {
std::string test_name_without_param(test_name);
RE2::GlobalReplace(&test_name_without_param, R"(/\d)", "");
// Remove id numbers which can be very sensitive to minor pass pipeline
// changes
LOG(ERROR) << got->DumpIr();
XLS_ASSERT_OK_AND_ASSIGN(
auto strip_pkg,
StripPackage(got,
StripOptions{.new_package_name = test_name_without_param,
.strip_location_info = false,
.strip_node_names = true,
.strip_function_names = false,
.strip_chan_names = false,
.strip_reg_names = false}));
ExpectEqualToGoldenFile(
absl::StrFormat("xls/flows/testdata/ir_wrapper_test_%s%s.ir",
test_name_without_param,
proc_scoped_channels ? "PSC" : ""),
got);
strip_pkg->DumpIr());
}

void ExpectIr(std::string_view got, std::string_view test_name) {
ExpectVersionSpecificIr(got, test_name, false);
void ExpectIrStr(std::string_view got, std::string_view test_name) {
std::string test_name_without_param(test_name);
RE2::GlobalReplace(&test_name_without_param, R"(/\d)", "");
ExpectEqualToGoldenFile(
absl::StrFormat("xls/flows/testdata/ir_wrapper_test_%s.ir",
test_name_without_param),
got);
}
void ExpectIr(Package* p, std::string_view test_name) {
ExpectVersionSpecificIr(p, test_name, false);
}

std::string TestName() {
Expand Down Expand Up @@ -128,10 +149,10 @@ pub fn GetLatency() -> s64 {
ir_wrapper.GetIrFunction("GetLatency"));

XLS_VLOG_LINES(3, get_latency->DumpIr());
ExpectIr(get_latency->DumpIr(), TestName() + "_get_latency");
ExpectIrStr(get_latency->DumpIr(), TestName() + "_get_latency");

XLS_ASSERT_OK_AND_ASSIGN(Package * package, ir_wrapper.GetIrPackage());
ExpectIr(package->DumpIr(), TestName() + "_package");
ExpectIr(package, TestName() + "_package");

// Test that that the jit for the function can be retrieved and run.
XLS_ASSERT_OK_AND_ASSIGN(
Expand Down Expand Up @@ -186,7 +207,7 @@ TEST_P(IrWrapperTest, DslxProcsToIrOk) {
XLS_VLOG_LINES(3, top_proc->DumpIr());

XLS_ASSERT_OK_AND_ASSIGN(Package * package, ir_wrapper.GetIrPackage());
ExpectVersionSpecificIr(package->DumpIr(), TestName(), GetParam());
ExpectVersionSpecificIr(package, TestName(), GetParam());

// Test that that the jit for the proc can be retrieved and run.
XLS_ASSERT_OK_AND_ASSIGN(SerialProcRuntime * proc_runtime,
Expand Down
20 changes: 10 additions & 10 deletions xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOk.ir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test_package
package DslxProcsToIrOk

file_number 0 "top_module.x"

Expand All @@ -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)

proc __top__foo_0_next() {
tok: token = after_all(id=4)
receive.18: (token, bits[32]) = receive(tok, channel=test_package__in_0, id=18)
tok__1: token = tuple_index(receive.18, index=0, id=7, pos=[(0,12,13)])
receive.19: (token, bits[32]) = receive(tok__1, channel=test_package__in_1, id=19)
a: bits[32] = tuple_index(receive.18, index=1, id=8, pos=[(0,12,18)])
b: bits[32] = tuple_index(receive.19, index=1, id=12, pos=[(0,13,18)])
tok__2: token = tuple_index(receive.19, index=0, id=11, pos=[(0,13,13)])
add.13: bits[32] = add(a, b, id=13, pos=[(0,14,36)])
tok__3: token = send(tok__2, add.13, channel=test_package__output, id=20)
after_all.1: token = after_all(id=1)
receive.2: (token, bits[32]) = receive(after_all.1, channel=test_package__in_0, id=2)
tuple_index.3: token = tuple_index(receive.2, index=0, id=3, pos=[(0,12,13)])
receive.4: (token, bits[32]) = receive(tuple_index.3, channel=test_package__in_1, id=4)
tuple_index.5: bits[32] = tuple_index(receive.2, index=1, id=5, pos=[(0,12,18)])
tuple_index.6: bits[32] = tuple_index(receive.4, index=1, id=6, pos=[(0,13,18)])
tuple_index.7: token = tuple_index(receive.4, index=0, id=7, pos=[(0,13,13)])
add.8: bits[32] = add(tuple_index.5, tuple_index.6, id=8, pos=[(0,14,36)])
send.9: token = send(tuple_index.7, add.8, channel=test_package__output, id=9)
}
20 changes: 10 additions & 10 deletions xls/flows/testdata/ir_wrapper_test_DslxProcsToIrOkPSC.ir
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package test_package
package DslxProcsToIrOk

file_number 0 "top_module.x"

top proc __top__foo_0_next<in_0: bits[32] in, in_1: bits[32] in, output: bits[32] out>() {
chan_interface in_0(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
chan_interface in_1(direction=receive, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
chan_interface output(direction=send, kind=streaming, strictness=proven_mutually_exclusive, flow_control=ready_valid, flop_kind=none)
tok: token = after_all(id=5)
receive.19: (token, bits[32]) = receive(tok, channel=in_0, id=19)
tok__1: token = tuple_index(receive.19, index=0, id=8, pos=[(0,12,13)])
receive.20: (token, bits[32]) = receive(tok__1, channel=in_1, id=20)
a: bits[32] = tuple_index(receive.19, index=1, id=9, pos=[(0,12,18)])
b: bits[32] = tuple_index(receive.20, index=1, id=13, pos=[(0,13,18)])
tok__2: token = tuple_index(receive.20, index=0, id=12, pos=[(0,13,13)])
add.14: bits[32] = add(a, b, id=14, pos=[(0,14,36)])
tok__3: token = send(tok__2, add.14, channel=output, id=21)
after_all.1: token = after_all(id=1)
receive.2: (token, bits[32]) = receive(after_all.1, channel=in_0, id=2)
tuple_index.3: token = tuple_index(receive.2, index=0, id=3, pos=[(0,12,13)])
receive.4: (token, bits[32]) = receive(tuple_index.3, channel=in_1, id=4)
tuple_index.5: bits[32] = tuple_index(receive.2, index=1, id=5, pos=[(0,12,18)])
tuple_index.6: bits[32] = tuple_index(receive.4, index=1, id=6, pos=[(0,13,18)])
tuple_index.7: token = tuple_index(receive.4, index=0, id=7, pos=[(0,13,13)])
add.8: bits[32] = add(tuple_index.5, tuple_index.6, id=8, pos=[(0,14,36)])
send.9: token = send(tuple_index.7, add.8, channel=output, id=9)
}
4 changes: 2 additions & 2 deletions xls/flows/testdata/ir_wrapper_test_DslxToIrOk_package.ir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test_package
package DslxToIrOk_package

file_number 0 "top_module.x"

fn __top__GetLatency() -> bits[64] {
ret params_latency: bits[64] = literal(value=7, id=3, pos=[(0,2,17)])
ret literal.1: bits[64] = literal(value=7, id=1, pos=[(0,2,17)])
}
Loading
Loading