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 467 - (view) (download)

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 :    
14 :     val codegen : CFG.cfg -> unit
15 :     sharing CFG.I = InsnProps.I
16 :     sharing MLTree.Constant = InsnProps.I.Constant
17 :     sharing MLTree.PseudoOp = CFG.P
18 :     ) : FLOWGRAPH_GEN =
19 :     struct
20 :    
21 :     structure I = CFG.I
22 :     structure C = I.C
23 :     structure S = MLTree.Stream
24 :     structure T = MLTree
25 :     structure P = CFG.P
26 :     structure Builder = ControlFlowGraphGenFn
27 :     (structure CFG = CFG
28 :     structure Stream = S
29 :     structure InsnProps = InsnProps
30 :     )
31 :    
32 :     type flowgraph = CFG.cfg
33 :    
34 :     fun newStream() =
35 :     let val cfg = ref(CFG.new(I.C.regmap()))
36 :     val {stream,next} = Builder.builder(!cfg)
37 :     val S.STREAM{beginCluster,endCluster,pseudoOp,emit,exitBlock,
38 :     comment,annotation,defineLabel,entryLabel,alias,phi,...}
39 :     = stream
40 :     fun exit liveRegs =
41 :     let val addReg = C.addCell C.GP
42 :     val addFreg = C.addCell C.FP
43 :     val addCCreg = C.addCell C.CC
44 :     (* we don't care about memory locations that may be live. *)
45 :     fun live(T.GPR(T.REG(_,r))::rest, acc) = live(rest, addReg(r, acc))
46 :     | live(T.FPR(T.FREG(_,f))::rest, acc) = live(rest, addFreg(f, acc))
47 :     | live(T.CCR(T.CC c)::rest, acc) = live(rest, addCCreg(c, acc))
48 :     | live(_::rest, acc) = live(rest, acc)
49 :     | live([], acc) = acc
50 :    
51 :     val lout = live(liveRegs, C.empty)
52 :     in exitBlock(lout) end
53 :    
54 :     fun endCFG a =
55 :     let val _ = endCluster a
56 :     val oldCFG = !cfg
57 :     val newCFG = CFG.new(I.C.regmap())
58 :     in cfg := newCFG;
59 :     next newCFG;
60 :     codegen oldCFG
61 :     end
62 :    
63 :     in S.STREAM{beginCluster= beginCluster,
64 :     endCluster = endCFG,
65 :     pseudoOp = pseudoOp,
66 :     emit = emit,
67 :     exitBlock = exit,
68 :     comment = comment,
69 :     annotation = annotation,
70 :     defineLabel = defineLabel,
71 :     entryLabel = entryLabel,
72 :     alias = alias,
73 :     phi = phi
74 :     }
75 :     end
76 :    
77 :     end
78 :    

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