Skip to content

Commit

Permalink
Doing "LTO" makes stencils smaller?
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Dec 13, 2024
1 parent 94b8f8b commit f5bcb83
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Tools/jit/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"R_AARCH64_MOVW_UABS_G3",
"R_X86_64_64",
"R_X86_64_GOTPCREL",
"R_X86_64_GOTPCRELX",
"R_X86_64_PC32",
"R_X86_64_REX_GOTPCRELX",
"X86_64_RELOC_BRANCH",
"X86_64_RELOC_GOT",
"X86_64_RELOC_GOT_LOAD",
Expand Down
4 changes: 1 addition & 3 deletions Tools/jit/_stencils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ class HoleValue(enum.Enum):
# x86_64-unknown-linux-gnu:
"R_X86_64_64": "patch_64",
"R_X86_64_GOTPCREL": "patch_32r",
"R_X86_64_GOTPCRELX": "patch_x86_64_32rx",
"R_X86_64_PC32": "patch_32r",
"R_X86_64_REX_GOTPCRELX": "patch_x86_64_32rx",
# x86_64-apple-darwin:
"X86_64_RELOC_BRANCH": "patch_32r",
"X86_64_RELOC_GOT": "patch_x86_64_32rx",
Expand Down Expand Up @@ -241,7 +239,7 @@ def remove_jump(self, *, alignment: int = 1) -> None:
jump = b"\x00\x00\x00\x14"
case Hole(
offset=offset,
kind="R_X86_64_GOTPCRELX",
kind="R_X86_64_GOTPCREL",
value=HoleValue.GOT,
symbol="_JIT_CONTINUE",
addend=addend,
Expand Down
12 changes: 7 additions & 5 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def _handle_relocation(
async def _compile(
self, opname: str, c: pathlib.Path, tempdir: pathlib.Path
) -> _stencils.StencilGroup:
lto = tempdir / f"{opname}-lto.o"
o = tempdir / f"{opname}.o"
args = [
f"--target={self.triple}",
Expand All @@ -119,11 +120,12 @@ async def _compile(
f"-I{CPYTHON / 'Python'}",
f"-I{CPYTHON / 'Tools' / 'jit'}",
"-O3",
"-c",
"--compile",
# Shorten full absolute file paths in the generated code (like the
# __FILE__ macro and assert failure messages) for reproducibility:
f"-ffile-prefix-map={CPYTHON}=.",
f"-ffile-prefix-map={tempdir}=.",
"-flto",
# This debug info isn't necessary, and bloats out the JIT'ed code.
# We *may* be able to re-enable this, process it, and JIT it for a
# nicer debugging experience... but that needs a lot more research:
Expand All @@ -138,11 +140,13 @@ async def _compile(
"-fno-stack-protector",
"-std=c11",
"-o",
f"{o}",
f"{lto}",
f"{c}",
*self.args,
]
await _llvm.run("clang", args, echo=self.verbose)
lto_args = ["-flto", "-r", "-o", f"{o}", f"{lto}"]
await _llvm.run("clang", lto_args, echo=self.verbose)
return await self._parse(o)

async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
Expand Down Expand Up @@ -359,9 +363,7 @@ def _handle_relocation(
"Type": {
"Name": "R_AARCH64_ADR_GOT_PAGE"
| "R_AARCH64_LD64_GOT_LO12_NC"
| "R_X86_64_GOTPCREL"
| "R_X86_64_GOTPCRELX"
| "R_X86_64_REX_GOTPCRELX" as kind
| "R_X86_64_GOTPCREL" as kind
},
}:
offset += base
Expand Down

0 comments on commit f5bcb83

Please sign in to comment.