diff --git a/cl/_testgo/equal/out.ll b/cl/_testgo/equal/out.ll index fec88027..fdd5222f 100644 --- a/cl/_testgo/equal/out.ll +++ b/cl/_testgo/equal/out.ll @@ -98,6 +98,22 @@ _llgo_0: ret void } +define i64 @"main.init#1$1"(i64 %0, i64 %1) { +_llgo_0: + %2 = add i64 %0, %1 + ret i64 %2 +} + +define void @"main.init#1$2"(ptr %0) { +_llgo_0: + %1 = load { ptr }, ptr %0, align 8 + %2 = extractvalue { ptr } %1, 0 + %3 = load i64, ptr %2, align 4 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + ret void +} + define void @"main.init#2"() { _llgo_0: call void @main.assert(i1 true) @@ -780,21 +796,9 @@ declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplu declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) -define void @"main.init#1$2"(ptr %0) { -_llgo_0: - %1 = load { ptr }, ptr %0, align 8 - %2 = extractvalue { ptr } %1, 0 - %3 = load i64, ptr %2, align 4 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - ret void -} +declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64) -define i64 @"main.init#1$1"(i64 %0, i64 %1) { -_llgo_0: - %2 = add i64 %0, %1 - ret i64 %2 -} +declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) @@ -815,7 +819,3 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Interface"(%"github.com/go declare void @"github.com/goplus/llgo/internal/runtime.InitNamed"(ptr, %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String", ptr, %"github.com/goplus/llgo/internal/runtime.Slice", %"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.init"() - -declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64) - -declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) diff --git a/cl/_testgo/goroutine/out.ll b/cl/_testgo/goroutine/out.ll index 87077df0..ef8f5b75 100644 --- a/cl/_testgo/goroutine/out.ll +++ b/cl/_testgo/goroutine/out.ll @@ -72,10 +72,6 @@ _llgo_3: ; preds = %_llgo_1, %_llgo_0 br i1 %22, label %_llgo_2, label %_llgo_1 } -declare void @"github.com/goplus/llgo/internal/runtime.init"() - -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) - define void @"main.main$1"(ptr %0, %"github.com/goplus/llgo/internal/runtime.String" %1) { _llgo_0: call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %1) @@ -86,6 +82,10 @@ _llgo_0: ret void } +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) + declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) declare ptr @malloc(i64) diff --git a/cl/_testlibgo/sync/out.ll b/cl/_testlibgo/sync/out.ll new file mode 100644 index 00000000..1c8a0e79 --- /dev/null +++ b/cl/_testlibgo/sync/out.ll @@ -0,0 +1 @@ +; \ No newline at end of file diff --git a/cl/_testrt/builtin/out.ll b/cl/_testrt/builtin/out.ll index 858d32ef..74b754b6 100644 --- a/cl/_testrt/builtin/out.ll +++ b/cl/_testrt/builtin/out.ll @@ -613,6 +613,29 @@ _llgo_3: ; preds = %_llgo_1 ret i32 0 } +define void @"main.main$1"() { +_llgo_0: + %0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0 + store ptr @6, ptr %1, align 8 + %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1 + store i64 2, ptr %2, align 4 + %3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + ret void +} + +define void @"main.main$2"(ptr %0) { +_llgo_0: + %1 = load { ptr }, ptr %0, align 8 + %2 = extractvalue { ptr } %1, 0 + %3 = load i64, ptr %2, align 4 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + ret void +} + declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) declare void @"github.com/goplus/llgo/internal/runtime.init"() @@ -664,31 +687,8 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr) declare i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice", ptr, i64, i64) -define void @"main.main$2"(ptr %0) { -_llgo_0: - %1 = load { ptr }, ptr %0, align 8 - %2 = extractvalue { ptr } %1, 0 - %3 = load i64, ptr %2, align 4 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - ret void -} - declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) -define void @"main.main$1"() { -_llgo_0: - %0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0 - store ptr @6, ptr %1, align 8 - %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1 - store i64 2, ptr %2, align 4 - %3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - ret void -} - declare ptr @"github.com/goplus/llgo/internal/runtime.NewStringIter"(%"github.com/goplus/llgo/internal/runtime.String") declare { i1, i64, i32 } @"github.com/goplus/llgo/internal/runtime.StringIterNext"(ptr) diff --git a/cl/_testrt/closure/out.ll b/cl/_testrt/closure/out.ll index 326344f3..88e47a5c 100644 --- a/cl/_testrt/closure/out.ll +++ b/cl/_testrt/closure/out.ll @@ -50,28 +50,18 @@ _llgo_0: ret i32 0 } -declare void @"github.com/goplus/llgo/internal/runtime.init"() - define void @"main.main$1"(i64 %0, i64 %1) { _llgo_0: %2 = call i32 (ptr, ...) @printf(ptr @0, i64 %0, i64 %1) ret void } -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) - define void @"main.main$2"(i64 %0, i64 %1) { _llgo_0: %2 = call i32 (ptr, ...) @printf(ptr @1, i64 %0, i64 %1) ret void } -define linkonce void @"__llgo_stub.main.main$2"(ptr %0, i64 %1, i64 %2) { -_llgo_0: - tail call void @"main.main$2"(i64 %1, i64 %2) - ret void -} - define void @"main.main$3"(ptr %0) { _llgo_0: %1 = load { ptr }, ptr %0, align 8 @@ -83,6 +73,16 @@ _llgo_0: ret void } +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) + +define linkonce void @"__llgo_stub.main.main$2"(ptr %0, i64 %1, i64 %2) { +_llgo_0: + tail call void @"main.main$2"(i64 %1, i64 %2) + ret void +} + declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) declare i32 @printf(ptr, ...) diff --git a/cl/_testrt/eface/out.ll b/cl/_testrt/eface/out.ll index d24c6978..2b0e6229 100644 --- a/cl/_testrt/eface/out.ll +++ b/cl/_testrt/eface/out.ll @@ -463,6 +463,11 @@ _llgo_0: ret i32 0 } +define void @"main.main$1"() { +_llgo_0: + ret void +} + declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) @@ -886,11 +891,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.ArrayOf"(i64, ptr) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) -define void @"main.main$1"() { -_llgo_0: - ret void -} - declare ptr @"github.com/goplus/llgo/internal/runtime.Func"(%"github.com/goplus/llgo/internal/runtime.Slice", %"github.com/goplus/llgo/internal/runtime.Slice", i1) declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr) diff --git a/cl/_testrt/intgen/out.ll b/cl/_testrt/intgen/out.ll index 6f36fcc2..4eaa98d6 100644 --- a/cl/_testrt/intgen/out.ll +++ b/cl/_testrt/intgen/out.ll @@ -170,6 +170,19 @@ _llgo_9: ; preds = %_llgo_7 ret i32 0 } +define i32 @"main.main$1"(ptr %0) { +_llgo_0: + %1 = load { ptr }, ptr %0, align 8 + %2 = extractvalue { ptr } %1, 0 + %3 = load i32, ptr %2, align 4 + %4 = mul i32 %3, 2 + %5 = extractvalue { ptr } %1, 0 + store i32 %4, ptr %5, align 4 + %6 = extractvalue { ptr } %1, 0 + %7 = load i32, ptr %6, align 4 + ret i32 %7 +} + declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1) @@ -186,19 +199,6 @@ _llgo_0: declare i32 @printf(ptr, ...) -define i32 @"main.main$1"(ptr %0) { -_llgo_0: - %1 = load { ptr }, ptr %0, align 8 - %2 = extractvalue { ptr } %1, 0 - %3 = load i32, ptr %2, align 4 - %4 = mul i32 %3, 2 - %5 = extractvalue { ptr } %1, 0 - store i32 %4, ptr %5, align 4 - %6 = extractvalue { ptr } %1, 0 - %7 = load i32, ptr %6, align 4 - ret i32 %7 -} - declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) define i32 @"main.next$bound"(ptr %0) { diff --git a/cl/_testrt/named/out.ll b/cl/_testrt/named/out.ll index 337619ac..a9c450d2 100644 --- a/cl/_testrt/named/out.ll +++ b/cl/_testrt/named/out.ll @@ -123,10 +123,6 @@ _llgo_0: ret i32 0 } -declare void @"github.com/goplus/llgo/internal/runtime.init"() - -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) - define i64 @"main.main$1"(ptr %0, i64 %1) { _llgo_0: %2 = load { ptr }, ptr %0, align 8 @@ -138,6 +134,10 @@ _llgo_0: ret i64 %7 } +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) + declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) declare i32 @printf(ptr, ...) diff --git a/cl/_testrt/qsort/out.ll b/cl/_testrt/qsort/out.ll index 2d507d3a..03a2fe69 100644 --- a/cl/_testrt/qsort/out.ll +++ b/cl/_testrt/qsort/out.ll @@ -59,12 +59,6 @@ _llgo_3: ; preds = %_llgo_1 ret i32 0 } -declare void @"github.com/goplus/llgo/internal/runtime.init"() - -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) - -declare void @qsort(ptr, i64, i64, ptr) - define i32 @"main.main$1"(ptr %0, ptr %1) { _llgo_0: %2 = load i64, ptr %0, align 4 @@ -74,6 +68,12 @@ _llgo_0: ret i32 %5 } +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) + +declare void @qsort(ptr, i64, i64, ptr) + declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1) declare i32 @printf(ptr, ...) diff --git a/cl/_testrt/result/out.ll b/cl/_testrt/result/out.ll index dde63bee..3866d8ec 100644 --- a/cl/_testrt/result/out.ll +++ b/cl/_testrt/result/out.ll @@ -19,6 +19,12 @@ _llgo_0: ret { ptr, ptr } %3 } +define i64 @"main.add$1"(i64 %0, i64 %1) { +_llgo_0: + %2 = add i64 %0, %1 + ret i64 %2 +} + define { { ptr, ptr }, i64 } @main.add2() { _llgo_0: %0 = alloca { ptr, ptr }, align 8 @@ -32,6 +38,12 @@ _llgo_0: ret { { ptr, ptr }, i64 } %mrv1 } +define i64 @"main.add2$1"(i64 %0, i64 %1) { +_llgo_0: + %2 = add i64 %0, %1 + ret i64 %2 +} + define void @main.init() { _llgo_0: %0 = load i1, ptr @"main.init$guard", align 1 @@ -72,32 +84,6 @@ _llgo_0: ret i32 0 } -define i64 @"main.add$1"(i64 %0, i64 %1) { -_llgo_0: - %2 = add i64 %0, %1 - ret i64 %2 -} - -define linkonce i64 @"__llgo_stub.main.add$1"(ptr %0, i64 %1, i64 %2) { -_llgo_0: - %3 = tail call i64 @"main.add$1"(i64 %1, i64 %2) - ret i64 %3 -} - -define i64 @"main.add2$1"(i64 %0, i64 %1) { -_llgo_0: - %2 = add i64 %0, %1 - ret i64 %2 -} - -define linkonce i64 @"__llgo_stub.main.add2$1"(ptr %0, i64 %1, i64 %2) { -_llgo_0: - %3 = tail call i64 @"main.add2$1"(i64 %1, i64 %2) - ret i64 %3 -} - -declare void @"github.com/goplus/llgo/internal/runtime.init"() - define { ptr, ptr } @"main.main$1"() { _llgo_0: %0 = alloca { ptr, ptr }, align 8 @@ -109,14 +95,28 @@ _llgo_0: ret { ptr, ptr } %3 } -declare i32 @printf(ptr, ...) - define i64 @"main.main$1$1"(i64 %0, i64 %1) { _llgo_0: %2 = add i64 %0, %1 ret i64 %2 } +define linkonce i64 @"__llgo_stub.main.add$1"(ptr %0, i64 %1, i64 %2) { +_llgo_0: + %3 = tail call i64 @"main.add$1"(i64 %1, i64 %2) + ret i64 %3 +} + +define linkonce i64 @"__llgo_stub.main.add2$1"(ptr %0, i64 %1, i64 %2) { +_llgo_0: + %3 = tail call i64 @"main.add2$1"(i64 %1, i64 %2) + ret i64 %3 +} + +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare i32 @printf(ptr, ...) + define linkonce i64 @"__llgo_stub.main.main$1$1"(ptr %0, i64 %1, i64 %2) { _llgo_0: %3 = tail call i64 @"main.main$1$1"(i64 %1, i64 %2) diff --git a/internal/lib/sync/sync.go b/internal/lib/sync/sync.go index 63f22d78..35ad736b 100644 --- a/internal/lib/sync/sync.go +++ b/internal/lib/sync/sync.go @@ -46,11 +46,14 @@ func (o *Once) Do(f func()) { if *(*c.Long)(unsafe.Pointer(o)) == 0 { // try init *(*sync.Once)(o) = sync.OnceInit } - (*sync.Once)(o).Do(func() { + onceDo(o, func() { ptr := onceParam.Get() (*(*func())(ptr))() c.Free(ptr) }) } +//go:linkname onceDo C.pthread_once +func onceDo(o *Once, f func()) c.Int + // -----------------------------------------------------------------------------