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

[RTG] Add simple linear scan register allocation pass #8058

Open
wants to merge 1 commit into
base: maerhart-rtg-emit-assembly
Choose a base branch
from

Conversation

maerhart
Copy link
Member

@maerhart maerhart commented Jan 9, 2025

No description provided.

@maerhart maerhart added the RTG Involving the `rtg` dialect label Jan 9, 2025
@maerhart maerhart requested a review from darthscsi January 9, 2025 21:53
@maerhart maerhart force-pushed the maerhart-rtg-emit-assembly branch from 44b5801 to babe1f2 Compare January 9, 2025 22:01
@maerhart maerhart force-pushed the maerhart-rtg-register-allocation-pass branch from 1c09e5a to 1b0c7ae Compare January 9, 2025 22:03
@maerhart maerhart force-pushed the maerhart-rtg-emit-assembly branch from babe1f2 to 8ed5c6e Compare January 21, 2025 11:02
@maerhart maerhart force-pushed the maerhart-rtg-register-allocation-pass branch from 1b0c7ae to 16bd532 Compare January 21, 2025 11:06
Copy link
Contributor

@darthscsi darthscsi left a comment

Choose a reason for hiding this comment

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

LGTM. Obviously this will evolve and get a bit more sophisticated, but looks good for now.

LLVM_DEBUG(llvm::dbgs() << "=== Processing test @" << testOp.getSymName()
<< "\n\n");

DenseMap<Operation *, unsigned> opIndices;
Copy link
Contributor

Choose a reason for hiding this comment

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

mlir has an index value built into operations. I think it is only relative to a single block. It's used/updated by dominance analysis.

return signalPassFailure();
}

// TODO: support labels and control-flow loops (jumps in general)
Copy link
Contributor

Choose a reason for hiding this comment

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

yea, this is interesting. We need to be able to deal with fixed-value jumps, jumptables, label relative jumps, etc. We will probably need an op interface for this. Something to resolve computed live ranges.


// Handle virtual registers.
rtg::RegisterAttrInterface availableReg;
for (auto reg : lr->regOp.getAllowedRegs()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we prioritizing/ordering registers just by their declaration order or by their index? Presumably things like stack pointers should be picked last and temporary (ABI-wise) registers picked first? Obviously this shouldn't be required, but if we want to simplify entry/exit (and temporary entry/exit for calls) into tests, this might be good.

Also might be good to know what registers are touched in a region, but maybe that is an analysis later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, registers earlier in the allowedRegisters attribute are picked first, so helper functions can be created by the payload dialect writers that add all legal registers to this list in the priority order they prefer. But we can always change that to be specified by a Dialect interface.

Yes, an analysis to check which fixed registers are already in use in the region would allow better allocation and I'm planning to add that some time later. It's not critical right now and keeps this PR simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RTG Involving the `rtg` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants