Skip to content

php-in-php: JIT Refcount LLVM — shrink __ref__ zval refcount layer via VmValue PHP helpers (#1492) #9570

Description

@PurHur

Category

php-in-php | runtime

Problem

JIT/AOT still embed a large generated LLVM module for zval refcount/typeinfo manipulation: lib/JIT/Builtin/Refcount.php (~1.7k lines, from Refcount.pre) defines __ref__ structs and helpers (__ref__init, __ref__separate, disableRefcount, …) used across Type/String_.php, SpaceshipCompareJit, and string/object builtins.

This is compiler runtime semantics that should live in PHP (lib/VM/Variable.php, ext/standard/VmString.php, shared value lifecycle) with JIT lowering calling thin ABI trampolines — not a growing hand-maintained LLVM refcount IR graph.

North star #1492: shrink C/LLVM runtime; port behavior into PHP sources this repo owns.

php-src reference

  • Zend refcounting is in C (Zend/zend_types.h, zend_string.h) — reference only; port semantics to PHP VM value model, do not grow runtime/*.c.

Repro (scope probe)

wc -l lib/JIT/Builtin/Refcount.php lib/JIT/Builtin/Refcount.pre
rg '__ref__' lib/JIT/Builtin/ --count | sort -t: -k2 -nr | head

Today: widespread __ref__* LLVM types; no consolidated PHP VmRefcount helper for JIT callbacks.

Scope (this repo)

Area Work
Audit Map each Refcount.php symbol to VM PHP equivalent (COW, separate string, typeinfo)
PHP New lib/VM/VmRefcount.php or extend lib/VM/Variable.php with documented lifecycle API
JIT Replace inline LLVM refcount IR with calls to PHP-backed runtime helpers (pattern: #9515 PowInt, #9476 Spaceship)
Delete Shrink Refcount.pre / generated Refcount.php line count in PR body
Forbidden New permanent refcount logic in runtime/*.c

Done when

  • Hot paths (string COW / refcount inc-dec on JIT string ops) call PHP VM helpers through thin LLVM bridge
  • wc -l lib/JIT/Builtin/Refcount.php reduced materially (target: >30% vs baseline; cite count in PR)
  • ./script/ci-fast.sh green; JIT string/compliance subset unchanged (php-src-strict)
  • PR notes php-src reference paths + lines removed from LLVM layer

Verification

make bootstrap-selfhost-vm-driver-execute-probe
./script/ci-fast.sh --filter VMTest
# targeted JIT string phpt as touched

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions