-
Notifications
You must be signed in to change notification settings - Fork 981
createInlineAsm:avoid mapupdate collect after call #5009
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
luoliwoshang
wants to merge
2
commits into
tinygo-org:dev
Choose a base branch
from
luoliwoshang:fix-asmfull-mapupdate-bug
base: dev
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.
+99
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,21 @@ | ||
package main | ||
|
||
import "device" | ||
|
||
// Test the specific bug case: AsmFull should use call-time input register value (42), not post-call value (44) | ||
func testAsmFullBug() uintptr { | ||
place := make(map[string]interface{}) | ||
place["input"] = uint32(42) | ||
|
||
// This should use input=42 at call time, return the moved value | ||
result := device.AsmFull("mov {}, {input}", place) | ||
|
||
// This update should NOT affect the AsmFull result (was the bug) | ||
place["input"] = uint32(44) | ||
|
||
return result | ||
} | ||
|
||
func main() { | ||
_ = testAsmFullBug() | ||
} |
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,73 @@ | ||
; ModuleID = 'asmfull_bug.go' | ||
source_filename = "asmfull_bug.go" | ||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" | ||
target triple = "wasm32-unknown-wasi" | ||
|
||
%runtime._interface = type { ptr, ptr } | ||
|
||
@"reflect/types.type:basic:uint32" = linkonce_odr constant { i8, ptr } { i8 -54, ptr @"reflect/types.type:pointer:basic:uint32" }, align 4 | ||
@"reflect/types.type:pointer:basic:uint32" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:basic:uint32" }, align 4 | ||
@"main$string" = internal unnamed_addr constant [5 x i8] c"input", align 1 | ||
@"main$string.1" = internal unnamed_addr constant [5 x i8] c"input", align 1 | ||
|
||
; Function Attrs: allockind("alloc,zeroed") allocsize(0) | ||
declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 | ||
|
||
declare void @runtime.trackPointer(ptr nocapture readonly, ptr, ptr) #1 | ||
|
||
; Function Attrs: nounwind | ||
define hidden void @main.init(ptr %context) unnamed_addr #2 { | ||
entry: | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind | ||
define hidden i32 @main.testAsmFullBug(ptr %context) unnamed_addr #2 { | ||
entry: | ||
%hashmap.value1 = alloca %runtime._interface, align 8 | ||
%hashmap.value = alloca %runtime._interface, align 8 | ||
%stackalloc = alloca i8, align 1 | ||
%0 = call ptr @runtime.hashmapMake(i32 8, i32 8, i32 8, i8 1, ptr undef) #4 | ||
call void @runtime.trackPointer(ptr %0, ptr nonnull %stackalloc, ptr undef) #4 | ||
call void @runtime.trackPointer(ptr nonnull @"reflect/types.type:basic:uint32", ptr nonnull %stackalloc, ptr undef) #4 | ||
call void @runtime.trackPointer(ptr nonnull inttoptr (i32 42 to ptr), ptr nonnull %stackalloc, ptr undef) #4 | ||
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %hashmap.value) | ||
store ptr @"reflect/types.type:basic:uint32", ptr %hashmap.value, align 4 | ||
%hashmap.value.repack2 = getelementptr inbounds i8, ptr %hashmap.value, i32 4 | ||
store ptr inttoptr (i32 42 to ptr), ptr %hashmap.value.repack2, align 4 | ||
call void @runtime.hashmapStringSet(ptr %0, ptr nonnull @"main$string", i32 5, ptr nonnull %hashmap.value, ptr undef) #4 | ||
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %hashmap.value) | ||
%1 = call i32 asm sideeffect "mov $0, ${1}", "=&r,r"(i32 42) #4 | ||
call void @runtime.trackPointer(ptr nonnull @"reflect/types.type:basic:uint32", ptr nonnull %stackalloc, ptr undef) #4 | ||
call void @runtime.trackPointer(ptr nonnull inttoptr (i32 44 to ptr), ptr nonnull %stackalloc, ptr undef) #4 | ||
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %hashmap.value1) | ||
store ptr @"reflect/types.type:basic:uint32", ptr %hashmap.value1, align 4 | ||
%hashmap.value1.repack3 = getelementptr inbounds i8, ptr %hashmap.value1, i32 4 | ||
store ptr inttoptr (i32 44 to ptr), ptr %hashmap.value1.repack3, align 4 | ||
call void @runtime.hashmapStringSet(ptr %0, ptr nonnull @"main$string.1", i32 5, ptr nonnull %hashmap.value1, ptr undef) #4 | ||
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %hashmap.value1) | ||
ret i32 %1 | ||
} | ||
|
||
declare ptr @runtime.hashmapMake(i32, i32, i32, i8, ptr) #1 | ||
|
||
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) | ||
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3 | ||
|
||
declare void @runtime.hashmapStringSet(ptr dereferenceable_or_null(40), ptr, i32, ptr, ptr) #1 | ||
|
||
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) | ||
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3 | ||
|
||
; Function Attrs: nounwind | ||
define hidden void @main.main(ptr %context) unnamed_addr #2 { | ||
entry: | ||
%0 = call i32 @main.testAsmFullBug(ptr undef) | ||
ret void | ||
} | ||
|
||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" } | ||
attributes #1 = { "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" } | ||
attributes #2 = { nounwind "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" } | ||
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } | ||
attributes #4 = { nounwind } |
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.
Instead of extracting
collectInlineAsmRegisters
, why not name the outer loop and usebreak <name>
? Something like: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.
Thanks for the great suggestion! You're absolutely right - using labeled break is cleaner and more idiomatic. I've updated the code accordingly. I initially went with function extraction due to personal preference, but your approach is definitely better with fewer code changes. Thanks for the review!