compiler: define atomic intrinsic functions directly

This changes the compiler from treating calls to sync/atomic.* functions
as special calls (emitted directly at the call site) to actually
defining their declarations when there is no Go SSA implementation. And
rely on the inliner to inline these very small functions.
This works a bit better in practice. For example, this makes it possible
to use these functions in deferred function calls.

This commit is a bit large because it also needs to refactor a few
things to make it possible to define such intrinsic functions.
This commit is contained in:
Ayke van Laethem
2022-06-20 14:40:35 +02:00
committed by Ron Evans
parent 6dff85c756
commit e1052f921c
5 changed files with 87 additions and 38 deletions
+11
View File
@@ -81,6 +81,9 @@ func main() {
// test atomic.Value load/store operations
testValue(int(3), int(-2))
testValue("", "foobar", "baz")
// Test atomic operations as deferred values.
testDefer()
}
func testValue(values ...interface{}) {
@@ -93,3 +96,11 @@ func testValue(values ...interface{}) {
}
}
}
func testDefer() {
n1 := int32(5)
defer func() {
println("deferred atomic add:", n1)
}()
defer atomic.AddInt32(&n1, 3)
}
+1
View File
@@ -33,3 +33,4 @@ StoreUint32: 20
StoreUint64: 20
StoreUintptr: 20
StorePointer: true
deferred atomic add: 8