-
Notifications
You must be signed in to change notification settings - Fork 49
ltoplugin: preserve names for shared sret slots #2345
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
Open
zhouguangyuan0718
wants to merge
1
commit into
xgo-dev:main
Choose a base branch
from
zhouguangyuan0718:codex/fix-lto-shared-sret
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| ; RUN: opt -load-pass-plugin=%plugin -passes=llgo-lto-pre-globaldce -S %s | FileCheck %s | ||
|
|
||
| target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
|
|
||
| %reflect.Value = type { ptr } | ||
|
|
||
| @query = private unnamed_addr constant [5 x i8] c"Query" | ||
| @mutation = private unnamed_addr constant [8 x i8] c"Mutation" | ||
| @subscription = private unnamed_addr constant [12 x i8] c"Subscription" | ||
|
|
||
| declare void @reflect.Value.MethodByName(ptr sret(%reflect.Value), ptr, i64) | ||
| declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata) | ||
| declare void @llvm.assume(i1) | ||
|
|
||
| define void @shared_sret(ptr %receiver) { | ||
| entry: | ||
| %ret = alloca %reflect.Value | ||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @query, i64 5) #0 | ||
| %query.fn = load ptr, ptr %ret | ||
| %query.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %query.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %query.ok = extractvalue { ptr, i1 } %query.checked, 1 | ||
| call void @llvm.assume(i1 %query.ok) | ||
|
|
||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @mutation, i64 8) #0 | ||
| %mutation.fn = load ptr, ptr %ret | ||
| %mutation.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %mutation.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %mutation.ok = extractvalue { ptr, i1 } %mutation.checked, 1 | ||
| call void @llvm.assume(i1 %mutation.ok) | ||
|
|
||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @subscription, i64 12) #0 | ||
| %subscription.fn = load ptr, ptr %ret | ||
| %subscription.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %subscription.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %subscription.ok = extractvalue { ptr, i1 } %subscription.checked, 1 | ||
| call void @llvm.assume(i1 %subscription.ok) | ||
| ret void | ||
| } | ||
|
|
||
| define void @shared_sret_unknown(ptr %receiver, ptr %dynamic.name, i64 %dynamic.len) { | ||
| entry: | ||
| %ret = alloca %reflect.Value | ||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @query, i64 5) #0 | ||
| %query.fn = load ptr, ptr %ret | ||
| %query.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %query.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %query.ok = extractvalue { ptr, i1 } %query.checked, 1 | ||
| call void @llvm.assume(i1 %query.ok) | ||
|
|
||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" %dynamic.name, i64 %dynamic.len) #0 | ||
| %dynamic.fn = load ptr, ptr %ret | ||
| %dynamic.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %dynamic.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %dynamic.ok = extractvalue { ptr, i1 } %dynamic.checked, 1 | ||
| call void @llvm.assume(i1 %dynamic.ok) | ||
| ret void | ||
| } | ||
|
|
||
| define void @shared_sret_duplicate(ptr %receiver) { | ||
| entry: | ||
| %ret = alloca %reflect.Value | ||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @query, i64 5) #0 | ||
| %first.fn = load ptr, ptr %ret | ||
| %first.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %first.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %first.ok = extractvalue { ptr, i1 } %first.checked, 1 | ||
| call void @llvm.assume(i1 %first.ok) | ||
|
|
||
| call void @reflect.Value.MethodByName(ptr sret(%reflect.Value) %ret, ptr "llgo.reflect.methodbyname.name"="1" @query, i64 5) #0 | ||
| %second.fn = load ptr, ptr %ret | ||
| %second.checked = call { ptr, i1 } @llvm.type.checked.load(ptr %second.fn, i32 0, metadata !"go.method.value.reflect") | ||
| %second.ok = extractvalue { ptr, i1 } %second.checked, 1 | ||
| call void @llvm.assume(i1 %second.ok) | ||
| ret void | ||
| } | ||
|
|
||
| ; CHECK-LABEL: define void @shared_sret( | ||
| ; CHECK: call void @reflect.Value.MethodByName({{.*}}@query | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Query") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Mutation") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Subscription") | ||
| ; CHECK: call void @reflect.Value.MethodByName({{.*}}@mutation | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Query") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Mutation") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Subscription") | ||
| ; CHECK: call void @reflect.Value.MethodByName({{.*}}@subscription | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Query") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Mutation") | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Subscription") | ||
| ; CHECK-NOT: !"go.method.value.reflect" | ||
|
|
||
| ; CHECK-LABEL: define void @shared_sret_unknown( | ||
| ; CHECK-NOT: !"go.method.value.reflect.Query" | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect") | ||
| ; CHECK-NOT: !"go.method.value.reflect.Query" | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect") | ||
| ; CHECK-NOT: !"go.method.value.reflect.Query" | ||
| ; CHECK: ret void | ||
|
|
||
| ; CHECK-LABEL: define void @shared_sret_duplicate( | ||
| ; CHECK: call void @reflect.Value.MethodByName({{.*}}@query | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Query") | ||
| ; CHECK-NOT: !"go.method.value.reflect.Query" | ||
| ; CHECK: call void @reflect.Value.MethodByName({{.*}}@query | ||
| ; CHECK: @llvm.type.checked.load({{.*}}!"go.method.value.reflect.Query") | ||
| ; CHECK-NOT: !"go.method.value.reflect.Query" | ||
| ; CHECK: ret void | ||
|
|
||
| attributes #0 = { "llgo.reflect.methodbyname"="value" } |
Oops, something went wrong.
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.
Behavior note:
MaxReflectMethodNames(32) is now applied to the union of names across the whole shared group, not per call. A shared slot with several calls whose combined unique names exceed 32 will hit the cap inaddName, setKnownNames=false, and refine none of them (falling back to the generic marker). This is safe/conservative, but the shared budget is a subtle change from the previous per-call limit — worth a one-line comment here so a future maintainer isn't surprised.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.
Added a comment that the bounded name budget applies to the combined shared group and that exceeding it preserves the generic markers.