This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Switch FloatModeKind enum class to use bitmask enums
ClosedPublic

Authored by jolanta.jensen on Jun 20 2022, 4:05 AM.

Details

Summary

Using bitmask enums simplifies and clarifies the code.

Diff Detail

Event Timeline

jolanta.jensen created this revision.Jun 20 2022, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 4:05 AM
jolanta.jensen requested review of this revision.Jun 20 2022, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 4:05 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman accepted this revision.Jun 22 2022, 11:47 AM

LGTM aside from a tiny naming nit. Thank you for the cleanup!

clang/include/clang/Basic/TargetInfo.h
896–897

Alternatively, you can get rid of the local variable entirely.

This revision is now accepted and ready to land.Jun 22 2022, 11:47 AM

Removed an unnecessary local variable.

aaron.ballman accepted this revision.Jun 27 2022, 7:25 AM

LGTM, thanks!

aaron.ballman requested changes to this revision.Jun 27 2022, 10:51 AM
aaron.ballman added a subscriber: shafik.
aaron.ballman added inline comments.
clang/include/clang/Basic/TargetInfo.h
225–228

Whoops, I missed this (thanks @shafik for asking me about it in private)!

I believe the original code was setting the field width to be 1 << 5 bits wide instead of specifying it as being 6 bits wide.

This revision now requires changes to proceed.Jun 27 2022, 10:51 AM

Correcting computation of RealTypeUsesObjCFPRetMask.

jolanta.jensen added inline comments.Jun 28 2022, 9:16 AM
clang/include/clang/Basic/TargetInfo.h
225–228

Oh dear, I was to replace log2 with bitWidth and I only did half the job. Thanks for spotting!

aaron.ballman accepted this revision.Jun 28 2022, 12:44 PM

LGTM again, this time for real.

clang/include/clang/Basic/TargetInfo.h
225–228

Yeah, it was a great catch -- the code would have worked, but been space inefficient, which likely would have been a head scratcher for somebody later wondering why the code was written that way. :-)

This revision is now accepted and ready to land.Jun 28 2022, 12:44 PM

@jolanta.jensen, I was on vacation last week and missed my opportunity to comment on this. I know the change has already landed, but I added a few comments anyway.

clang/include/clang/Basic/TargetInfo.h
226–227

I believe this can be simplified to:

: llvm::BitWidth<FloatModeKind>;

(It should never be necessary to reach directly into a "detail" namespace from user code)

896

This again directly uses the "detail" namespace. I think this would be better written as:

return (FloatModeKind)RealTypeUsesObjCFPRetMask & T;
clang/lib/Basic/Targets/X86.h
423–425

Since RealTypeUsesObjCFPRetMask is declared as unsigned, it would be best to cast to unsigned instead of int here.

703

Likewise, cast to unsigned here.

@tahonermann, I addressed your comments in https://reviews.llvm.org/D129373. I just need to remove a tab that crept in and it seems to be more difficult than I thought as my code does not seem to have any tab and reformatting the code does not change the file.