Skip to content

Expand the resource sharing pass to include additions and subtractions. #2297

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
Jun 11, 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
7 changes: 7 additions & 0 deletions docs_src/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ purposes only.
re-using the same hardware resources (e.g., multiplier) for multiple
mutually-exclusive operations. This transformation might increase the
critical path latency. Defaults to `false`.
* `--force_resource_sharing=true|false`: Controls whether to use the heuristic
to decide when it is profitable to apply the resource sharing optimization.
When set to true, the resource sharing optimization applies the
transformation assuming it is always profitable. Finally, this option is
only used when the resource sharing pass is enabled. Defaults to `false`.
* `--area_model=MODEL`: Specify the area model to use during the IR
optimizations. Defaults to `asap7`.

## [`print_bom`](https://github.com/google/xls/tree/main/xls/tools/print_bom.cc)

Expand Down
4 changes: 4 additions & 0 deletions xls/build_rules/xls_ir_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def _optimize_ir(ctx, src, original_input_files):
"use_context_narrowing_analysis",
"optimize_for_best_case_throughput",
"enable_resource_sharing",
"force_resource_sharing",
"area_model",
"top",
)

Expand Down Expand Up @@ -469,6 +471,8 @@ def get_benchmark_ir_cmd(ctx, src, append_cmd_line_args = True):
"use_context_narrowing_analysis",
"optimize_for_best_case_throughput",
"enable_resource_sharing",
"force_resource_sharing",
"area_model",
"run_evaluators",
] + _CODEGEN_FLAGS + _SCHEDULING_FLAGS

Expand Down
2 changes: 2 additions & 0 deletions xls/build_rules/xls_macros.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ Examples:
"use_context_narrowing_analysis",
"optimize_for_best_case_throughput",
"enable_resource_sharing",
"force_resource_sharing",
"area_model",
)
opt_ir_args = {
k: v
Expand Down
8 changes: 8 additions & 0 deletions xls/dev_tools/benchmark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ ABSL_FLAG(
"but at the cost of constraining the schedule and thus increasing area.");
ABSL_FLAG(bool, enable_resource_sharing, false,
"Enable the resource sharing optimization to save area.");
ABSL_FLAG(
bool, force_resource_sharing, false,
"Force the resource sharing pass to apply the transformation where "
"it is legal to do so, overriding therefore the profitability "
"heuristic of such pass. This option is only used when the resource "
"sharing pass is enabled. This option should be used for testing only.");
ABSL_FLAG(std::string, area_model, "asap7",
"Area model to use for optimizations.");
ABSL_FLAG(bool, run_evaluators, true,
"Whether to run the JIT and interpreter.");
ABSL_FLAG(bool, compare_delay_to_synthesis, false,
Expand Down
5 changes: 5 additions & 0 deletions xls/passes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,13 @@ cc_library(
":pass_base",
":post_dominator_analysis",
":query_engine",
"//xls/common/status:ret_check",
"//xls/common/status:status_macros",
"//xls/estimators/area_model:area_estimator",
"//xls/estimators/area_model:area_estimators",
"//xls/ir",
"//xls/ir:bits",
"//xls/ir:function_builder",
"//xls/ir:op",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/container:flat_hash_map",
Expand Down Expand Up @@ -3946,6 +3950,7 @@ cc_test(
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/types:span",
"@cppitertools",
"@googletest//:gtest",
],
Expand Down
6 changes: 6 additions & 0 deletions xls/passes/optimization_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ struct OptimizationPassOptions : public PassOptionsBase {

// Enable resource sharing to reduce area
bool enable_resource_sharing = false;

// Force resource sharing to apply the transformation when is legal
bool force_resource_sharing = false;

// Area model to use
std::string area_model = "asap7";
};

class OptimizationContext {
Expand Down
Loading