This is an archive of the discontinued LLVM Phabricator instance.

[LLDB] Add an llvm::Optional version of GetRegisterInfo
ClosedPublic

Authored by DavidSpickett on Sep 23 2022, 7:56 AM.

Details

Summary

We have some 500 ish uses of the bool plus ref version
so changing them all at once isn't a great idea.

This adds an overload that doesn't take a RegisterInfo&
and returns an optional.

Once I'm done switching all the existing callers I'll
remove the original function.

Benefits of optional over bool plus ref:

  • The intent of the function is clear from the prototype.
  • It's harder to forget to check if the return is valid, and if you do you'll get an assert.
  • You don't hide ununsed variables, which happens because passing by ref marks a variable used.
  • You can't forget to reset the RegisterInfo in between calls.

Diff Detail

Event Timeline

DavidSpickett created this revision.Sep 23 2022, 7:56 AM
DavidSpickett requested review of this revision.Sep 23 2022, 7:56 AM
DavidSpickett added a reviewer: clayborg.EditedSep 23 2022, 8:04 AM
DavidSpickett added a subscriber: clayborg.

@clayborg As promised on https://reviews.llvm.org/D134041.

The strategy is:

  • Make the original function concrete and have it call the optional version.
  • Derived classes implement the optional version.
  • One by one (or rather, manageable patch by manageable patch) switch the callers to the optional version.
  • Remove the original function.

I've stacked the changes to do that onto this one, lldb is buildable and passes tests at all points. ARM is by far the largest, even if it is fairly mechanical changes.

You'll see some dodgy stuff like &(*info) because some APIs want a RegisterInfo*, but that's another rabbit hole I do want to look at but not here.

DavidSpickett edited the summary of this revision. (Show Details)Sep 23 2022, 8:07 AM

I appreciate this is a lot of churn for code that likely "just works" (or in reality, "isn't used very often") but with the recent riscv changes I'd like to modernise this area where possible. If this is too much at least I know to look for smaller opportunities in future.

clayborg accepted this revision.Sep 23 2022, 12:36 PM
This revision is now accepted and ready to land.Sep 23 2022, 12:36 PM