Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions native/llvm-codegen/src/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ std::optional<ProgramPartitions> partitionProgramText(StringRef Text,

// An internal function referenced by exactly one other function, and by
// no global, is a whole-program inlining candidate; keep it with that
// function so its partition can inline it without importing.
// function so its partition can inline it without importing. A function
// body larger than this is past LLVM's inline cost limit even for the only
// call to a local function, so it is placed by its own name. Otherwise a
// program's module initializers, which only the entry point calls, would
// all share the entry point's partition.
constexpr size_t MaxInlinedBodyBytes = 256 * 1024;
constexpr unsigned Shared = ~1u;
std::vector<unsigned> Referrer(Symbols.size(), NoPartition);
for (unsigned I = 0; I < Symbols.size(); ++I) {
Expand All @@ -441,7 +446,8 @@ std::optional<ProgramPartitions> partitionProgramText(StringRef Text,
for (unsigned Steps = 0; Steps < 1024; ++Steps) {
const Symbol &S = Symbols[Root];
unsigned Parent = Referrer[Root];
if (!S.Local || Parent == NoPartition || Parent == Shared ||
if (!S.Local || S.Body.size() > MaxInlinedBodyBytes ||
Parent == NoPartition || Parent == Shared ||
Symbols[Parent].Kind != SymbolKind::Function || Parent == I)
break;
Root = Parent;
Expand Down
4 changes: 2 additions & 2 deletions native/llvm-codegen/src/partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct ProgramPartitions {
// 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
// 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);
Expand Down
Loading