diff --git a/basis/compiler/tree/finalization/finalization-docs.factor b/basis/compiler/tree/finalization/finalization-docs.factor new file mode 100644 index 0000000000..cd1ef16528 --- /dev/null +++ b/basis/compiler/tree/finalization/finalization-docs.factor @@ -0,0 +1,11 @@ +USING: assocs compiler.tree help.markup help.syntax kernel ; +IN: compiler.tree.finalization + +ARTICLE: "compiler.tree.finalization" "Final pass cleans up high-level IR" +"This is a late-stage optimization. See the vocab " { $vocab-link "compiler.tree.late-optimizations" } "." +$nl +"This pass runs after propagation, so that it can expand type predicates; these cannot be expanded before propagation since we need to see 'fixnum?' instead of 'tag 0 eq?' and so on, for semantic reasoning." +$nl +"We also delete empty stack shuffles and copies to facilitate tail call optimization in the code generator." ; + +ABOUT: "compiler.tree.finalization" diff --git a/basis/compiler/tree/finalization/finalization.factor b/basis/compiler/tree/finalization/finalization.factor index 29974230f3..0ada655b80 100644 --- a/basis/compiler/tree/finalization/finalization.factor +++ b/basis/compiler/tree/finalization/finalization.factor @@ -8,17 +8,6 @@ kernel math.partial-dispatch memoize sequences stack-checker.dependencies words ; IN: compiler.tree.finalization -! This is a late-stage optimization. -! See the comment in compiler.tree.late-optimizations. - -! This pass runs after propagation, so that it can expand -! type predicates; these cannot be expanded before -! propagation since we need to see 'fixnum?' instead of -! 'tag 0 eq?' and so on, for semantic reasoning. - -! We also delete empty stack shuffles and copies to facilitate -! tail call optimization in the code generator. - GENERIC: finalize* ( node -- nodes ) : finalize ( nodes -- nodes' ) [ finalize* ] map-nodes ; diff --git a/basis/compiler/tree/late-optimizations/late-optimizations-docs.factor b/basis/compiler/tree/late-optimizations/late-optimizations-docs.factor new file mode 100644 index 0000000000..57c1c03dfb --- /dev/null +++ b/basis/compiler/tree/late-optimizations/late-optimizations-docs.factor @@ -0,0 +1,7 @@ +USING: assocs compiler.tree help.markup help.syntax kernel ; +IN: compiler.tree.late-optimizations + +ARTICLE: "compiler.tree.late-optimizations" "Utilities used by several optimization passes run in the later stages" +"Late optimizations modify the tree such that stack flow information is no longer accurate, since we punt in " { $link splice-quot } " and don't update everything that we should; this simplifies the code, improves performance, and we don't need the stack flow information after this pass anyway." ; + +ABOUT: "compiler.tree.late-optimizations" diff --git a/basis/compiler/tree/late-optimizations/late-optimizations.factor b/basis/compiler/tree/late-optimizations/late-optimizations.factor index 85a6464231..3c295b7403 100644 --- a/basis/compiler/tree/late-optimizations/late-optimizations.factor +++ b/basis/compiler/tree/late-optimizations/late-optimizations.factor @@ -6,12 +6,6 @@ compiler.tree.normalization compiler.tree.propagation compiler.tree.recursive namespaces sequences ; IN: compiler.tree.late-optimizations -! Late optimizations modify the tree such that stack flow -! information is no longer accurate, since we punt in -! 'splice-quot' and don't update everything that we should; -! this simplifies the code, improves performance, and we -! don't need the stack flow information after this pass anyway. - : splice-quot ( quot -- nodes ) [ build-tree diff --git a/basis/compiler/tree/normalization/normalization-docs.factor b/basis/compiler/tree/normalization/normalization-docs.factor new file mode 100644 index 0000000000..4289a4c4ed --- /dev/null +++ b/basis/compiler/tree/normalization/normalization-docs.factor @@ -0,0 +1,12 @@ +USING: assocs compiler.tree help.markup help.syntax kernel ; +IN: compiler.tree.normalization + +ARTICLE: "compiler.tree.normalization" "Normalize IR created by high level IR builder to simplify subsequent passes" +"A transform pass done before optimization can begin to fix up some oddities in the tree output by the stack checker:" +{ $list + { + "We rewrite the code so that all " { $link #introduce } " nodes are replaced with a single one, at the beginning of a program. This simplifies subsequent analysis." } + { "We normalize " { $link #call-recursive } " as follows. The stack checker says that the inputs of a #call-recursive are the entire stack at the time of the call. This is a conservative estimate; we don't know the exact number of stack values it touches until the " { $link #return-recursive } " node has been visited, because of row polymorphism. So in the normalize pass, we split a #call-recursive into a #copy of the unchanged values and a #call-recursive with trimmed inputs and outputs." } +} ; + +ABOUT: "compiler.tree.normalization" diff --git a/basis/compiler/tree/normalization/normalization.factor b/basis/compiler/tree/normalization/normalization.factor index e7e8a62983..30f6f6d9d4 100644 --- a/basis/compiler/tree/normalization/normalization.factor +++ b/basis/compiler/tree/normalization/normalization.factor @@ -7,22 +7,6 @@ kernel math math.order namespaces sequences stack-checker.backend stack-checker.branches ; IN: compiler.tree.normalization -! A transform pass done before optimization can begin to -! fix up some oddities in the tree output by the stack checker: -! -! - We rewrite the code so that all #introduce nodes are -! replaced with a single one, at the beginning of a program. -! This simplifies subsequent analysis. -! -! - We normalize #call-recursive as follows. The stack checker -! says that the inputs of a #call-recursive are the entire stack -! at the time of the call. This is a conservative estimate; we -! don't know the exact number of stack values it touches until -! the #return-recursive node has been visited, because of row -! polymorphism. So in the normalize pass, we split a -! #call-recursive into a #copy of the unchanged values and a -! #call-recursive with trimmed inputs and outputs. - GENERIC: normalize* ( node -- node' ) SYMBOL: introduction-stack diff --git a/basis/compiler/tree/tree-docs.factor b/basis/compiler/tree/tree-docs.factor index 6c860916a2..03306fc6b4 100644 --- a/basis/compiler/tree/tree-docs.factor +++ b/basis/compiler/tree/tree-docs.factor @@ -1,5 +1,5 @@ USING: assocs help.markup help.syntax kernel quotations sequences -stack-checker.alien stack-checker.visitor words ; +stack-checker.alien stack-checker.values stack-checker.visitor words ; IN: compiler.tree HELP: node @@ -25,10 +25,18 @@ HELP: #call } ; HELP: #introduce -{ $class-description "SSA tree node that puts an input value from the \"outside\" on the stack." } ; +{ $class-description "SSA tree node that puts an input value from the \"outside\" on the stack. It is used to \"introduce\" data stack parameter whenever they are needed. It has the following slots:" + { $table + { { $slot "out-d" } { "Array of values of the parameters being introduced." } } + } +} ; HELP: #push -{ $class-description "SSA tree node that puts a literal value on the stack." } +{ $class-description "SSA tree node that puts a literal value on the stack. It has the following slots:" + { $table + { { $slot "out-d" } { "A one item array containing the " { $link } " of the literal being pushed." } } + } +} { $notes "A " { $link quotation } " is also a literal." } ; HELP: #shuffle