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 744 - (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 : leunga 744 | CLUSTER of {comp : compressed list}
38 : monnier 247
39 :     val clusterList : compressed list ref = ref []
40 :     fun cleanUp() = clusterList := []
41 :    
42 : leunga 744 fun bbsched(cluster as F.CLUSTER{blocks, ...}) = let
43 : monnier 247 fun compress(F.PSEUDO pOp::rest) = PSEUDO pOp::compress rest
44 :     | compress(F.LABEL lab::rest) = LABEL lab:: compress rest
45 :     | compress(F.BBLOCK{insns, ...}::rest) = let
46 :     fun mkCode(0, [], [], code) = code
47 :     | mkCode(size, insns, [], code) = FIXED{size=size, insns=insns}:: code
48 :     | mkCode(size, insns, instr::instrs, code) = let
49 :     val s = J.minSize instr
50 :     in
51 :     if J.isSdi instr then let
52 :     val sdi = SDI{size=ref s, insn=instr}
53 :     in
54 :     if size = 0 then
55 :     mkCode(0, [], instrs, sdi::code)
56 :     else
57 :     mkCode(0, [], instrs,
58 :     sdi::FIXED{size=size, insns=insns}::code)
59 :     end
60 :     else mkCode(size+s, instr::insns, instrs, code)
61 :     end
62 :     in
63 :     CODE(mkCode(0, [], !insns, [])) :: compress rest
64 :     end
65 :     | compress [] = []
66 : george 545 | compress _ = error "compress"
67 : leunga 744 in clusterList:=CLUSTER{comp = compress blocks}:: (!clusterList)
68 : monnier 247 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 : leunga 744 fun adjust(CLUSTER{comp}::cluster, pos, changed) = let
84 : monnier 247 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 : leunga 744 val newSize = J.sdiSize(insn, Label.addrOf, pos)
92 : monnier 247 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 : george 545 | f _ = error "adjust.f"
101 : monnier 247 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 : monnier 429 val Emitter.S.STREAM{emit,defineLabel,beginCluster,pseudoOp,...} =
112 :     Emitter.makeStream []
113 : monnier 411
114 : leunga 744 fun emitCluster(CLUSTER{comp},loc) = let
115 : monnier 411 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 : george 545 | process _ = error "process"
125 : monnier 411 in foldl process loc comp
126 : monnier 247 end
127 : george 545 | emitCluster _ = error "emitCluster"
128 : monnier 247
129 :     val compressed = (rev (!clusterList)) before cleanUp()
130 :     in
131 : monnier 429 beginCluster(fixpoint compressed);
132 : monnier 411 foldl emitCluster 0 compressed;
133 : monnier 247 ()
134 :     end (*finish*)
135 :    
136 :     end (* bbsched2 *)
137 :    
138 :    

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