mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-25 06:24:27 +08:00
Large executables were simplified and inlined as one module before the optimizer split them, so most of a release build ran on a single core, and any edit recompiled the whole program. The LLVM helper now divides the program before optimization. It splits the emitter's assembly text directly, so partitions also parse concurrently, and falls back to LLVM's module splitter for any input outside the emitter's grammar. Internal functions referenced by a single function stay with that function, and globals stay with their first user. Optimized partitions follow the ThinLTO model: each is simplified and summarized on its own thread, a thin link imports small functions across partitions for inlining and returns unexported hidden definitions to internal linkage, then each partition is optimized and compiled on its own thread. Unoptimized partitions compile independently, so dev builds of large programs are parallel too. A private per-helper cache directory stores simplified partitions under the hash of their source and objects under the hash of the module after importing, so a rebuild recompiles only the partitions an edit can affect. To keep unchanged partitions identical across edits, each partition numbers its metadata in first-use order, lists only the debug compile units it uses, and orders declarations by name, and interned string constants are named by their content rather than first-use order. Partition counts are powers of two that depend only on the module size, up to 64, so output stays the same on every host and functions keep their partition across ordinary edits. LLVM text that arrives in parts is written in large batches and handed to the helper in place instead of being written a second time.
32 lines
1.2 KiB
C++
32 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ADT/StringSet.h"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace scriptc {
|
|
|
|
// A program module divided into independently compilable textual modules.
|
|
struct ProgramPartitions {
|
|
// One complete LLVM assembly module per partition.
|
|
std::vector<std::string> Sources;
|
|
// Definitions that were not internal in the original module. Every other
|
|
// definition was internal and is promoted to hidden visibility only so the
|
|
// partitions can reference each other.
|
|
llvm::StringSet<> PublicSymbols;
|
|
};
|
|
|
|
// Divides the LLVM assembly scriptc emits into Count modules without parsing
|
|
// it, so the partitions can be parsed concurrently. Functions are placed by a
|
|
// stable hash of their name; an internal function referenced by exactly one
|
|
// other function stays with that function, and a global stays with the first
|
|
// function that references it. Returns nullopt for any construct outside the
|
|
// emitter's narrow top-level grammar; callers then split a parsed module.
|
|
std::optional<ProgramPartitions> partitionProgramText(llvm::StringRef Text,
|
|
unsigned Count);
|
|
|
|
} // namespace scriptc
|