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/trunk/src/compiler/CodeGen/main/machine-gen.sml
ViewVC logotype

View of /sml/trunk/src/compiler/CodeGen/main/machine-gen.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1016 - (download) (annotate)
Tue Jan 15 23:10:06 2002 UTC (17 years, 8 months ago) by george
File size: 4355 byte(s)
1. Since COPY instructions are no longer native to the architecture,
   a generic functor can be used to implement the expandCopies function.

2. Allowed EXPORT and IMPORT pseudo-op declarations to appear inside a
   TEXT segment.
(*
 * This is a generic functor that hooks everything together 
 * into an MLRISC backend.
 *)

functor MachineGen
  (structure MachSpec   : MACH_SPEC            (* machine specifications *) 
   structure Ext        : SMLNJ_MLTREE_EXT
   structure InsnProps  : INSN_PROPERTIES      (* instruction properties *)
   structure CpsRegs    : CPSREGS              (* CPS registers *)
		      where T.Region=CPSRegions
		        and T.Constant=SMLNJConstant 
			and T.Extension=Ext
   structure ClientPseudoOps : SMLNJ_PSEUDO_OPS
   structure PseudoOps  : PSEUDO_OPS     (* pseudo ops *)
	 	      where T = CpsRegs.T
		        and Client = ClientPseudoOps
   structure MLTreeComp : MLTREECOMP           (* instruction selection *)
		      where I = InsnProps.I
			and TS.T = CpsRegs.T
		        and TS.S.P = PseudoOps
   structure Asm        : INSTRUCTION_EMITTER  (* assembly *)
		      where S.P = PseudoOps
			and I = MLTreeComp.I
   structure Shuffle    : SHUFFLE              (* shuffling copies *) 
		      where I = Asm.I
   structure BackPatch  : BBSCHED              (* machine code emitter *)
		      where CFG = MLTreeComp.CFG
   structure RA         : CFG_OPTIMIZATION     (* register allocator *)
		      where CFG = BackPatch.CFG
   structure CCalls     : C_CALLS	       (* native C call generator *)
		      where T = CpsRegs.T
   structure OmitFramePtr : OMIT_FRAME_POINTER 
		      where CFG=RA.CFG
  ) : MACHINE_GEN =
struct

   structure G		= Graph 
   structure CFG        = BackPatch.CFG
   structure P          = InsnProps
   structure I          = CFG.I
   structure Cells      = I.C 
   structure T          = MLTreeComp.TS.T
   structure Stream     = MLTreeComp.TS
   structure Asm        = Asm
   structure Shuffle    = Shuffle
   structure MachSpec   = MachSpec
   structure MLTreeComp = MLTreeComp

   (* expand copies into their primitive moves.
    * Copies are no longer treated as span dependent, which was a hack.
    *)
   structure ExpandCpys = 
      CFGExpandCopies
	  (structure CFG = CFG   
	   structure Shuffle = Shuffle)

   fun omitFramePointer(cfg as G.GRAPH graph) = let
     val CFG.INFO{annotations, ...} = #graph_info graph 
   in
     if #contains MLRiscAnnotations.USES_VIRTUAL_FRAME_POINTER (!annotations) then 
     	(OmitFramePtr.omitframeptr
	     {vfp=CpsRegs.vfp, cfg=cfg, idelta=SOME 0:Int32.int option};
	 cfg)
     else cfg
   end     

   type mlriscPhase = string * (CFG.cfg -> CFG.cfg) 

   fun phase x = Stats.doPhase (Stats.makePhase x)
   fun makePhase(name,f) = (name, phase name f)

   val mc         = phase "MLRISC BackPatch.bbsched" BackPatch.bbsched
   val finish     = phase "MLRISC BackPatch.finish" BackPatch.finish
   val ra         = phase "MLRISC ra" RA.run
   val omitfp     = phase "MLRISC omit frame pointer" omitFramePointer
   val expandCpys = phase "MLRISC expand copies" ExpandCpys.run

   val raPhase = ("ra",ra)


   val optimizerHook = 
     ref [("ra", ra),
	  ("omitfp", omitfp),
	  ("expand copies", expandCpys)
	 ]

     
   (* Flowgraph generation *)
   structure FlowGraphGen =
      BuildFlowgraph(
         structure CFG = CFG
	 structure Props = InsnProps
	 structure Stream = MLTreeComp.TS.S)

   (* GC Invocation *)
   structure InvokeGC =
      InvokeGC(structure C     = CpsRegs
               structure MS    = MachSpec
	       structure CFG   = CFG
	       structure TS    = MLTreeComp.TS
              )

   fun compile cluster =
   let fun runPhases([],cluster) = cluster
         | runPhases((_,f)::phases,cluster) = runPhases(phases,f cluster)
   in  mc(runPhases(!optimizerHook,cluster))
   end
 
   (* compilation of CPS to MLRISC *)
   structure MLTreeGen =
      MLRiscGen(structure MachineSpec=MachSpec
                structure MLTreeComp=MLTreeComp
		structure Ext = Ext
                structure C=CpsRegs
                structure InvokeGC=InvokeGC
		structure ClientPseudoOps =ClientPseudoOps
                structure PseudoOp=PseudoOps
                structure Flowgen=FlowGraphGen
		structure CCalls = CCalls
		structure Cells = Cells
                val compile = compile
               )
	       

   val gen = phase "MLRISC MLTreeGen.codegen" MLTreeGen.codegen

   fun codegen x = 
       (* initialize all hidden states first *)
       (Label.reset();
        InvokeGC.init();   
        BackPatch.cleanUp(); 
        gen x
       )

end

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