Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix bug in predecessor detection
  • Loading branch information
brandtbucher committed Jun 23, 2025
commit 77a8ba147b27a7f3c665187b70de2df4ecb1f01f
16 changes: 10 additions & 6 deletions Tools/jit/_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,21 @@ def _blocks(self) -> typing.Generator[_Block, None, None]:

def _body(self) -> str:
lines = []
hot = True
for block in self._blocks():
if hot != block.hot:
hot = block.hot
lines.append(f"# JIT: {'HOT' if hot else 'COLD'} ".ljust(80, "#"))
lines.extend(block.noise)
lines.extend(block.instructions)
return "\n".join(lines)

def _predecessors(self, block: _Block) -> typing.Generator[_Block, None, None]:
for block in self._blocks():
if block.target is block or (block.fallthrough and block.link is block):
yield block
for predecessor in self._blocks():
if predecessor.target is block or (
predecessor.fallthrough and predecessor.link is block
):
yield predecessor

def _insert_continue_label(self) -> None:
for end in reversed(list(self._blocks())):
Expand All @@ -153,7 +159,7 @@ def _insert_continue_label(self) -> None:
end.link, align.link, continuation.link = align, continuation, end.link

def _mark_hot_blocks(self) -> None:
todo = [self._lookup_label(f"{self.prefix}_JIT_CONTINUE")]
todo = list(self._blocks())[-1:]
while todo:
block = todo.pop()
block.hot = True
Expand Down Expand Up @@ -227,7 +233,6 @@ class OptimizerAArch64(Optimizer):


class OptimizerX86(Optimizer):

_branches = _X86_BRANCHES
_re_branch = re.compile(
rf"\s*(?P<instruction>{'|'.join(_X86_BRANCHES)})\s+(?P<target>[\w.]+)"
Expand All @@ -237,7 +242,6 @@ class OptimizerX86(Optimizer):


class OptimizerX86Windows(OptimizerX86):

def _preprocess(self, text: str) -> str:
text = super()._preprocess(text)
# rex64 jumpq *__imp__JIT_CONTINUE(%rip) -> jmp _JIT_CONTINUE
Expand Down
9 changes: 1 addition & 8 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ async def _compile(
f"-I{CPYTHON / 'Tools' / 'jit'}",
"-O3",
"-S",
# "-c",
# Shorten full absolute file paths in the generated code (like the
# __FILE__ macro and assert failure messages) for reproducibility:
f"-ffile-prefix-map={CPYTHON}=.",
Expand All @@ -161,13 +160,7 @@ async def _compile(
]
await _llvm.run("clang", args_s, echo=self.verbose)
self.optimizer(s, prefix=self.prefix).run()
args_o = [
f"--target={self.triple}",
"-c",
"-o",
f"{o}",
f"{s}",
]
args_o = [f"--target={self.triple}", "-c", "-o", f"{o}", f"{s}"]
await _llvm.run("clang", args_o, echo=self.verbose)
return await self._parse(o)

Expand Down