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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/IR/mlrisc-cfg-gen2.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/IR/mlrisc-cfg-gen2.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 498 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/IR/mlrisc-cfg-gen2.sml

1 : monnier 467 (*
2 :     * This module builds a CFG from a stream of instructions.
3 :     * We use the FLOWGRPAH_GEN interface here, which is the
4 :     * default interface used by the core MLRISC.
5 :     *
6 :     * -- Allen
7 :     *)
8 :    
9 :     functor CFGGen
10 :     (structure CFG : CONTROL_FLOW_GRAPH
11 :     structure InsnProps : INSN_PROPERTIES
12 :     structure MLTree : MLTREE
13 :     sharing CFG.I = InsnProps.I
14 :     sharing MLTree.Constant = InsnProps.I.Constant
15 :     sharing MLTree.PseudoOp = CFG.P
16 :     ) : FLOWGRAPH_GEN =
17 :     struct
18 :    
19 :     structure I = CFG.I
20 :     structure C = I.C
21 :     structure S = MLTree.Stream
22 :     structure T = MLTree
23 :     structure P = CFG.P
24 :     structure Builder = ControlFlowGraphGenFn
25 :     (structure CFG = CFG
26 :     structure Stream = S
27 :     structure InsnProps = InsnProps
28 :     )
29 :    
30 :     type flowgraph = CFG.cfg
31 :    
32 : monnier 498 fun newStream{compile,flowgraph} =
33 :     let val cfg = ref(case flowgraph of
34 :     NONE => CFG.new(I.C.regmap())
35 :     | SOME cfg => cfg
36 :     )
37 : monnier 467 val {stream,next} = Builder.builder(!cfg)
38 :     val S.STREAM{beginCluster,endCluster,pseudoOp,emit,exitBlock,
39 :     comment,annotation,defineLabel,entryLabel,alias,phi,...}
40 :     = stream
41 :     fun exit liveRegs =
42 :     let val addReg = C.addCell C.GP
43 :     val addFreg = C.addCell C.FP
44 :     val addCCreg = C.addCell C.CC
45 :     (* we don't care about memory locations that may be live. *)
46 :     fun live(T.GPR(T.REG(_,r))::rest, acc) = live(rest, addReg(r, acc))
47 :     | live(T.FPR(T.FREG(_,f))::rest, acc) = live(rest, addFreg(f, acc))
48 :     | live(T.CCR(T.CC c)::rest, acc) = live(rest, addCCreg(c, acc))
49 :     | live(_::rest, acc) = live(rest, acc)
50 :     | live([], acc) = acc
51 :    
52 :     val lout = live(liveRegs, C.empty)
53 :     in exitBlock(lout) end
54 :    
55 :     fun endCFG a =
56 :     let val _ = endCluster a
57 :     val oldCFG = !cfg
58 :     val newCFG = CFG.new(I.C.regmap())
59 :     in cfg := newCFG;
60 :     next newCFG;
61 : monnier 498 compile oldCFG
62 : monnier 467 end
63 :    
64 :     in S.STREAM{beginCluster= beginCluster,
65 :     endCluster = endCFG,
66 :     pseudoOp = pseudoOp,
67 :     emit = emit,
68 :     exitBlock = exit,
69 :     comment = comment,
70 :     annotation = annotation,
71 :     defineLabel = defineLabel,
72 :     entryLabel = entryLabel,
73 :     alias = alias,
74 :     phi = phi
75 :     }
76 :     end
77 :    
78 :     end
79 :    

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