mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-31 07:23:06 +08:00
Optimized executables with at most 1 MiB of LLVM text were compiled as one module on one thread. With more than 128 KiB of LLVM text they now pass several outputs and `--split codegen` to the LLVM helper. The helper optimizes the module whole, as for a single output, then divides its functions in module order into runs of about the same instruction count and generates code for each run on its own thread. - The output count is 4 or 8 and depends only on the module's size (nativeCodegenParts), so artifacts never vary with the host. Node and native compiler builds pass the same outputs. - The helper writes the optimized module to bitcode once with its use-list order. Every output after the first parses it and turns the other outputs' definitions into declarations; the first output does the same to the optimized module in place. Each function's machine code matches a single-output build except for jumps to a definition that another output also uses. - Only local definitions that another output uses become hidden. Dead constant users are dropped before unused declarations are removed, so no output names a thread-local variable it does not use. - When one run would hold more than three quarters of the instructions, the first output is generated from the optimized module as for a single output and the others are empty objects. - Dev builds, partitioned builds and program-object validation are unchanged.