8000 Rip out _Py_TIER2, replace with _Py_JIT · python/cpython@70e18a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 70e18a5

Browse files
committed
Rip out _Py_TIER2, replace with _Py_JIT
The value is a bitflag: - 0: off - 1: JIT, on by default - 3: JIT, off by default (not yet implemented, requires fiddling pystate.c) - 4: tier 2 interpreter, on by default
1 parent f228a06 commit 70e18a5

15 files changed

+37
-49
lines changed

Include/Python.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@
5151
# error "The limited API is not currently supported in the free-threaded build"
5252
#endif
5353

54-
// The JIT depends on TIER2
55-
#ifdef _Py_JIT
56-
#define _Py_TIER2 _Py_JIT
57-
#endif
58-
5954
// Include Python header files
6055
#include "pyport.h"
6156
#include "pymacro.h"

Modules/_opcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ _opcode_get_executor_impl(PyObject *module, PyObject *code, int offset)
367367
Py_TYPE(code)->tp_name);
368368
return NULL;
369369
}
370-
#ifdef _Py_TIER2
370+
#ifdef _Py_JIT
371371
return (PyObject *)PyUnstable_GetExecutor((PyCodeObject *)code, offset);
372372
#else
373373
PyErr_Format(PyExc_RuntimeError,

Modules/_testinternalcapi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ get_co_framesize(PyObject *self, PyObject *arg)
985985
return PyLong_FromLong(code->co_framesize);
986986
}
987987

988-
#ifdef _Py_TIER2
988+
#ifdef _Py_JIT
989989

990990
static PyObject *
991991
new_counter_optimizer(PyObject *self, PyObject *arg)
@@ -1015,7 +1015,7 @@ static PyObject *
10151015
get_optimizer(PyObject *self, PyObject *Py_UNUSED(ignored))
10161016
{
10171017
PyObject *opt = NULL;
1018-
#ifdef _Py_TIER2
1018+
#ifdef _Py_JIT
10191019
opt = (PyObject *)PyUnstable_GetOptimizer();
10201020
#endif
10211021
if (opt == NULL) {
@@ -2027,7 +2027,7 @@ static PyMethodDef module_functions[] = {
20272027
{"iframe_getline", iframe_getline, METH_O, NULL},
20282028
{"iframe_getlasti", iframe_getlasti, METH_O, NULL},
20292029
{"get_co_framesize", get_co_framesize, METH_O, NULL},
2030-
#ifdef _Py_TIER2
2030+
#ifdef _Py_JIT
20312031
{"get_optimizer", get_optimizer, METH_NOARGS, NULL},
20322032
{"set_optimizer", set_optimizer, METH_O, NULL},
20332033
{"new_counter_optimizer", new_counter_optimizer, METH_NOARGS, NULL},
@@ -2081,7 +2081,7 @@ static PyMethodDef module_functions[] = {
20812081
{"py_thread_id", get_py_thread_id, METH_NOARGS},
20822082
#endif
20832083
{"set_immortalize_deferred", set_immortalize_deferred, METH_VARARGS},
2084-
#ifdef _Py_TIER2
2084+
#ifdef _Py_JIT
20852085
{"uop_symbols_test", _Py_uop_symbols_test, METH_NOARGS},
20862086
#endif
20872087
{NULL, NULL} /* sentinel */

Objects/codeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ PyCode_GetFreevars(PyCodeObject *code)
14961496
return _PyCode_GetFreevars(code);
14971497
}
14981498

1499-
#ifdef _Py_TIER2
1499+
#ifdef _Py_JIT
15001500

15011501
static void
15021502
clear_executors(PyCodeObject *co)
@@ -1743,7 +1743,7 @@ code_dealloc(PyCodeObject *co)
17431743

17441744
PyMem_Free(co_extra);
17451745
}
1746-
#ifdef _Py_TIER2
1746+
#ifdef _Py_JIT
17471747
if (co->co_executors != NULL) {
17481748
clear_executors(co);
17491749
}

Objects/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ static PyTypeObject* static_types[] = {
22812281
&_PyBufferWrapper_Type,
22822282
&_PyContextTokenMissing_Type,
22832283
&_PyCoroWrapper_Type,
2284-
#ifdef _Py_TIER2
2284+
#ifdef _Py_JIT
22852285
&_PyCounterExecutor_Type,
22862286
&_PyCounterOptimizer_Type,
22872287
&_PyDefaultOptimizer_Type,
@@ -2306,7 +2306,7 @@ static PyTypeObject* static_types[] = {
23062306
&_PyPositionsIterator,
23072307
&_PyUnicodeASCIIIter_Type,
23082308
&_PyUnion_Type,
2309-
#ifdef _Py_TIER2
2309+
#ifdef _Py_JIT
23102310
&_PyUOpExecutor_Type,
23112311
&_PyUOpOptimizer_Type,
23122312
#endif

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ dummy_func(
23552355
CHECK_EVAL_BREAKER();
23562356
assert(oparg <= INSTR_OFFSET());
23572357
JUMPBY(-oparg);
2358-
#ifdef _Py_TIER2
2358+
#ifdef _Py_JIT
23592359
#if ENABLE_SPECIALIZATION
23602360
_Py_BackoffCounter counter = this_instr[1].counter;
23612361
if (backoff_counter_triggers(counter) && this_instr->op.code == JUMP_BACKWARD) {
@@ -2381,7 +2381,7 @@ dummy_func(
23812381
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
23822382
}
23832383
#endif /* ENABLE_SPECIALIZATION */
2384-
#endif /* _Py_TIER2 */
2384+
#endif /* _Py_JIT */
23852385
}
23862386

23872387
pseudo(JUMP) = {
@@ -2395,7 +2395,7 @@ dummy_func(
23952395
};
23962396

23972397
tier1 inst(ENTER_EXECUTOR, (--)) {
2398-
#ifdef _Py_TIER2
2398+
#ifdef _Py_JIT
23992399
int prevoparg = oparg;
24002400
CHECK_EVAL_BREAKER();
24012401
if (this_instr->op.code != ENTER_EXECUTOR ||
@@ -2415,7 +2415,7 @@ dummy_func(
24152415
GOTO_TIER_TWO(executor);
24162416
#else
24172417
assert(0);
2418-
#endif /* _Py_TIER2 */
2418+
#endif /* _Py_JIT */
24192419
}
24202420

24212421
replaced op(_POP_JUMP_IF_FALSE, (cond -- )) {

Python/ceval.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
755755
_Py_CODEUNIT *next_instr;
756756
PyObject **stack_pointer;
757757

758-
#if defined(_Py_TIER2) && !defined(_Py_JIT)
758+
#if _Py_JIT & 4
759759
/* Tier 2 interpreter state */
760760
_PyExecutorObject *current_executor = NULL;
761761
const _PyUOpInstruction *next_uop = NULL;
@@ -959,15 +959,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
959959
goto error;
960960

961961

962-
#ifdef _Py_TIER2
962+
#if _Py_JIT & 4 /* Tier 2 interpreter */
963963

964964
// Tier 2 is also here!
965965
enter_tier_two:
966966

967-
#ifdef _Py_JIT
968-
assert(0);
969-
#else
970-
971967
#undef LOAD_IP
972968
#define LOAD_IP(UNUSED) (void)0
973969

@@ -1112,9 +1108,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11121108
tstate->previous_executor = (PyObject *)current_executor;
11131109
GOTO_TIER_TWO(exit->executor);
11141110

1115-
#endif // _Py_JIT
1116-
1117-
#endif // _Py_TIER2
1111+
#endif /* _Py_JIT & 4 */
11181112

11191113
}
11201114

Python/generated_cases.c.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/instrumentation.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ instrument_lock_held(PyCodeObject *code, PyInterpreterState *interp)
17021702
);
17031703
return 0;
17041704
}
1705-
#ifdef _Py_TIER2
1705+
#ifdef _Py_JIT
17061706
if (code->co_executors != NULL) {
17071707
_PyCode_Clear_Executors(code);
17081708
}
@@ -1945,7 +1945,7 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
19451945
goto done;
19461946
}
19471947
set_global_version(tstate, new_version);
1948-
#ifdef _Py_TIER2
1948+
#ifdef _Py_JIT
19491949
_Py_Executors_InvalidateAll(interp, 1);
19501950
#endif
19511951
res = instrument_all_executing_code_objects(interp);
@@ -1987,7 +1987,7 @@ _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEvent
19871987
code->_co_instrumentation_version -= MONITORING_VERSION_INCREMENT;
19881988
}
19891989

1990-
#ifdef _Py_TIER2
1990+
#ifdef _Py_JIT
19911991
_Py_Executors_InvalidateDependency(interp, code, 1);
19921992
#endif
19931993

Python/optimizer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifdef _Py_JIT
2+
13
#include "Python.h"
24
#include "opcode.h"
35
#include "pycore_interp.h"
@@ -15,8 +17,6 @@
1517
#include <stdint.h>
1618
#include <stddef.h>
1719

18-
#ifdef _Py_TIER2
19-
2020
#define NEED_OPCODE_METADATA
2121
#include "pycore_uop_metadata.h" // Uop tables
2222
#undef NEED_OPCODE_METADATA
@@ -1625,4 +1625,4 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
16251625
}
16261626
}
16271627

1628-
#endif /* _Py_TIER2 */
1628+
#endif /* _Py_JIT */

Python/optimizer_analysis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <stdint.h>
3434
#include <stddef.h>
3535

36-
#ifdef _Py_TIER2
36+
#ifdef _Py_JIT
3737

3838
#ifdef Py_DEBUG
3939
extern const char *_PyUOpName(int index);
@@ -606,4 +606,4 @@ _Py_uop_analyze_and_optimize(
606606
return length;
607607
}
608608

609-
#endif /* _Py_TIER2 */
609+
#endif /* _Py_JIT */

Python/optimizer_symbols.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef _Py_JIT
12

23
#include "Python.h"
34

@@ -11,8 +12,6 @@
1112
#include <stdint.h>
1213
#include <stddef.h>
1314

14-
#ifdef _Py_TIER2
15-
1615
/* Symbols
1716
=======
1817
@@ -509,4 +508,4 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
509508
return NULL;
510509
}
511510

512-
#endif /* _Py_TIER2 */
511+
#endif /* _Py_JIT */

Python/pylifecycle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ static int
621621
builtins_dict_watcher(PyDict_WatchEvent event, PyObject *dict, PyObject *key, PyObject *new_value)
622622
{
623623
PyInterpreterState *interp = _PyInterpreterState_GET();
624-
#ifdef _Py_TIER2
624+
#ifdef _Py_JIT
625625
if (interp->rare_events.builtin_dict < _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS) {
626626
_Py_Executors_InvalidateAll(interp, 1);
627627
}
@@ -1265,7 +1265,7 @@ init_interp_main(PyThreadState *tstate)
12651265

12661266
// Turn on experimental tier 2 (uops-based) optimizer
12671267
// This is also needed when the JIT is enabled
1268-
#ifdef _Py_TIER2
1268+
#ifdef _Py_JIT
12691269
if (is_main_interp) {
12701270
PyObject *opt = PyUnstable_Optimizer_NewUOpOptimizer();
12711271
if (opt == NULL) {
@@ -1636,7 +1636,7 @@ finalize_modules(PyThreadState *tstate)
16361636
{
16371637
PyInterpreterState *interp = tstate->interp;
16381638

1639-
#ifdef _Py_TIER2
1639+
#ifdef _Py_JIT
16401640
// Invalidate all executors and turn off tier 2 optimizer
16411641
_Py_Executors_InvalidateAll(interp, 0);
16421642
_PyOptimizerObject *old = _Py_SetOptimizer(interp, NULL);

Python/pystate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ init_interpreter(PyInterpreterState *interp,
653653
}
654654
interp->sys_profile_initialized = false;
655655
interp->sys_trace_initialized = false;
656-
#ifdef _Py_TIER2
656+
#ifdef _Py_JIT
657657
(void)_Py_SetOptimizer(interp, NULL);
658658
interp->executor_list_head = NULL;
659659
#endif
@@ -808,7 +808,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
808808
tstate->_status.cleared = 0;
809809
}
810810

811-
#ifdef _Py_TIER2
811+
#ifdef _Py_JIT
812812
_PyOptimizerObject *old = _Py_SetOptimizer(interp, NULL);
813813
assert(old != NULL);
814814
Py_DECREF(old);
@@ -2824,7 +2824,7 @@ _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
28242824
if (eval_frame == interp->eval_frame) {
28252825
return;
28262826
}
2827-
#ifdef _Py_TIER2
2827+
#ifdef _Py_JIT
28282828
if (eval_frame != NULL) {
28292829
_Py_Executors_InvalidateAll(interp, 1);
28302830
}

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ static PyObject *
21652165
sys__clear_internal_caches_impl(PyObject *module)
21662166
/*[clinic end generated code: output=0ee128670a4966d6 input=253e741ca744f6e8]*/
21672167
{
2168-
#ifdef _Py_TIER2
2168+
#ifdef _Py_JIT
21692169
PyInterpreterState *interp = _PyInterpreterState_GET();
21702170
_Py_Executors_InvalidateAll(interp, 0);
21712171
#endif

0 commit comments

Comments
 (0)
0