Skip to content

Commit

Permalink
Renames and fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Sep 27, 2023
1 parent 8d76c0a commit c54707a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
10 changes: 4 additions & 6 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,9 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) \
do { if (_Py_stats && PyFunction_Check(callable)) _Py_stats->call_stats.eval_calls[name]++; } while (0)
#define GC_STAT_ADD(gen, name, n) do { if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n); } while (0)
#define OPTIMIZATION_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
#define OPT_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
#define UOP_EXE_INC(opname) do { if (_Py_stats) _Py_stats->optimization_stats.opcode[opname].execution_count++; } while (0)
#define OPTIMIZE_UNSUPPORTED_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.unsupported_opcode[opname]++; } while (0)
#define OPTIMIZE_TRACE_STACK_OVERFLOW() do { if (_Py_stats) _Py_stats->optimization_stats.trace_stack_overflow++; } while (0)
#define OPT_UNSUPPORTED_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.unsupported_opcode[opname]++; } while (0)

// Export for '_opcode' shared extension
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
Expand All @@ -300,10 +299,9 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
#define EVAL_CALL_STAT_INC(name) ((void)0)
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) ((void)0)
#define GC_STAT_ADD(gen, name, n) ((void)0)
#define OPTIMIZATION_STAT_INC(name) ((void)0)
#define OPT_STAT_INC(name) ((void)0)
#define UOP_EXE_INC(opname) ((void)0)
#define OPTIMIZE_UNSUPPOTED_OPCODE(opname) ((void)0)
#define OPTIMIZE_TRACE_STACK_OVERFLOW() ((void)0)
#define OPT_UNSUPPORTED_OPCODE(opname) ((void)0)
#endif // !Py_STATS

// Utility functions for reading/writing 32/64-bit values in the inline caches.
Expand Down
4 changes: 2 additions & 2 deletions Python/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject

CHECK_EVAL_BREAKER();

OPTIMIZATION_STAT_INC(traces_executed);
OPT_STAT_INC(traces_executed);
_Py_CODEUNIT *ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
int pc = 0;
int opcode;
Expand All @@ -81,7 +81,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
operand,
(int)(stack_pointer - _PyFrame_Stackbase(frame)));
pc++;
OPTIMIZATION_STAT_INC(uops_executed);
OPT_STAT_INC(uops_executed);
assert(opcode < 512);
UOP_EXE_INC(opcode);
switch (opcode) {
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

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

12 changes: 6 additions & 6 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ translate_bytecode_to_trace(
if (trace_length + (n) > max_length) { \
DPRINTF(2, "No room for %s (need %d, got %d)\n", \
(opname), (n), max_length - trace_length); \
OPTIMIZATION_STAT_INC(trace_too_long); \
OPT_STAT_INC(trace_too_long); \
goto done; \
} \
reserved = (n); // Keep ADD_TO_TRACE / ADD_TO_STUB honest
Expand All @@ -473,7 +473,7 @@ translate_bytecode_to_trace(
#define TRACE_STACK_PUSH() \
if (trace_stack_depth >= TRACE_STACK_SIZE) { \
DPRINTF(2, "Trace stack overflow\n"); \
OPTIMIZATION_STAT_INC(trace_stack_overflow); \
OPT_STAT_INC(trace_stack_overflow); \
ADD_TO_TRACE(_SET_IP, 0, 0); \
goto done; \
} \
Expand Down Expand Up @@ -574,7 +574,7 @@ translate_bytecode_to_trace(
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0);
}
else {
OPTIMIZATION_STAT_INC(inner_loop);
OPT_STAT_INC(inner_loop);
DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n");
}
goto done;
Expand Down Expand Up @@ -641,7 +641,7 @@ translate_bytecode_to_trace(
// LOAD_CONST + _POP_FRAME.
if (trace_stack_depth == 0) {
DPRINTF(2, "Trace stack underflow\n");
OPTIMIZATION_STAT_INC(trace_stack_underflow);
OPT_STAT_INC(trace_stack_underflow);
goto done;
}
}
Expand Down Expand Up @@ -718,7 +718,7 @@ translate_bytecode_to_trace(
PyUnicode_AsUTF8(new_code->co_qualname),
PyUnicode_AsUTF8(new_code->co_filename),
new_code->co_firstlineno);
OPTIMIZATION_STAT_INC(recursive_call);
OPT_STAT_INC(recursive_call);
ADD_TO_TRACE(_SET_IP, 0, 0);
goto done;
}
Expand Down Expand Up @@ -898,7 +898,7 @@ uop_optimize(
// Error or nothing translated
return trace_length;
}
OPTIMIZATION_STAT_INC(traces_created);
OPT_STAT_INC(traces_created);
char *uop_optimize = Py_GETENV("PYTHONUOPSOPTIMIZE");
if (uop_optimize != NULL && *uop_optimize > '0') {
trace_length = _Py_uop_analyze_and_optimize(code, trace, trace_length, curr_stackentries);
Expand Down
2 changes: 1 addition & 1 deletion Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ print_optimization_stats(FILE *out, OptimizationStats *stats)
fprintf(out, "Optimization inner loop: %" PRIu64 "\n", stats->inner_loop);
fprintf(out, "Optimization recursive call: %" PRIu64 "\n", stats->recursive_call);

char** names;
char* const* names;
for (int i = 0; i < 512; i++) {
if (i < 256) {
names = _PyOpcode_OpName;
Expand Down

0 comments on commit c54707a

Please sign in to comment.