1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
target triple = "x86_64-pc-linux-gnu"
@heap = global [10000 x i64] zeroinitializer, align 16
@astack = global [10000 x i64*] zeroinitializer, align 16
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
@INT = constant {i64, i64, i64*, i64, i8, i8, i8}
{i64 0, i64 0, i64* inttoptr (i64 0 to i64*), i64 3, i8 73, i8 78, i8 84}
attributes #0 = { alwaysinline }
define private i64** @_push_local_astack(i64** %asp.0, i64** %aspstart, i64** %globasp.0) #0 {
entry:
br label %loop
loop:
%asp = phi i64** [%asp.0, %entry], [%asp.1, %loop.0]
%globasp = phi i64** [%globasp.0, %entry], [%globasp.1, %loop.0]
%t.0 = icmp eq i64** %asp, %aspstart
br i1 %t.0, label %done, label %loop.0
done:
ret i64** %globasp
loop.0:
%globasp.1 = getelementptr i64*, i64** %globasp, i64 1
%n = load i64*, i64** %asp
store i64* %n, i64** %globasp.1
%asp.1 = getelementptr i64*, i64** %asp, i64 -1
br label %loop
}
define private i64* @addI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = add i64 %t.0, %t.1
store i64 %t.2, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @eqI_b(i64 %i, i64 %n, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 -1
%t.0 = load i64, i64* %bsp.1
%t.1 = icmp eq i64 %t.0, %i
%t.2 = zext i1 %t.1 to i64
store i64 %t.2, i64* %bsp.2
ret i64* %bsp.2
}
define private i64** @fillI_b(i64 %b_offset, i64 %a_offset, i64* %bsp.0, i64** %asp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %b_offset
%t.0 = load i64, i64* %bsp.1
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %a_offset
%n.0 = load i64*, i64** %asp.1
%INT.0 = ptrtoint {i64, i64, i64*, i64, i8, i8, i8}* @INT to i64
%INT.1 = add i64 %INT.0, 2
store i64 %INT.1, i64* %n.0
%n.1 = getelementptr i64, i64* %n.0, i64 1
store i64 %t.0, i64* %n.1
ret i64** %asp.0
}
define private i64** @jsr_eval(i64 %n, i64** %asp.0, i64** %aspstart, i64** %globasp.0) #0 {
; TODO in case %n != 0 do we need to push it to the top of the stack?
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %n
%n.0 = load i64*, i64** %asp.1
%d.0 = load i64, i64* %n.0
%t.0 = and i64 %d.0, 2
%t.1 = icmp eq i64 %t.0, 0
br i1 %t.1, label %eval, label %done
done:
ret i64** %asp.0
eval:
%globasp.1 = call i64** @_push_local_astack(i64** %asp.0, i64** %aspstart, i64** %globasp.0)
%nentry.0 = inttoptr i64 %d.0 to i64*(i64*, i64**)*
%n.1 = call i64* %nentry.0(i64* %n.0, i64** %globasp.1)
store i64* %n.1, i64** %asp.1
ret i64** %asp.0
}
define private i64* @ltI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = icmp slt i64 %t.0, %t.1
%t.3 = zext i1 %t.2 to i64
store i64 %t.3, i64* %bsp.1
ret i64* %bsp.1
}
define private i64** @pop_a1(i64** %asp.0) #0 {
store i64* undef, i64** %asp.0
%asp.1 = getelementptr i64*, i64** %asp.0, i64 -1
ret i64** %asp.1
}
define private i64* @pop_b1(i64* %bsp.0) #0 {
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
ret i64* %bsp.1
}
define private i64* @print_int(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @printf_d, i64 0, i64 0), i64 %t.0)
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
ret i64* %bsp.1
}
define private i64* @push_b(i64 %n, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n
%t.0 = load i64, i64* %bsp.1
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %t.0, i64* %bsp.2
ret i64* %bsp.2
}
define private i64** @push_node(i64* %label, i64 %arity, i64** %asp.0) #0 {
entry:
%n.0 = load i64*, i64** %asp.0
%label.0 = ptrtoint i64* %label to i64
store i64 %label.0, i64* %n.0
br label %loop
loop:
%asp.1 = phi i64** [%asp.0, %entry], [%asp.2, %loop.0]
%arity.0 = phi i64 [%arity, %entry], [%arity.1, %loop.0]
%t.0 = icmp eq i64 %arity.0, 0
br i1 %t.0, label %done, label %loop.0
done:
ret i64** %asp.1
loop.0:
%n.1 = getelementptr i64, i64* %n.0, i64 %arity
%n.2 = load i64, i64* %n.1
%n.3 = inttoptr i64 %n.2 to i64*
%asp.2 = getelementptr i64*, i64** %asp.1, i64 1
store i64* %n.3, i64** %asp.2
%arity.1 = sub i64 %arity.0, 1
br label %loop
}
define private i64* @pushI(i64 %i, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %i, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @pushI_a(i64 %n, i64* %bsp.0, i64** %asp.0) #0 {
%asp.1 = getelementptr i64*, i64** %asp.0, i64 %n
%n.0 = load i64*, i64** %asp.1
%n.1 = getelementptr i64, i64* %n.0, i64 1
%t.0 = load i64, i64* %n.1
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 -1
store i64 %t.0, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @subI(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
%t.1 = load i64, i64* %bsp.1
%t.2 = sub i64 %t.0, %t.1
store i64 %t.2, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @update_b(i64 %n1, i64 %n2, i64* %bsp.0) #0 {
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 %n1
%t.0 = load i64, i64* %bsp.1
%bsp.2 = getelementptr i64, i64* %bsp.0, i64 %n2
store i64 %t.0, i64* %bsp.2
ret i64* %bsp.0
}
define private i64* @updatepop_b01(i64* %bsp.0) #0 {
%t.0 = load i64, i64* %bsp.0
store i64 undef, i64* %bsp.0
%bsp.1 = getelementptr i64, i64* %bsp.0, i64 1
store i64 %t.0, i64* %bsp.1
ret i64* %bsp.1
}
define private i64* @peek_a(i64** %asp) #0 {
%t = load i64*, i64** %asp
ret i64* %t
}
define private i64 @peek_b(i64* %bsp) #0 {
%t = load i64, i64* %bsp
ret i64 %t
}
define i64* @_cycle_in_spine(i64** %globasp) prefix {i8*, i64} {i8* inttoptr (i64 0 to i8*), i64 0} {
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @printf_cycle, i64 0, i64 0))
unreachable
}
define i64* @e_fib_eqI_b_nfib(i64* %n, i64** %globasp) prefix {i8*, i64} {i8* inttoptr (i64 0 to i8*), i64 1} {
%astack = alloca i64*, i64 10
%asp.000 = getelementptr i64*, i64** %astack
%bstack = alloca i64, i64 10
%bsp.000 = getelementptr i64, i64* %bstack, i64 9
%asp.001 = getelementptr i64*, i64** %asp.000, i64 1
store i64* %n, i64** %asp.001
%t.0 = bitcast i64*(i64**)* @_cycle_in_spine to i64*
%asp.002 = call i64** @push_node(i64* %t.0, i64 1, i64** %asp.001)
%t.1 = call i64* @peek_a(i64** %asp.002)
%asp.003 = call i64** @pop_a1(i64** %asp.002)
%globasp.0 = call i64** @_push_local_astack(i64** %asp.003, i64** %asp.000, i64** %globasp)
%t.2 = call i64 @ea1(i64* %t.1, i64** %globasp.0)
%bsp.001 = call i64* @pushI(i64 %t.2, i64* %bsp.000)
%asp.004 = call i64** @fillI_b(i64 0, i64 -0, i64* %bsp.001, i64** %asp.003)
%bsp.002 = call i64* @pop_b1(i64* %bsp.001)
%t.3 = call i64* @peek_a(i64** %asp.004)
%asp.005 = call i64** @pop_a1(i64** %asp.004)
ret i64* %t.3
}
define private i64 @ea1(i64* %n, i64** %globasp) {
%astack = alloca i64*, i64 10
%asp.000 = getelementptr i64*, i64** %astack, i64 0
%bstack = alloca i64, i64 10
%bsp.000 = getelementptr i64, i64* %bstack, i64 9
%asp.001 = getelementptr i64*, i64** %asp.000, i64 1
store i64* %n, i64** %asp.001
%asp.002 = call i64** @jsr_eval(i64 -0, i64** %asp.001, i64** %asp.000, i64** %globasp)
%bsp.001 = call i64* @pushI_a(i64 -0, i64* %bsp.000, i64** %asp.002)
%asp.003 = call i64** @pop_a1(i64** %asp.002)
%t.0 = call i64 @peek_b(i64* %bsp.001)
%bsp.002 = call i64* @pop_b1(i64* %bsp.001)
%t.1 = tail call i64 @s1(i64 %t.0, i64** %globasp)
ret i64 %t.1
}
define i64 @e_fib_eqI_b_sfib(i64 %arg, i64** %globasp) #0 {
%r = tail call i64 @s1(i64 %arg, i64** %globasp)
ret i64 %r
}
define private i64 @s1(i64 %arg, i64** %globasp) #0 {
%astack = alloca i64*, i64 10000
%asp.000 = getelementptr i64*, i64** %astack
%bstack = alloca i64, i64 10000
%bsp.000 = getelementptr i64, i64* %bstack, i64 9999
%bsp.001 = call i64* @pushI(i64 %arg, i64* %bsp.000)
%bsp.002 = call i64* @eqI_b(i64 0, i64 0, i64* %bsp.001)
%t.0 = call i64 @peek_b(i64* %bsp.002)
%bsp.003 = call i64* @pop_b1(i64* %bsp.002)
%t.1 = trunc i64 %t.0 to i1
br i1 %t.1, label %case.1, label %l.0
l.0:
%bsp.004 = call i64* @eqI_b(i64 1, i64 0, i64* %bsp.003)
%t.2 = call i64 @peek_b(i64* %bsp.004)
%bsp.005 = call i64* @pop_b1(i64* %bsp.004)
%t.3 = trunc i64 %t.2 to i1
br i1 %t.3, label %case.2, label %case.3
case.1:
%bsp.100 = call i64* @pop_b1(i64* %bsp.003)
%bsp.101 = call i64* @pushI(i64 1, i64* %bsp.100)
%r.1 = call i64 @peek_b(i64* %bsp.101)
%bsp.102 = call i64* @pop_b1(i64* %bsp.101)
ret i64 %r.1
case.2:
%bsp.200 = call i64* @pop_b1(i64* %bsp.005)
%bsp.201 = call i64* @pushI(i64 1, i64* %bsp.200)
%r.2 = call i64 @peek_b(i64* %bsp.201)
%bsp.202 = call i64* @pop_b1(i64* %bsp.201)
ret i64 %r.2
case.3:
%bsp.300 = call i64* @pushI(i64 1, i64* %bsp.005)
%bsp.301 = call i64* @push_b(i64 1, i64* %bsp.300)
%bsp.302 = call i64* @subI(i64* %bsp.301)
%arg.0 = call i64 @peek_b(i64* %bsp.302)
%bsp.302.0 = call i64* @pop_b1(i64* %bsp.302)
%ret.0 = call i64 @s1(i64 %arg.0, i64** %globasp)
%bsp.303 = call i64* @pushI(i64 %ret.0, i64* %bsp.302.0)
%bsp.304 = call i64* @pushI(i64 2, i64* %bsp.303)
%bsp.305 = call i64* @push_b(i64 2, i64* %bsp.304)
%bsp.306 = call i64* @subI(i64* %bsp.305)
%arg.1 = call i64 @peek_b(i64* %bsp.306)
%bsp.306.0 = call i64* @pop_b1(i64* %bsp.306)
%ret.1 = call i64 @s1(i64 %arg.1, i64** %globasp)
%bsp.307 = call i64* @pushI(i64 %ret.1, i64* %bsp.306.0)
%bsp.308 = call i64* @update_b(i64 1, i64 2, i64* %bsp.307)
%bsp.309 = call i64* @updatepop_b01(i64* %bsp.308)
%bsp.310 = call i64* @addI(i64* %bsp.309)
%r.3 = call i64 @peek_b(i64* %bsp.310)
%bsp.311 = call i64* @pop_b1(i64* %bsp.310)
ret i64 %r.3
}
define i64 @main() {
%heap = bitcast [10000 x i64]* @heap to i64*
%astack = bitcast [10000 x i64*]* @astack to i64**
%n.0 = getelementptr i64, i64* %heap
%INT.0 = ptrtoint {i64, i64, i64*, i64, i8, i8, i8}* @INT to i64
%INT.1 = add i64 %INT.0, 2
store i64 %INT.1, i64* %n.0
%n.0.0 = getelementptr i64, i64* %n.0, i64 1
store i64 43, i64* %n.0.0
%n.1 = getelementptr i64, i64* %n.0, i64 2
store i64 ptrtoint (i64*(i64*,i64**)* @e_fib_eqI_b_nfib to i64), i64* %n.1
%t.0 = ptrtoint i64* %n.0 to i64
%n.1.0 = getelementptr i64, i64* %n.1, i64 1
store i64 %t.0, i64* %n.1.0
%n.2 = call i64* @e_fib_eqI_b_nfib(i64* %n.1, i64** %astack)
%n.3 = getelementptr i64, i64* %n.2, i64 1
%r = load i64, i64* %n.3
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @printf_d, i64 0, i64 0), i64 %r)
call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @printf_c, i64 0, i64 0), i64 10)
ret i64 0
}
|