-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[opt] Re-work broadenSingleElementStores to use projections. #32318
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef VALIDATION_TEST_SILOPTIMIZER_FOO_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zoecarver Can you change the name of this file to something more meaningful? I didn't notice the name when I was reviewing. |
||
#define VALIDATION_TEST_SILOPTIMIZER_FOO_H | ||
|
||
struct Foo { | ||
int x; | ||
~Foo() {} | ||
}; | ||
|
||
struct Loadable { | ||
int x; | ||
}; | ||
|
||
struct Bar { | ||
Loadable y; | ||
~Bar() {} | ||
}; | ||
|
||
#endif // VALIDATION_TEST_SILOPTIMIZER_FOO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Foo { | ||
header "foo.h" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// RUN: %target-sil-opt -silgen-cleanup %s -I %S/Inputs -enable-sil-verify-all -enable-cxx-interop | %FileCheck %s | ||
|
||
sil_stage canonical | ||
|
||
import Builtin | ||
import Swift | ||
import SwiftShims | ||
import Foo | ||
|
||
// Make sure we don't try to create a struct here. Foo is not loadable, even | ||
// though it's only property is. | ||
// CHECK-LABEL: @test_foo | ||
// CHECK: bb0 | ||
// CHECK-NEXT: [[E:%.*]] = struct_element_addr | ||
// CHECK-NEXT: store %1 to [trivial] [[E]] | ||
// CHECK-NEXT: tuple | ||
// CHECK-NEXT: return | ||
// CHECK-LABEL: end sil function 'test_foo' | ||
sil shared [transparent] [serializable] [ossa] @test_foo : $@convention(method) (Int32, @thin Foo.Type) -> @out Foo { | ||
bb0(%0 : $*Foo, %1 : $Int32, %2 : $@thin Foo.Type): | ||
%3 = struct_element_addr %0 : $*Foo, #Foo.x | ||
store %1 to [trivial] %3 : $*Int32 | ||
%5 = tuple () | ||
return %5 : $() | ||
} | ||
|
||
// Make sure we create a struct for the first (loadable) type but not the second | ||
// type (Bar). | ||
// CHECK-LABEL: @test_bar | ||
// CHECK: bb0 | ||
// CHECK-NEXT: [[E:%.*]] = struct_element_addr | ||
// CHECK-NEXT: [[AGG:%.*]] = struct $Loadable (%1 : $Int32) | ||
// CHECK-NEXT: store [[AGG]] to [trivial] [[E]] | ||
// CHECK-NEXT: tuple | ||
// CHECK-NEXT: return | ||
// CHECK-LABEL: end sil function 'test_bar' | ||
sil shared [transparent] [serializable] [ossa] @test_bar : $@convention(method) (Int32, @thin Bar.Type) -> @out Bar { | ||
bb0(%0 : $*Bar, %1 : $Int32, %2 : $@thin Bar.Type): | ||
%3 = struct_element_addr %0 : $*Bar, #Bar.y | ||
%3a = struct_element_addr %3 : $*Loadable, #Loadable.x | ||
store %1 to [trivial] %3a : $*Int32 | ||
%5 = tuple () | ||
return %5 : $() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atrick what do you think about supporting opaque types here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What cases are you trying to handle by doing that? Can you find out if it's possible to have
baseAddrType.isLoadable(*f) == true
AND
baseAddrType.aggregateHasUnreferenceableStorage() == false
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
baseAddrType.isLoadable(*f) && baseAddrType.aggregateHasUnreferenceableStorage() == true
? If not, I think that's most loadable types.I think if we have a trivial struct with a bitfield that would do it:
struct Foo { int x : 3; };
. That struct will be loadable (even though, maybe it shouldn't be) but will also have un-referenceable storage (x).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so what case are you trying to handle? A struct with a single opaque property? So that "store" would need to actually be a
copy_addr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atrick my understanding is that has unreferencable storage is for things from c/c++ that have memory/other things that are not exposed to swift. To me it is sort of like an early, hacky resilience-esque sort of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not trying to handle any particular case. Currently, we will bail on opaque types. I just wanted to make sure that's the correct behavior.
I think this is true, yes. But most non-loadable types are non-loadable for ABI reasons, or to make sure calling conventions work with the C++ definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLoadable seems like a sensible bailout considering we're dealing with storing values at its address