InstructionReordering.ts — react Source File
Architecture documentation for InstructionReordering.ts, a typescript file in the react codebase. 11 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR dc3f5251_a95c_3c77_5550_3882c13a37c9["InstructionReordering.ts"] 0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 0423f759_97e0_9101_4634_ed555abc5ca9 6976a9ee_9d8e_4f16_3016_495f39aff2fd["PrintHIR.ts"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 6976a9ee_9d8e_4f16_3016_495f39aff2fd 1bdf9e01_ffb0_1422_a451_e62965a1969b["printInstruction"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 1bdf9e01_ffb0_1422_a451_e62965a1969b 2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 2f3caf55_cc64_415c_55dd_9771ba7dc210 10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 10043bf1_f7ee_9ed9_307a_fe3edfd02b09 21b1eb1e_eaf5_5238_3a24_f56eb8ef7278["eachInstructionValueLValue"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 21b1eb1e_eaf5_5238_3a24_f56eb8ef7278 b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> b2fc2985_a7ba_9865_c2a3_2a7531f27d44 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 41232a25_deb6_6e83_05a8_ae9f961656f7 eb9d33f9_42c1_205c_93e6_8e1365a31839["utils.ts"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> eb9d33f9_42c1_205c_93e6_8e1365a31839 4663af75_e270_25e3_3415_1230be609d66["getOrInsertWith"] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 4663af75_e270_25e3_3415_1230be609d66 2ed45bcd_6c82_3ccd_0e20_fa96b5111055[".."] dc3f5251_a95c_3c77_5550_3882c13a37c9 --> 2ed45bcd_6c82_3ccd_0e20_fa96b5111055 e3cfc07a_10c8_5dcd_e270_e8e14c29309b["Pipeline.ts"] e3cfc07a_10c8_5dcd_e270_e8e14c29309b --> dc3f5251_a95c_3c77_5550_3882c13a37c9 style dc3f5251_a95c_3c77_5550_3882c13a37c9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {CompilerError} from '..';
import {
BasicBlock,
Environment,
GeneratedSource,
HIRFunction,
IdentifierId,
Instruction,
InstructionId,
Place,
isExpressionBlockKind,
makeInstructionId,
markInstructionIds,
} from '../HIR';
import {printInstruction} from '../HIR/PrintHIR';
import {
eachInstructionLValue,
eachInstructionValueLValue,
eachInstructionValueOperand,
eachTerminalOperand,
} from '../HIR/visitors';
import {getOrInsertWith} from '../Utils/utils';
/**
* This pass implements conservative instruction reordering to move instructions closer to
* to where their produced values are consumed. The goal is to group instructions in a way that
* is more optimal for future optimizations. Notably, MergeReactiveScopesThatAlwaysInvalidateTogether
* can only merge two candidate scopes if there are no intervenining instructions that are used by
* some later code: instruction reordering can move those intervening instructions later in many cases,
* thereby allowing more scopes to merge together.
*
* The high-level approach is to build a dependency graph where nodes correspond either to
* instructions OR to a particular lvalue assignment of another instruction. So
* `Destructure [x, y] = z` creates 3 nodes: one for the instruction, and one each for x and y.
* The lvalue nodes depend on the instruction node that assigns them.
*
* Dependency edges are added for all the lvalues and rvalues of each instruction, so for example
* the node for `t$2 = CallExpression t$0 ( t$1 )` will take dependencies on the nodes for t$0 and t$1.
*
* Individual instructions are grouped into two categories:
* - "Reorderable" instructions include a safe set of instructions that we know are fine to reorder.
* This includes JSX elements/fragments/text, primitives, template literals, and globals.
* These instructions are never emitted until they are referenced, and can even be moved across
* basic blocks until they are used.
* - All other instructions are non-reorderable, and take an explicit dependency on the last such
* non-reorderable instruction in their block. This largely ensures that mutations are serialized,
* since all potentially mutating instructions are in this category.
*
* The only remaining mutation not handled by the above is variable reassignment. To ensure that all
* reads/writes of a variable access the correct version, all references (lvalues and rvalues) to
* each named variable are serialized. Thus `x = 1; y = x; x = 2; z = x` will establish a chain
* of dependencies and retain the correct ordering.
*
// ... (444 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does InstructionReordering.ts do?
InstructionReordering.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Optimization subdomain.
What functions are defined in InstructionReordering.ts?
InstructionReordering.ts defines 8 function(s): emit, findReferencedRangeOfTemporaries, getDepth, getReorderability, instructionReordering, print, printNode, reorderBlock.
What does InstructionReordering.ts depend on?
InstructionReordering.ts imports 11 module(s): .., PrintHIR.ts, eachInstructionLValue, eachInstructionValueLValue, eachInstructionValueOperand, eachTerminalOperand, getOrInsertWith, index.ts, and 3 more.
What files import InstructionReordering.ts?
InstructionReordering.ts is imported by 1 file(s): Pipeline.ts.
Where is InstructionReordering.ts in the architecture?
InstructionReordering.ts is located at compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts (domain: BabelCompiler, subdomain: Optimization, directory: compiler/packages/babel-plugin-react-compiler/src/Optimization).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free