Skip to content

Commit 77a8ba1

Browse files
committed
Fix bug in predecessor detection
1 parent 4cfabf5 commit 77a8ba1

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Tools/jit/_optimizers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,21 @@ def _blocks(self) -> typing.Generator[_Block, None, None]:
131131

132132
def _body(self) -> str:
133133
lines = []
134+
hot = True
134135
for block in self._blocks():
136+
if hot != block.hot:
137+
hot = block.hot
138+
lines.append(f"# JIT: {'HOT' if hot else 'COLD'} ".ljust(80, "#"))
135139
lines.extend(block.noise)
136140
lines.extend(block.instructions)
137141
return "\n".join(lines)
138142

139143
def _predecessors(self, block: _Block) -> typing.Generator[_Block, None, None]:
140-
for block in self._blocks():
141-
if block.target is block or (block.fallthrough and block.link is block):
142-
yield block
144+
for predecessor in self._blocks():
145+
if predecessor.target is block or (
146+
predecessor.fallthrough and predecessor.link is block
147+
):
148+
yield predecessor
143149

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

155161
def _mark_hot_blocks(self) -> None:
156-
todo = [self._lookup_label(f"{self.prefix}_JIT_CONTINUE")]
162+
todo = list(self._blocks())[-1:]
157163
while todo:
158164
block = todo.pop()
159165
block.hot = True
@@ -227,7 +233,6 @@ class OptimizerAArch64(Optimizer):
227233

228234

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

238243

239244
class OptimizerX86Windows(OptimizerX86):
240-
241245
def _preprocess(self, text: str) -> str:
242246
text = super()._preprocess(text)
243247
# rex64 jumpq *__imp__JIT_CONTINUE(%rip) -> jmp _JIT_CONTINUE

Tools/jit/_targets.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ async def _compile(
136136
f"-I{CPYTHON / 'Tools' / 'jit'}",
137137
"-O3",
138138
"-S",
139-
# "-c",
140139
# Shorten full absolute file paths in the generated code (like the
141140
# __FILE__ macro and assert failure messages) for reproducibility:
142141
f"-ffile-prefix-map={CPYTHON}=.",
@@ -161,13 +160,7 @@ async def _compile(
161160
]
162161
await _llvm.run("clang", args_s, echo=self.verbose)
163162
self.optimizer(s, prefix=self.prefix).run()
164-
args_o = [
165-
f"--target={self.triple}",
166-
"-c",
167-
"-o",
168-
f"{o}",
169-
f"{s}",
170-
]
163+
args_o = [f"--target={self.triple}", "-c", "-o", f"{o}", f"{s}"]
171164
await _llvm.run("clang", args_o, echo=self.verbose)
172165
return await self._parse(o)
173166

0 commit comments

Comments
 (0)