This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2021-01-13 15:03 by Mark.Shannon, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31116 closed iritkatriel, 2022-02-03 22:11
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
2022-04-11 14:59:40adminsetgithub: 87092
2022-02-03 22:11:26iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29298
2022-01-26 18:26:39iritkatrielsetnosy: + iritkatriel
2022-01-26 18:08:42brandtbuchersetnosy: + brandtbucher
2022-01-26 17:42:04corona10setnosy: + corona10
2021-01-13 15:52:32gvanrossumsetnosy: + gvanrossum
messages: + msg385043
2021-01-13 15:03:23Mark.Shannoncreate