This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Only expose getXXXSize functions in TypeSize
ClosedPublic

Authored by gchatelet on Jan 6 2023, 6:50 AM.

Details

Summary

Currently 'TypeSize' exposes two functions that serve the same purpose:

  • getFixedSize / getFixedValue
  • getKnownMinSize / getKnownMinValue

source : https://github.com/llvm/llvm-project/blob/bf82070ea465969e9ae86a31dfcbf94c2a7b4c4c/llvm/include/llvm/Support/TypeSize.h#L337-L338

This patch offers to remove one of the two and stick to a single function in the code base.

Diff Detail

Event Timeline

gchatelet created this revision.Jan 6 2023, 6:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2023, 6:50 AM
gchatelet requested review of this revision.Jan 6 2023, 6:50 AM
sdesmalen added inline comments.Jan 6 2023, 7:01 AM
llvm/include/llvm/Support/TypeSize.h
319–322

They're both only used once below, so I think you can remove the private interface and just call the parent class' method directly?

gchatelet marked an inline comment as done.Jan 6 2023, 7:05 AM
gchatelet added inline comments.
llvm/include/llvm/Support/TypeSize.h
319–322

I could but then the methods would still be visible. Another option is to mark the functions protected in FixedOrScalableQuantity and make them public only in ElementCount.

sdesmalen accepted this revision.Jan 6 2023, 7:12 AM
sdesmalen added inline comments.
llvm/include/llvm/Support/TypeSize.h
319–322

Ah of course, I didn't realise they were inherited. In that case I'm happy with this approach, because for TypeSize we made a stylistic exception to have something called getKnownMinSize, whereas in other circumstances the default getKnownMinValue is appropriate.

This revision is now accepted and ready to land.Jan 6 2023, 7:12 AM
gchatelet updated this revision to Diff 486872.Jan 6 2023, 7:19 AM
gchatelet marked an inline comment as done.
  • Make functions private with the using keyword
gchatelet added inline comments.Jan 6 2023, 7:21 AM
llvm/include/llvm/Support/TypeSize.h
319–322

I forgot that I could use using to make the functions private. It's better than redefining them.

Thx for the review @sdesmalen

I think we should keep a single one, but just to bikeshed, a TypeSize has a Value, not a Size, so I would keep getFixedValue.

llvm/include/llvm/Support/TypeSize.h
319–322

Well that does not really make it private because you can cast to base and call.

This revision was landed with ongoing or failed builds.Jan 6 2023, 7:25 AM
This revision was automatically updated to reflect the committed changes.
gchatelet reopened this revision.Jan 6 2023, 7:30 AM

I've reverted the patch so we can discuss further whether we want to keep the Size version of the Value version.

This revision is now accepted and ready to land.Jan 6 2023, 7:30 AM
foad added a comment.Jan 6 2023, 7:40 AM

This caused a build failure in clang: lib/CodeGen/CGDecl.cpp:1344:46: error: 'getFixedValue' is a private member of 'llvm::TypeSize'

This caused a build failure in clang: lib/CodeGen/CGDecl.cpp:1344:46: error: 'getFixedValue' is a private member of 'llvm::TypeSize'

Yep just noticed as well, thx for the heads up @foad.

sdesmalen@ do you feel strongly about the getXXXSize version of the functions?
I tend to agree with courbet@ that getXXXValue is more correct (semantically speaking). Also it makes the implementation simpler.

gchatelet updated this revision to Diff 487333.Jan 9 2023, 1:35 AM

rebase after revert

sdesmalen added a comment.EditedJan 9 2023, 1:36 AM

sdesmalen@ do you feel strongly about the getXXXSize version of the functions?
I tend to agree with courbet@ that getXXXValue is more correct (semantically speaking). Also it makes the implementation simpler.

I agree that having one interface for the same thing is better than two, so dropping the getXXXSize() interfaces in favour of getXXXValue() makes sense to me. Thanks for checking!

gchatelet updated this revision to Diff 487339.Jan 9 2023, 1:53 AM
  • Fix missing clang change
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 1:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I've created https://reviews.llvm.org/D141267 to get a feel of what it looks like to only keep the Size version.

gchatelet closed this revision.Jan 12 2023, 1:28 AM

So i've submitted the following patches which remove the usage of TypeSize::getFixedSize() and TypeSize::getKnownMinSize()

  • rG6916ebd02650: [clang][NFC] Use the TypeSize::getXXXValue() instead of TypeSize::getXXXSize).Wed, Jan 11, 5:08 PM
  • rGca8485578652: [mlir][NFC] Use TypeSize::getFixedValue() instead of TypeSize::getFixedSize().Wed, Jan 11, 5:22 PM
  • rGfbd207fd6f6b: [NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize().Wed, Jan 11, 5:29 PM
  • rG48f5d77eeed4: [NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize().Wed, Jan 11, 5:37 PM
  • rG8fd5558b2976: [NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize().Wed, Jan 11, 5:49 PM

I've also marked the functions deprecated so downstream users can fix their codebase.

  • rG1dcaa2bdf230: Marking TypeSize getFixedSize() and getKnownMinSize() deprecated.

I'm marking this patch as closed.