Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/x86/ra/x86Spill.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/x86/ra/x86Spill.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 247, Sat Apr 17 18:47:13 1999 UTC revision 411, Fri Sep 3 00:25:03 1999 UTC
# Line 21  Line 21 
21    
22    
23  functor X86Spill(structure Instr: X86INSTR  functor X86Spill(structure Instr: X86INSTR
24                   structure Asm : EMITTER_NEW where I = Instr (* XXX *)                   structure Asm : INSTRUCTION_EMITTER where I = Instr (* XXX *)
25    
26                   ) : X86SPILL = struct                   ) : X86SPILL = struct
27    
# Line 48  Line 48 
48    fun immedOrReg(I.Direct r) = true    fun immedOrReg(I.Direct r) = true
49      | immedOrReg opnd = immed opnd      | immedOrReg opnd = immed opnd
50    
51    fun eqEA(I.Displace{base=b1, disp=d1}, I.Displace{base=b2, disp=d2}) =    fun eqEA(I.Displace{base=b1, disp=d1,...},I.Displace{base=b2, disp=d2,...}) =
52        b1=b2 andalso        b1=b2 andalso
53         (case (d1, d2)         (case (d1, d2)
54           of (I.Immed i1, I.Immed i2) => i1 = i2           of (I.Immed i1, I.Immed i2) => i1 = i2
# Line 63  Line 63 
63    fun spill(instr, reg, spillLoc) = let    fun spill(instr, reg, spillLoc) = let
64      fun done code = {code=code, proh=[], instr=NONE}      fun done code = {code=code, proh=[], instr=NONE}
65      fun rewrite new old = if old=reg then new else old      fun rewrite new old = if old=reg then new else old
66    in      fun spillIt instr =
67      case instr      case instr
68      of I.CALL(opnd, (r,f,c), uses) => let      of I.CALL(opnd, (r,f,c), uses, mem) => let
69           val tmpR = newReg()           val tmpR = newReg()
70         in         in
71           {proh=[tmpR],           {proh=[tmpR],
72            instr=SOME(I.CALL(opnd, (map (rewrite tmpR) r,f,c), uses)),            instr=SOME(I.CALL(opnd, (map (rewrite tmpR) r,f,c), uses, mem)),
73            code=[I.MOVE{mvOp=I.MOVL, src=I.Direct tmpR, dst=spillLoc}] }            code=[I.MOVE{mvOp=I.MOVL, src=I.Direct tmpR, dst=spillLoc}] }
74         end         end
75       | I.MOVE{mvOp=I.MOVZX, src, dst} => let(* dst must always be a register *)       | I.MOVE{mvOp=I.MOVZX, src, dst} => let(* dst must always be a register *)
# Line 122  Line 122 
122       | I.POP _ => done [I.POP spillLoc]       | I.POP _ => done [I.POP spillLoc]
123       | I.COPY _ => error "spill: COPY"       | I.COPY _ => error "spill: COPY"
124       | I.FNSTSW  => error "spill: FNSTSW"       | I.FNSTSW  => error "spill: FNSTSW"
125         | I.ANNOTATION{i,a} => spillIt i
126       | _ => error "spill"       | _ => error "spill"
127      in spillIt instr
128    end    end
129    
130    fun reload(instr, reg, spillLoc) = let    fun reload(instr, reg, spillLoc) = let
131      fun operand(rt, opnd) =      fun operand(rt, opnd) =
132        (case opnd        (case opnd
133         of I.Direct r => if r=reg then I.Direct rt else opnd         of I.Direct r => if r=reg then I.Direct rt else opnd
134          | I.Displace{base, disp} =>          | I.Displace{base, disp, mem} =>
135             if base=reg then I.Displace{base=rt, disp=disp} else opnd             if base=reg then I.Displace{base=rt, disp=disp, mem=mem} else opnd
136          | I.Indexed{base=NONE, index, scale, disp} =>          | I.Indexed{base=NONE, index, scale, disp, mem=mem} =>
137             if index=reg then             if index=reg then
138               I.Indexed{base=NONE, index=rt, scale=scale, disp=disp}               I.Indexed{base=NONE, index=rt, scale=scale, disp=disp, mem=mem}
139             else opnd             else opnd
140          | I.Indexed{base as SOME b, index, scale, disp} =>          | I.Indexed{base as SOME b, index, scale, disp, mem=mem} =>
141             if b=reg then             if b=reg then
142               operand(rt, I.Indexed{base=SOME rt, index=index,               operand(rt, I.Indexed{base=SOME rt, index=index,
143                                     scale=scale, disp=disp})                                     scale=scale, disp=disp, mem=mem})
144             else if index=reg then             else if index=reg then
145               I.Indexed{base=base, index=rt, scale=scale, disp=disp}               I.Indexed{base=base, index=rt, scale=scale, disp=disp, mem=mem}
146                  else opnd                  else opnd
147          | opnd => opnd          | opnd => opnd
148        (*esac*))        (*esac*))
149    
150      fun uses(I.Direct r) = r = reg      (* XXX *)      fun uses(I.Direct r) = r = reg      (* XXX *)
151        | uses(I.Displace{base, disp}) = base=reg        | uses(I.Displace{base, disp, mem}) = base=reg
152        | uses(I.Indexed{base=NONE, index, scale, disp}) = index=reg        | uses(I.Indexed{base=NONE, index, scale, disp, mem}) = index=reg
153        | uses(I.Indexed{base=SOME b, index, scale, disp})= b=reg orelse index=reg        | uses(I.Indexed{base=SOME b, index, scale, disp, mem})=
154              b=reg orelse index=reg
155        | uses _ = false        | uses _ = false
156      fun done c = {code=c, proh=[]}      fun done c = {code=c, proh=[]}
157      fun rewrite rt r = if r=reg then rt else r      fun rewrite rt r = if r=reg then rt else r
# Line 157  Line 160 
160        val tmpR = newReg()        val tmpR = newReg()
161      in {code=[ldSpillLoc(tmpR), f tmpR], proh=[tmpR]}      in {code=[ldSpillLoc(tmpR), f tmpR], proh=[tmpR]}
162      end      end
163    in      fun reloadIt instr =
164      case instr      case instr
165      of I.JMP(I.Direct _, labs) => {code=[I.JMP(spillLoc, labs)], proh=[]}      of I.JMP(I.Direct _, labs) => {code=[I.JMP(spillLoc, labs)], proh=[]}
166       | I.JMP(opnd, labs) => withTmp(fn tmpR => I.JMP(operand(tmpR, opnd), labs))       | I.JMP(opnd, labs) => withTmp(fn tmpR => I.JMP(operand(tmpR, opnd), labs))
167       | I.JCC{opnd=I.Direct _, cond} => done[I.JCC{opnd=spillLoc, cond=cond}]       | I.JCC{opnd=I.Direct _, cond} => done[I.JCC{opnd=spillLoc, cond=cond}]
168       | I.JCC{opnd, cond} =>       | I.JCC{opnd, cond} =>
169          withTmp(fn tmpR => I.JCC{opnd=operand(tmpR, opnd), cond=cond})          withTmp(fn tmpR => I.JCC{opnd=operand(tmpR, opnd), cond=cond})
170       | I.CALL(opnd, defs, uses as (r,f,c)) =>       | I.CALL(opnd, defs, uses as (r,f,c), mem) =>
171          withTmp(fn tmpR =>          withTmp(fn tmpR =>
172                    I.CALL(operand(tmpR, opnd), defs, (map (rewrite tmpR) r, f,c)))                    I.CALL(operand(tmpR, opnd), defs,
173                             (map (rewrite tmpR) r, f,c), mem))
174       | I.MOVE{mvOp, src, dst as I.Direct _} =>       | I.MOVE{mvOp, src, dst as I.Direct _} =>
175          withTmp(fn tmpR =>I.MOVE{mvOp=mvOp, src=operand(tmpR, src), dst=dst})          withTmp(fn tmpR =>I.MOVE{mvOp=mvOp, src=operand(tmpR, src), dst=dst})
176       | I.MOVE{mvOp, src as I.Direct _, dst} =>       | I.MOVE{mvOp, src as I.Direct _, dst} =>
# Line 207  Line 211 
211          withTmp(fn tmpR =>          withTmp(fn tmpR =>
212                    I.FBINARY{binOp=binOp, src=operand(tmpR, src), dst=dst})                    I.FBINARY{binOp=binOp, src=operand(tmpR, src), dst=dst})
213    
214         | I.ANNOTATION{i,a} => reloadIt i
215       | _ => error "reload"       | _ => error "reload"
216      in reloadIt instr
217    end (*reload*)    end (*reload*)
218    
219    fun fspill(instr, reg, spillLoc) =    fun fspill(instr, reg, spillLoc) =
220      (case instr      (case instr
221        of I.FSTP _ => {proh=[], instr=NONE, code=[I.FSTP spillLoc]}        of I.FSTP _ => {proh=[], instr=NONE, code=[I.FSTP spillLoc]}
222           | I.ANNOTATION{i,a} => fspill(i, reg, spillLoc)
223         | _ => error "fspill"         | _ => error "fspill"
224      (*esac*))      (*esac*))
225    
# Line 224  Line 231 
231               {code=[I.FBINARY{binOp=binOp, src=spillLoc, dst=dst}],               {code=[I.FBINARY{binOp=binOp, src=spillLoc, dst=dst}],
232                proh=[]}                proh=[]}
233             else error "freload:FBINARY"             else error "freload:FBINARY"
234           | I.ANNOTATION{i,a} => freload(i, reg, spillLoc)
235         | _  => error "freload"         | _  => error "freload"
236      (*esac*))      (*esac*))
237  end  end

Legend:
Removed from v.247  
changed lines
  Added in v.411

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