mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +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.
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace scriptc {
|
|
|
|
struct EmitOptions {
|
|
std::string Input;
|
|
// One output per program partition; several require object output.
|
|
std::vector<std::string> Outputs;
|
|
std::string FileType = "obj";
|
|
std::string Target;
|
|
std::string OptLevel = "2";
|
|
std::string RelocationModel = "pic";
|
|
std::string DiagnosticFormat = "json";
|
|
std::string SourcePath;
|
|
// Runtime bitcode whose small functions are imported available_externally.
|
|
std::vector<std::string> ImportBitcode;
|
|
// Private directory for reusable partition artifacts; empty disables reuse.
|
|
std::string CacheDirectory;
|
|
// Instruments the program for IR profiling. The instrumented executable
|
|
// writes raw profiles to this path pattern (LLVM_PROFILE_FILE overrides it
|
|
// at run time). Empty: no instrumentation.
|
|
std::string ProfileGenerate;
|
|
// Indexed profile (.profdata) that guides optimization. Empty: none.
|
|
std::string ProfileUse;
|
|
// With several outputs: optimize the module whole and divide only its code
|
|
// generation among the outputs.
|
|
bool SplitCodegen = false;
|
|
};
|
|
|
|
std::optional<EmitOptions> parseEmitOptions(int Argc, char **Argv);
|
|
int emit(const EmitOptions &Options);
|
|
|
|
} // namespace scriptc
|