This is an archive of the discontinued LLVM Phabricator instance.

[MC] Add MCRegisterInfo::regunits for iteration over register units
ClosedPublic

Authored by barannikov88 on Jun 4 2023, 8:36 AM.

Diff Detail

Event Timeline

barannikov88 created this revision.Jun 4 2023, 8:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2023, 8:36 AM

Add template parameter

Add a comment for MCRegUnit (cloned from CodeGenRegisters.h)

barannikov88 published this revision for review.Jun 5 2023, 3:08 AM
barannikov88 added reviewers: foad, qcolombet.
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2023, 3:08 AM
foad added inline comments.Jun 5 2023, 6:27 AM
llvm/include/llvm/MC/MCRegister.h
23–29

Do you need to touch MCRegister.h? There is already an introductory comment like this near the definition of MCRegUnitIterator in MCRegisterInfo.h.

barannikov88 added inline comments.Jun 5 2023, 6:37 AM
llvm/include/llvm/MC/MCRegister.h
23–29

I've always been confused by register units and their difference from physical registers.
This is the first place I'd search for the definition of a register unit.

I'm hoping to turn this typedef into a class for stricter type checking some day.

Use regunits() in two more places

Had a glance at the patch and it looks generally good to me.
One comment below and work with @foad to address his comment.

llvm/include/llvm/MC/MCRegisterInfo.h
250

Could you refactor the code to share the implementation with MCRegUnitIterator::MCRegUnitIterator?
E.g., a static helper function.

barannikov88 added inline comments.Jun 11 2023, 1:26 PM
llvm/include/llvm/MC/MCRegisterInfo.h
250

There is indeed code duplication between mc_*_iterator and MC*Iterator classes. AIUI MC version was supposed to replace mc_ version eventually.
They don't have common base class to extract this to. I tried to address code duplication in D152655, please take a look.

Restore lost comment

Drop inline on declaration

  • Use regunits() in two more places
  • Comment the default constructor
barannikov88 added inline comments.Jun 11 2023, 6:50 PM
llvm/include/llvm/MC/MCRegister.h
23–29

@foad I really think MCRegUnit needs to be documented.
I can move the introductory comment you mentioned here. Would that be ok for you?

foad added inline comments.Jun 12 2023, 7:36 AM
llvm/include/llvm/MC/MCRegister.h
23–29

Sure. The only thing I don't like is having two different introductory comments in two different places.

  • Move the comment about register units to MCRegister.h
  • Add const to iterator value type so that operator-> works
barannikov88 marked 3 inline comments as done.Jun 12 2023, 2:29 PM
barannikov88 added inline comments.
llvm/include/llvm/MC/MCRegister.h
23–29

I've moved the comment from MCRegisterInfo.h here as is.

barannikov88 marked an inline comment as done.

Rebase

foad accepted this revision.Jun 15 2023, 1:42 AM

I think this is a great readability improvement. Thanks! How close are we to being able to remove the old MCRegUnitIterator?

This revision is now accepted and ready to land.Jun 15 2023, 1:42 AM
foad added a comment.Jun 15 2023, 1:47 AM

How close are we to being able to remove the old MCRegUnitIterator?

Sorry, I misunderstood. You are not adding a new regunit iterator, so there is no "old" one to remove.

How close are we to being able to remove the old MCRegUnitIterator?

Sorry, I misunderstood. You are not adding a new regunit iterator, so there is no "old" one to remove.

I am guessing you meant getting rid of the old approach -- constructing an iterator directly from Reg and TRI
and calling isValid() for determining whether we can iterate further. That is, make the iterators more STL-like.
There is only a dozen of such uses left, half of them in MachineCopyPropagation.cpp.
I didn't address them in this patch because they require non-straightforward changes.

This revision was landed with ongoing or failed builds.Jun 15 2023, 7:40 PM
This revision was automatically updated to reflect the committed changes.