This is an archive of the discontinued LLVM Phabricator instance.

Register/MCRegister: Add conversion operators to avoid use of implicit convert to unsigned. NFC
ClosedPublic

Authored by dsanders on Aug 2 2019, 3:00 PM.

Details

Summary

This has no functional effect but makes it more obvious which parts of the
compiler do not use Register/MCRegister when you mark the implicit conversion
deprecated.

Implicit conversions for comparisons accounted for ~20% (~3k of ~13k) of
the implicit conversions when I first measured it. I haven't maintained
those numbers as other patches have landed though so it may be out of date.

Event Timeline

dsanders created this revision.Aug 2 2019, 3:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2019, 3:00 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Aug 4 2019, 8:36 PM
llvm/include/llvm/CodeGen/Register.h
127–128

Why are both the signed and unsigned versions necessary?

dsanders marked an inline comment as done.Aug 5 2019, 11:36 AM
dsanders added inline comments.
llvm/include/llvm/CodeGen/Register.h
127–128

For the unsigned case, it's because it can't tell which operator to use for MCRegister == unsigned. It can do either:

  • MCRegister::operator==(*this, MCRegister(Other))
  • or, unsigned::operator==(unsigned(*this), Other)

For the signed case, it's the same problem but the operator==(MCRegister, unsigned) is also a candidate

https://godbolt.org/z/8JMcTs

arsenm accepted this revision.Aug 5 2019, 11:41 AM

LGTM

This revision is now accepted and ready to land.Aug 5 2019, 11:41 AM
This revision was automatically updated to reflect the committed changes.

The windows bot for LLDB is still broken after the partial fix for the breakage:

http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/7472

The windows bot for LLDB is still broken after the partial fix for the breakage:

http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/7472

Sorry about that. I thought I'd pushed a revert of both commits about an hour ago but I hadn't noticed that terminal was waiting for my password.

dsanders marked an inline comment as done.Aug 5 2019, 5:54 PM
dsanders added inline comments.
llvm/include/llvm/CodeGen/Register.h
127–128

It turns out MSVC needed one for unsigned short (MCPhysReg) too. That change has been made in the re-commit (r367965) but I should mention that I also moved MCPhysReg's declaration to MCRegister.h so that it can use the real name.