8000 gh-93678: add _testinternalcapi.optimize_cfg() and test utils for compiler optimization unit tests by iritkatriel · Pull Request #96007 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-93678: add _testinternalcapi.optimize_cfg() and test utils for compiler optimization unit tests #96007

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

Merged
merged 11 commits into from
Aug 24, 2022
Merged
Changes from 1 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
Prev Previous commit
calculate block ID and use it for label, instead of address
  • Loading branch information
iritkatriel committed Aug 23, 2022
commit ebb10bb482c3c94c2f9f6f2a308f48f4abd17e22
15 changes: 7 additions & 8 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9691,8 +9691,12 @@ cfg_to_instructions(cfg_builder *g)
if (instructions == NULL) {
return NULL;
}
int lbl = 1;
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
PyObject *lbl = PyLong_FromUnsignedLongLong((uintptr_t)b);
b->b_label = lbl++;
}
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
PyObject *lbl = PyLong_FromLong(b->b_label);
if (lbl == NULL) {
goto error;
}
Expand All @@ -9704,14 +9708,9 @@ cfg_to_instructions(cfg_builder *g)
for (int i = 0; i < b->b_iused; i++) {
struct instr *instr = &b->b_instr[i];
struct location loc = instr->i_loc;
uintptr_t arg = instr->i_oparg;
if (HAS_TARGET(instr->i_opcode)) {
/* Use the address of the block as its unique ID (for the label) */
arg = (uintptr_t)instr->i_target;
}

int arg = HAS_TARGET(instr->i_opcode) ? instr->i_target->b_label : instr->i_oparg;
PyObject *inst_tuple = Py_BuildValue(
"(iLiiii)", instr->i_opcode, arg,
"(iiiiii)", instr->i_opcode, arg,
loc.lineno, loc.end_lineno,
loc.col_offset, loc.end_col_offset);
if (inst_tuple == NULL) {
Expand Down
0