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

Annotation of /sml/trunk/src/MLRISC/backpatch/backpatch.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 430 - (view) (download)

1 : monnier 247 (* 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 : monnier 411 structure Emitter : INSTRUCTION_EMITTER
13 : monnier 247 sharing Emitter.P = Flowgraph.P
14 :     sharing Flowgraph.I = Jumps.I = Emitter.I): BBSCHED =
15 :    
16 :     struct
17 :    
18 :     structure F = Flowgraph
19 :     structure I = F.I
20 :     structure C = I.C
21 :     structure E = Emitter
22 :     structure J = Jumps
23 :     structure P = Flowgraph.P
24 :    
25 : monnier 411 fun error msg = MLRiscErrorMsg.error("BBSched",msg)
26 : monnier 247
27 :     datatype code =
28 :     SDI of {size : int ref, (* variable sized *)
29 :     insn : I.instruction}
30 :     | FIXED of {size: int, (* size of fixed instructions *)
31 :     insns: I.instruction list}
32 :    
33 :     datatype compressed =
34 :     PSEUDO of P.pseudo_op
35 :     | LABEL of Label.label
36 :     | CODE of code list
37 : monnier 411 | CLUSTER of {comp : compressed list, regmap : int -> int}
38 : monnier 247
39 :     val clusterList : compressed list ref = ref []
40 :     fun cleanUp() = clusterList := []
41 :    
42 :     fun bbsched(cluster as F.CLUSTER{blocks, regmap, ...}) = let
43 : monnier 411 val regmap = C.lookup regmap
44 : monnier 247 fun compress(F.PSEUDO pOp::rest) = PSEUDO pOp::compress rest
45 :     | compress(F.LABEL lab::rest) = LABEL lab:: compress rest
46 :     | compress(F.BBLOCK{insns, ...}::rest) = let
47 :     fun mkCode(0, [], [], code) = code
48 :     | mkCode(size, insns, [], code) = FIXED{size=size, insns=insns}:: code
49 :     | mkCode(size, insns, instr::instrs, code) = let
50 :     val s = J.minSize instr
51 :     in
52 :     if J.isSdi instr then let
53 :     val sdi = SDI{size=ref s, insn=instr}
54 :     in
55 :     if size = 0 then
56 :     mkCode(0, [], instrs, sdi::code)
57 :     else
58 :     mkCode(0, [], instrs,
59 :     sdi::FIXED{size=size, insns=insns}::code)
60 :     end
61 :     else mkCode(size+s, instr::insns, instrs, code)
62 :     end
63 :     in
64 :     CODE(mkCode(0, [], !insns, [])) :: compress rest
65 :     end
66 :     | compress [] = []
67 :     in clusterList:=CLUSTER{comp = compress blocks, regmap=regmap}:: (!clusterList)
68 :     end
69 :    
70 :     fun finish() = let
71 :     fun labels(PSEUDO pOp::rest, pos) =
72 :     (P.adjustLabels(pOp, pos); labels(rest, pos+P.sizeOf(pOp,pos)))
73 :     | labels(LABEL lab::rest, pos) =
74 :     (Label.setAddr(lab,pos); labels(rest, pos))
75 :     | labels(CODE code::rest, pos) = let
76 :     fun size(FIXED{size, ...}) = size
77 :     | size(SDI{size, ...}) = !size
78 :     in labels(rest, List.foldl (fn (c, b) => size(c) + b) pos code)
79 :     end
80 :     | labels(CLUSTER{comp, ...}::rest, pos) = labels(rest, labels(comp,pos))
81 :     | labels([], pos) = pos
82 :    
83 :     fun adjust(CLUSTER{comp, regmap}::cluster, pos, changed) = let
84 :     fun f (PSEUDO pOp::rest, pos, changed) =
85 :     f(rest, pos+P.sizeOf(pOp,pos), changed)
86 :     | f (LABEL _::rest, pos, changed) = f(rest, pos, changed)
87 :     | f (CODE code::rest, pos, changed) = let
88 :     fun doCode(FIXED{size, ...}::rest, pos, changed) =
89 :     doCode(rest, pos+size, changed)
90 :     | doCode(SDI{size, insn}::rest, pos, changed) = let
91 :     val newSize = J.sdiSize(insn, regmap, Label.addrOf, pos)
92 :     in
93 :     if newSize <= !size then doCode(rest, !size + pos, changed)
94 :     else (size:=newSize; doCode(rest, newSize+pos, true))
95 :     end
96 :     | doCode([], pos, changed) = f(rest, pos, changed)
97 :     in doCode(code, pos, changed)
98 :     end
99 :     | f ([], pos, changed) = adjust(cluster, pos, changed)
100 :     in f(comp, pos, changed)
101 :     end
102 :     | adjust(_::_, _, _) = error "adjust"
103 :     | adjust([], _, changed) = changed
104 :    
105 :     fun fixpoint zl = let
106 :     val size = labels(zl, 0)
107 :     in if adjust(zl, 0, false) then fixpoint zl else size
108 :     end
109 :    
110 : monnier 429 val Emitter.S.STREAM{emit,defineLabel,beginCluster,pseudoOp,...} =
111 :     Emitter.makeStream []
112 : monnier 411
113 :     fun emitCluster(CLUSTER{comp, regmap},loc) = let
114 :     val emit = emit regmap
115 :     fun process(PSEUDO pOp,loc) = (pseudoOp pOp; loc + P.sizeOf(pOp,loc))
116 :     | process(LABEL lab,loc) = (defineLabel lab; loc)
117 :     | process(CODE code,loc) = let
118 :     fun emitInstrs insns = app emit insns
119 :     fun e(FIXED{insns, size,...},loc) = (emitInstrs insns; loc+size)
120 :     | e(SDI{size, insn},loc) =
121 :     (emitInstrs(J.expand(insn, !size, loc)); !size + loc)
122 :     in foldl e loc code
123 : monnier 247 end
124 : monnier 411 in foldl process loc comp
125 : monnier 247 end
126 :    
127 :     val compressed = (rev (!clusterList)) before cleanUp()
128 :     in
129 : monnier 429 beginCluster(fixpoint compressed);
130 : monnier 411 foldl emitCluster 0 compressed;
131 : monnier 247 ()
132 :     end (*finish*)
133 :    
134 :     end (* bbsched2 *)
135 :    
136 :    

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