Skip to content

backend: add multi-block support to RA - #6217

Open
tobiasgrosser wants to merge 12 commits into
mainfrom
tobias/ra_multi_bb
Open

backend: add multi-block support to RA#6217
tobiasgrosser wants to merge 12 commits into
mainfrom
tobias/ra_multi_bb

Conversation

@tobiasgrosser

@tobiasgrosser tobiasgrosser commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR is a simple test to see if a PO walk would give us a baseline register allocator for multiple blocks.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.89%. Comparing base (14f06c1) to head (92be932).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6217      +/-   ##
==========================================
+ Coverage   86.88%   86.89%   +0.01%     
==========================================
  Files         430      430              
  Lines       64394    64419      +25     
  Branches     7385     7390       +5     
==========================================
+ Hits        55948    55977      +29     
+ Misses       6877     6875       -2     
+ Partials     1569     1567       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread .vscode/launch.json
@tobiasgrosser
tobiasgrosser marked this pull request as ready for review June 25, 2026 13:47
@superlopuh superlopuh changed the title add multi-block support to RA backend: add multi-block support to RA Jun 25, 2026
@superlopuh superlopuh added the backend Compiler backend in xDSL label Jun 25, 2026
Comment thread xdsl/dialects/riscv_cf.py

def allocate_registers(self, allocator: BlockAllocator) -> None:
"""
Allocates registers to the operands of this operation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change the doc string to something like this?

Suggested change
Allocates registers to the operands of this operation.
Allocates registers to the operands of this operation.
The successors must already be allocated, else raises PassFailedException.
Allocates operands corresponding to block arguments to corresponding registers, then allocates rs1 and rs2.

It would be nice to be defensive here to catch cases that aren't yet supported and have a nice error when we hit them.

Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a test with a loop to see what happens there? The reason why we added the live in check was to check that values that are live-in to a loop were fully excluded from the loop body allocation, as they're live until the end of the loop iteration, and not until their last use in lexical order. I'm a little concerned about removing that check entirely, and it feels like having similar logic for cycles in blocks would be wise.

@Samielakkad Samielakkad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multi-block direction makes sense, but I think add_regalloc_stats changed behavior in a surprising way.

Before this PR, stats were computed once after the function block was allocated and one riscv.comment was inserted before the function. Now the stats block sits inside:

for block in PostOrderIterator(func.body.blocks[0]):
    ...
    if add_regalloc_stats:
        ...
        Rewriter.insert_op(..., InsertPoint.before(func))

So a multi-block function will insert one stats comment per block, all before the same function. The stats are also computed over only block.walk() at that point, while the old comment described the whole function allocation.

If the intent is still function-level stats, this probably wants to move back outside the block loop and walk func.body after all blocks are allocated. If block-level stats are intended, the comment text should probably include the block name/order so repeated comments are interpretable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Compiler backend in xDSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants