(* This file is intended to load MLRISC optimization modules within
 * the toplevel interactive loop. At present various compiler data
 * structures can be graphically viewed. 
 *)

(* The following steps are required:
  Requires:
     daVinci: ftp://ftp.uni-bremen.de/pub/graphics/daVinci, 
    or
     vcg: http://www.cs.uni-sb.de/RW/users/sander/html/gsvcg1.html
  

  1. Load the optimizer sources:

	CM.make "src/compiler/MLRISC-OPTIMIZER.cm";

  2. At the top level execute:

       structure M = Compiler.Control.MLRISC;

       M.mlrisc :=true;				(* enable optimizer *)
       M.getString "viewer" := "daVinci";	(* set viewer *)
       M.getFlag "view-IR" := true;		(* enable viewer *)
       M.mlrisc_phases :=			(* set phases *)
	 ["cluster->cfg", "view-dom", "cfg->cluster"];

  3. Compiling anything from here onwards, will go through the 
     optimizer. 

  Currently, the optimizer uses two different representations:
  the cluster and the IR.  The cluster is the old representation used
  in the register allocator and instruction selection.  The IR
  is the new representation.  Most new optimizations operate on
  the new IR.

  Several phases are possible in the mlrisc_phases list such as:

   a. view-cfg  -- view control flow graph
   b. view-dom  -- view dominator tree
   c. view-pdom -- view post dominator tree
   d. view-doms -- view dominator tree and post dominator tree together.
                   The post dominator is upside down.
   e. view-cdg  -- view control dependence graph
   f. view-loop -- show loop nesting tree
   g. guess     -- apply static branch prediction
                   (this need better machine descriptions)
   h. reshape   -- reorder the branch structure using frequencies 
                    gathered by static branch prediction

  All phases above transform IR into IR, so 
  they must be enclosed in phases "cluster->cfg", and "cfg->cluster",
  which translate clusters into IRs and vice versa.  In addition,
  there is a phase "copy-prop", which performs copy propagation on
  clusters.
*)

Library
  structure Compiler
  structure MLRISCOptimizer
is

  basis.cm
  comp-lib.cm
  viscomp-lib.cm
  smlnj-lib.cm
  host-compiler.cm

  MLRISC.cm
	(* Could use the anchors to eliminate the path *)
  ../MLRISC/MLRISC-IR.cm
  ../MLRISC/MLRISC-Visual.cm
  ../MLRISC/MLRISC-Graphs.cm
  ../MLRISC/MLRISC-ir.cm
  ../MLRISC/MLRISC-Lib.cm

  CodeGen/optimizer/mlrisc-optimizer.sml
