Skip to content

Commit 2e71eb3

Browse files
committed
all tests pass again
1 parent ee63147 commit 2e71eb3

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed

conditionals.rkt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(class compile-reg-R0
1111
(super-new)
1212

13-
(inherit liveness-ss first-offset variable-size in-memory?)
13+
(inherit liveness-ss first-offset variable-size in-memory?
14+
color-graph identify-home)
15+
(inherit-field largest-color)
1416

1517
(define/public (comparison-ops)
1618
(set 'eq? '< '<= '> '>=))
@@ -368,6 +370,10 @@
368370
,new-els-ss ,(cdr els-lives))
369371
(set-union live-after-thn live-after-els
370372
(free-vars cnd)))]
373+
[`(program ,xs (type ,ty) ,ss ...)
374+
(define-values (new-ss lives) ((liveness-ss (set)) ss))
375+
(assert "lives ss size" (= (length (cdr lives)) (length new-ss)))
376+
`(program (,xs ,(cdr lives)) (type ,ty) ,@new-ss)]
371377
[else ((super uncover-live live-after) ast)]
372378
)))
373379

@@ -390,9 +396,37 @@
390396
(define new-thn (map build-inter thn-ss thn-lives))
391397
(define new-els (map build-inter els-ss els-lives))
392398
`(if ,cnd ,new-thn ,new-els)]
399+
[`(program (,xs ,lives) (type ,ty) ,ss ...)
400+
(define G (make-graph xs))
401+
(define new-ss
402+
(for/list ([inst ss] [live-after lives])
403+
((build-interference live-after G) inst)))
404+
(print-dot G "./interfere.dot")
405+
`(program (,xs ,G) (type ,ty) ,@new-ss)]
393406
[else ((super build-interference live-after G) ast)]
394407
)))
395408

409+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410+
;; allocate-registers
411+
412+
(define/override (allocate-registers)
413+
(lambda (ast)
414+
(match ast
415+
;; just adding the hanlding of (type ,ty) -Jeremy
416+
[`(program (,locals ,IG ,MG) (type ,ty) ,ss ...)
417+
(define color (color-graph IG MG locals))
418+
(define homes
419+
(make-hash
420+
(for/list ([x locals])
421+
(cons x (identify-home (hash-ref color x))))))
422+
(define num-spills
423+
(max 0 (- (add1 largest-color)
424+
(vector-length registers-for-alloc))))
425+
(define stk-size (* num-spills (variable-size)))
426+
`(program ,stk-size (type ,ty)
427+
,@(map (assign-homes homes) ss))]
428+
)))
429+
396430
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
397431
;; assign-homes : homes -> pseudo-x86 -> pseudo-x86
398432
(define/override (assign-homes homes)

dynamic-typing.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@
446446
(lambda (x)
447447
(vomit "select instructions" x)
448448
(match x
449-
[`(assign ,lhs (vector-ref ,e-vec (has-type ,i ,Integer)))
449+
[`(assign ,lhs (vector-ref ,e-vec ,i))
450450
#:when (not (number? i))
451451
(define lhs^ ((select-instructions) lhs))
452452
(define e-vec^ ((select-instructions) e-vec))
@@ -456,7 +456,7 @@
456456
(imulq (int 8) (reg r11))
457457
(addq ,e-vec^ (reg r11))
458458
(movq (deref r11 0) ,lhs^))]
459-
[`(assign ,lhs (vector-set! ,e-vec (has-type ,i ,Integer) ,e-arg))
459+
[`(assign ,lhs (vector-set! ,e-vec ,i ,e-arg))
460460
#:when (not (number? i))
461461
(define lhs^ ((select-instructions) lhs))
462462
(define e-vec^ ((select-instructions) e-vec))

int_exp.rkt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,6 @@
146146
[`(reg ,r) `(reg ,r)]
147147
[`(deref ,r ,n) `(deref ,r ,n)]
148148
[`(callq ,f) `(callq ,f)]
149-
[`(program (,xs ...) (type ,ty) ,ss ...)
150-
;; create mapping of variables to stack locations
151-
(define (make-stack-loc n)
152-
`(deref rbp ,(- (+ (first-offset)
153-
(* (variable-size) n)))))
154-
(define new-homes
155-
(make-hash (map cons xs
156-
(map make-stack-loc
157-
(stream->list (in-range 0 (length xs)))))))
158-
(define stack-space (align
159-
(* (length xs)
160-
(variable-size))
161-
16))
162-
`(program ,stack-space (type ,ty)
163-
,@(map (assign-homes new-homes) ss))]
164149
[`(program (,xs ...) ,ss ...)
165150
;; create mapping of variables to stack locations
166151
(define (make-stack-loc n)

interp.rkt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(define program (make-parameter '()))
2121

2222
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23-
;; Interpreters for S0: integer arithmetic and 'let'
23+
;; Interpreters for R0: integer arithmetic and 'let'
2424

2525
(define interp-R0
2626
(class object%
@@ -166,7 +166,7 @@
166166
)) ;; class interp-R0
167167

168168
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
169-
;; Interpreters for S1: Booleans and conditionals
169+
;; Interpreters for R1: Booleans and conditionals
170170

171171
(define interp-R1
172172
(class interp-R0
@@ -387,7 +387,7 @@
387387
));; class interp-R1
388388

389389
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
390-
;; Interpreters for S2: Vectors
390+
;; Interpreters for R2: Vectors
391391

392392
(define interp-R2
393393
(class interp-R1
@@ -730,7 +730,7 @@
730730
));; interp-R2
731731

732732
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
733-
;; Interpreters for S3: functions
733+
;; Interpreters for R3: functions
734734

735735

736736
(define interp-R3
@@ -789,6 +789,8 @@
789789
[`(program (type ,ty) ,ds ... ,body)
790790
((interp-F env) `(program ,@ds ,body))]
791791
[`(program ,ds ... ,body)
792+
((initialize!) runtime-config:rootstack-size
793+
runtime-config:heap-size)
792794
(let ([top-level (map (interp-F '()) ds)])
793795
((interp-F top-level) body))]
794796
;; For R3
@@ -954,7 +956,7 @@
954956
)) ;; end interp-R3
955957

956958
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
957-
;; Interpreters for S4: lambda
959+
;; Interpreters for R4: lambda
958960

959961
(define interp-R4
960962
(class interp-R3
@@ -1006,6 +1008,8 @@
10061008
[`(program (type ,ty) ,ds ... ,body)
10071009
((interp-F env) `(program ,@ds ,body))]
10081010
[`(program ,ds ... ,body)
1011+
((initialize!) runtime-config:rootstack-size
1012+
runtime-config:heap-size)
10091013
(let ([top-level (map (interp-F '()) ds)])
10101014
;; Use set-cdr! on define lambda's for mutual recursion
10111015
(for/list ([b top-level])

register_allocator.rkt

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@
6262
(define/public (uncover-live live-after)
6363
(lambda (ast)
6464
(match ast
65-
[`(program ,xs (type ,ty) ,ss ...)
66-
(define-values (new-ss lives) ((liveness-ss (set)) ss))
67-
(assert "lives ss size" (= (length (cdr lives)) (length new-ss)))
68-
`(program (,xs ,(cdr lives)) (type ,ty) ,@new-ss)]
6965
[`(program ,xs ,ss ...)
7066
(define-values (new-ss lives) ((liveness-ss (set)) ss))
7167
(assert "lives ss size" (= (length (cdr lives)) (length new-ss)))
@@ -95,13 +91,6 @@
9591
#:when (not (equal? v u)))
9692
(add-edge G u v)))
9793
ast]
98-
[`(program (,xs ,lives) (type ,ty) ,ss ...)
99-
(define G (make-graph xs))
100-
(define new-ss
101-
(for/list ([inst ss] [live-after lives])
102-
((build-interference live-after G) inst)))
103-
(print-dot G "./interfere.dot")
104-
`(program (,xs ,G) (type ,ty) ,@new-ss)]
10594
[`(program (,xs ,lives) ,ss ...)
10695
(define G (make-graph xs))
10796
(define new-ss
@@ -127,19 +116,8 @@
127116
(add-edge G s d)
128117
'())
129118
ast]
130-
[`(program (,xs ,IG) (type ,ty) ,ss ...)
131-
(define MG (make-graph xs)) ;; JGS
132-
(define new-ss
133-
(if use-move-biasing
134-
(let ([nss
135-
(for/list ([inst ss])
136-
((build-move-graph MG) inst))])
137-
(print-dot MG "./move.dot")
138-
nss)
139-
ss))
140-
`(program (,xs ,IG ,MG) (type ,ty) ,@new-ss)]
141119
[`(program (,xs ,IG) ,ss ...)
142-
(define MG (make-graph xs)) ;; JGS
120+
(define MG (make-graph xs))
143121
(define new-ss
144122
(if use-move-biasing
145123
(let ([nss
@@ -230,7 +208,7 @@
230208
(define/public (allocate-registers)
231209
(lambda (ast)
232210
(match ast
233-
[`(program (,locals ,IG ,MG) (type ,ty) ,ss ...)
211+
[`(program (,locals ,IG ,MG) ,ss ...)
234212
(define color (color-graph IG MG locals))
235213
(define homes
236214
(make-hash
@@ -240,7 +218,7 @@
240218
(max 0 (- (add1 largest-color)
241219
(vector-length registers-for-alloc))))
242220
(define stk-size (* num-spills (variable-size)))
243-
`(program ,stk-size (type ,ty)
221+
`(program ,stk-size
244222
,@(map (assign-homes homes) ss))]
245223
)))
246224

0 commit comments

Comments
 (0)