Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-106360: Support very basic superblock introspection#106422

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
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
PrevPrevious commit
NextNext commit
Add len() and indexing support to uop superblocks.
  • Loading branch information
@markshannon
markshannon committedJul 4, 2023
commit46e99e6f59fa36e077392499d82a52927a5db61a
9 changes: 6 additions & 3 deletionsInclude/internal/pycore_opcode.h
View file
Open in desktop

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

6 changes: 2 additions & 4 deletionsPython/opcode_metadata.h
View file
Open in desktop

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

49 changes: 45 additions & 4 deletionsPython/optimizer.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,6 @@ uop_name(int index) {
return _PyOpcode_uop_name[index];
}

#ifdef Py_DEBUG
static PyObject *
uop_str(_PyUOpExecutorObject *self)
{
Expand DownExpand Up@@ -352,7 +351,50 @@ uop_str(_PyUOpExecutorObject *self)
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
}
#endif

static Py_ssize_t
uop_len(_PyUOpExecutorObject *self)
{
int count = 1;
for (; count < _Py_UOP_MAX_TRACE_LENGTH; count++) {
if (self->trace[count-1].opcode == EXIT_TRACE) {
break;
}
}
return count;
}

static PyObject *
uop_item(_PyUOpExecutorObject *self, Py_ssize_t index)
{
for (int i = 0; i < _Py_UOP_MAX_TRACE_LENGTH; i++) {
if (self->trace[i].opcode == EXIT_TRACE) {
break;
}
if (i != index) {
continue;
}
const char *name = uop_name(self->trace[i].opcode);
PyObject *oname = _PyUnicode_FromASCII(name, strlen(name));
if (oname == NULL) {
return NULL;
}
PyObject *operand = PyLong_FromUnsignedLongLong(self->trace[i].operand);
if (operand == NULL) {
Py_DECREF(oname);
return NULL;
}
PyObject *args[2] = { oname, operand };
return _PyTuple_FromArraySteal(args, 2);
}
PyErr_SetNone(PyExc_IndexError);
return NULL;
}

PySequenceMethods uop_as_sequence = {
.sq_length = (lenfunc)uop_len,
.sq_item = (ssizeargfunc)uop_item,
};

static PyTypeObject UOpExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
Expand All@@ -361,9 +403,8 @@ static PyTypeObject UOpExecutor_Type = {
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.tp_dealloc = (destructor)uop_dealloc,
#ifdef Py_DEBUG
.tp_str = (reprfunc)uop_str,
#endif
.tp_as_sequence = &uop_as_sequence,
};

static int
Expand Down
7 changes: 4 additions & 3 deletionsTools/build/generate_opcode_h.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,14 +184,15 @@ def main(opcode_py,
fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}")

iobj.write("\n")
iobj.write("#ifdef Py_DEBUG\n")
iobj.write(f"static const char *const _PyOpcode_OpName[{NUM_OPCODES}] = {{\n")
iobj.write(f"\nextern const char *const _PyOpcode_OpName[{NUM_OPCODES}];\n")
iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")
iobj.write(f"const char *const _PyOpcode_OpName[{NUM_OPCODES}] = {{\n")
for op, name in enumerate(opname_including_specialized):
if name[0] != "<":
op = name
iobj.write(f''' [{op}] = "{name}",\n''')
iobj.write("};\n")
iobj.write("#endif\n")
iobj.write("#endif // NEED_OPCODE_TABLES\n")

iobj.write("\n")
iobj.write("#define EXTRA_CASES \\\n")
Expand Down
6 changes: 2 additions & 4 deletionsTools/cases_generator/generate_cases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,9 +1220,7 @@ def write_metadata(self) -> None:
self.out.emit("#ifndef NEED_OPCODE_METADATA")
self.out.emit("extern const struct opcode_metadata _PyOpcode_opcode_metadata[512];")
self.out.emit("extern const struct opcode_macro_expansion _PyOpcode_macro_expansion[256];")
self.out.emit("#ifdef Py_DEBUG")
self.out.emit("extern const char * const _PyOpcode_uop_name[512];")
self.out.emit("#endif")
self.out.emit("#else")

self.out.emit("const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {")
Expand DownExpand Up@@ -1269,10 +1267,10 @@ def write_metadata(self) -> None:
case _:
typing.assert_never(thing)

self.out.emit("#ifdefPy_DEBUG")
self.out.emit("#ifdefNEED_OPCODE_METADATA")
with self.out.block("const char * const _PyOpcode_uop_name[512] =", ";"):
self.write_uop_items(lambda name, counter: f"[{counter}] = \"{name}\",")
self.out.emit("#endif")
self.out.emit("#endif // NEED_OPCODE_METADATA")

self.out.emit("#endif")

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp