From 736c4b8b644886b945aafd7ed5ccf00e06bf1e96 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 4 Dec 2004 03:12:58 +0000 Subject: [PATCH] more work on optimizer --- TODO.FACTOR.txt | 8 ++- library/compiler/linearizer.factor | 29 +++++++---- library/compiler/optimizer.factor | 80 ++++++++++++++++++++++++------ library/inference/dataflow.factor | 14 +++--- library/inference/inference.factor | 9 ++-- library/inference/stack.factor | 5 -- library/inference/words.factor | 54 +++++++++++++++----- library/test/dataflow.factor | 6 +-- 8 files changed, 146 insertions(+), 59 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 1fe6b805fb..ea8e98ee4e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -10,8 +10,12 @@ - type inference - handle odd base cases, with code after ifte - handle recursion with when, when* etc -- lifting -- stack ops and alien-call need special nodes +- optimizer rewrite stack ops +- optimizer nested ifte +- optimizer recursive call +- dataflow make block nodes for inlined words +- dataflow recursive calls marked as so +- alien-call need special nodes + linearizer/generator: diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index c2b0f2b162..dab206d6ee 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -36,19 +36,19 @@ USE: combinators ! Linear IR nodes. This is in addition to the symbols already ! defined in dataflow vocab. -SYMBOL: #branch-t ( branch if top of stack is true ) -SYMBOL: #branch ( unconditional branch ) -SYMBOL: #label ( branch target ) +SYMBOL: #jump-label-t ( branch if top of stack is true ) +SYMBOL: #jump-label ( unconditional branch ) SYMBOL: #jump ( tail-call ) -: linear, ( param op -- ) - swons , ; +: linear, ( node -- ) + #! Add a node to the linear IR. + [ node-op get node-param get ] bind cons , ; : >linear ( node -- ) #! Dataflow OPs have a linearizer word property. This #! quotation is executed to convert the node into linear #! form. - "linearizer" [ drop linear, ] apply-dataflow ; + "linearizer" [ linear, ] apply-dataflow ; : (linearize) ( dataflow -- ) [ >linear ] each ; @@ -59,24 +59,31 @@ SYMBOL: #jump ( tail-call ) #! jumps and labels, and turns dataflow IR nodes into #! lists where the first element is an operation, and the #! rest is arguments. - [ (linearize) f #return linear, ] make-list ; + [ (linearize) ] make-list ; :