mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
LlEmitter's field list and constructor are where most concurrent edits to emitter.ts collide. A feature now defines its state in its own file with defineModuleState (emitter-state.ts) and reads it through the returned key, so it no longer edits the class. The loop optimizations' twelve fields and their per-function setup move to loop-state.ts; the emitted IR is unchanged. scripts/split holds the transforms used for the emitter and lowering splits, and rehome-split.mjs, which carries an open branch across a split.
35 lines
1.5 KiB
Plaintext
35 lines
1.5 KiB
Plaintext
/* The loop optimizations' per-function state: counted loops, dense array
|
|
* loops, byte windows and typed-array loop versioning, and the unaliased
|
|
* local arrays they rely on. */
|
|
import { findUnaliasedLocalArrays } from "../../ir/array-length-stability.js";
|
|
import type { IrFunction, IrStmt } from "../../ir/ir.js";
|
|
import { findInitializedByteLoopBindings } from "./byte-windows.js";
|
|
import type { DenseArrayLoop } from "./dense-array-loops.js";
|
|
import type { LlEmitter } from "./emitter.js";
|
|
|
|
/** Sets the loop state for `fn` at the start of its emission; `numericFn`
|
|
* is `fn` with its initializer bindings (emitFunction). */
|
|
export function beginFunctionLoops(
|
|
emitter: LlEmitter,
|
|
fn: IrFunction,
|
|
numericFn: IrFunction,
|
|
): void {
|
|
const loops = LOOPS.of(emitter);
|
|
loops.unaliasedArrays = findUnaliasedLocalArrays(fn);
|
|
loops.countedLoopsEnabled = emitter.debug === null && !fn.async && !fn.generator;
|
|
loops.byteWindowsEnabled = loops.countedLoopsEnabled;
|
|
loops.bytesLoopVersionsEnabled = loops.countedLoopsEnabled;
|
|
loops.bytesLoopEntries = null;
|
|
loops.bytesLoopFunction = fn;
|
|
loops.denseLoopsEnabled = loops.countedLoopsEnabled;
|
|
loops.denseLoop = null;
|
|
loops.denseLoopEntries =
|
|
loops.denseLoopsEnabled && numericFn.locals.some((l) => l.type.kind === "array")
|
|
? findInitializedByteLoopBindings(fn)
|
|
: new Map();
|
|
loops.byteWindowEntries =
|
|
loops.byteWindowsEnabled && numericFn.locals.some((l) => l.type.kind === "bytes")
|
|
? findInitializedByteLoopBindings(fn)
|
|
: new Map();
|
|
}
|