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

Diff of /sml/trunk/src/MLRISC/x86/mltree/x86.sml

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

revision 731, Fri Nov 10 22:57:45 2000 UTC revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 70  Line 70 
70    structure LE = I.LabelExp    structure LE = I.LabelExp
71    structure A = MLRiscAnnotations    structure A = MLRiscAnnotations
72    
73    type instrStream = (I.instruction,C.regmap,C.cellset) T.stream    type instrStream = (I.instruction,C.cellset) T.stream
74    type mltreeStream = (T.stm,C.regmap,T.mlrisc list) T.stream    type mltreeStream = (T.stm,T.mlrisc list) T.stream
75    
76    datatype kind = REAL | INTEGER    datatype kind = REAL | INTEGER
77    
# Line 91  Line 91 
91    val rewriteMemReg = rewriteMemReg    val rewriteMemReg = rewriteMemReg
92    
93    (* The following hardcoded *)    (* The following hardcoded *)
94    fun isMemReg r = rewriteMemReg andalso r >= 8 andalso r < 32    fun isMemReg r = rewriteMemReg andalso
95                       let val r = C.registerNum r
96                       in  r >= 8 andalso r < 32
97                       end
98    fun isFMemReg r = if enableFastFPMode andalso !fast_floating_point    fun isFMemReg r = if enableFastFPMode andalso !fast_floating_point
99                      then r >= 32+8 andalso r < 32+32                      then let val r = C.registerNum r
100                             in r >= 8 andalso r < 32 end
101                      else true                      else true
102    val isAnyFMemReg = List.exists (fn r => r >= 32+8 andalso r < 32+32)    val isAnyFMemReg = List.exists (fn r =>
103                                      let val r = C.registerNum r
104                                      in  r >= 8 andalso r < 32 end
105                                     )
106    
107    val ST0 = C.ST 0    val ST0 = C.ST 0
108    val ST7 = C.ST 7    val ST7 = C.ST 7
# Line 106  Line 113 
113    fun selectInstructions    fun selectInstructions
114         (instrStream as         (instrStream as
115          S.STREAM{emit,defineLabel,entryLabel,pseudoOp,annotation,          S.STREAM{emit,defineLabel,entryLabel,pseudoOp,annotation,
116                   beginCluster,endCluster,exitBlock,alias,phi,comment,...}) =                   beginCluster,endCluster,exitBlock,comment,...}) =
117    let exception EA    let exception EA
118    
119        (* label where a trap is generated -- one per cluster *)        (* label where a trap is generated -- one per cluster *)
# Line 154  Line 161 
161        fun copy([], [], an) = ()        fun copy([], [], an) = ()
162          | copy(dst, src, an) =          | copy(dst, src, an) =
163            let fun mvInstr{dst as I.MemReg rd, src as I.MemReg rs} =            let fun mvInstr{dst as I.MemReg rd, src as I.MemReg rs} =
164                    if rd = rs then [] else                    if C.sameColor(rd,rs) then [] else
165                    let val tmpR = I.Direct(newReg())                    let val tmpR = I.Direct(newReg())
166                    in  [I.MOVE{mvOp=I.MOVL, src=src, dst=tmpR},                    in  [I.MOVE{mvOp=I.MOVL, src=src, dst=tmpR},
167                         I.MOVE{mvOp=I.MOVL, src=tmpR, dst=dst}]                         I.MOVE{mvOp=I.MOVL, src=tmpR, dst=dst}]
168                    end                    end
169                  | mvInstr{dst=I.Direct rd, src=I.Direct rs} =                  | mvInstr{dst=I.Direct rd, src=I.Direct rs} =
170                      if rd = rs then []                      if C.sameColor(rd,rs) then []
171                      else [I.COPY{dst=[rd], src=[rs], tmp=NONE}]                      else [I.COPY{dst=[rd], src=[rs], tmp=NONE}]
172                  | mvInstr{dst, src} = [I.MOVE{mvOp=I.MOVL, src=src, dst=dst}]                  | mvInstr{dst, src} = [I.MOVE{mvOp=I.MOVL, src=src, dst=dst}]
173            in            in
174               emits (Shuffle.shuffle{mvInstr=mvInstr, ea=IntReg}               emits (Shuffle.shuffle{mvInstr=mvInstr, ea=IntReg}
175                 {regmap=fn r => r, tmp=SOME(I.Direct(newReg())),                 {tmp=SOME(I.Direct(newReg())),
176                  dst=dst, src=src})                  dst=dst, src=src})
177            end            end
178    
# Line 241  Line 248 
248                fun mvInstr{dst, src} = [I.FMOVE{fsize=fsize, src=src, dst=dst}]                fun mvInstr{dst, src} = [I.FMOVE{fsize=fsize, src=src, dst=dst}]
249            in            in
250                emits (Shuffle.shuffle{mvInstr=mvInstr, ea=RealReg}                emits (Shuffle.shuffle{mvInstr=mvInstr, ea=RealReg}
251                  {regmap=fn r => r,                  {tmp=case dst of
                  tmp=case dst of  
252                         [_] => NONE                         [_] => NONE
253                       |  _  => SOME(I.FPR(newReg())),                       |  _  => SOME(I.FPR(newReg())),
254                   dst=dst, src=src})                   dst=dst, src=src})
# Line 265  Line 271 
271    
272        (* Move and annotate *)        (* Move and annotate *)
273        fun move'(src as I.Direct s, dst as I.Direct d, an) =        fun move'(src as I.Direct s, dst as I.Direct d, an) =
274            if s=d then ()            if C.sameColor(s,d) then ()
275            else mark(I.COPY{dst=[d], src=[s], tmp=NONE}, an)            else mark(I.COPY{dst=[d], src=[s], tmp=NONE}, an)
276          | move'(src, dst, an) = mark(I.MOVE{mvOp=I.MOVL, src=src, dst=dst}, an)          | move'(src, dst, an) = mark(I.MOVE{mvOp=I.MOVL, src=src, dst=dst}, an)
277    
# Line 358  Line 364 
364            (* generate code for tree and ensure that it is not in %esp *)            (* generate code for tree and ensure that it is not in %esp *)
365            and exprNotEsp tree =            and exprNotEsp tree =
366                let val r = expr tree                let val r = expr tree
367                in  if r = C.esp then                in  if C.sameColor(r, C.esp) then
368                       let val tmp = newReg()                       let val tmp = newReg()
369                       in  move(I.Direct r, I.Direct tmp); tmp end                       in  move(I.Direct r, I.Direct tmp); tmp end
370                    else r                    else r
# Line 370  Line 376 
376              | displace(trees, t, b as SOME base, NONE, _, d) = (* no index *)              | displace(trees, t, b as SOME base, NONE, _, d) = (* no index *)
377                (* make t the index, but make sure that it is not %esp! *)                (* make t the index, but make sure that it is not %esp! *)
378                let val i = expr t                let val i = expr t
379                in  if i = C.esp then                in  if C.sameColor(i, C.esp) then
380                      (* swap base and index *)                      (* swap base and index *)
381                      if base <> C.esp then                      if C.sameColor(base, C.esp) then
382                         doEA(trees, SOME i, b, 0, d)                         doEA(trees, SOME i, b, 0, d)
383                      else  (* base and index = %esp! *)                      else  (* base and index = %esp! *)
384                         let val index = newReg()                         let val index = newReg()
# Line 451  Line 457 
457        and doExpr(exp, rd : I.C.cell, an) =        and doExpr(exp, rd : I.C.cell, an) =
458            let val rdOpnd = IntReg rd            let val rdOpnd = IntReg rd
459    
460                fun equalRd(I.Direct r) = r = rd                fun equalRd(I.Direct r) = C.sameColor(r, rd)
461                  | equalRd(I.MemReg r) = r = rd                  | equalRd(I.MemReg r) = C.sameColor(r, rd)
462                  | equalRd _ = false                  | equalRd _ = false
463    
464                   (* Emit a binary operator.  If the destination is                   (* Emit a binary operator.  If the destination is
# Line 765  Line 771 
771                    (* Generate addition *)                    (* Generate addition *)
772                fun addition(e1, e2) =                fun addition(e1, e2) =
773                    case e1 of                    case e1 of
774                      T.REG(_,rs) => if rs = rd then addN e2 else addition1(e1,e2)                      T.REG(_,rs) => if C.sameColor(rs,rd) then addN e2
775                                       else addition1(e1,e2)
776                    | _ => addition1(e1,e2)                    | _ => addition1(e1,e2)
777                and addition1(e1, e2) =                and addition1(e1, e2) =
778                    case e2 of                    case e2 of
779                      T.REG(_,rs) => if rs = rd then addN e1 else addition2(e1,e2)                      T.REG(_,rs) => if C.sameColor(rs,rd) then addN e1
780                                       else addition2(e1,e2)
781                    | _ => addition2(e1,e2)                    | _ => addition2(e1,e2)
782                and addition2(e1,e2) =                and addition2(e1,e2) =
783                  (dstMustBeReg(fn (dstR, _) =>                  (dstMustBeReg(fn (dstR, _) =>
# Line 852  Line 860 
860               | T.LOAD(8, ea, mem) => load8(ea, mem)               | T.LOAD(8, ea, mem) => load8(ea, mem)
861               | T.LOAD(16, ea, mem) => load16(ea, mem)               | T.LOAD(16, ea, mem) => load16(ea, mem)
862               | T.LOAD(32, ea, mem) => load32(ea, mem)               | T.LOAD(32, ea, mem) => load32(ea, mem)
863               | T.CVTI2I(_,T.SIGN_EXTEND,_,T.LOAD(8,ea,mem)) => load8s(ea, mem)               | T.SX(_,_,T.LOAD(8,ea,mem)) => load8s(ea, mem)
864               | T.CVTI2I(_,T.SIGN_EXTEND,_,T.LOAD(16,ea,mem)) => load16s(ea, mem)               | T.SX(_,_,T.LOAD(16,ea,mem)) => load16s(ea, mem)
865    
866               | T.COND(32, T.CMP(ty, cc, t1, t2), T.LI yes, T.LI no) =>               | T.COND(32, T.CMP(ty, cc, t1, t2), T.LI yes, T.LI no) =>
867                   setcc(ty, cc, t1, t2, toInt32 yes, toInt32 no)                   setcc(ty, cc, t1, t2, toInt32 yes, toInt32 no)
# Line 931  Line 939 
939             * The zero is for setting the condition code!             * The zero is for setting the condition code!
940             * I have no idea why this is used.             * I have no idea why this is used.
941             *)             *)
942        and doCCexpr(T.CMP(ty, cc, t1, t2), 0, an) =        and doCCexpr(T.CMP(ty, cc, t1, t2), rd, an) =
943              if C.sameColor(rd, C.eflags) then
944            (cmp(false, ty, cc, t1, t2, an); ())            (cmp(false, ty, cc, t1, t2, an); ())
945              else
946                 error "doCCexpr: cmp"
947          | doCCexpr(T.CCMARK(e,A.MARKREG f),rd,an) = (f rd; doCCexpr(e,rd,an))          | doCCexpr(T.CCMARK(e,A.MARKREG f),rd,an) = (f rd; doCCexpr(e,rd,an))
948          | doCCexpr(T.CCMARK(e,a), rd, an) = doCCexpr(e,rd,a::an)          | doCCexpr(T.CCMARK(e,a), rd, an) = doCCexpr(e,rd,a::an)
949          | doCCexpr(T.CCEXT e, cd, an) =          | doCCexpr(T.CCEXT e, cd, an) =
# Line 1000  Line 1011 
1011         (* convert mlrisc to cellset:         (* convert mlrisc to cellset:
1012          *)          *)
1013         and cellset mlrisc =         and cellset mlrisc =
1014             let val addCCReg = C.addCell C.CC             let val addCCReg = C.CellSet.add
1015                 fun g([],acc) = acc                 fun g([],acc) = acc
1016                   | g(T.GPR(T.REG(_,r))::regs,acc)  = g(regs,C.addReg(r,acc))                   | g(T.GPR(T.REG(_,r))::regs,acc)  = g(regs,C.addReg(r,acc))
1017                   | g(T.FPR(T.FREG(_,f))::regs,acc) = g(regs,C.addFreg(f,acc))                   | g(T.FPR(T.FREG(_,f))::regs,acc) = g(regs,C.addFreg(f,acc))
# Line 1018  Line 1029 
1029            let val src = (* movb has to use %eax as source. Stupid x86! *)            let val src = (* movb has to use %eax as source. Stupid x86! *)
1030                   case immedOrReg(operand d) of                   case immedOrReg(operand d) of
1031                       src as I.Direct r =>                       src as I.Direct r =>
1032                         if r = C.eax then src else (move(src, eax); eax)                         if C.sameColor(r,C.eax)
1033                           then src else (move(src, eax); eax)
1034                     | src => src                     | src => src
1035            in  mark(I.MOVE{mvOp=I.MOVB, src=src, dst=address(ea,mem)},an)            in  mark(I.MOVE{mvOp=I.MOVB, src=src, dst=address(ea,mem)},an)
1036            end            end
# Line 1034  Line 1046 
1046          | branch(T.FCMP(fty, fcc, t1, t2), lab, an) =          | branch(T.FCMP(fty, fcc, t1, t2), lab, an) =
1047             fbranch(fty, fcc, t1, t2, lab, an)             fbranch(fty, fcc, t1, t2, lab, an)
1048          | branch(ccexp, lab, an) =          | branch(ccexp, lab, an) =
1049             (doCCexpr(ccexp, 0, []);             (doCCexpr(ccexp, C.eflags, []);
1050              mark(I.JCC{cond=cond(Gen.condOf ccexp), opnd=immedLabel lab}, an)              mark(I.JCC{cond=cond(Gen.condOf ccexp), opnd=immedLabel lab}, an)
1051             )             )
1052    
# Line 1173  Line 1185 
1185        and fload'(fty, ea, mem, fd, an) =        and fload'(fty, ea, mem, fd, an) =
1186              let val ea = address(ea, mem)              let val ea = address(ea, mem)
1187              in  mark(fld(fty, ea), an);              in  mark(fld(fty, ea), an);
1188                  if fd = ST0 then () else emit(fstp(fty, I.FDirect fd))                  if C.sameColor(fd,ST0) then ()
1189                    else emit(fstp(fty, I.FDirect fd))
1190              end              end
1191    
1192        and fexpr' e = (reduceFexp(64, e, []); C.ST(0))        and fexpr' e = (reduceFexp(64, e, []); C.ST(0))
1193    
1194            (* generate floating point expression and put the result in fd *)            (* generate floating point expression and put the result in fd *)
1195        and doFexpr'(fty, T.FREG(_, fs), fd, an) =        and doFexpr'(fty, T.FREG(_, fs), fd, an) =
1196              (if fs = fd then ()              (if C.sameColor(fs,fd) then ()
1197               else mark(I.FCOPY{dst=[fd], src=[fs], tmp=NONE}, an)               else mark(I.FCOPY{dst=[fd], src=[fs], tmp=NONE}, an)
1198              )              )
1199          | doFexpr'(_, T.FLOAD(fty, ea, mem), fd, an) =          | doFexpr'(_, T.FLOAD(fty, ea, mem), fd, an) =
1200              fload'(fty, ea, mem, fd, an)              fload'(fty, ea, mem, fd, an)
1201          | doFexpr'(fty, T.FEXT fexp, fd, an) =          | doFexpr'(fty, T.FEXT fexp, fd, an) =
1202              (ExtensionComp.compileFext (reducer()) {e=fexp, fd=fd, an=an};              (ExtensionComp.compileFext (reducer()) {e=fexp, fd=fd, an=an};
1203               if fd = ST0 then () else emit(fstp(fty, I.FDirect fd))               if C.sameColor(fd,ST0) then () else emit(fstp(fty, I.FDirect fd))
1204              )              )
1205          | doFexpr'(fty, e, fd, an) =          | doFexpr'(fty, e, fd, an) =
1206              (reduceFexp(fty, e, []);              (reduceFexp(fty, e, []);
1207               if fd = ST0 then () else mark(fstp(fty, I.FDirect fd), an)               if C.sameColor(fd,ST0) then ()
1208                 else mark(fstp(fty, I.FDirect fd), an)
1209              )              )
1210    
1211            (*            (*
# Line 1271  Line 1285 
1285                    in  suBinary(fty, binop, ibinop, t1, t2) end                    in  suBinary(fty, binop, ibinop, t1, t2) end
1286    
1287                and sameTree(LEAF(_, T.FREG(t1,f1), []),                and sameTree(LEAF(_, T.FREG(t1,f1), []),
1288                             LEAF(_, T.FREG(t2,f2), [])) = t1=t2 andalso f1=f2                             LEAF(_, T.FREG(t2,f2), [])) =
1289                            t1 = t2 andalso C.sameColor(f1,f2)
1290                  | sameTree _ = false                  | sameTree _ = false
1291    
1292                (* Traverse tree and generate code *)                (* Traverse tree and generate code *)
# Line 1470  Line 1485 
1485    
1486        and doFexpr''(fty, e, fd, an) =        and doFexpr''(fty, e, fd, an) =
1487            case e of            case e of
1488              T.FREG(_,fs) => if fs = fd then ()              T.FREG(_,fs) => if C.sameColor(fs,fd) then ()
1489                              else fcopy''(fty, [fd], [fs], an)                              else fcopy''(fty, [fd], [fs], an)
1490              (* Stupid x86 does everything as 80-bits internally. *)              (* Stupid x86 does everything as 80-bits internally. *)
1491    
# Line 1536  Line 1551 
1551          | stmt(T.CCMV(ccd, e), an) = doCCexpr(e, ccd, an)          | stmt(T.CCMV(ccd, e), an) = doCCexpr(e, ccd, an)
1552          | stmt(T.COPY(_, dst, src), an) = copy(dst, src, an)          | stmt(T.COPY(_, dst, src), an) = copy(dst, src, an)
1553          | stmt(T.FCOPY(fty, dst, src), an) = fcopy(fty, dst, src, an)          | stmt(T.FCOPY(fty, dst, src), an) = fcopy(fty, dst, src, an)
1554          | stmt(T.JMP(ctrl, e, labs), an) = jmp(e, labs, an)          | stmt(T.JMP(e, labs), an) = jmp(e, labs, an)
1555          | stmt(T.CALL{funct, targets, defs, uses, cdefs, cuses, region}, an) =          | stmt(T.CALL{funct, targets, defs, uses, region, ...}, an) =
1556               call(funct,targets,defs,uses,region,an)               call(funct,targets,defs,uses,region,an)
1557          | stmt(T.RET _, an) = mark(I.RET NONE, an)          | stmt(T.RET _, an) = mark(I.RET NONE, an)
1558          | stmt(T.STORE(8, ea, d, mem), an) = store8(ea, d, mem, an)          | stmt(T.STORE(8, ea, d, mem), an) = store8(ea, d, mem, an)
1559          | stmt(T.STORE(16, ea, d, mem), an) = store16(ea, d, mem, an)          | stmt(T.STORE(16, ea, d, mem), an) = store16(ea, d, mem, an)
1560          | stmt(T.STORE(32, ea, d, mem), an) = store32(ea, d, mem, an)          | stmt(T.STORE(32, ea, d, mem), an) = store32(ea, d, mem, an)
1561          | stmt(T.FSTORE(fty, ea, d, mem), an) = fstore(fty, ea, d, mem, an)          | stmt(T.FSTORE(fty, ea, d, mem), an) = fstore(fty, ea, d, mem, an)
1562          | stmt(T.BCC(ctrl, cc, lab), an) = branch(cc, lab, an)          | stmt(T.BCC(cc, lab), an) = branch(cc, lab, an)
1563          | stmt(T.DEFINE l, _) = defineLabel l          | stmt(T.DEFINE l, _) = defineLabel l
1564          | stmt(T.ANNOTATION(s, a), an) = stmt(s, a::an)          | stmt(T.ANNOTATION(s, a), an) = stmt(s, a::an)
1565          | stmt(T.EXT s, an) =          | stmt(T.EXT s, an) =
# Line 1598  Line 1613 
1613               entryLabel  = entryLabel,               entryLabel  = entryLabel,
1614               comment     = comment,               comment     = comment,
1615               annotation  = annotation,               annotation  = annotation,
1616               exitBlock   = fn mlrisc => exitBlock(cellset mlrisc),               exitBlock   = fn mlrisc => exitBlock(cellset mlrisc)
              alias       = alias,  
              phi         = phi  
1617            }            }
1618    
1619    in  self()    in  self()

Legend:
Removed from v.731  
changed lines
  Added in v.744

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