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/IR/mlrisc-liveness.sml
ViewVC logotype

View of /sml/branches/SMLNJ/src/MLRISC/IR/mlrisc-liveness.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (download) (annotate)
Fri Sep 3 00:25:03 1999 UTC (19 years, 11 months ago) by monnier
File size: 2437 byte(s)
version 110.19
(*
 * This module performs liveness analysis.
 * It is implemented by instantiating the data flow analyzer module.
 *
 * -- Allen
 *)

signature LIVENESS_ANALYSIS =
sig
  
   structure CFG : CONTROL_FLOW_GRAPH
   structure I   : INSTRUCTIONS
       sharing CFG.I = I

   val liveness : 
       { cfg     : CFG.cfg,
         liveOut : CFG.block Graph.node -> RegSet.regset,
         defUse  : CFG.block Graph.node -> RegSet.regset * RegSet.regset
       } -> unit

   val getLiveness : CFG.cfg -> Graph.node_id -> 
                           {livein: RegSet.regset, liveout: RegSet.regset}

end

functor LivenessAnalysisFn(CFG : CONTROL_FLOW_GRAPH) : LIVENESS_ANALYSIS =
struct

   structure CFG = CFG
   structure I   = CFG.I
   structure A   = Annotations
   structure S   = RegSet
   structure G   = Graph

   val {put : (S.regset * S.regset) * A.annotations -> A.annotations,
        get, 
        rmv} = A.new() 

   structure Liveness =
      DataflowFn
         (struct
              structure CFG   = CFG
              type domain     = S.regset
              val  forward    = false
              val  bot        = S.empty
              val  ==         = S.==
              val  join       = S.union
              val  op +       = S.+
              val  op -       = S.-
              type dataflow_info = 
                  { liveOut : CFG.block Graph.node -> S.regset,
                    defUse  : CFG.block Graph.node -> S.regset * S.regset
                  }

              fun prologue(cfg,{defUse,liveOut}) (b,b') =
                  let val (def,use) = defUse(b,b')
                      val live_out  = liveOut(b,b')
                  in  { input    = live_out,
	                output   = (live_out - def) + use,
	                transfer = fn live_out => (live_out - def) + use
                      }
                  end

              fun epilogue _ { node = (b,CFG.BLOCK{annotations,...}), 
                               input=liveOut, output=liveIn } = 
                  annotations := put((liveIn,liveOut),!annotations)
         end
        )

   fun liveness {cfg,liveOut,defUse} = 
      (Liveness.analyze(cfg,{liveOut=liveOut,defUse=defUse}); ())

   fun getLiveness (G.GRAPH cfg) b = 
       let val CFG.BLOCK{annotations,...} = #node_info cfg b
       in  case get(!annotations) of
              SOME(x,y) => {livein=x,liveout=y}
           |  NONE => {livein=S.empty,liveout=S.empty}
       end

end


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