Skip to content

Commit

Permalink
compiler.cfg.representations.selection: some initial docs from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjourne authored and mrjbq7 committed Jul 29, 2015
1 parent 31aae02 commit cdf9a85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 19 additions & 0 deletions basis/compiler/cfg/representations/selection/selection-docs.factor
@@ -0,0 +1,19 @@
USING: help.markup help.syntax math sequences ;
IN: compiler.cfg.representations.selection

HELP: costs
{ $var-description "Maps vreg to representation to cost." } ;

HELP: increase-cost
{ $values { "rep" "representation symbol" } { "scc" "?" } { "factor" integer } }
{ $description "Increase cost of keeping vreg in rep, making a choice of rep less likely. If the rep is not in the cost alist, it means this representation is prohibited." } ;

HELP: init-costs
{ $description "Initialize cost as 0 for each possibility." } ;

HELP: minimize-costs
{ $values { "costs" sequence } { "representations" sequence } }
{ $description "For every vreg, compute preferred representation, that minimizes costs." } ;

HELP: tagged-vregs
{ $var-description "Vregs which must be tagged at the definition site because there is at least one usage that is not int-rep. If all usages are int-rep it is safe to untag at the definition site." } ;
9 changes: 0 additions & 9 deletions basis/compiler/cfg/representations/selection/selection.factor
Expand Up @@ -12,9 +12,6 @@ FROM: assocs => change-at ;
FROM: namespaces => set ;
IN: compiler.cfg.representations.selection

! vregs which must be tagged at the definition site because
! there is at least one usage that is not int-rep. If all usages
! are int-rep it is safe to untag at the definition site.
SYMBOL: tagged-vregs

SYMBOL: vreg-reps
Expand Down Expand Up @@ -62,17 +59,12 @@ SYMBOL: possibilities
! For every vreg, compute the cost of keeping it in every possible
! representation.

! Cost map maps vreg to representation to cost.
SYMBOL: costs

: init-costs ( -- )
! Initialize cost as 0 for each possibility.
possibilities get [ [ 0 ] H{ } map>assoc ] assoc-map costs set ;

: increase-cost ( rep scc factor -- )
! Increase cost of keeping vreg in rep, making a choice of rep less
! likely. If the rep is not in the cost alist, it means this
! representation is prohibited.
[ costs get at 2dup key? ] dip
'[ [ current-loop-nesting 10^ _ * + ] change-at ] [ 2drop ] if ;

Expand Down Expand Up @@ -137,7 +129,6 @@ M: vreg-insn compute-insn-costs
[ [ compute-insn-costs ] each-non-phi ] bi
] each-basic-block ;

! For every vreg, compute preferred representation, that minimizes costs.
: minimize-costs ( costs -- representations )
[ nip assoc-empty? ] assoc-reject
[ >alist alist-min first ] assoc-map ;
Expand Down

0 comments on commit cdf9a85

Please sign in to comment.