-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement LLVM IR Witness Method Elimination for Swift witness tables. #39287
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
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
// Tests that under -enable-llvm-wme, LLVM GlobalDCE is able to remove unused | ||
// witness methods, and that used witness methods are not removed (by running | ||
// the program). | ||
|
||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-wme %s -emit-ir -o %t/main.ll | ||
// RUN: %target-clang %t/main.ll -isysroot %sdk -L%swift_obj_root/lib/swift/%target-sdk-name -flto -o %t/main | ||
// RUN: %target-run %t/main | %FileCheck %s | ||
|
||
// RUN: %llvm-nm --defined-only %t/main | %FileCheck %s --check-prefix=NM | ||
|
||
// REQUIRES: executable_test | ||
|
||
// Test disabled until LLVM GlobalDCE supports Swift vtables. | ||
// REQUIRES: rdar81868930 | ||
|
||
protocol TheProtocol { | ||
func func1_live() | ||
func func2_dead() | ||
} | ||
|
||
struct MyStruct : TheProtocol { | ||
func func1_live() { print("MyStruct.func1_live") } | ||
func func2_dead() { print("MyStruct.func2_dead") } | ||
} | ||
|
||
let x: TheProtocol = MyStruct() | ||
x.func1_live() | ||
// CHECK: MyStruct.func1_live | ||
|
||
// NM: $s4main8MyStructV10func1_liveyyF | ||
// NM-NOT: $s4main8MyStructV10func2_deadyyF |
This file contains hidden or 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,49 @@ | ||
// Tests that under -enable-llvm-wme, IRGen marks wtables and wcall sites with | ||
// the right attributes and intrinsics. | ||
|
||
// RUN: %target-build-swift -Xfrontend -disable-objc-interop -Xfrontend -enable-llvm-wme \ | ||
// RUN: %s -emit-ir -o - | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize | ||
|
||
protocol TheProtocol { | ||
func func1_live() | ||
func func2_dead() | ||
} | ||
|
||
struct MyStruct : TheProtocol { | ||
func func1_live() { print("MyStruct.func1_live") } | ||
func func2_dead() { print("MyStruct.func2_dead") } | ||
} | ||
|
||
// CHECK: @"$s4main8MyStructVAA11TheProtocolAAWP" = | ||
// CHECK-SAME: i8* bitcast (%swift.protocol_conformance_descriptor* @"$s4main8MyStructVAA11TheProtocolAAMc" to i8*) | ||
// CHECK-SAME: i8* bitcast (void (%T4main8MyStructV*, %swift.type*, i8**)* @"$s4main8MyStructVAA11TheProtocolA2aDP10func1_liveyyFTW" to i8*) | ||
// CHECK-SAME: i8* bitcast (void (%T4main8MyStructV*, %swift.type*, i8**)* @"$s4main8MyStructVAA11TheProtocolA2aDP10func2_deadyyFTW" to i8*) | ||
// CHECK-64-SAME: align 8, !type !0, !type !1, !vcall_visibility !2 | ||
// CHECK-32-SAME: align 4, !type !0, !type !1, !vcall_visibility !2 | ||
|
||
func test1() { | ||
// CHECK: define hidden swiftcc void @"$s4main5test1yyF"() | ||
let x: MyStruct = MyStruct() | ||
x.func1_live() | ||
// CHECK: call swiftcc void @"$s4main8MyStructVACycfC"() | ||
// CHECK-NEXT: call swiftcc void @"$s4main8MyStructV10func1_liveyyF"() | ||
// CHECK-NEXT: ret void | ||
} | ||
|
||
func test2() { | ||
// CHECK: define hidden swiftcc void @"$s4main5test2yyF"() | ||
let x: TheProtocol = MyStruct() | ||
x.func1_live() | ||
// CHECK: [[WTABLE:%.*]] = load i8**, i8*** {{.*}} | ||
// CHECK: [[SLOT:%.*]] = getelementptr inbounds i8*, i8** [[WTABLE]], i32 1 | ||
// CHECK: [[SLOTASPTR:%.*]] = bitcast i8** [[SLOT]] to i8* | ||
// CHECK: call { i8*, i1 } @llvm.type.checked.load(i8* [[SLOTASPTR]], i32 0, metadata !"$s4main11TheProtocolP10func1_liveyyFTq") | ||
} | ||
|
||
// CHECK-64: !0 = !{i64 8, !"$s4main11TheProtocolP10func1_liveyyFTq"} | ||
// CHECK-64: !1 = !{i64 16, !"$s4main11TheProtocolP10func2_deadyyFTq"} | ||
// CHECK-64: !2 = !{i64 1} | ||
|
||
// CHECK-32: !0 = !{i64 4, !"$s4main11TheProtocolP10func1_liveyyFTq"} | ||
// CHECK-32: !1 = !{i64 8, !"$s4main11TheProtocolP10func2_deadyyFTq"} | ||
// CHECK-32: !2 = !{i64 1} |
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.
Do we loose the information that the load is invariant? This could lead to code size losses as compared to the regular mode because redundant loads are not removed.
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 think you're right, we're losing the "invariant" marker here. It's not even a LoadInst anymore, so we can't just add it. But I think it should be possible to improve how LLVM lowers the
@llvm.type.checked.load
call into an actual load, and pass an invariant marker to it that way. But that needs some LLVM support first -- would you be okay if I mentioned it here as a TODO/FIXME comment and left it as a separate improvement to follow up?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.
Sounds good to me.