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 545 - (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 : george 545 | compress _ = error "compress"
68 : monnier 247 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 : george 545 | f _ = error "adjust.f"
102 : monnier 247 in f(comp, pos, changed)
103 :     end
104 :     | adjust(_::_, _, _) = error "adjust"
105 :     | adjust([], _, changed) = changed
106 :    
107 :     fun fixpoint zl = let
108 :     val size = labels(zl, 0)
109 :     in if adjust(zl, 0, false) then fixpoint zl else size
110 :     end
111 :    
112 : monnier 429 val Emitter.S.STREAM{emit,defineLabel,beginCluster,pseudoOp,...} =
113 :     Emitter.makeStream []
114 : monnier 411
115 :     fun emitCluster(CLUSTER{comp, regmap},loc) = let
116 :     val emit = emit regmap
117 :     fun process(PSEUDO pOp,loc) = (pseudoOp pOp; loc + P.sizeOf(pOp,loc))
118 :     | process(LABEL lab,loc) = (defineLabel lab; loc)
119 :     | process(CODE code,loc) = let
120 :     fun emitInstrs insns = app emit insns
121 :     fun e(FIXED{insns, size,...},loc) = (emitInstrs insns; loc+size)
122 :     | e(SDI{size, insn},loc) =
123 :     (emitInstrs(J.expand(insn, !size, loc)); !size + loc)
124 :     in foldl e loc code
125 : monnier 247 end
126 : george 545 | process _ = error "process"
127 : monnier 411 in foldl process loc comp
128 : monnier 247 end
129 : george 545 | emitCluster _ = error "emitCluster"
130 : monnier 247
131 :     val compressed = (rev (!clusterList)) before cleanUp()
132 :     in
133 : monnier 429 beginCluster(fixpoint compressed);
134 : monnier 411 foldl emitCluster 0 compressed;
135 : monnier 247 ()
136 :     end (*finish*)
137 :    
138 :     end (* bbsched2 *)
139 :    
140 :    

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