Skip to content

Commit 34a2bec

Browse files
committed
[compiler] Instruction reordering
Adds a pass just after DCE to reorder safely reorderable instructions (jsx, primitives, globals) closer to where they are used, to allow other optimization passes to be more effective. Notably, the reordering allows scope merging to be more effective, since that pass relies on two scopes not having intervening instructions — in many cases we can now reorder such instructions out of the way and unlock merging, as demonstrated in the changed fixtures. The algorithm itself is described in the docblock. note: This is a cleaned up version of #29579 that is ready for review. ghstack-source-id: 447d764f4728d54b944f3a511859a17722da0fd2 Pull Request resolved: #29863
1 parent 2774208 commit 34a2bec

File tree

5 files changed

+406
-3
lines changed

5 files changed

+406
-3
lines changed

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
deadCodeElimination,
4242
pruneMaybeThrows,
4343
} from "../Optimization";
44+
import { instructionReordering } from "../Optimization/InstructionReordering";
4445
import {
4546
CodegenFunction,
4647
alignObjectMethodScopes,
@@ -71,6 +72,7 @@ import {
7172
import { alignMethodCallScopes } from "../ReactiveScopes/AlignMethodCallScopes";
7273
import { alignReactiveScopesToBlockScopesHIR } from "../ReactiveScopes/AlignReactiveScopesToBlockScopesHIR";
7374
import { pruneAlwaysInvalidatingScopes } from "../ReactiveScopes/PruneAlwaysInvalidatingScopes";
75+
import pruneInitializationDependencies from "../ReactiveScopes/PruneInitializationDependencies";
7476
import { stabilizeBlockIds } from "../ReactiveScopes/StabilizeBlockIds";
7577
import { eliminateRedundantPhi, enterSSA, leaveSSA } from "../SSA";
7678
import { inferTypes } from "../TypeInference";
@@ -91,7 +93,6 @@ import {
9193
validatePreservedManualMemoization,
9294
validateUseMemo,
9395
} from "../Validation";
94-
import pruneInitializationDependencies from "../ReactiveScopes/PruneInitializationDependencies";
9596

9697
export type CompilerPipelineValue =
9798
| { kind: "ast"; name: string; value: CodegenFunction }
@@ -202,6 +203,9 @@ function* runWithEnvironment(
202203
deadCodeElimination(hir);
203204
yield log({ kind: "hir", name: "DeadCodeElimination", value: hir });
204205

206+
instructionReordering(hir);
207+
yield log({ kind: "hir", name: "InstructionReordering", value: hir });
208+
205209
pruneMaybeThrows(hir);
206210
yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
207211

0 commit comments

Comments
 (0)