MCPcopy Index your code
hub / github.com/python/cpython / _invert_hot_branches

Method _invert_hot_branches

Tools/jit/_optimizers.py:359–396  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

357 todo.extend(pre for pre in self._predecessors(block) if not pre.hot)
358
359 def _invert_hot_branches(self) -> None:
360 for branch in self._blocks():
361 link = branch.link
362 if link is None:
363 continue
364 jump = link.resolve()
365 # Before:
366 # je HOT
367 # jmp COLD
368 # After:
369 # jne COLD
370 # jmp HOT
371 if (
372 # block ends with a branch to hot code...
373 branch.target
374 and branch.fallthrough
375 and branch.target.hot
376 # ...followed by a jump to cold code with no other predecessors:
377 and jump.target
378 and not jump.fallthrough
379 and not jump.target.hot
380 and len(jump.instructions) == 1
381 and list(self._predecessors(jump)) == [branch]
382 ):
383 assert jump.target.label
384 assert branch.target.label
385 inverted = self._invert_branch(
386 branch.instructions[-1], jump.target.label
387 )
388 # Check to see if the branch can even be inverted:
389 if inverted is None:
390 continue
391 branch.instructions[-1] = inverted
392 jump.instructions[-1] = jump.instructions[-1].update_target(
393 branch.target.label
394 )
395 branch.target, jump.target = jump.target, branch.target
396 jump.hot = True
397
398 def _remove_redundant_jumps(self) -> None:
399 # Zero-length jumps can be introduced by _insert_continue_label and

Callers 1

runMethod · 0.95

Calls 6

_blocksMethod · 0.95
_predecessorsMethod · 0.95
_invert_branchMethod · 0.95
listClass · 0.85
update_targetMethod · 0.80
resolveMethod · 0.45

Tested by

no test coverage detected