An overview of the TurboFan compiler
Google Proprietary
Overview
What is TurboFan?
Why a portable assembler?
Google Proprietary
The TurboFan architecture / entry points
Google Proprietary
Backend
Intel, ARM, MIPS,
PowerPC, etc. code
Code
Assembler
CodeStub
Assembler
Scheduler
Schedule
Machine
Graph
Wasm
Compiler
Optimizer
Simplified
Graph
JavaScript
Graphs
Inliner &
Lowerings
Bytecode
GraphBuilder
Ast
GraphBuilder
TurboFan as a portable assembler
Google Proprietary
Motivation
Traditionally V8 contains a lot of hand-written native code:
Native code on the web efforts:
Google Proprietary
Goals
Google Proprietary
CodeAssembler vs. CodeStubAssembler
Google Proprietary
Benefits
Google Proprietary
TurboFan as JavaScript compiler
Google Proprietary
Motivation
Crankshaft served us well, but has various shortcomings:
Google Proprietary
Goals
Google Proprietary
V8 compilation overview
Google Proprietary
Source code
Parser
AST
FullCode
Generator
Intel, ARM, MIPS,
PowerPC, etc. code
Bytecode
Generator
Bytecode
TurboFan
Crankshaft
TurboFan pipeline (high-level)
Google Proprietary
Ast
GraphBuilder
AST
Typer
Intel, ARM, MIPS,
PowerPC, etc. code
Typed Optimization
Bytecode
Inlining &
Native Context Specialization
Bytecode
GraphBuilder
JavaScript Graph
Inlinee JavaScript
Graphs
Load/Store/CallIC feedback
Simplified Graph
Type feedback
Simplified Graph
Static type information
General
Optimization
Schedule
(CFG)
Code
Generation
Graph Building
Google Proprietary
Native Context Specialization & Inlining
Google Proprietary
Typer & Typed Optimization
Google Proprietary
General Optimizations
Google Proprietary
General Optimizations
Google Proprietary
Code Generation
Google Proprietary
Code generation example
Generate code for add
function add(x, y) { return x + y; }
Run with --turbo --ignition-staging
add(1,2);�add(2,3);�%OptimizeFunctionOnNextCall(add);�add(3,4);
Almost optimal code sequence already (Smi representation missing)
Google Proprietary
Code generation example
-- B0 start (construct frame) --�0x3caafc104060 0 55 push rbp�0x3caafc104061 1 4889e5 REX.W movq rbp,rsp�0x3caafc104064 4 56 push rsi�0x3caafc104065 5 57 push rdi�0x3caafc104066 6 493ba5600c0000 REX.W cmpq rsp,[r13+0xc60]�0x3caafc10406d 13 0f863d000000 jna 80 (0x3caafc1040b0)� -- B2 start --� -- B3 start (deconstruct frame) --�0x3caafc104073 19 488b4518 REX.W movq rax,[rbp+0x18]�0x3caafc104077 23 a801 test al,0x1�0x3caafc104079 25 0f8548000000 jnz 103 (0x3caafc1040c7)�0x3caafc10407f 31 488b5d10 REX.W movq rbx,[rbp+0x10]�0x3caafc104083 35 f6c301 testb rbx,0x1�0x3caafc104086 38 0f8540000000 jnz 108 (0x3caafc1040cc)�0x3caafc10408c 44 488bd3 REX.W movq rdx,rbx�0x3caafc10408f 47 48c1ea20 REX.W shrq rdx, 32�0x3caafc104093 51 488bc8 REX.W movq rcx,rax�0x3caafc104096 54 48c1e920 REX.W shrq rcx, 32�0x3caafc10409a 58 03d1 addl rdx,rcx�0x3caafc10409c 60 0f802f000000 jo 113 (0x3caafc1040d1)�0x3caafc1040a2 66 48c1e220 REX.W shlq rdx, 32�0x3caafc1040a6 70 488bc2 REX.W movq rax,rdx�0x3caafc1040a9 73 488be5 REX.W movq rsp,rbp�0x3caafc1040ac 76 5d pop rbp�0x3caafc1040ad 77 c21800 ret 0x18� -- B4 start (no frame) --� -- B1 start (deferred) --
0x3caafc1040b0 80 48bbd012abb3397f0000 REX.W movq rbx,0x7f39b3ab12d0�0x3caafc1040ba 90 33c0 xorl rax,rax�0x3caafc1040bc 92 488b75f8 REX.W movq rsi,[rbp-0x8]� -- real.js:229:12 --�0x3caafc1040c0 96 e87b02f0ff call 0x3caafc004340 ;; code: STUB�0x3caafc1040c5 101 ebac jmp 19 (0x3caafc104073)�0x3caafc1040c7 103 e834ffd7ff call 0x3caafbe84000 ;; deoptimization bailout 0�0x3caafc1040cc 108 e839ffd7ff call 0x3caafbe8400a ;; deoptimization bailout 1�0x3caafc1040d1 113 e83effd7ff call 0x3caafbe84014 ;; deoptimization bailout 2�0x3caafc1040d6 118 90 nop�0x3caafc1040d7 119 90 nop�0x3caafc1040d8 120 90 nop�0x3caafc1040d9 121 90 nop�0x3caafc1040da 122 90 nop�0x3caafc1040db 123 90 nop�0x3caafc1040dc 124 90 nop�0x3caafc1040dd 125 90 nop�0x3caafc1040de 126 90 nop�0x3caafc1040df 127 90 nop�0x3caafc1040e0 128 90 nop�0x3caafc1040e1 129 90 nop�0x3caafc1040e2 130 90 nop�0x3caafc1040e3 131 90 nop� ;;; Safepoint table.
Google Proprietary
Where do we stand?
Google Proprietary
Peak-performance benchmarks
Google Proprietary
What’s coming?
Google Proprietary
Future
Google Proprietary
Upcoming talks
Google Proprietary
Questions?
Google Proprietary