Skip to content

Commit a6c745c

Browse files
Sean Purser-Haskellcopybara-github
authored andcommitted
Do not mark literals as direct-in, as this can make loop feedbacks un-decomposable.
PiperOrigin-RevId: 862391373
1 parent df6a997 commit a6c745c

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

xls/contrib/xlscc/continuations.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,18 @@ OptimizationContext::GetSourcesSetTreeNodeInfoForFunction(
280280

281281
absl::StatusOr<bool> OptimizationContext::CheckNodeSourcesInSet(
282282
xls::FunctionBase* in_function, xls::Node* node,
283-
absl::flat_hash_set<const xls::Param*> sources_set) {
283+
absl::flat_hash_set<const xls::Param*> sources_set,
284+
bool allow_empty_sources_result) {
284285
// Save lazy node analysis for each function for efficiency
285286
XLS_ASSIGN_OR_RETURN(SourcesSetNodeInfo * info,
286287
GetSourcesSetNodeInfoForFunction(in_function));
287288

288289
ParamSet param_sources = info->GetSingleInfoForNode(node);
289290

290-
// No param sources will return true
291+
if (param_sources.empty()) {
292+
return allow_empty_sources_result;
293+
}
294+
291295
bool all_in_set = true;
292296
for (const xls::Param* param : param_sources) {
293297
CHECK_EQ(param->function_base(), in_function);
@@ -2090,10 +2094,14 @@ absl::Status Translator::MarkDirectIns(GeneratedFunction& func,
20902094
continue;
20912095
}
20922096

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

20992107
first_slice = false;

xls/contrib/xlscc/generate_fsm.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ absl::Status NewFSMGenerator::LayoutValuesToSaveForNewFSMStates(
539539
if (key.value->direct_in) {
540540
continue;
541541
}
542+
if (key.value->literal.has_value()) {
543+
continue;
544+
}
542545
state.values_to_save.insert(key.value);
543546
}
544547
}

xls/contrib/xlscc/translator_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,8 @@ class OptimizationContext {
13041304

13051305
absl::StatusOr<bool> CheckNodeSourcesInSet(
13061306
xls::FunctionBase* in_function, xls::Node* node,
1307-
absl::flat_hash_set<const xls::Param*> sources_set);
1307+
absl::flat_hash_set<const xls::Param*> sources_set,
1308+
bool allow_empty_sources_result = true);
13081309

13091310
private:
13101311
absl::flat_hash_map<xls::FunctionBase*, std::unique_ptr<SourcesSetNodeInfo>>

xls/contrib/xlscc/unit_tests/continuations_test.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,9 @@ TEST_F(ContinuationsTest, PipelinedLoopBackwardsPropagation) {
10601060

10611061
EXPECT_EQ(SliceInputsDeclCount(third_slice, "i"), 2);
10621062
EXPECT_EQ(SliceInputsDeclCount(third_slice, "a"), 2);
1063-
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/true,
1063+
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/false,
10641064
/*is_feedback=*/false, /*func=*/func));
1065-
EXPECT_TRUE(SliceInputsDecl(third_slice, "i", /*direct_in=*/true,
1065+
EXPECT_TRUE(SliceInputsDecl(third_slice, "i", /*direct_in=*/false,
10661066
/*is_feedback=*/false, /*func=*/func));
10671067
EXPECT_TRUE(SliceInputsDecl(third_slice, "a", /*direct_in=*/false,
10681068
/*is_feedback=*/true, /*func=*/func));
@@ -1322,9 +1322,9 @@ TEST_F(ContinuationsTest, PipelinedLoopNothingOutside) {
13221322
++slice_it;
13231323
const xlscc::GeneratedFunctionSlice& third_slice = *slice_it;
13241324

1325-
EXPECT_TRUE(SliceOutputsDecl(first_slice, "a", /*direct_in*/ true));
1326-
EXPECT_TRUE(SliceOutputsDecl(first_slice, "i", /*direct_in*/ true));
1327-
EXPECT_TRUE(SliceOutputsDecl(first_slice, "c", /*direct_in*/ true));
1325+
EXPECT_TRUE(SliceOutputsDecl(first_slice, "a", /*direct_in*/ false));
1326+
EXPECT_TRUE(SliceOutputsDecl(first_slice, "i", /*direct_in*/ false));
1327+
EXPECT_TRUE(SliceOutputsDecl(first_slice, "c", /*direct_in*/ false));
13281328

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

21332133
EXPECT_TRUE(SliceOutputsDecl(second_slice, "ctrl"));
2134-
EXPECT_TRUE(SliceOutputsDecl(second_slice, "a", /*direct_in=*/true));
2135-
EXPECT_TRUE(SliceOutputsDecl(second_slice, "i", /*direct_in=*/true));
2134+
EXPECT_TRUE(SliceOutputsDecl(second_slice, "a", /*direct_in=*/false));
2135+
EXPECT_TRUE(SliceOutputsDecl(second_slice, "i", /*direct_in=*/false));
21362136

21372137
EXPECT_EQ(SliceInputsDeclCount(third_slice, "i"), 2);
21382138
EXPECT_EQ(SliceInputsDeclCount(third_slice, "a"), 2);
@@ -2420,15 +2420,12 @@ TEST_F(ContinuationsTest, ContinuationLiteralDecomposed) {
24202420
++slice_it;
24212421
const xlscc::GeneratedFunctionSlice& second_slice = *slice_it;
24222422

2423-
// TODO(seanhaskell): Calling literals direct-in is stopped them from being
2424-
// decomposed. This makes loops less efficient
2425-
2426-
EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/true,
2423+
EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/false,
24272424
/*is_feedback=*/false, /*func=*/func,
2428-
/*decl_index=*/-1));
2425+
/*decl_index=*/0));
24292426
EXPECT_TRUE(SliceInputsDecl(second_slice, "x", /*direct_in=*/false,
24302427
/*is_feedback=*/true, /*func=*/func,
2431-
/*decl_index=*/-1));
2428+
/*decl_index=*/0));
24322429
}
24332430

24342431
TEST_F(ContinuationsTest, StaticThisDecomposed) {

0 commit comments

Comments
 (0)