Skip to content

Commit

Permalink
Try to convince Clang to reorder jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Oct 17, 2024
1 parent d8c8648 commit 15229e0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Tools/jit/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ do { \
return ((jit_func)&ALIAS)(frame, stack_pointer, tstate); \
} while (0)

// This feels icky. To convince Clang to put the jump to _JIT_CONTINUE at the
// end of the function, we need to pretend that it's "unlikely" (and that jumps
// for errors and deopts are "likely")... :(
#define PATCH_JUMP_FROM_HERE(ALIAS) [[clang::likely]] PATCH_JUMP(ALIAS)
#define PATCH_JUMP_FROM_TAIL(ALIAS) [[clang::unlikely]] PATCH_JUMP(ALIAS)

#undef JUMP_TO_JUMP_TARGET
#define JUMP_TO_JUMP_TARGET() PATCH_JUMP(_JIT_JUMP_TARGET)
#define JUMP_TO_JUMP_TARGET() PATCH_JUMP_FROM_HERE(_JIT_JUMP_TARGET)

#undef JUMP_TO_ERROR
#define JUMP_TO_ERROR() PATCH_JUMP(_JIT_ERROR_TARGET)
#define JUMP_TO_ERROR() PATCH_JUMP_FROM_HERE(_JIT_ERROR_TARGET)

#undef WITHIN_STACK_BOUNDS
#define WITHIN_STACK_BOUNDS() 1
Expand Down Expand Up @@ -115,7 +121,7 @@ _JIT_ENTRY(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState
default:
Py_UNREACHABLE();
}
PATCH_JUMP(_JIT_CONTINUE);
PATCH_JUMP_FROM_TAIL(_JIT_CONTINUE);
// Labels that the instruction implementations expect to exist:

error_tier_two:
Expand Down

0 comments on commit 15229e0

Please sign in to comment.