Title: Split compiler into code-gen, optimizer and assembler.
Type: Stage:
Components: Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, gvanrossum
Priority: normal Keywords:

Created on 2021-01-13 15:03 by Mark.Shannon, last changed 2021-01-13 15:52 by gvanrossum.

Messages (2)
msg385033 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-01-13 15:03
Currently the compiler operates in three main passes:


The problem is that these passes use the same basic-block based CFG, leading to unnecessary coupling and inefficiencies.
A basic block CFG is awkward and error-prone for the code-gen, but not very efficient for the optimizer and assembler.

A better design would be for the code-gen to create a single linear sequence of instructions. The optimizer would take this and produce a list of extended-blocks for the assembler to consume.

code-gen -> (list of instructions) -> optimizer
optimizer -> (list of extended blocks) -> assembler

(Extended blocks have a single entry and multiple exits, unlike basic blocks which have a single entry and single exit)

This would:
1. Reduce memory use considerably (the size of instruction and block data structures would be about 60% of current)
2. Be faster (Less CFG management).
3. Produce better code (extended blocks are a better unit for optimization that basic blocks).
4. Be easier to maintain:
  a) Code-gen wouldn't have to worry about creating a correct CFG.
  b) The optimizer wouldn't need to handle empty blocks and track which basic blocks form an extended block.

Apart from the changes to the compiler, it would help if we made all branch instructions absolute (or have a backward dual) to accommodate free reordering of blocks in the optimizer.
msg385043 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-13 15:52
SGTM. But I’m not the one who has to work with it.
Date User Action Args
2021-01-13 15:52:32gvanrossumsetnosy: + gvanrossum
messages: + msg385043
2021-01-13 15:03:23Mark.Shannoncreate