GH-113464: Display a warning when building the JIT (GH-118481)

This commit is contained in:
Brandt Bucher 2024-05-01 14:35:49 -07:00 committed by GitHub
parent 39981fd07a
commit 424438b11e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 38 additions and 26 deletions

View file

@ -1,4 +1,5 @@
"""Utilities for invoking LLVM tools.""" """Utilities for invoking LLVM tools."""
import asyncio import asyncio
import functools import functools
import os import os

View file

@ -1,4 +1,5 @@
"""Schema for the JSON produced by llvm-readobj --elf-output-style=JSON.""" """Schema for the JSON produced by llvm-readobj --elf-output-style=JSON."""
import typing import typing
HoleKind: typing.TypeAlias = typing.Literal[ HoleKind: typing.TypeAlias = typing.Literal[

View file

@ -1,4 +1,5 @@
"""Core data structures for compiled code templates.""" """Core data structures for compiled code templates."""
import dataclasses import dataclasses
import enum import enum
import sys import sys
@ -29,7 +30,7 @@ class HoleValue(enum.Enum):
OPARG = enum.auto() OPARG = enum.auto()
# The current uop's operand on 64-bit platforms (exposed as _JIT_OPERAND): # The current uop's operand on 64-bit platforms (exposed as _JIT_OPERAND):
OPERAND = enum.auto() OPERAND = enum.auto()
# The current uop's operand on 32-bit platforms (exposed as _JIT_OPERAND_HI and _JIT_OPERAND_LO): # The current uop's operand on 32-bit platforms (exposed as _JIT_OPERAND_HI/LO):
OPERAND_HI = enum.auto() OPERAND_HI = enum.auto()
OPERAND_LO = enum.auto() OPERAND_LO = enum.auto()
# The current uop's target (exposed as _JIT_TARGET): # The current uop's target (exposed as _JIT_TARGET):
@ -203,9 +204,8 @@ class StencilGroup:
"""Fix up all GOT and internal relocations for this stencil group.""" """Fix up all GOT and internal relocations for this stencil group."""
for hole in self.code.holes.copy(): for hole in self.code.holes.copy():
if ( if (
hole.kind in { hole.kind
"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26" in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"}
}
and hole.value is HoleValue.ZERO and hole.value is HoleValue.ZERO
): ):
self.code.pad(alignment) self.code.pad(alignment)

View file

@ -1,4 +1,5 @@
"""Target-specific code generation, parsing, and processing.""" """Target-specific code generation, parsing, and processing."""
import asyncio import asyncio
import dataclasses import dataclasses
import hashlib import hashlib
@ -40,8 +41,8 @@ class _Target(typing.Generic[_S, _R]):
args: typing.Sequence[str] = () args: typing.Sequence[str] = ()
ghccc: bool = False ghccc: bool = False
prefix: str = "" prefix: str = ""
stable: bool = False
debug: bool = False debug: bool = False
force: bool = False
verbose: bool = False verbose: bool = False
def _compute_digest(self, out: pathlib.Path) -> str: def _compute_digest(self, out: pathlib.Path) -> str:
@ -186,12 +187,19 @@ class _Target(typing.Generic[_S, _R]):
tasks.append(group.create_task(coro, name=opname)) tasks.append(group.create_task(coro, name=opname))
return {task.get_name(): task.result() for task in tasks} return {task.get_name(): task.result() for task in tasks}
def build(self, out: pathlib.Path, *, comment: str = "") -> None: def build(
self, out: pathlib.Path, *, comment: str = "", force: bool = False
) -> None:
"""Build jit_stencils.h in the given directory.""" """Build jit_stencils.h in the given directory."""
if not self.stable:
warning = f"JIT support for {self.triple} is still experimental!"
request = "Please report any issues you encounter.".center(len(warning))
outline = "=" * len(warning)
print("\n".join(["", outline, warning, request, outline, ""]))
digest = f"// {self._compute_digest(out)}\n" digest = f"// {self._compute_digest(out)}\n"
jit_stencils = out / "jit_stencils.h" jit_stencils = out / "jit_stencils.h"
if ( if (
not self.force not force
and jit_stencils.exists() and jit_stencils.exists()
and jit_stencils.read_text().startswith(digest) and jit_stencils.read_text().startswith(digest)
): ):
@ -450,9 +458,7 @@ class _MachO(
} | { } | {
"Offset": offset, "Offset": offset,
"Symbol": {"Name": s}, "Symbol": {"Name": s},
"Type": { "Type": {"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind},
"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind
},
}: }:
offset += base offset += base
s = s.removeprefix(self.prefix) s = s.removeprefix(self.prefix)
@ -481,23 +487,26 @@ class _MachO(
def get_target(host: str) -> _COFF | _ELF | _MachO: def get_target(host: str) -> _COFF | _ELF | _MachO:
"""Build a _Target for the given host "triple" and options.""" """Build a _Target for the given host "triple" and options."""
# ghccc currently crashes Clang when combined with musttail on aarch64. :( # ghccc currently crashes Clang when combined with musttail on aarch64. :(
target: _COFF | _ELF | _MachO
if re.fullmatch(r"aarch64-apple-darwin.*", host): if re.fullmatch(r"aarch64-apple-darwin.*", host):
return _MachO(host, alignment=8, prefix="_") target = _MachO(host, alignment=8, prefix="_")
if re.fullmatch(r"aarch64-pc-windows-msvc", host): elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll"] args = ["-fms-runtime-lib=dll"]
return _COFF(host, alignment=8, args=args) target = _COFF(host, alignment=8, args=args)
if re.fullmatch(r"aarch64-.*-linux-gnu", host): elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
args = ["-fpic"] args = ["-fpic"]
return _ELF(host, alignment=8, args=args) target = _ELF(host, alignment=8, args=args)
if re.fullmatch(r"i686-pc-windows-msvc", host): elif re.fullmatch(r"i686-pc-windows-msvc", host):
args = ["-DPy_NO_ENABLE_SHARED"] args = ["-DPy_NO_ENABLE_SHARED"]
return _COFF(host, args=args, ghccc=True, prefix="_") target = _COFF(host, args=args, ghccc=True, prefix="_")
if re.fullmatch(r"x86_64-apple-darwin.*", host): elif re.fullmatch(r"x86_64-apple-darwin.*", host):
return _MachO(host, ghccc=True, prefix="_") target = _MachO(host, ghccc=True, prefix="_")
if re.fullmatch(r"x86_64-pc-windows-msvc", host): elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll"] args = ["-fms-runtime-lib=dll"]
return _COFF(host, args=args, ghccc=True) target = _COFF(host, args=args, ghccc=True)
if re.fullmatch(r"x86_64-.*-linux-gnu", host): elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
args = ["-fpic"] args = ["-fpic"]
return _ELF(host, args=args, ghccc=True) target = _ELF(host, args=args, ghccc=True)
raise ValueError(host) else:
raise ValueError(host)
return target

View file

@ -1,4 +1,5 @@
"""Utilities for writing StencilGroups out to a C header file.""" """Utilities for writing StencilGroups out to a C header file."""
import typing import typing
import _schema import _schema

View file

@ -1,4 +1,5 @@
"""Build an experimental just-in-time compiler for CPython.""" """Build an experimental just-in-time compiler for CPython."""
import argparse import argparse
import pathlib import pathlib
import shlex import shlex
@ -23,6 +24,5 @@ if __name__ == "__main__":
) )
args = parser.parse_args() args = parser.parse_args()
args.target.debug = args.debug args.target.debug = args.debug
args.target.force = args.force
args.target.verbose = args.verbose args.target.verbose = args.verbose
args.target.build(pathlib.Path.cwd(), comment=comment) args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)