8000 Start new FSM IR generation by copybara-service[bot] · Pull Request #2399 · google/xls · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Start new FSM IR generation #2399

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
Jul 1, 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
12 changes: 12 additions & 0 deletions xls/contrib/xlscc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ cc_library(
"//xls/ir",
"//xls/ir:bits",
"//xls/ir:function_builder",
"//xls/ir:op",
"//xls/ir:source_location",
"//xls/ir:type",
"//xls/ir:value",
Expand All @@ -154,6 +155,7 @@ cc_library(
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@llvm-project//clang:ast",
"@llvm-project//clang:basic",
Expand All @@ -169,12 +171,21 @@ cc_library(
"generate_fsm.h",
],
deps = [
":tracked_bvalue",
":translator_types",
":xlscc_logging",
"//xls/common:math_util",
"//xls/common/status:status_macros",
"//xls/ir",
"//xls/ir:bits",
"//xls/ir:function_builder",
"//xls/ir:source_location",
"//xls/ir:state_element",
"//xls/ir:value",
"//xls/ir:value_utils",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
Expand All @@ -199,6 +210,7 @@ cc_library(
],
deps = [
":cc_parser",
":generate_fsm",
":hls_block_cc_proto",
":metadata_output_cc_proto",
":node_manipulation",
Expand Down
35 changes: 26 additions & 9 deletions xls/contrib/xlscc/continuations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Translator::ConvertBValuesToContinuationOutputsForCurrentSlice(
absl::flat_hash_map<const TrackedBValue*, std::string>& name_found_for_bval,
absl::flat_hash_map<const TrackedBValue*, const clang::NamedDecl*>&
decls_by_bval_top_context,
const xls::SourceInfo& loc) {
int64_t* total_bvals_out, const xls::SourceInfo& loc) {
XLSCC_CHECK(!context().sf->slices.empty(), loc);
GeneratedFunctionSlice& current_slice = context().sf->slices.back();
std::vector<NATIVE_BVAL> ret_vals;
Expand All @@ -126,6 +126,8 @@ Translator::ConvertBValuesToContinuationOutputsForCurrentSlice(
TrackedBValue::Lock lock = std::move(std::get<0>(locked_bvalues));
std::vector<TrackedBValue*> bvalues = std::get<1>(locked_bvalues);

*total_bvals_out = bvalues.size();

std::vector<xls::Node*> tracked_nodes_in_order;
absl::flat_hash_map<xls::Node*, std::vector<TrackedBValue*>>
tracked_bvalues_by_node;
Expand Down Expand Up @@ -303,8 +305,12 @@ absl::Status Translator::AddContinuationsToNewSlice(
name_found_for_bval,
const absl::flat_hash_map<const TrackedBValue*, const clang::NamedDecl*>&
decls_by_bval_top_context,
const xls::SourceInfo& loc) {
int64_t total_bvals, const xls::SourceInfo& loc) {
// Create continuation inputs

absl::flat_hash_map<const ContinuationInput*, TrackedBValue*>
bvals_by_continuation_input;

for (ContinuationValue& continuation_out : last_slice.continuations_out) {
const std::vector<TrackedBValue*>& bvals =
bvalues_by_continuation_output.at(&continuation_out);
Expand All @@ -320,6 +326,8 @@ absl::Status Translator::AddContinuationsToNewSlice(
.name = name_found,
10000 .decls = continuation_out.decls});

bvals_by_continuation_input[&new_slice.continuations_in.back()] = bval;

if (decls_by_bval_top_context.contains(bval)) {
const clang::NamedDecl* top_context_decl =
decls_by_bval_top_context.at(bval);
Expand All @@ -332,11 +340,14 @@ absl::Status Translator::AddContinuationsToNewSlice(
}

// Each TrackedBValue gets its own input
XLSCC_CHECK(bvals_by_continuation_input.size() == total_bvals, loc);
XLSCC_CHECK_GE(new_slice.continuations_in.size(),
last_slice.continuations_out.size(), loc);
XLSCC_CHECK_EQ(last_slice.continuations_out.size(),
bvalues_by_continuation_output.size(), loc);

absl::flat_hash_set<TrackedBValue*> bvals_set;

// Update TrackedBValues
for (const ContinuationInput& continuation_in : new_slice.continuations_in) {
XLSCC_CHECK_NE(continuation_in.continuation_out, nullptr, loc);
Expand Down Expand Up @@ -366,14 +377,16 @@ absl::Status Translator::AddContinuationsToNewSlice(
}
XLSCC_CHECK(in_bval.valid(), loc);

const std::vector<TrackedBValue*>& bvals =
bvalues_by_continuation_output.at(continuation_in.continuation_out);
TrackedBValue* bval = bvals_by_continuation_input.at(&continuation_in);

for (TrackedBValue* bval : bvals) {
*bval = in_bval;
}
*bval = in_bval;

XLSCC_CHECK(!bvals_set.contains(bval), loc);
bvals_set.insert(bval);
}

XLSCC_CHECK(bvals_set.size() == total_bvals, loc);

return absl::OkStatus();
}

Expand Down Expand Up @@ -406,11 +419,14 @@ absl::Status Translator::NewContinuation(IOOp& op) {
absl::flat_hash_map<const TrackedBValue*, const clang::NamedDecl*>
decls_by_bval_top_context;

int64_t total_bvals = 0;

XLS_ASSIGN_OR_RETURN(
std::vector<NATIVE_BVAL> ret_vals,
ConvertBValuesToContinuationOutputsForCurrentSlice(
bvalues_by_continuation_output, continuation_outputs_by_bval,
name_found_for_bval, decls_by_bval_top_context, loc));
name_found_for_bval, decls_by_bval_top_context,
/*total_bvals_out=*/&total_bvals, loc));

// TODO(seanhaskell): Turn into a check when subroutine calls work with new
// FSM
Expand Down Expand Up @@ -456,7 +472,7 @@ absl::Status Translator::NewContinuation(IOOp& op) {
XLS_RETURN_IF_ERROR(AddContinuationsToNewSlice(
op, last_slice, new_slice, bvalues_by_continuation_output,
continuation_outputs_by_bval, name_found_for_bval,
decls_by_bval_top_context, loc));
decls_by_bval_top_context, total_bvals, loc));

return absl::OkStatus();
}
Expand Down Expand Up @@ -865,6 +881,7 @@ absl::Status RemoveDuplicateInputs(GeneratedFunction& func, bool& changed,
continue;
}
slice.continuations_in.erase(input_it);
changed = true;
}
}
}
Expand Down
Loading
0