compiler: move GC passes to the transform package

This commit is contained in:
Ayke van Laethem
2019-11-17 20:37:45 +01:00
committed by Ron Evans
parent 3d3e48179e
commit f0bb3c092d
9 changed files with 611 additions and 359 deletions
+29
View File
@@ -0,0 +1,29 @@
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"
%runtime._string = type { i8*, i32 }
%runtime._interface = type { i32, i8* }
@globalInt = constant i32 5
@globalString = constant %runtime._string zeroinitializer
@globalInterface = constant %runtime._interface zeroinitializer
@runtime.trackedGlobalsLength = external global i32
@runtime.trackedGlobalsBitmap = external global [0 x i8]
@runtime.trackedGlobalsStart = external global i32
define void @main() {
%1 = load i32, i32* @globalInt
%2 = load %runtime._string, %runtime._string* @globalString
%3 = load %runtime._interface, %runtime._interface* @globalInterface
ret void
}
define void @runtime.markGlobals() {
; Very small subset of what runtime.markGlobals would really do.
; Just enough to make sure the transformation is correct.
%1 = load i32, i32* @runtime.trackedGlobalsStart
%2 = load i32, i32* @runtime.trackedGlobalsLength
%3 = getelementptr inbounds [0 x i8], [0 x i8]* @runtime.trackedGlobalsBitmap, i32 0, i32 0
%4 = load i8, i8* %3
ret void
}
+27
View File
@@ -0,0 +1,27 @@
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"
%runtime._string = type { i8*, i32 }
%runtime._interface = type { i32, i8* }
@globalInt = constant i32 5
@runtime.trackedGlobalsLength = global i32 4
@runtime.trackedGlobalsBitmap = external global [0 x i8]
@runtime.trackedGlobalsStart = global i32 ptrtoint ({ %runtime._string, %runtime._interface }* @tinygo.trackedGlobals to i32)
@tinygo.trackedGlobals = internal unnamed_addr global { %runtime._string, %runtime._interface } zeroinitializer
@runtime.trackedGlobalsBitmap.1 = global [1 x i8] c"\09"
define void @main() {
%1 = load i32, i32* @globalInt
%2 = load %runtime._string, %runtime._string* getelementptr inbounds ({ %runtime._string, %runtime._interface }, { %runtime._string, %runtime._interface }* @tinygo.trackedGlobals, i32 0, i32 0)
%3 = load %runtime._interface, %runtime._interface* getelementptr inbounds ({ %runtime._string, %runtime._interface }, { %runtime._string, %runtime._interface }* @tinygo.trackedGlobals, i32 0, i32 1)
ret void
}
define void @runtime.markGlobals() {
%1 = load i32, i32* @runtime.trackedGlobalsStart
%2 = load i32, i32* @runtime.trackedGlobalsLength
%3 = getelementptr inbounds [0 x i8], [0 x i8]* bitcast ([1 x i8]* @runtime.trackedGlobalsBitmap.1 to [0 x i8]*), i32 0, i32 0
%4 = load i8, i8* %3
ret void
}
+52
View File
@@ -0,0 +1,52 @@
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"
%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 }
@runtime.stackChainStart = external global %runtime.stackChainObject*
@someGlobal = global i8 3
declare void @runtime.trackPointer(i8* nocapture readonly)
declare noalias nonnull i8* @runtime.alloc(i32)
; Generic function that returns a pointer (that must be tracked).
define i8* @getPointer() {
ret i8* @someGlobal
}
define i8* @needsStackSlots() {
; Tracked pointer. Although, in this case the value is immediately returned
; so tracking it is not really necessary.
%ptr = call i8* @runtime.alloc(i32 4)
call void @runtime.trackPointer(i8* %ptr)
ret i8* %ptr
}
; Check some edge cases of pointer tracking.
define i8* @needsStackSlots2() {
; Only one stack slot should be created for this (but at the moment, one is
; created for each call to runtime.trackPointer).
%ptr1 = call i8* @getPointer()
call void @runtime.trackPointer(i8* %ptr1)
call void @runtime.trackPointer(i8* %ptr1)
call void @runtime.trackPointer(i8* %ptr1)
; Create a pointer that does not need to be tracked (but is tracked).
%ptr2 = getelementptr i8, i8* @someGlobal, i32 0
call void @runtime.trackPointer(i8* %ptr2)
; Here is finally the point where an allocation happens.
%unused = call i8* @runtime.alloc(i32 4)
call void @runtime.trackPointer(i8* %unused)
ret i8* %ptr1
}
; Return a pointer from a caller. Because it doesn't allocate, no stack objects
; need to be created.
define i8* @noAllocatingFunction() {
%ptr = call i8* @getPointer()
call void @runtime.trackPointer(i8* %ptr)
ret i8* %ptr
}
+58
View File
@@ -0,0 +1,58 @@
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"
%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 }
@runtime.stackChainStart = global %runtime.stackChainObject* null
@someGlobal = global i8 3
declare void @runtime.trackPointer(i8* nocapture readonly)
declare noalias nonnull i8* @runtime.alloc(i32)
define i8* @getPointer() {
ret i8* @someGlobal
}
define i8* @needsStackSlots() {
%gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8* }
store { %runtime.stackChainObject*, i32, i8* } { %runtime.stackChainObject* null, i32 1, i8* null }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject
%1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart
%2 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 0
store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2
%3 = bitcast { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject to %runtime.stackChainObject*
store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart
%ptr = call i8* @runtime.alloc(i32 4)
%4 = getelementptr { %runtime.stackChainObject*, i32, i8* }, { %runtime.stackChainObject*, i32, i8* }* %gc.stackobject, i32 0, i32 2
store i8* %ptr, i8** %4
store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart
ret i8* %ptr
}
define i8* @needsStackSlots2() {
%gc.stackobject = alloca { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }
store { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* } { %runtime.stackChainObject* null, i32 4, i8* null, i8* null, i8* null, i8* null }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject
%1 = load %runtime.stackChainObject*, %runtime.stackChainObject** @runtime.stackChainStart
%2 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 0
store %runtime.stackChainObject* %1, %runtime.stackChainObject** %2
%3 = bitcast { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject to %runtime.stackChainObject*
store %runtime.stackChainObject* %3, %runtime.stackChainObject** @runtime.stackChainStart
%ptr1 = call i8* @getPointer()
%4 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 4
store i8* %ptr1, i8** %4
%5 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 3
store i8* %ptr1, i8** %5
%6 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 2
store i8* %ptr1, i8** %6
%ptr2 = getelementptr i8, i8* @someGlobal, i32 0
%unused = call i8* @runtime.alloc(i32 4)
%7 = getelementptr { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }, { %runtime.stackChainObject*, i32, i8*, i8*, i8*, i8* }* %gc.stackobject, i32 0, i32 5
store i8* %unused, i8** %7
store %runtime.stackChainObject* %1, %runtime.stackChainObject** @runtime.stackChainStart
ret i8* %ptr1
}
define i8* @noAllocatingFunction() {
%ptr = call i8* @getPointer()
ret i8* %ptr
}