Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
43df9b3
compiler uses instruction stream to create codeobjects
iritkatriel Feb 25, 2023
2b43f88
remove unused code
iritkatriel Feb 26, 2023
52a1d1d
use newg all the way
iritkatriel Feb 26, 2023
9b737f1
remove double processing
iritkatriel Feb 26, 2023
083b8b1
split cfg_builder_use_label/cfg_builder_addop to separate versions fo…
iritkatriel Feb 26, 2023
a56bafe
codegen functions take an instr_stream
iritkatriel Feb 27, 2023
8be1b28
free isntr_stream. Attach it to compiluer_unit (not cfg_builder)
iritkatriel Feb 27, 2023
741f773
move things around
iritkatriel Feb 27, 2023
fb07525
labels generated by instr_stream instead of cfg_builder
iritkatriel Feb 27, 2023
1b06bf8
add implicit RETURN NONE to the stream
iritkatriel Feb 27, 2023
142a7f1
remove u_cfg_builder
iritkatriel Feb 27, 2023
f9f8443
init the cfg_builder in instr_stream_to_cfg
iritkatriel Feb 27, 2023
f6fcde9
stream->sequence
iritkatriel Feb 28, 2023
84f5a9d
instr->cfg_instr, codegen_instr->instr
iritkatriel Feb 28, 2023
cd0225d
make sure we always emit something to jump to at the end
iritkatriel Feb 28, 2023
b8f4acf
INSTR_STREAM --> INSTR_SEQUENCE
iritkatriel Feb 28, 2023
258f142
free the cfg_builder in the test harness
iritkatriel Mar 1, 2023
e5653ee
Merge branch 'main' into instruction-stream
iritkatriel Mar 1, 2023
788da74
Merge branch 'main' into instruction-stream
iritkatriel Mar 2, 2023
fd7f2b3
#ifndef NDEBUG around cfg_builder_check
iritkatriel Mar 2, 2023
57fbe36
create shared helper function for resizing arrays
iritkatriel Mar 3, 2023
dc9f1f5
remove obsolete comment
iritkatriel Mar 3, 2023
f20e480
Merge branch 'main' into instruction-stream
iritkatriel Mar 6, 2023
fa1c66a
address code review
iritkatriel Mar 7, 2023
3528176
tweak comments
iritkatriel Mar 7, 2023
fb13e36
index -> idx to avoid github's hilighting
iritkatriel Mar 7, 2023
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
Next Next commit
init the cfg_builder in instr_stream_to_cfg
  • Loading branch information
iritkatriel committed Feb 28, 2023
commit f9f844342b87fc00f5a007964dd18950921401e0
22 changes: 8 additions & 14 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ typedef struct instr_stream_ {
int *s_labelmap; /* label id --> instr offset */
int s_labelmap_size;
int s_next_free_label; /* next free label id */

} instr_stream;

#define INITIAL_INSTR_STREAM_SIZE 100
Expand Down Expand Up @@ -563,8 +562,12 @@ cfg_builder_addop(cfg_builder *g, int opcode, int oparg, location loc)
return basicblock_addop(g->g_curblock, opcode, oparg, loc);
}

static int cfg_builder_init(cfg_builder *g);

static int
instr_stream_to_cfg(instr_stream *is, cfg_builder *g) {
memset(g, 0, sizeof(cfg_builder));
RETURN_IF_ERROR(cfg_builder_init(g));
/* Note: there can be more than one label for the same offset */
for (int i = 0; i < is->s_used; i++) {
for (int j=0; j < is->s_labelmap_size; j++) {
Expand Down Expand Up @@ -8675,6 +8678,9 @@ prepare_localsplus(struct compiler* c, cfg_builder *g, int code_flags)
int numdropped = fix_cell_offsets(c, g->g_entryblock, cellfixedoffsets);
PyMem_Free(cellfixedoffsets); // At this point we're done with it.
cellfixedoffsets = NULL;
if (numdropped < 0) {
return ERROR;
}

nlocalsplus -= numdropped;
return nlocalsplus;
Expand Down Expand Up @@ -8719,10 +8725,6 @@ assemble(struct compiler *c, int addNone)
}

/** Preprocessing **/
memset(g, 0, sizeof(cfg_builder));
if (cfg_builder_init(g) < 0) {
goto error;
}
if (instr_stream_to_cfg(INSTR_STREAM(c), g) < 0) {
goto error;
}
Expand Down Expand Up @@ -8754,7 +8756,6 @@ assemble(struct compiler *c, int addNone)
if (mark_except_handlers(g->g_entryblock) < 0) {
goto error;
}

if (label_exception_targets(g->g_entryblock)) {
goto error;
}
Expand All @@ -8767,7 +8768,6 @@ assemble(struct compiler *c, int addNone)
if (optimize_cfg(g, consts, c->c_const_cache)) {
goto error;
}

if (remove_unused_consts(g->g_entryblock, consts) < 0) {
goto error;
}
Expand All @@ -8779,16 +8779,15 @@ assemble(struct compiler *c, int addNone)
if (duplicate_exits_without_lineno(g) < 0) {
goto error;
}

propagate_line_numbers(g->g_entryblock);

guarantee_lineno_for_exits(g->g_entryblock, c->u->u_firstlineno);

if (push_cold_blocks_to_end(g, code_flags) < 0) {
goto error;
}

/** Assembly **/

int nlocalsplus = prepare_localsplus(c, g, code_flags);
if (nlocalsplus < 0) {
goto error;
Expand All @@ -8798,7 +8797,6 @@ assemble(struct compiler *c, int addNone)
if (maxdepth < 0) {
goto error;
}

/* TO DO -- For 3.12, make sure that `maxdepth <= MAX_ALLOWED_STACK_USE` */

convert_exception_handlers_to_nops(g->g_entryblock);
Expand Down Expand Up @@ -10004,10 +10002,6 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
}

cfg_builder g;
memset(&g, 0, sizeof(cfg_builder));
if (cfg_builder_init(&g) < 0) {
goto finally;
}
if (instr_stream_to_cfg(INSTR_STREAM(c), &g) < 0) {
goto finally;
}
Expand Down