Skip to content

[RegAllocFast] Document the allocation algorithm. NFC - #219835

Open
MaskRay wants to merge 8 commits into
llvm:mainfrom
MaskRay:pr/rafast-comments
Open

[RegAllocFast] Document the allocation algorithm. NFC#219835
MaskRay wants to merge 8 commits into
llvm:mainfrom
MaskRay:pr/rafast-comments

Conversation

@MaskRay

@MaskRay MaskRay commented Aug 30, 2026

Copy link
Copy Markdown
Member

Add a file-level overview: block-local allocation, a stack slot for every
value crossing a block boundary, no liveness analysis or coalescing, and a
backward walk where uses acquire registers and defs release them.

Correct two stale claims: RegUnitStates is indexed by register unit, not
by physical register, and allocateInstruction() runs eight phases rather
than the two its comment described.

Drop a redundant local in reloadAtBegin(), and assert the def operand
that isTiedToNotUndef() documents.

Aided by Opus 5

RegUnitStates is indexed by register unit, not by physical register, and
holds a tagged union whose default case is a virtual register number.
Record why that cannot collide with the RegUnitState enumerators, and
that regLiveIn is a reloadAtBegin() scratch marker the backward walk
never observes.

allocateInstruction() described itself as a two-step algorithm while the
body runs eight phases in a different order; list the phases and the
constraints that fix their order.

LiveOut and Reloaded are the two reasons a def must spill.

Drop a redundant local in reloadAtBegin().

Aided by Opus 5

@nkotikal nkotikal 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.

Most of the changes make sense and are helpful, but I'm a bit concerned about scope here, as the changes seem a bit scattered (especially removing the P.PhysReg local variable).

I do agree that it's redundant but doesn't seem like it follows this PR's overall documentation theme.

Comment thread llvm/lib/CodeGen/RegAllocFast.cpp Outdated

// Returns true if MO is tied and the operand it's tied to is not Undef (not
// Undef is not the same thing as Def).
// Returns true if MO is tied to an operand that is not undef.

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.

Do you think it's worth keeping the notUndef != Def line for clarity?

@MaskRay MaskRay Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The original comment parses badly.

How about // Returns true if MO is tied to an operand that is not undef. A tie to an undef operand carries no value, so such a def needs no live-through handling.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Better comment.

// Returns true if this def (MO) ties to a use that actually carries a value
// (not undef).

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.

That makes sense, lgtm

@MaskRay

MaskRay commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

Most of the changes make sense and are helpful, but I'm a bit concerned about scope here, as the changes seem a bit scattered (especially removing the P.PhysReg local variable).

I do agree that it's redundant but doesn't seem like it follows this PR's overall documentation theme.

The MCRegister Reg = P.PhysReg; cleanup is a small change that is not worth a dedicated commit...

@MaskRay MaskRay changed the title [RegAllocFast] Document the allocator state and operand phases. NFC [RegAllocFast] Document the allocation algorithm. NFC Sep 2, 2026
@arsenm

arsenm commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Most of the changes make sense and are helpful, but I'm a bit concerned about scope here, as the changes seem a bit scattered (especially removing the P.PhysReg local variable).
I do agree that it's redundant but doesn't seem like it follows this PR's overall documentation theme.

The MCRegister Reg = P.PhysReg; cleanup is a small change that is not worth a dedicated commit...

Disagree, I don't want to see any code changes in a documentation commit

@MaskRay

MaskRay commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Most of the changes make sense and are helpful, but I'm a bit concerned about scope here, as the changes seem a bit scattered (especially removing the P.PhysReg local variable).
I do agree that it's redundant but doesn't seem like it follows this PR's overall documentation theme.

The MCRegister Reg = P.PhysReg; cleanup is a small change that is not worth a dedicated commit...

Disagree, I don't want to see any code changes in a documentation commit

OK, I can extract it with the assert to a separate cleanup, but with how bad our stacked PR story is I'd like to know whether the code change or documentation change is acceptable first...

@MaskRay

MaskRay commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Most of the changes make sense and are helpful, but I'm a bit concerned about scope here, as the changes seem a bit scattered (especially removing the P.PhysReg local variable).
I do agree that it's redundant but doesn't seem like it follows this PR's overall documentation theme.

The MCRegister Reg = P.PhysReg; cleanup is a small change that is not worth a dedicated commit...

Disagree, I don't want to see any code changes in a documentation commit

OK, I can extract it with the assert to a separate cleanup, but with how bad our stacked PR story is I'd like to know whether the code change or documentation change is acceptable first...

Extracted to #221120

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants