Skip to content

Commit fdfa7a6

Browse files
committed
Add support in MergeConsecutiveBlocks
1 parent 0c37255 commit fdfa7a6

2 files changed

Lines changed: 7 additions & 49 deletions

File tree

compiler/packages/babel-plugin-react-compiler/src/HIR/MergeConsecutiveBlocks.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
6363
loc: null,
6464
suggestions: null,
6565
});
66-
if (predecessor.terminal.kind !== 'goto' || predecessor.kind !== 'block') {
66+
67+
const predecessorValueWithNoInstructions =
68+
predecessor.kind === 'value' && predecessor.instructions.length === 0;
69+
if (
70+
predecessor.terminal.kind !== 'goto' ||
71+
(predecessor.kind !== 'block' && !predecessorValueWithNoInstructions)
72+
) {
6773
/*
6874
* The predecessor is not guaranteed to transfer control to this block,
6975
* they aren't consecutive.

compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,13 @@ function applyConstantPropagation(
190190
}
191191

192192
const testValue = read(constants, branchBlock.terminal.test);
193-
194193
if (testValue !== null && testValue.kind === 'Primitive') {
195194
hasChanges = true;
196195
const targetBlockId = testValue.value
197196
? branchBlock.terminal.consequent
198197
: branchBlock.terminal.alternate;
199198

200-
// I think I can only set this if the block isn't
201-
// used in a value position by its predecessor
202-
// block.kind = 'block';
203-
204199
const chosenBlock = fn.body.blocks.get(targetBlockId);
205-
const otherBlock = fn.body.blocks.get(
206-
branchBlock.terminal.consequent === targetBlockId
207-
? branchBlock.terminal.alternate
208-
: branchBlock.terminal.consequent,
209-
);
210-
211200
if (chosenBlock?.terminal.kind === 'goto') {
212201
block.terminal = {
213202
kind: 'goto',
@@ -216,44 +205,7 @@ function applyConstantPropagation(
216205
id: terminal.id,
217206
loc: terminal.loc,
218207
};
219-
220-
// debugger;
221-
// console.log(chosenBlock.id, Array.from(chosenBlock.preds));
222-
// const allPredsAreBlockBlocks = Array.from(chosenBlock.preds).every(
223-
// predId => {
224-
// const predBlock = fn.body.blocks.get(predId);
225-
// return predBlock?.kind === 'block';
226-
// },
227-
// );
228-
229-
// console.log('allPredsAreBlockBlocks', allPredsAreBlockBlocks);
230-
231-
// chosenBlock.kind = 'block';
232-
// if (allPredsAreBlockBlocks) {
233-
// block.kind = 'block';
234-
// }
235208
}
236-
237-
// const fallthrough = fn.body.blocks.get(
238-
// branchBlock.terminal.fallthrough,
239-
// );
240-
241-
// if (fallthrough?.terminal.kind == 'goto') {
242-
// fallthrough.kind = 'block';
243-
// }
244-
245-
// const consequent = fn.body.blocks.get(
246-
// branchBlock.terminal.consequent,
247-
// )!;
248-
// const alternate = fn.body.blocks.get(branchBlock.terminal.alternate)!;
249-
250-
// if (consequent.terminal.kind === 'goto') {
251-
// consequent.kind = 'block';
252-
// }
253-
254-
// if (alternate.terminal.kind === 'goto') {
255-
// alternate.kind = 'block';
256-
// }
257209
}
258210

259211
break;

0 commit comments

Comments
 (0)