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
12 changes: 4 additions & 8 deletions lib/JIT/BootstrapCompileSmokeM3Emit.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,14 @@ public static function emitRuntimeParseAndCompileDefault(
Value $code,
Value $filename
): Value {
$script = $context->builder->call(
self::runtimeSpine($context, 'parse', '__object__*', ['__object__*', '__string__*', '__string__*']),
// Emit-helper must compile inventory-scale sources (bin/compile.php, lib/Compiler.php) for M5;
// the old emit-smoke subset is only valid for trivial fixtures.
return $context->builder->call(
self::runtimeSpine($context, 'parseandcompile', '__object__*', ['__object__*', '__string__*', '__string__*']),
$runtimeThis,
$code,
$filename
);

return $context->builder->call(
self::runtimeSpine($context, 'compileemitsmoke', '__object__*', ['__object__*', '__object__*']),
$runtimeThis,
$script
);
}

/** Register native LLVM for Runtime::parseandcompile / parseandcompileemitsmoke (#2516). */
Expand Down
41 changes: 29 additions & 12 deletions lib/JIT/M3EmitTuTrivialEchoAot.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,45 @@ public static function emitParseAndCompileWithTrivialFallback(
return $defaultEmit($context, $runtimeThis, $code, $filename);
}
$objPtr = $context->getTypeFromString('__object__*');
$current = $defaultEmit($context, $runtimeThis, $code, $filename);
foreach (array_reverse($context->m3EmitTuLinktimeSidecarEntries) as $index => $entry) {
$entries = array_reverse($context->m3EmitTuLinktimeSidecarEntries);
$merge = BasicBlockHelper::append($context, 'm3te_pac_merge');
$defaultBb = BasicBlockHelper::append($context, 'm3te_pac_default');

/** @var list<array{Value,\PHPLLVM\BasicBlock}> $incoming */
$incoming = [];

// Avoid calling $defaultEmit eagerly: the trivial sources are common and $defaultEmit may
// exercise heavy compiler paths (and historically can trip LLVM 9 emit-TU runtime init).
foreach ($entries as $index => $entry) {
$tag = 'e'.(string) $index;
$cached = $context->builder->load($entry['sourceGlobal']);
$matches = JitStringCompare::identical($context, $code, $cached);
$fail = BasicBlockHelper::append($context, 'm3te_pac_prev_'.$tag);
$ok = BasicBlockHelper::append($context, 'm3te_pac_sidecar_'.$tag);
$merge = BasicBlockHelper::append($context, 'm3te_pac_done_'.$tag);
$fail = BasicBlockHelper::append($context, 'm3te_pac_next_'.$tag);
$context->builder->branchIf($matches, $ok, $fail);
$context->builder->positionAtEnd($fail);
$context->builder->branch($merge);

$context->builder->positionAtEnd($ok);
$sidecarBlock = $context->builder->call($context->functions[$entry['sentinelLc']]);
$context->builder->branch($merge);
$context->builder->positionAtEnd($merge);
$phi = $context->builder->phi($objPtr);
$phi->addIncoming($current, $fail);
$phi->addIncoming($sidecarBlock, $ok);
$current = $phi;
$incoming[] = [$sidecarBlock, $ok];

$context->builder->positionAtEnd($fail);
}

// No sidecar matched — fall back to the real parse+compile path.
$context->builder->branch($defaultBb);
$context->builder->positionAtEnd($defaultBb);
$default = $defaultEmit($context, $runtimeThis, $code, $filename);
$context->builder->branch($merge);
$incoming[] = [$default, $defaultBb];

$context->builder->positionAtEnd($merge);
$phi = $context->builder->phi($objPtr);
foreach ($incoming as [$val, $bb]) {
$phi->addIncoming($val, $bb);
}

return $current;
return $phi;
}

/** Runtime::standalone native for emit-helper SPINE — copy matched sidecar to outfile. */
Expand Down