Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-116291: Tier 2 - True function inlining redux #116290

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0114bb7
Add frame support functions
Fidget-Spinner Feb 20, 2024
d210b5d
Abstract interp analysis done
Fidget-Spinner Feb 20, 2024
f165138
Add frame inlining heuristics
Fidget-Spinner Feb 20, 2024
7551b65
inlining decision pass
Fidget-Spinner Feb 21, 2024
683927d
add inline markers
Fidget-Spinner Feb 21, 2024
4100b61
more analysis work
Fidget-Spinner Feb 21, 2024
11262ea
propagate non inlineable
Fidget-Spinner Feb 21, 2024
e4a68e3
Merge remote-tracking branch 'upstream/main' into tier2_inliner
Fidget-Spinner Feb 21, 2024
7856988
rewrite loads/store, remove replicates for load and store
Fidget-Spinner Feb 21, 2024
7b69a62
frame reconstruction
Fidget-Spinner Feb 21, 2024
e1ee2ad
fix a bunch of bugs in the abstract interp
Fidget-Spinner Feb 21, 2024
7a12a7b
Simplify
Fidget-Spinner Mar 3, 2024
1791803
Merge remote-tracking branch 'upstream/main' into tier2_inliner_redux
Fidget-Spinner Mar 3, 2024
9734d90
Fix main merge problems
Fidget-Spinner Mar 3, 2024
f0274cb
fix methods
Fidget-Spinner Mar 3, 2024
2eff546
cleanup more
Fidget-Spinner Mar 3, 2024
1322578
make tests pass
Fidget-Spinner Mar 3, 2024
16efbe0
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 3, 2024
2e65b86
remove false check
Fidget-Spinner Mar 3, 2024
f74c315
Merge branch 'tier2_inliner_redux' of github.com:Fidget-Spinner/cpyth…
Fidget-Spinner Mar 3, 2024
df20f69
Merge remote-tracking branch 'upstream/main' into tier2_inliner_redux
Fidget-Spinner Mar 3, 2024
24b127f
fix failing tests
Fidget-Spinner Mar 4, 2024
b04215f
Merge remote-tracking branch 'upstream/main' into tier2_inliner_redux
Fidget-Spinner Mar 4, 2024
e84eeed
Implement _GROW_TIER2_FRAME without adding tier2_extra_size
gvanrossum Mar 5, 2024
dad9100
Merge commit '23db9c62272' into kenjin_tier2_inliner_redux
gvanrossum Mar 6, 2024
c7ad988
Replace _PUSH_FRAME_INLINEABLE body with assert(0) since it can never…
gvanrossum Mar 6, 2024
2f9539b
Don't ever decrement datastack_top!
gvanrossum Mar 6, 2024
29217e0
Remove commented-out comment and assert
gvanrossum Mar 6, 2024
73a0cd2
Merge remote-tracking branch 'upstream/main' into tier2_inliner_redux
Fidget-Spinner Mar 6, 2024
8820429
Add extern decl for real_localsplus_idx().
gvanrossum Mar 7, 2024
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
31 changes: 31 additions & 0 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct _PyInterpreterFrame {
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
int stacktop; /* Offset of TOS from localsplus */
uint16_t return_offset; /* Only relevant during a function call */
uint16_t tier2_extra_size; /* How many extra entries is at the end of localsplus for tier 2 inlining */
Fidget-Spinner marked this conversation as resolved.
Show resolved Hide resolved
char owner;
/* Locals and stack */
PyObject *localsplus[1];
Expand Down Expand Up @@ -131,6 +132,7 @@ _PyFrame_Initialize(
frame->instr_ptr = _PyCode_CODE(code);
frame->return_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;
frame->tier2_extra_size = 0;

for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
frame->localsplus[i] = NULL;
Expand Down Expand Up @@ -258,6 +260,35 @@ _PyThreadState_PushFrame(PyThreadState *tstate, size_t size);

void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame);


/* Converts frame for tier 2.
* Adds stack space at the end of the current frame for Tier 2 execution.
* The frame that is being expanded MUST be the current executing frame, and
* it must be at the top of the datastack.
* */
static inline int
_PyFrame_ConvertToTier2(PyThreadState *tstate, _PyInterpreterFrame *frame,
int localsplus_grow)
{
assert(localsplus_grow > 0);
// Already grown previously
if (frame->tier2_extra_size >= localsplus_grow) {
return 0;
}
if (frame->owner != FRAME_OWNED_BY_THREAD) {
return 1;
}
if (!_PyThreadState_HasStackSpace(tstate, localsplus_grow)) {
Fidget-Spinner marked this conversation as resolved.
Show resolved Hide resolved
return 1;
}
assert(_PyThreadState_HasStackSpace(tstate, localsplus_grow));
assert(tstate->current_frame == frame);
tstate->datastack_top += localsplus_grow;
assert(tstate->datastack_top < tstate->datastack_limit);
frame->tier2_extra_size += localsplus_grow;
return 0;
}

/* Pushes a frame without checking for space.
* Must be guarded by _PyThreadState_HasStackSpace()
* Consumes reference to func. */
Expand Down
8 changes: 8 additions & 0 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ struct _Py_UOpsAbstractFrame {
_Py_UopsSymbol **stack_pointer;
_Py_UopsSymbol **stack;
_Py_UopsSymbol **locals;

// Reflects the real localsplus that will be used in the VM.
// This may differ from locals if the frame is inlined.
// For an inlined frame, the inlinee shares the same localsplus
// as the inliner.
_Py_UopsSymbol **real_localsplus;
bool is_inlineable;
};

typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
Expand Down Expand Up @@ -107,6 +114,7 @@ extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
_Py_UopsSymbol **localsplus_start,
int n_locals_already_filled,
int curr_stackentries);
extern _Py_UOpsAbstractFrame *_Py_uop_prev_frame(_Py_UOpsContext *ctx);
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);

PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
Expand Down
188 changes: 96 additions & 92 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading