Skip to content
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

dialects/riscv: Add liveness block naive register allocation strategy #1220

Merged
merged 10 commits into from Jul 7, 2023

Conversation

compor
Copy link
Collaborator

@compor compor commented Jun 30, 2023

This PR adds a liveness use-def register allocation strategy that works on blocks.
It traverses the use-def SSA chain backwards (i.e., from uses to defs) and

  1. allocates registers for operands
  2. frees registers for results (since that will be the last time they appear when going backwards)
for op in block.walk_reverse():
  for operand in op.operands:
     if operand is not allocated:
          allocate(operand)
  
for result in op.results:
  if result is not allocated:
      allocate(result)
      free_before_next_instruction.append(result)
  else:
      free(result)

@compor compor added the dialects Changes on the dialects label Jun 30, 2023
@compor compor self-assigned this Jun 30, 2023
@compor compor changed the title (riscv) Add liveness block naive register allocation strategy dialects/riscv: Add liveness block naive register allocation strategy Jun 30, 2023
@codecov
Copy link

codecov bot commented Jun 30, 2023

Codecov Report

Patch coverage: 87.27% and project coverage change: -0.01 ⚠️

Comparison is base (9a718f6) 88.94% compared to head (d7aa81e) 88.93%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1220      +/-   ##
==========================================
- Coverage   88.94%   88.93%   -0.01%     
==========================================
  Files         175      175              
  Lines       23590    23642      +52     
  Branches     3568     3587      +19     
==========================================
+ Hits        20981    21026      +45     
- Misses       2042     2044       +2     
- Partials      567      572       +5     
Impacted Files Coverage Δ
xdsl/backend/riscv/register_allocation.py 83.65% <86.53%> (+2.17%) ⬆️
xdsl/transforms/riscv_register_allocation.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@compor compor force-pushed the christos/riscv/backwards-block-naive branch from 6f5d6e1 to c694fd1 Compare July 5, 2023 09:36
Copy link
Collaborator

@adutilleul adutilleul left a comment

Choose a reason for hiding this comment

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

LGTM, I feel that more code could be shared amongst all strategies, like for instance having a proper abstraction for a RegisterSet; an helper like walk_blocks would also make the code easier to read but this should be done in other PRs.

@compor
Copy link
Collaborator Author

compor commented Jul 6, 2023

LGTM, I feel that more code could be shared amongst all strategies, like for instance having a proper abstraction for a RegisterSet; an helper like walk_blocks would also make the code easier to read but this should be done in other PRs.

I agree, but not for this PR ;) I'm glad that this makes it obvious though!

@compor compor merged commit e38225e into main Jul 7, 2023
10 checks passed
@compor compor deleted the christos/riscv/backwards-block-naive branch July 7, 2023 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants