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

Annotation of /sml/trunk/src/MLRISC/mlrisc/bbsched2.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (view) (download)

1 : monnier 16 (* bbsched2.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     (** bbsched2.sml - invoke scheduling after span dependent resolution **)
8 :    
9 :     functor BBSched2
10 :     (structure Flowgraph : FLOWGRAPH
11 :     structure Jumps : SDI_JUMPS
12 :     structure Emitter : EMITTER_NEW
13 :    
14 : monnier 167 sharing Emitter.P = Flowgraph.P
15 : monnier 16 sharing Flowgraph.I = Jumps.I = Emitter.I): BBSCHED =
16 :    
17 :     struct
18 :    
19 :     structure F = Flowgraph
20 :     structure I = F.I
21 :     structure C = I.C
22 :     structure E = Emitter
23 :     structure J = Jumps
24 :     structure P = Flowgraph.P
25 :    
26 :     fun error msg = MLRiscErrorMsg.impossible ("BBSched."^msg)
27 :    
28 :     datatype code =
29 :     SDI of {size : int ref, (* variable sized *)
30 :     insn : I.instruction}
31 :     | FIXED of {size: int, (* size of fixed instructions *)
32 :     insns: I.instruction list}
33 :    
34 :     datatype compressed =
35 :     PSEUDO of P.pseudo_op
36 :     | LABEL of Label.label
37 :     | CODE of code list
38 :     | CLUSTER of {comp : compressed list, regmap : int Intmap.intmap}
39 :    
40 :     val clusterList : compressed list ref = ref []
41 :     fun cleanUp() = clusterList := []
42 :    
43 :     fun bbsched(cluster as F.CLUSTER{blocks, regmap, ...}) = let
44 :     fun compress(F.PSEUDO pOp::rest) = PSEUDO pOp::compress rest
45 :     | compress(F.LABEL lab::rest) = LABEL lab:: compress rest
46 :     | compress(F.ORDERED blks::rest) = compress(blks@rest)
47 :     | compress(F.BBLOCK{insns, ...}::rest) = let
48 :     fun mkCode(0, [], [], code) = code
49 :     | mkCode(size, insns, [], code) = FIXED{size=size, insns=insns}:: code
50 :     | mkCode(size, insns, instr::instrs, code) = let
51 :     val s = J.minSize instr
52 :     in
53 :     if J.isSdi instr then let
54 :     val sdi = SDI{size=ref s, insn=instr}
55 :     in
56 :     if size = 0 then
57 :     mkCode(0, [], instrs, sdi::code)
58 :     else
59 :     mkCode(0, [], instrs,
60 :     sdi::FIXED{size=size, insns=insns}::code)
61 :     end
62 :     else mkCode(size+s, instr::insns, instrs, code)
63 :     end
64 :     in
65 :     CODE(mkCode(0, [], !insns, [])) :: compress rest
66 :     end
67 :     | compress [] = []
68 :     in clusterList:=CLUSTER{comp = compress blocks, regmap=regmap}:: (!clusterList)
69 :     end
70 :    
71 :     fun finish() = let
72 :     fun labels(PSEUDO pOp::rest, pos) =
73 :     (P.adjustLabels(pOp, pos); labels(rest, pos+P.sizeOf(pOp,pos)))
74 :     | labels(LABEL lab::rest, pos) =
75 :     (Label.setAddr(lab,pos); labels(rest, pos))
76 :     | labels(CODE code::rest, pos) = let
77 :     fun size(FIXED{size, ...}) = size
78 :     | size(SDI{size, ...}) = !size
79 :     in labels(rest, List.foldl (fn (c, b) => size(c) + b) pos code)
80 :     end
81 :     | labels(CLUSTER{comp, ...}::rest, pos) = labels(rest, labels(comp,pos))
82 :     | labels([], pos) = pos
83 :    
84 :     fun adjust(CLUSTER{comp, regmap}::cluster, pos, changed) = let
85 :     fun f (PSEUDO pOp::rest, pos, changed) =
86 :     f(rest, pos+P.sizeOf(pOp,pos), changed)
87 :     | f (LABEL _::rest, pos, changed) = f(rest, pos, changed)
88 :     | f (CODE code::rest, pos, changed) = let
89 :     fun doCode(FIXED{size, ...}::rest, pos, changed) =
90 :     doCode(rest, pos+size, changed)
91 :     | doCode(SDI{size, insn}::rest, pos, changed) = let
92 :     val newSize = J.sdiSize(insn, regmap, Label.addrOf, pos)
93 :     in
94 :     if newSize <= !size then doCode(rest, !size + pos, changed)
95 :     else (size:=newSize; doCode(rest, newSize+pos, true))
96 :     end
97 :     | doCode([], pos, changed) = f(rest, pos, changed)
98 :     in doCode(code, pos, changed)
99 :     end
100 :     | f ([], pos, changed) = adjust(cluster, pos, changed)
101 :     in f(comp, pos, changed)
102 :     end
103 :     | adjust(_::_, _, _) = error "adjust"
104 :     | adjust([], _, changed) = changed
105 :    
106 :     fun fixpoint zl = let
107 :     val size = labels(zl, 0)
108 :     in if adjust(zl, 0, false) then fixpoint zl else size
109 :     end
110 :    
111 :     fun emitCluster(CLUSTER{comp, regmap}) = let
112 :     fun emit(PSEUDO pOp) = E.pseudoOp pOp
113 :     | emit(LABEL lab) = E.defineLabel lab
114 :     | emit(CODE code) = let
115 :     fun emitInstrs insns = app (fn i => E.emitInstr(i, regmap)) insns
116 :     fun e(FIXED{insns, ...}) = emitInstrs insns
117 :     | e(SDI{size, insn}) = emitInstrs(J.expand(insn, !size))
118 :     in app e code
119 :     end
120 :     in app emit comp
121 :     end
122 :    
123 :     val compressed = (rev (!clusterList)) before cleanUp()
124 :     in
125 :     E.init(fixpoint compressed);
126 :     app emitCluster compressed
127 :     end (*finish*)
128 :    
129 :     end (* bbsched2 *)
130 :    
131 :    
132 :     (*
133 : monnier 167 * $Log: bbsched2.sml,v $
134 : monnier 223 * Revision 1.2 1998/10/06 14:07:44 george
135 :     * Flowgraph has been removed from modules that do not need it.
136 :     * Changes to compiler/CodeGen/*/*{MLTree,CG}.sml necessary.
137 :     * [leunga]
138 :     *
139 : monnier 167 * Revision 1.1.1.1 1998/04/08 18:39:02 george
140 :     * Version 110.5
141 :     *
142 : monnier 16 *)

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