Skip to content

[SIL] NFC: Shrink SILGlobalVariable by 16 bytes #32135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2020

Conversation

davezarzycki
Copy link
Contributor

There are two changes here. One is simply moving a boolean. The other involves a specialization of llvm::Optional for SILLocation. This seems to tantalizingly close. When optimizations are enabled, only two tests fail but without optimizations, the Glibc swift module fails to build. Before I debug this further, is this a good idea? This technically collapses a level of optionality.

eeckstein
eeckstein previously approved these changes Jun 2, 2020
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@davezarzycki
Copy link
Contributor Author

Thanks @eeckstein – I was concerned because it looks like llvm::Optional doesn't specialize pointers, which seems like both an obvious optimization and an obvious correctness goal.

@gribozavr
Copy link
Contributor

Is llvm::Optional intended to be specialized like this? I'm concerned we would be forking its API inadvertently, because nothing forces us to keep this copy in sync.

@davezarzycki
Copy link
Contributor Author

Hi @gribozavr – Ya, that's my concern as well and the lack of a pointer specialization was hint that llvm::Optional isn't designed to be specialized (which is disappointing). Who might know the answer?

@davezarzycki davezarzycki requested review from jckarter and removed request for jckarter June 4, 2020 12:47
@jckarter
Copy link
Contributor

jckarter commented Jun 4, 2020

I share @gribozavr's concern. Maybe we can just not use Optional for the storage, and wrap it in Optional via an accessor instead.

@davezarzycki
Copy link
Contributor Author

That was my first choice, but got shy of that approach because it required making SILLocation() public and I figured it was private for a reason. Am I wrong?

@jckarter
Copy link
Contributor

jckarter commented Jun 4, 2020

We could maybe expose it as a static SILLocation invalid() method.

@rjmccall
Copy link
Contributor

rjmccall commented Jun 4, 2020

We could maybe expose it as a static SILLocation invalid() method.

Yeah, I like that plan better than exposing a default constructor.

@davezarzycki davezarzycki marked this pull request as ready for review June 5, 2020 11:09
@davezarzycki
Copy link
Contributor Author

@swift-ci please test

@davezarzycki davezarzycki requested a review from eeckstein June 5, 2020 11:10
@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

Build failed
Swift Test OS X Platform
Git Sha - ffc254570364dd60a5b8e4003f3d0dfc2fc2c3d8

@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

Build failed
Swift Test Linux Platform
Git Sha - ffc254570364dd60a5b8e4003f3d0dfc2fc2c3d8

@davezarzycki
Copy link
Contributor Author

Oops. I had to force push an update. I realized after the fact that setLocation() wasn't updating the HasLocation boolean, but as it turns out nothing calls said function, so I just deleted it and made the SILLocation const.

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

Build failed
Swift Test Linux Platform
Git Sha - da60232cf5c3220127bb97cae62a994ac4c03abb

@swift-ci
Copy link
Contributor

swift-ci commented Jun 5, 2020

Build failed
Swift Test OS X Platform
Git Sha - da60232cf5c3220127bb97cae62a994ac4c03abb

@davezarzycki davezarzycki dismissed eeckstein’s stale review June 5, 2020 11:44

A new approach

@davezarzycki
Copy link
Contributor Author

Ping. Now that this has been simplified to the suggested SILLocation::invalid() approach, can I get a LGTM? Thanks :-)

@gribozavr
Copy link
Contributor

@davezarzycki IDK who might know the answer, but since I can't easily find such specializations in LLVM codebase, I think it is safe to say it is not supported. If you are up for a templates programming adventure, you could refactor llvm::Optional to have a traits-based design (like dense map traits) that will allow to optimize the storage without forking the public API.

@davezarzycki
Copy link
Contributor Author

Ya, a "extra inhabitants" trait (like Swift's internal logic for Swift code) would make llvm::Optional far more efficient.

I'm still looking for a LGTM sign off when somebody has the time. In particular, the const'ifying of the SILLocation given that nothing is updating the location after the SILGlobalVariable is created.

@gribozavr
Copy link
Contributor

gribozavr commented Jun 10, 2020

This PR looks good to me, but unfortunately I'm not familiar with this code sufficiently to be comfortable actually approving -- sorry!

@davezarzycki
Copy link
Contributor Author

Ping @jckarter, @eeckstein. Might I get a LGTM review?

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davezarzycki davezarzycki merged commit d9073c8 into swiftlang:master Jun 11, 2020
@davezarzycki davezarzycki deleted the pr32135 branch June 11, 2020 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants