Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/branches/SMLNJ/src/MLRISC/gc-safety/gc-gen.sml
ViewVC logotype

View of /sml/branches/SMLNJ/src/MLRISC/gc-safety/gc-gen.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 475 - (download) (annotate)
Wed Nov 10 22:59:58 1999 UTC (19 years, 8 months ago) by monnier
File size: 2432 byte(s)
version 110.24
(*
 * This module is reponsible for generating garbage collection 
 * code for all gc-points in the program.  That is, we delay the generation
 * of garbage collection code until all optimizations have been performed.
 * The gc code to be generated is determined by a callback to the client.
 *)

functor GCGen
   (structure MLTreeComp : MLTREECOMP
    structure IR         : MLRISC_IR
    structure GCMap      : GC_MAP
    structure InsnProps  : INSN_PROPERTIES
       sharing MLTreeComp.T.Constant = IR.I.Constant
       sharing MLTreeComp.T.PseudoOp = IR.CFG.P
       sharing IR.I = InsnProps.I = MLTreeComp.I
   ) : GC_GEN =
struct

   structure C   = IR.I.C
   structure T   = MLTreeComp.T
   structure IR  = IR
   structure CFG = IR.CFG
   structure GC  = GCMap.GC
   structure G   = Graph
   structure A   = Array
   structure Liveness = 
      GCLiveness(structure IR = IR
                 structure GCMap = GCMap
                 structure InsnProps = InsnProps)

   structure Gen = InstrGen
      (structure MLTree = T
       structure I = IR.I
      )

   type callgcCallback =
        { id     : int,
          label  : Label.label,
          roots  : (C.cell * GC.gctype) list,
          stream : (T.stm,C.regmap) T.stream
        } -> unit

   val debug = MLRiscControl.getFlag "debug-gc-gen"

   fun gcGen {callgc} (IR as G.GRAPH cfg) =
   let (*
        * Run gc-typed liveness analysis
        *)
       val table = Liveness.liveness IR

       (*
        * Check if a block is a GC point
        *)
       fun isGCPoint an = #contains BasicAnnotations.CALLGC an

       (*
        * For each gc-point, invoke the callback to generate GC code.
        *)
       fun process(b,b' as CFG.BLOCK{annotations,insns,...}) =
           if isGCPoint(!annotations) then
           let val stream = MLTreeComp.selectInstructions (Gen.newStream insns)
               val {liveIn,liveOut} = A.sub(table,b)
               val roots = liveIn
           in  if !debug then
                  print("id="^Int.toString b^
                        " roots="^Liveness.GCTypeMap.toString roots^"\n")
               else ();
                  callgc{ id     = b,
                          label  = CFG.defineLabel b',
                          roots  = liveIn,
                          stream = stream
                        }
           end
           else ()
           
       val _ = #forall_nodes cfg process
   in  IR
   end

end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0