aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fib_eqI_b.ll4
-rw-r--r--fib_ltI.ll4
-rw-r--r--nfib.ll4
-rw-r--r--nfib_nsa.ll4
-rw-r--r--rts.ll29
5 files changed, 34 insertions, 11 deletions
diff --git a/fib_eqI_b.ll b/fib_eqI_b.ll
index 58be88a..12a3c95 100644
--- a/fib_eqI_b.ll
+++ b/fib_eqI_b.ll
@@ -133,8 +133,8 @@ case.3:
}
define i64 @main() {
- %hp.0 = bitcast [100000000 x i64]* @heap to i64*
- %astack = bitcast [10000 x i64*]* @astack to i64**
+ %hp.0 = call i64* @_alloc_heap(i64 10000)
+ %astack = call i64** @_alloc_a_stack(i64 10000)
%n.0 = getelementptr i64, i64* %hp.0
%INT.0 = ptrtoint {i64, i64, i64*, i64, i8, i8, i8}* @INT to i64
diff --git a/fib_ltI.ll b/fib_ltI.ll
index 3c26df7..f8a14a2 100644
--- a/fib_ltI.ll
+++ b/fib_ltI.ll
@@ -57,8 +57,8 @@ define private i64 @_s2(i64 %arg, i64** %globasp) {
}
define i64 @main() {
- %heap = bitcast [100000000 x i64]* @heap to i64*
- %astack = bitcast [10000 x i64*]* @astack to i64**
+ %heap = call i64* @_alloc_heap(i64 10000)
+ %astack = call i64** @_alloc_a_stack(i64 10000)
%r = call i64 @_s2(i64 43, i64** %astack)
diff --git a/nfib.ll b/nfib.ll
index ccec313..dcae8f0 100644
--- a/nfib.ll
+++ b/nfib.ll
@@ -63,8 +63,8 @@ define private i64 @_s2(i64 %arg, i64** %globasp) {
}
define i64 @main() {
- %heap = bitcast [100000000 x i64]* @heap to i64*
- %astack = bitcast [10000 x i64*]* @astack to i64**
+ %heap = call i64* @_alloc_heap(i64 1000)
+ %astack = call i64** @_alloc_a_stack(i64 1000)
%r = call i64 @_s2(i64 43, i64** %astack)
diff --git a/nfib_nsa.ll b/nfib_nsa.ll
index 051cdb0..f7843a7 100644
--- a/nfib_nsa.ll
+++ b/nfib_nsa.ll
@@ -218,8 +218,8 @@ define private {i64, i64*} @s2 (i64 %arg1, i64 %arg2, i64* %hp.0) {
}
define i64 @main() {
- %hp.0 = bitcast [100000000 x i64]* @heap to i64*
- %astack = bitcast [10000 x i64*]* @astack to i64**
+ %hp.0 = call i64* @_alloc_heap(i64 100000000)
+ %astack = call i64** @_alloc_a_stack(i64 10000)
%n.0 = getelementptr i64, i64* %hp.0
store i64 ptrtoint ({i64*,i64*}(i64*,i64**,i64*)* @n5 to i64), i64* %n.0
diff --git a/rts.ll b/rts.ll
index 1a7d587..1181167 100644
--- a/rts.ll
+++ b/rts.ll
@@ -1,15 +1,38 @@
target triple = "x86_64-pc-linux-gnu"
+declare i8* @malloc(i64)
+
declare i64 @printf(i8*, ...)
@printf_d = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@printf_c = private unnamed_addr constant [3 x i8] c"%c\00", align 1
@printf_cycle = private unnamed_addr constant [16 x i8] c"cycle in spine\0a\00", align 1
-@heap = global [100000000 x i64] zeroinitializer, align 16
-@astack = global [10000 x i64*] zeroinitializer, align 16
-
attributes #0 = { alwaysinline }
+define private i64* @_alloc_heap(i64 %n) alwaysinline {
+ %s.0 = alloca i64
+ %s.1 = getelementptr i64, i64* %s.0, i64 1
+ %s.0.0 = ptrtoint i64* %s.0 to i64
+ %s.1.0 = ptrtoint i64* %s.1 to i64
+ %s.2 = sub i64 %s.1.0, %s.0.0
+ %s.3 = mul i64 %s.2, %n
+ %r.0 = call i8* @malloc(i64 %s.3)
+ %r.1 = bitcast i8* %r.0 to i64*
+ ret i64* %r.1
+}
+
+define private i64** @_alloc_a_stack(i64 %n) alwaysinline {
+ %s.0 = alloca i64*
+ %s.1 = getelementptr i64*, i64** %s.0, i64 1
+ %s.0.0 = ptrtoint i64** %s.0 to i64
+ %s.1.0 = ptrtoint i64** %s.1 to i64
+ %s.2 = sub i64 %s.1.0, %s.0.0
+ %s.3 = mul i64 %s.2, %n
+ %r.0 = call i8* @malloc(i64 %s.3)
+ %r.1 = bitcast i8* %r.0 to i64**
+ ret i64** %r.1
+}
+
define private i64** @_push_local_astack(i64** %asp.0, i64** %aspstart, i64** %globasp.0) #0 {
entry:
br label %loop