| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| PyObject *freevars = NULL; | ||
| PyObject *cellvars = NULL; | ||
| PyObject *bytecode = NULL; | ||
| // PyObject *bytecode = NULL; |
There was a problem hiding this comment.
Did you forget this?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, thanks.
Sorry, something went wrong.
|
Mostly, this looks pretty good. Consider removing the peephole.c file altogether. It was originally part of compile.c and got separated out when it got too large. We can more the PyCode_Optimize() function back to compile.c. Ideally, we could drop it from the public api as part of Victor's PEP to overhaul the C API. One small loss is that the current code has macros that provide meaningful opcode groupings like UNCONDITIONAL_JUMP, CONDITIONAL_JUMP, ABSOLUTE_JUMP, and JUMPS_ON_TRUE. I always found those grouping helpful for reasoning about the code. |
Sorry, something went wrong.
| Py_XINCREF(code); | ||
| PyMem_Free(blocks); | ||
| PyMem_Free(codestr); | ||
| Py_INCREF(code); |
There was a problem hiding this comment.
You can use Py_UNUSED for the ones that are not code in the function declaration.
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 6b7019a 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
| if (!names || !varnames) | ||
| goto error; |
There was a problem hiding this comment.
| if (!names || !varnames) | |
| goto error; | |
| if (!names || !varnames) { | |
| goto error; | |
| } |
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
| optimize_cfg(struct assembler *a, PyObject *consts) | ||
| { | ||
| for (int i = 0; i < a->a_nblocks; i++) { | ||
| if (optimize_basic_block(a->a_reverse_postorder[i], consts)) { |
There was a problem hiding this comment.
Does this converge on one single iteration? What happens if you have a sequence of many jumps all together between blocks?
Sorry, something went wrong.
There was a problem hiding this comment.
No. Some jumps that can be eliminated will still remain.
This PR is aimed at closely mimicking the behavior of the existing peephole optimizer.
We can improve it later.
Sorry, something went wrong.
There was a problem hiding this comment.
This looks great and very compact! This is a very good work @markshannon ! I will do a more thorough review over the weekend but I have left some minor comments for now
Sorry, something went wrong.
| for (i = 0; i < n; ++i) { | ||
| VISIT(c, expr, (expr_ty)asdl_seq_GET(s, i)); | ||
| ADDOP_JABS(c, jumpi, end); | ||
| basicblock *next = compiler_new_block(c); |
There was a problem hiding this comment.
Huh? Why we need a new blocks here for connecting the jumps?
Sorry, something went wrong.
There was a problem hiding this comment.
All instructions following a jump or branch must start a new basic block.
We now need the CFG generated by the code generation pass to be correct, as we perform jump elimination on it, rather than the CFG recreated in peephole.c.
Longer term, I think the front end should use labels and CFG creation should be a pass in between the code generation pass and the optimizer.
Sorry, something went wrong.
|
@rhettinger The UNCONDITIONAL_JUMP, CONDITIONAL_JUMP, ABSOLUTE_JUMP, and JUMPS_ON_TRUE don't seem that useful in an instruction based optimizer. |
Sorry, something went wrong.
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Don't we need one of these?
| } | |
| } | |
| PyObject_Free(stack); |
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, thanks.
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit fda0bed 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
|
One final tweak. Jumps to empty blocks that were immediately followed by jumps were not being eliminated. The final commit fixes that. |
Sorry, something went wrong.
…honGH-21517) * Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
…honGH-21517) * Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
…honGH-21517) * Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
| Back | FazBrowse Home | New Git URL |
https://bugs.python.org/issue41323