EliminateRedundantPhi.ts — react Source File
Architecture documentation for EliminateRedundantPhi.ts, a typescript file in the react codebase. 11 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR d9a8ed15_9e19_8782_09a4_5122ac3f1a64["EliminateRedundantPhi.ts"] e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> e96f281e_f381_272d_2359_3e6a091c9a1d e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> e51fd0d2_bb38_cc97_7763_efe37f300a47 18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 18a78965_f593_105b_e5e8_07001321c2ec 4a73a9b9_07eb_502f_14c1_2f045ba2666c["BlockId"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 4a73a9b9_07eb_502f_14c1_2f045ba2666c 9241c5c1_a9a7_17bc_e41c_e967225008dd["HIRFunction"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 9241c5c1_a9a7_17bc_e41c_e967225008dd bd003dbd_e691_524b_0cf4_50e080ffea94["Identifier"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> bd003dbd_e691_524b_0cf4_50e080ffea94 c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> c7aaa235_c19e_3530_31c2_911f38eed3e0 2f3caf55_cc64_415c_55dd_9771ba7dc210["visitors.ts"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 2f3caf55_cc64_415c_55dd_9771ba7dc210 10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 10043bf1_f7ee_9ed9_307a_fe3edfd02b09 ccace1c3_85b7_a05e_c2a5_7eff8b3422ed["eachInstructionOperand"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> ccace1c3_85b7_a05e_c2a5_7eff8b3422ed 41232a25_deb6_6e83_05a8_ae9f961656f7["eachTerminalOperand"] d9a8ed15_9e19_8782_09a4_5122ac3f1a64 --> 41232a25_deb6_6e83_05a8_ae9f961656f7 style d9a8ed15_9e19_8782_09a4_5122ac3f1a64 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 '../CompilerError';
import {
BlockId,
GeneratedSource,
HIRFunction,
Identifier,
Place,
} from '../HIR/HIR';
import {
eachInstructionLValue,
eachInstructionOperand,
eachTerminalOperand,
} from '../HIR/visitors';
const DEBUG = false;
/*
* Pass to eliminate redundant phi nodes:
* - all operands are the same identifier, ie `x2 = phi(x1, x1, x1)`.
* - all operands are the same identifier *or* the output of the phi, ie `x2 = phi(x1, x2, x1, x2)`.
*
* In both these cases, the phi is eliminated and all usages of the phi identifier
* are replaced with the other operand (ie in both cases above, all usages of `x2` are replaced with `x1` .
*
* The algorithm is inspired by that in https://pp.ipd.kit.edu/uploads/publikationen/braun13cc.pdf
* but modified to reduce passes over the CFG. We visit the blocks in reverse postorder. Each time a redundant
* phi is encountered we add a mapping (eg x2 -> x1) to a rewrite table. Subsequent instructions, terminals,
* and phis rewrite all their identifiers based on this table. The algorithm loops over the CFG repeatedly
* until there are no new rewrites: for a CFG without back-edges it completes in a single pass.
*/
export function eliminateRedundantPhi(
fn: HIRFunction,
sharedRewrites?: Map<Identifier, Identifier>,
): void {
const ir = fn.body;
const rewrites: Map<Identifier, Identifier> =
sharedRewrites != null ? sharedRewrites : new Map();
/*
* Whether or the CFG has a back-edge (a loop). We determine this dynamically
* during the first iteration over the CFG by recording which blocks were already
* visited, and checking if a block has any predecessors that weren't visited yet.
* Because blocks are in reverse postorder, the only time this can occur is a loop.
*/
let hasBackEdge = false;
const visited: Set<BlockId> = new Set();
/*
* size tracks the number of rewrites at the beginning of each iteration, so we can
* compare to see if any new rewrites were added in that iteration.
*/
let size = rewrites.size;
do {
// ... (118 more lines)
Domain
Subdomains
Functions
Dependencies
Source
Frequently Asked Questions
What does EliminateRedundantPhi.ts do?
EliminateRedundantPhi.ts is a source file in the react codebase, written in typescript. It belongs to the MIRInfrastructure domain, HIR subdomain.
What functions are defined in EliminateRedundantPhi.ts?
EliminateRedundantPhi.ts defines 2 function(s): eliminateRedundantPhi, rewritePlace.
What does EliminateRedundantPhi.ts depend on?
EliminateRedundantPhi.ts imports 11 module(s): BlockId, CompilerError, CompilerError.ts, HIR.ts, HIRFunction, Identifier, Place, eachInstructionLValue, and 3 more.
Where is EliminateRedundantPhi.ts in the architecture?
EliminateRedundantPhi.ts is located at compiler/packages/babel-plugin-react-compiler/src/SSA/EliminateRedundantPhi.ts (domain: MIRInfrastructure, subdomain: HIR, directory: compiler/packages/babel-plugin-react-compiler/src/SSA).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free