mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-87092: change assembler to use instruction sequence instead of CFG (#103933)
This commit is contained in:
parent
84e7d0f0c7
commit
fbf3596c3e
5 changed files with 93 additions and 81 deletions
|
@ -166,16 +166,10 @@ _PyBasicblock_InsertInstruction(basicblock *block, int pos, cfg_instr *instr) {
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
_PyCfg_InstrSize(cfg_instr *instruction)
|
||||
static int
|
||||
instr_size(cfg_instr *instruction)
|
||||
{
|
||||
int opcode = instruction->i_opcode;
|
||||
assert(!IS_PSEUDO_OPCODE(opcode));
|
||||
int oparg = instruction->i_oparg;
|
||||
assert(HAS_ARG(opcode) || oparg == 0);
|
||||
int extended_args = (0xFFFFFF < oparg) + (0xFFFF < oparg) + (0xFF < oparg);
|
||||
int caches = _PyOpcode_Caches[opcode];
|
||||
return extended_args + 1 + caches;
|
||||
return _PyCompile_InstrSize(instruction->i_opcode, instruction->i_oparg);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -183,7 +177,7 @@ blocksize(basicblock *b)
|
|||
{
|
||||
int size = 0;
|
||||
for (int i = 0; i < b->b_iused; i++) {
|
||||
size += _PyCfg_InstrSize(&b->b_instr[i]);
|
||||
size += instr_size(&b->b_instr[i]);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
@ -492,7 +486,7 @@ resolve_jump_offsets(basicblock *entryblock)
|
|||
bsize = b->b_offset;
|
||||
for (int i = 0; i < b->b_iused; i++) {
|
||||
cfg_instr *instr = &b->b_instr[i];
|
||||
int isize = _PyCfg_InstrSize(instr);
|
||||
int isize = instr_size(instr);
|
||||
/* jump offsets are computed relative to
|
||||
* the instruction pointer after fetching
|
||||
* the jump instruction.
|
||||
|
@ -508,7 +502,7 @@ resolve_jump_offsets(basicblock *entryblock)
|
|||
assert(!IS_BACKWARDS_JUMP_OPCODE(instr->i_opcode));
|
||||
instr->i_oparg -= bsize;
|
||||
}
|
||||
if (_PyCfg_InstrSize(instr) != isize) {
|
||||
if (instr_size(instr) != isize) {
|
||||
extended_arg_recompile = 1;
|
||||
}
|
||||
}
|
||||
|
@ -520,7 +514,7 @@ resolve_jump_offsets(basicblock *entryblock)
|
|||
with a better solution.
|
||||
|
||||
The issue is that in the first loop blocksize() is called
|
||||
which calls _PyCfg_InstrSize() which requires i_oparg be set
|
||||
which calls instr_size() which requires i_oparg be set
|
||||
appropriately. There is a bootstrap problem because
|
||||
i_oparg is calculated in the second loop above.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue