docs/compiler/turbofan/compiler-turbofan.md
TurboFan is V8's top-tier optimizing compiler. It is responsible for generating the most efficient machine code possible for hot functions, utilizing all available type information and aggressive optimization techniques.
TurboFan has historically used a "Sea of Nodes" Intermediate Representation (IR). V8 has transitioned to a new IR framework called Turboshaft, which is now enabled by default for JavaScript. The current pipeline often uses a hybrid approach, starting with Sea of Nodes and lowering to Turboshaft for later phases.
In the Sea of Nodes representation, there is no strict control flow graph (CFG) during the early and middle optimization phases. Instead:
Turboshaft is the next-generation IR for V8. It uses a more structured control flow graph with basic blocks and linear sequences of operations within blocks. This makes certain optimizations easier to implement and reason about compared to the Sea of Nodes.
The compilation process is managed by the Pipeline class (defined in src/compiler/pipeline.h) and turboshaft::Pipeline (defined in src/compiler/turboshaft/pipelines.h). It consists of several phases, often spanning both IRs:
TurboFan generates highly specialized code based on optimistic assumptions (e.g., assuming a specific hidden class). To ensure correctness, it inserts checks before specialized operations.
If a check fails at runtime (e.g., a function receives an object with a Map it hasn't seen before), the code cannot continue. TurboFan triggers a Deoptimization (Deopt).
FeedbackVector is updated to reflect the new reality, so that a future re-optimization can take it into account.These are design documents that are mostly concerned with TurboFan internals.
These are design documents that also affect TurboFan in a significant way.