8000 gh-87092: compiler's CFG construction moved to after codegen stage by iritkatriel · Pull Request #102320 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-87092: compiler's CFG construction moved to after codegen stage #102320

8000
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 26 commits into from
Mar 7, 2023
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
labels generated by instr_stream instead of cfg_builder
  • Loading branch information
iritkatriel committed Feb 28, 2023
commit fb0752503c25bcd7d2294d034f2adfc16448198c
31 changes: 17 additions & 14 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ static struct jump_target_label_ NO_LABEL = {-1};
#define IS_LABEL(L) (!SAME_LABEL((L), (NO_LABEL)))

#define NEW_JUMP_TARGET_LABEL(C, NAME) \
jump_target_label NAME = cfg_new_label(CFG_BUILDER(C)); \
jump_target_label NAME = instr_stream_new_label(INSTR_STREAM(C)); \
if (!IS_LABEL(NAME)) { \
return ERROR; \
}

#define USE_LABEL(C, LBL) \
RETURN_IF_ERROR(instr_stream_add_label(INSTR_STREAM(C), (LBL).id))
RETURN_IF_ERROR(instr_stream_use_label(INSTR_STREAM(C), (LBL).id))

struct instr {
int i_opcode;
Expand Down Expand Up @@ -415,8 +415,6 @@ typedef struct cfg_builder_ {
basicblock *g_curblock;
/* label for the next instruction to be placed */
jump_target_label g_current_label;
/* next free label id */
int g_next_free_label;
} cfg_builder;

typedef struct codegen_instr_ {
Expand All @@ -431,8 +429,10 @@ typedef struct instr_stream_ {
int s_allocated;
int s_used;

int *s_labelmap;
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 @@ -463,8 +463,15 @@ instr_stream_next_inst(instr_stream *is) {
return is->s_used++;
}

static jump_target_label
instr_stream_new_label(instr_stream *is)
{
jump_target_label lbl = {is->s_next_free_label++};
return lbl;
}

static int
instr_stream_add_label(instr_stream *is, int lbl) {
instr_stream_use_label(instr_stream *is, int lbl) {
if (is->s_labelmap_size <= lbl) {
int old_size, new_size;
int *tmp = NULL;
Expand Down Expand Up @@ -970,7 +977,7 @@ dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset)
return dest;
}

static void
static int
cfg_builder_check(cfg_builder *g)
{
for (basicblock *block = g->g_block_list; block != NULL; block = block->b_list) {
Expand All @@ -985,6 +992,7 @@ cfg_builder_check(cfg_builder *g)
assert (block->b_ialloc == 0);
}
}
return SUCCESS;
}

static basicblock *cfg_builder_new_block(cfg_builder *g);
Expand Down Expand Up @@ -1107,13 +1115,6 @@ compiler_set_qualname(struct compiler *c)
return SUCCESS;
}

static jump_target_label
cfg_new_label(cfg_builder *g)
{
jump_target_label lbl = {g->g_next_free_label++};
return lbl;
}

/* Allocate a new block and return a pointer to it.
Returns NULL on error.
*/
Expand Down Expand Up @@ -8758,6 +8759,8 @@ assemble(struct compiler *c, int addNone)
cfg_builder *g = &newg;
int nblocks = 0;

//assert(cfg_builder_check(g));

for (basicblock *b = g->g_block_list; b != NULL; b = b->b_list) {
nblocks++;
}
Expand Down
0