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
14 changes: 11 additions & 3 deletions xls/contrib/xlscc/continuations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,18 @@ OptimizationContext::GetSourcesSetTreeNodeInfoForFunction(

absl::StatusOr<bool> OptimizationContext::CheckNodeSourcesInSet(
xls::FunctionBase* in_function, xls::Node* node,
absl::flat_hash_set<const xls::Param*> sources_set) {
absl::flat_hash_set<const xls::Param*> sources_set,
bool allow_empty_sources_result) {
// Save lazy node analysis for each function for efficiency
XLS_ASSIGN_OR_RETURN(SourcesSetNodeInfo * info,
GetSourcesSetNodeInfoForFunction(in_function));

ParamSet param_sources = info->GetSingleInfoForNode(node);

// No param sources will return true
if (param_sources.empty()) {
return allow_empty_sources_result;
}

bool all_in_set = true;
for (const xls::Param* param : param_sources) {
CHECK_EQ(param->function_base(), in_function);
Expand Down Expand Up @@ -2090,10 +2094,14 @@ absl::Status Translator::MarkDirectIns(GeneratedFunction& func,
continue;
}

// Don't count things that don't actually use any direct-ins as direct-in,
// for example literals. Allow literal substitution pass to prevent these
// from being stored in state elements.
XLS_ASSIGN_OR_RETURN(
continuation_out.direct_in,
context.CheckNodeSourcesInSet(
slice.function, continuation_out.output_node, direct_in_sources));
slice.function, continuation_out.output_node, direct_in_sources,
/*allow_empty_sources_result=*/false));
}

first_slice = false;
Expand Down
3 changes: 3 additions & 0 deletions xls/contrib/xlscc/generate_fsm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ absl::Status NewFSMGenerator::LayoutValuesToSaveForNewFSMStates(
if (key.value->direct_in) {
continue;
}
if (key.value->literal.has_value()) {
continue;
}
state.values_to_save.insert(key.value);
}
}
Expand Down
3 changes: 2 additions & 1 deletion xls/contrib/xlscc/translator_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,8 @@ class OptimizationContext {

absl::StatusOr<bool> CheckNodeSourcesInSet(
xls::FunctionBase* in_function, xls::Node* node,
absl::flat_hash_set<const xls::Param*> sources_set);
absl::flat_hash_set<const xls::Param*> sources_set,
bool allow_empty_sources_result = true);

private:
absl::flat_hash_map<xls::FunctionBase*, std::unique_ptr<SourcesSetNodeInfo>>
Expand Down
23 changes: 10 additions & 13 deletions xls/contrib/xlscc/unit_tests/continuations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,9 @@ TEST_F(ContinuationsTest, PipelinedLoopBackwardsPropagation) {

EXPECT_EQ(SliceInputsDeclCount(third_slice, "i"), 2);
EXPECT_EQ(SliceInputsDeclCount(third_slice, "a"), 2);
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/true,
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/false,
/*is_feedback=*/false, /*func=*/func));
EXPECT_TRUE(SliceInputsDecl(third_slice, "i", /*direct_in=*/true,
EXPECT_TRUE(SliceInputsDecl(third_slice, "i", /*direct_in=*/false,
/*is_feedback=*/false, /*func=*/func));
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/false,
/*is_feedback=*/true, /*func=*/func));
Expand Down Expand Up @@ -1322,9 +1322,9 @@ TEST_F(ContinuationsTest, PipelinedLoopNothingOutside) {
++slice_it;
const xlscc::GeneratedFunctionSlice& third_slice = *slice_it;

EXPECT_TRUE(SliceOutputsDecl(first_slice, "a", /*direct_in*/ true));
EXPECT_TRUE(SliceOutputsDecl(first_slice, "i", /*direct_in*/ true));
EXPECT_TRUE(SliceOutputsDecl(first_slice, "c", /*direct_in*/ true));
EXPECT_TRUE(SliceOutputsDecl(first_slice, "a", /*direct_in*/ false));
EXPECT_TRUE(SliceOutputsDecl(first_slice, "i", /*direct_in*/ false));
EXPECT_TRUE(SliceOutputsDecl(first_slice, "c", /*direct_in*/ false));

EXPECT_FALSE(SliceInputsDecl(second_slice, "i"));
EXPECT_FALSE(SliceInputsDecl(second_slice, "a"));
Expand Down Expand Up @@ -2131,8 +2131,8 @@ TEST_F(ContinuationsTest, PipelinedLoopBackwardsPropagationInSubroutine) {
const xlscc::GeneratedFunctionSlice& fourth_slice = *slice_it;

EXPECT_TRUE(SliceOutputsDecl(second_slice, "ctrl"));
EXPECT_TRUE(SliceOutputsDecl(second_slice, "a", /*direct_in=*/true));
EXPECT_TRUE(SliceOutputsDecl(second_slice, "i", /*direct_in=*/true));
EXPECT_TRUE(SliceOutputsDecl(second_slice, "a", /*direct_in=*/false));
EXPECT_TRUE(SliceOutputsDecl(second_slice, "i", /*direct_in=*/false));

EXPECT_EQ(SliceInputsDeclCount(third_slice, "i"), 2);
EXPECT_EQ(SliceInputsDeclCount(third_slice, "a"), 2);
Expand Down Expand Up @@ -2420,15 +2420,12 @@ TEST_F(ContinuationsTest, ContinuationLiteralDecomposed) {
++slice_it;
const xlscc::GeneratedFunctionSlice& second_slice = *slice_it;

// TODO(seanhaskell): Calling literals direct-in is stopped them from being
// decomposed. This makes loops less efficient

EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/true,
EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/false,
/*is_feedback=*/false, /*func=*/func,
/*decl_index=*/-1));
/*decl_index=*/0));
EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/false,
/*is_feedback=*/true, /*func=*/func,
/*decl_index=*/-1));
/*decl_index=*/0));
}

TEST_F(ContinuationsTest, StaticThisDecomposed) {
Expand Down
Loading