Skip to content

Commit 424438b

Browse files
authored
GH-113464: Display a warning when building the JIT (GH-118481)
1 parent 39981fd commit 424438b

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

Tools/jit/_llvm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for invoking LLVM tools."""
2+
23
import asyncio
34
import functools
45
import os

Tools/jit/_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Schema for the JSON produced by llvm-readobj --elf-output-style=JSON."""
2+
23
import typing
34

45
HoleKind: typing.TypeAlias = typing.Literal[

Tools/jit/_stencils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Core data structures for compiled code templates."""
2+
23
import dataclasses
34
import enum
45
import sys
@@ -29,7 +30,7 @@ class HoleValue(enum.Enum):
2930
OPARG = enum.auto()
3031
# The current uop's operand on 64-bit platforms (exposed as _JIT_OPERAND):
3132
OPERAND = enum.auto()
32-
# The current uop's operand on 32-bit platforms (exposed as _JIT_OPERAND_HI and _JIT_OPERAND_LO):
33+
# The current uop's operand on 32-bit platforms (exposed as _JIT_OPERAND_HI/LO):
3334
OPERAND_HI = enum.auto()
3435
OPERAND_LO = enum.auto()
3536
# The current uop's target (exposed as _JIT_TARGET):
@@ -203,9 +204,8 @@ def process_relocations(self, *, alignment: int = 1) -> None:
203204
"""Fix up all GOT and internal relocations for this stencil group."""
204205
for hole in self.code.holes.copy():
205206
if (
206-
hole.kind in {
207-
"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"
208-
}
207+
hole.kind
208+
in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"}
209209
and hole.value is HoleValue.ZERO
210210
):
211211
self.code.pad(alignment)

Tools/jit/_targets.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Target-specific code generation, parsing, and processing."""
2+
23
import asyncio
34
import dataclasses
45
import hashlib
@@ -40,8 +41,8 @@ class _Target(typing.Generic[_S, _R]):
4041
args: typing.Sequence[str] = ()
4142
ghccc: bool = False
4243
prefix: str = ""
44+
stable: bool = False
4345
debug: bool = False
44-
force: bool = False
4546
verbose: bool = False
4647

4748
def _compute_digest(self, out: pathlib.Path) -> str:
@@ -186,12 +187,19 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
186187
tasks.append(group.create_task(coro, name=opname))
187188
return {task.get_name(): task.result() for task in tasks}
188189

189-
def build(self, out: pathlib.Path, *, comment: str = "") -> None:
190+
def build(
191+
self, out: pathlib.Path, *, comment: str = "", force: bool = False
192+
) -> None:
190193
"""Build jit_stencils.h in the given directory."""
194+
if not self.stable:
195+
warning = f"JIT support for {self.triple} is still experimental!"
196+
request = "Please report any issues you encounter.".center(len(warning))
197+
outline = "=" * len(warning)
198+
print("\n".join(["", outline, warning, request, outline, ""]))
191199
digest = f"// {self._compute_digest(out)}\n"
192200
jit_stencils = out / "jit_stencils.h"
193201
if (
194-
not self.force
202+
not force
195203
and jit_stencils.exists()
196204
and jit_stencils.read_text().startswith(digest)
197205
):
@@ -450,9 +458,7 @@ def _handle_relocation(
450458
} | {
451459
"Offset": offset,
452460
"Symbol": {"Name": s},
453-
"Type": {
454-
"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind
455-
},
461+
"Type": {"Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind},
456462
}:
457463
offset += base
458464
s = s.removeprefix(self.prefix)
@@ -481,23 +487,26 @@ def _handle_relocation(
481487
def get_target(host: str) -> _COFF | _ELF | _MachO:
482488
"""Build a _Target for the given host "triple" and options."""
483489
# ghccc currently crashes Clang when combined with musttail on aarch64. :(
490+
target: _COFF | _ELF | _MachO
484491
if re.fullmatch(r"aarch64-apple-darwin.*", host):
485-
return _MachO(host, alignment=8, prefix="_")
486-
if re.fullmatch(r"aarch64-pc-windows-msvc", host):
492+
target = _MachO(host, alignment=8, prefix="_")
493+
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
487494
args = ["-fms-runtime-lib=dll"]
488-
return _COFF(host, alignment=8, args=args)
489-
if re.fullmatch(r"aarch64-.*-linux-gnu", host):
495+
target = _COFF(host, alignment=8, args=args)
496+
elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
490497
args = ["-fpic"]
491-
return _ELF(host, alignment=8, args=args)
492-
if re.fullmatch(r"i686-pc-windows-msvc", host):
498+
target = _ELF(host, alignment=8, args=args)
499+
elif re.fullmatch(r"i686-pc-windows-msvc", host):
493500
args = ["-DPy_NO_ENABLE_SHARED"]
494-
return _COFF(host, args=args, ghccc=True, prefix="_")
495-
if re.fullmatch(r"x86_64-apple-darwin.*", host):
496-
return _MachO(host, ghccc=True, prefix="_")
497-
if re.fullmatch(r"x86_64-pc-windows-msvc", host):
501+
target = _COFF(host, args=args, ghccc=True, prefix="_")
502+
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
503+
target = _MachO(host, ghccc=True, prefix="_")
504+
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
498505
args = ["-fms-runtime-lib=dll"]
499-
return _COFF(host, args=args, ghccc=True)
500-
if re.fullmatch(r"x86_64-.*-linux-gnu", host):
506+
target = _COFF(host, args=args, ghccc=True)
507+
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
501508
args = ["-fpic"]
502-
return _ELF(host, args=args, ghccc=True)
503-
raise ValueError(host)
509+
target = _ELF(host, args=args, ghccc=True)
510+
else:
511+
raise ValueError(host)
512+
return target

Tools/jit/_writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for writing StencilGroups out to a C header file."""
2+
23
import typing
34

45
import _schema

Tools/jit/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Build an experimental just-in-time compiler for CPython."""
2+
23
import argparse
34
import pathlib
45
import shlex
@@ -23,6 +24,5 @@
2324
)
2425
args = parser.parse_args()
2526
args.target.debug = args.debug
26-
args.target.force = args.force
2727
args.target.verbose = args.verbose
28-
args.target.build(pathlib.Path.cwd(), comment=comment)
28+
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)

0 commit comments

Comments
 (0)