mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
The helper keeps an internal function that exactly one other function references in its referrer's partition, so the partition can inline it. A program's module initializers are each called only from the entry point, so all of them, with every single-use helper they call, shared the entry point's partition. In the three.js nodes fixture that partition held 1.1 million lines of LLVM IR, almost five times the average, and set the native build's longest compile. A function whose body is larger than 256 KiB of LLVM text is past LLVM's inline cost limit even for the only call to a local function, so it is now placed by the hash of its own name. Its own single-use callees still stay with it.
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 unless its body is too large to
|
|
// inline, 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
|