|
@@ -9,18 +9,26 @@ Revising the architecture to better match Dybvig's P523 compiler
|
|
|
|
|
|
* to do: insert type checking
|
|
|
|
|
|
-
|
|
|
+--------------------------------------------------------------------------------
|
|
|
R1:
|
|
|
+
|
|
|
exp ::= x | n | (op exp*) | (let ([x exp]) exp)
|
|
|
R1 ::= (program exp)
|
|
|
|
|
|
+uniquify
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ exp ::= ...
|
|
|
+ R1 ::= (program () exp)
|
|
|
+
|
|
|
remove-complex-opera*
|
|
|
|
|
|
|
V
|
|
|
|
|
|
arg ::= x | n
|
|
|
exp ::= arg | (op arg*) | (let ([x exp]) exp)
|
|
|
- R2 ::= (program exp)
|
|
|
+ R2 ::= (program () exp)
|
|
|
|
|
|
|
|
|
create-CFG (the graph is empty for this assignment)
|
|
@@ -30,8 +38,8 @@ V
|
|
|
arg ::= x | n
|
|
|
exp ::= arg | (op arg*)
|
|
|
stmt ::= (assign x exp)
|
|
|
- tail ::= (return exp) | (stmt . tail)
|
|
|
- CFG ::= (program tail)
|
|
|
+ tail ::= (return exp) | (seq stmt tail)
|
|
|
+ C0 ::= (program () tail)
|
|
|
|
|
|
uncover-locals
|
|
|
|
|
|
@@ -40,8 +48,8 @@ V
|
|
|
arg ::= x | n
|
|
|
exp ::= arg | (op arg*)
|
|
|
stmt ::= (assign x exp)
|
|
|
- tail ::= (return exp) | (stmt . tail)
|
|
|
- CFG ::= (program (x ...) tail)
|
|
|
+ tail ::= (return exp) | (seq stmt tail)
|
|
|
+ C0 ::= (program ((locals . x*)) tail)
|
|
|
|
|
|
select-instructions
|
|
|
|
|
|
@@ -49,16 +57,15 @@ V
|
|
|
|
|
|
imm ::= (var x) | (deref r n) | (int n)
|
|
|
instr ::= (addq imm imm) | ...
|
|
|
- x86-CFG ::= (program (x ...) instr ...)
|
|
|
+ x86 ::= (program ((locals . x*)) instr ...)
|
|
|
|
|
|
-
|
|
|
assign-homes
|
|
|
|
|
|
|
V
|
|
|
|
|
|
imm ::= (reg r) | (deref r n) | (int n)
|
|
|
instr ::= (addq imm imm) | ...
|
|
|
- x86 ::= (program stack-size instr ...)
|
|
|
+ x86 ::= (program ((stack-space . n)) instr ...)
|
|
|
|
|
|
patch-instructions
|
|
|
|
|
|
@@ -84,7 +91,7 @@ type-check
|
|
|
V
|
|
|
|
|
|
exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
- R2 ::= (program (type type) exp)
|
|
|
+ R2 ::= (program ((type . type)) exp)
|
|
|
|
|
|
remove-complex-opera*
|
|
|
|
|
|
@@ -92,7 +99,7 @@ V
|
|
|
|
|
|
arg ::= x | n | #t | #f
|
|
|
exp ::= arg | (op arg*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
- R2 ::= (program (type type) exp)
|
|
|
+ R2 ::= (program ((type . type)) exp)
|
|
|
|
|
|
create-CFG
|
|
|
|
|
|
@@ -100,10 +107,10 @@ V
|
|
|
|
|
|
arg ::= x | n | #t | #f
|
|
|
exp ::= arg | (op arg*)
|
|
|
- tail ::= (jump label) | (if (rel-op exp*) label label) | (return exp)
|
|
|
- | (stmt . tail)
|
|
|
+ tail ::= (goto label) | (if (op arg*) ((goto label)) ((goto label)))
|
|
|
+ | (return exp) | (seq stmt tail)
|
|
|
stmt ::= (assign x exp)
|
|
|
- CFG ::= (program (type type) ([label . tail] ...) tail)
|
|
|
+ C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))) tail)
|
|
|
|
|
|
optimize-jumps
|
|
|
|
|
|
@@ -117,30 +124,147 @@ V
|
|
|
|
|
|
arg ::= x | n | #t | #f
|
|
|
exp ::= arg | (op arg*)
|
|
|
- tail ::= (jump label) | (if (rel-op exp*) label label) | (return exp)
|
|
|
- | (stmt . tail)
|
|
|
+ tail ::= (goto label) | (if (op exp*) (goto label) (goto label))
|
|
|
+ | (return exp) | (seq stmt tail)
|
|
|
stmt ::= (assign x exp)
|
|
|
- CFG ::= (program (x*) (type type) ([label . tail] ...) tail)
|
|
|
+ C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))
|
|
|
+ (locals . x*))
|
|
|
+ tail)
|
|
|
|
|
|
select-instructions
|
|
|
|
|
|
|
V
|
|
|
|
|
|
- tail ::= (jmp label) | (jmp-if cc label label) | (retq) | (instr . tail)
|
|
|
imm ::= (var x) | (deref r n) | (int n)
|
|
|
- instr ::= (addq imm imm) | ...
|
|
|
- x86-CFG ::= (program (x ...) (type type) ([label . tail] ...) tail)
|
|
|
+ instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
|
|
|
+ x86-CFG ::= (program ((locals . x*) (type . type)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
|
|
|
uncover-live, build-interference, allocate-registers
|
|
|
|
|
|
|
V
|
|
|
|
|
|
- tail ::= (jmp label) | (jmp-if cc label label) | (retq) | (instr . tail)
|
|
|
imm ::= (reg r) | (deref r n) | (int n)
|
|
|
- instr ::= (addq imm imm) | ...
|
|
|
- x86-CFG ::= (program (x ...) (type type) ([label . tail] ...) tail)
|
|
|
+ instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
|
|
|
+ x86-CFG ::= (program ((locals . x*) (type . type)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
|
|
|
print-x86
|
|
|
|
|
|
|
V
|
|
|
|
|
|
+--------------------------------------------------------------------------------
|
|
|
+
|
|
|
+R3:
|
|
|
+
|
|
|
+ exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
+ | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
|
|
|
+ | (void)
|
|
|
+ R2 ::= (program exp)
|
|
|
+
|
|
|
+type-check
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ type ::= ... | Void | (Vector type*)
|
|
|
+ exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
+ | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
|
|
|
+ | (void)
|
|
|
+ | (has-type exp type)
|
|
|
+ R2 ::= (program ((type . type)) exp)
|
|
|
+
|
|
|
+expose-allocation
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ type ::= ... | Void | (Vector type*)
|
|
|
+ exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
+ | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
|
|
|
+ | (void) | (has-type exp type)
|
|
|
+ | (collect n) | (allocate n type) | (global-value x)
|
|
|
+ R2 ::= (program ((type . type)) exp)
|
|
|
+
|
|
|
+remove-complex-opera*
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ arg ::= x | n | #t | #f | (void)
|
|
|
+ exp ::= arg | (op arg*) | (let ([x exp]) exp) | (if exp exp exp)
|
|
|
+ | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
|
|
|
+ | (void) | (has-type exp type)
|
|
|
+ | (collect n) | (allocate n type) | (global-value x)
|
|
|
+ R2 ::= (program ((type . type)) exp)
|
|
|
+
|
|
|
+create-CFG
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ arg ::= x | n | #t | #f | (void)
|
|
|
+ exp ::= arg | (op arg*) | (allocate n type) | (global-value x)
|
|
|
+ | (has-type exp type)
|
|
|
+ tail ::= (goto label) | (if (op arg*) ((goto label)) ((goto label)))
|
|
|
+ | (return exp) | (seq stmt tail)
|
|
|
+ stmt ::= (assign x exp) | (collect n)
|
|
|
+ C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))) tail)
|
|
|
+
|
|
|
+uncover-locals
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ ...
|
|
|
+ C1 ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (flow-graph . ((label . tail)*))) tail)
|
|
|
+
|
|
|
+select-instructions
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ imm ::= (var x) | (deref r n) | (int n) | (global-value x)
|
|
|
+ instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
|
|
|
+ x86-CFG ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
+
|
|
|
+uncover-live
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ imm ::= (var x) | (deref r n) | (int n) | (global-value x)
|
|
|
+ instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
|
|
|
+ block ::= (block (lives x**) instr*)
|
|
|
+ x86-CFG ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (flow-graph . ((label . block)*))) block)
|
|
|
+
|
|
|
+build-interference
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ ...
|
|
|
+ x86-CFG ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (conflicts . graph)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
+
|
|
|
+build-move-graph
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ ...
|
|
|
+ x86-CFG ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (conflicts . graph) (move-graph . graph)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
+
|
|
|
+allocate-registers
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ imm ::= (reg x) | (deref r n) | (int n) | (global-value x)
|
|
|
+ instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
|
|
|
+ x86-CFG ::= (program ((locals . ((x . type)*)) (type . type)
|
|
|
+ (flow-graph . ((label . instr*)*))) instr*)
|
|
|
+
|
|
|
+patch-instructions
|
|
|
+|
|
|
|
+V
|
|
|
+
|
|
|
+ same as above
|
|
|
+
|
|
|
+print-x96
|