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

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

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

revision 717, Sun Nov 5 15:07:51 2000 UTC revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 33  Line 33 
33    structure C   = PPCInstr.C    structure C   = PPCInstr.C
34    structure LE  = I.LabelExp    structure LE  = I.LabelExp
35    structure W32 = Word32    structure W32 = Word32
36      structure A   = MLRiscAnnotations
37    
38    fun error msg = MLRiscErrorMsg.error("PPC",msg)    fun error msg = MLRiscErrorMsg.error("PPC",msg)
39    
40    type instrStream = (I.instruction,C.regmap,C.cellset) T.stream    type instrStream = (I.instruction,C.cellset) T.stream
41    type mltreeStream = (T.stm,C.regmap,T.mlrisc list) T.stream    type mltreeStream = (T.stm,T.mlrisc list) T.stream
42    
43    val (intTy,naturalWidths) = if bit64mode then (64,[32,64]) else (32,[32])    val (intTy,naturalWidths) = if bit64mode then (64,[32,64]) else (32,[32])
44    structure Gen = MLTreeGen    structure Gen = MLTreeGen
# Line 60  Line 61 
61    fun SRLI32{r,i,d} =    fun SRLI32{r,i,d} =
62        I.ROTATEI{oper=I.RLWINM,ra=d,rs=r,sh=I.ImmedOp(32-i),mb=i,me=SOME(31)}        I.ROTATEI{oper=I.RLWINM,ra=d,rs=r,sh=I.ImmedOp(32-i),mb=i,me=SOME(31)}
63    
64      (*
65    val _ = if C.lr = 80 then () else error "LR must be encoded as 80!"    val _ = if C.lr = 80 then () else error "LR must be encoded as 80!"
66       *)
67    
68    (*    (*
69     * Integer multiplication     * Integer multiplication
# Line 104  Line 107 
107    fun selectInstructions    fun selectInstructions
108        (S.STREAM{emit,comment,        (S.STREAM{emit,comment,
109                  defineLabel,entryLabel,pseudoOp,annotation,                  defineLabel,entryLabel,pseudoOp,annotation,
110                  beginCluster,endCluster,exitBlock,phi,alias,...}) =                  beginCluster,endCluster,exitBlock,...}) =
111    let (* mark an instruction with annotations *)    let (* mark an instruction with annotations *)
112        fun mark'(instr,[]) = instr        fun mark'(instr,[]) = instr
113          | mark'(instr,a::an) = mark'(I.ANNOTATION{i=instr,a=a},an)          | mark'(instr,a::an) = mark'(I.ANNOTATION{i=instr,a=a},an)
# Line 115  Line 118 
118         * to this label.         * to this label.
119         *)         *)
120        val trapLabel : Label.label option ref = ref NONE        val trapLabel : Label.label option ref = ref NONE
121          val zeroR = C.r0
122    
123        val newReg = C.newReg        val newReg = C.newReg
124        val newFreg = C.newFreg        val newFreg = C.newFreg
# Line 127  Line 131 
131        fun unsigned6  i = 0 <= i andalso i < 64        fun unsigned6  i = 0 <= i andalso i < 64
132    
133        fun move(rs,rd,an) =        fun move(rs,rd,an) =
134          if rs=rd then ()          if C.sameColor(rs,rd) then ()
135          else mark(I.COPY{dst=[rd],src=[rs],impl=ref NONE,tmp=NONE},an)          else mark(I.COPY{dst=[rd],src=[rs],impl=ref NONE,tmp=NONE},an)
136    
137        fun fmove(fs,fd,an) =        fun fmove(fs,fd,an) =
138          if fs=fd then ()          if C.sameColor(fs,fd) then ()
139          else mark(I.FCOPY{dst=[fd],src=[fs],impl=ref NONE,tmp=NONE},an)          else mark(I.FCOPY{dst=[fd],src=[fs],impl=ref NONE,tmp=NONE},an)
140    
141        fun ccmove(ccs,ccd,an) =        fun ccmove(ccs,ccd,an) =
142          if ccd = ccs then () else mark(I.MCRF{bf=ccd, bfa=ccs},an)          if C.sameColor(ccd,ccs) then () else mark(I.MCRF{bf=ccd, bfa=ccs},an)
143    
144        fun copy(dst, src, an) =        fun copy(dst, src, an) =
145            mark(I.COPY{dst=dst, src=src, impl=ref NONE,            mark(I.COPY{dst=dst, src=src, impl=ref NONE,
# Line 164  Line 168 
168        in (wtoi high, wtoi low) end        in (wtoi high, wtoi low) end
169    
170        fun loadImmedHiLo(0, lo, rt, an) =        fun loadImmedHiLo(0, lo, rt, an) =
171              mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=0, im=I.ImmedOp lo}, an)              mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=zeroR, im=I.ImmedOp lo}, an)
172          | loadImmedHiLo(hi, lo, rt, an) =          | loadImmedHiLo(hi, lo, rt, an) =
173             (mark(I.ARITHI{oper=I.ADDIS, rt=rt, ra=0, im=I.ImmedOp hi}, an);             (mark(I.ARITHI{oper=I.ADDIS, rt=rt, ra=zeroR, im=I.ImmedOp hi}, an);
174              if lo = 0 then ()              if lo = 0 then ()
175                 else emit(I.ARITHI{oper=I.ADDI, rt=rt, ra=rt, im=I.ImmedOp lo}))                 else emit(I.ARITHI{oper=I.ADDI, rt=rt, ra=rt, im=I.ImmedOp lo}))
176    
177        fun loadImmed(n, rt, an) =        fun loadImmed(n, rt, an) =
178          if signed16 n then          if signed16 n then
179             mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=0 , im=I.ImmedOp n}, an)             mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=zeroR, im=I.ImmedOp n}, an)
180          else let val (hi, lo) = split n          else let val (hi, lo) = split n
181               in loadImmedHiLo(hi, lo, rt, an) end               in loadImmedHiLo(hi, lo, rt, an) end
182    
183        fun loadImmedw(w, rt, an) =        fun loadImmedw(w, rt, an) =
184            let val wtoi = Word32.toIntX            let val wtoi = Word32.toIntX
185            in  if w < 0w32768 then            in  if w < 0w32768 then
186                   mark(I.ARITHI{oper=I.ADDI,rt=rt,ra=0,im=I.ImmedOp(wtoi w)}, an)                   mark(I.ARITHI{oper=I.ADDI,rt=rt,ra=zeroR,
187                                   im=I.ImmedOp(wtoi w)}, an)
188                else                else
189                 let val hi = Word32.~>>(w, 0w16)                 let val hi = Word32.~>>(w, 0w16)
190                     val lo = Word32.andb(w, 0w65535)                     val lo = Word32.andb(w, 0w65535)
# Line 190  Line 195 
195            end            end
196    
197        fun loadLabel(lexp, rt, an) =        fun loadLabel(lexp, rt, an) =
198            mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=0, im=I.LabelOp lexp}, an)            mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=zeroR, im=I.LabelOp lexp}, an)
199    
200        fun loadConst(c, rt, an) =        fun loadConst(c, rt, an) =
201            mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=0, im=I.LabelOp(LE.CONST c)}, an)            mark(I.ARITHI{oper=I.ADDI, rt=rt, ra=zeroR,
202                            im=I.LabelOp(LE.CONST c)}, an)
203    
204        fun immedOpnd range (e1, e2 as T.LI i) =        fun immedOpnd range (e1, e2 as T.LI i) =
205             (expr e1, if range i then I.ImmedOp i else I.RegOp(expr e2))             (expr e1, if range i then I.ImmedOp i else I.RegOp(expr e2))
# Line 245  Line 251 
251    
252         (* convert mlrisc to cellset: *)         (* convert mlrisc to cellset: *)
253         and cellset mlrisc =         and cellset mlrisc =
254             let val addCCReg = C.addCell C.CC             let val addCCReg = C.CellSet.add
255                 fun g([],acc) = acc                 fun g([],acc) = acc
256                   | 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))
257                   | 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 262  Line 268 
268          | stmt(T.CCMV(ccd, ccexp), an) = doCCexpr(ccexp, ccd, an)          | stmt(T.CCMV(ccd, ccexp), an) = doCCexpr(ccexp, ccd, an)
269          | stmt(T.COPY(_, dst, src), an) = copy(dst, src, an)          | stmt(T.COPY(_, dst, src), an) = copy(dst, src, an)
270          | stmt(T.FCOPY(_, dst, src), an) = fcopy(dst, src, an)          | stmt(T.FCOPY(_, dst, src), an) = fcopy(dst, src, an)
271          | stmt(T.JMP(ctrl, T.LABEL lexp, labs),an) =          | stmt(T.JMP(T.LABEL lexp, labs),an) =
272               mark(I.B{addr=I.LabelOp lexp, LK=false},an)               mark(I.B{addr=I.LabelOp lexp, LK=false},an)
273          | stmt(T.JMP(ctrl, rexp, labs),an) =          | stmt(T.JMP(rexp, labs),an) =
274            let val rs = expr(rexp)            let val rs = expr(rexp)
275            in  emit(MTLR(rs));            in  emit(MTLR(rs));
276                mark(I.BCLR{bo=I.ALWAYS,bf=CR0,bit=I.LT,LK=false,labels=labs},an)                mark(I.BCLR{bo=I.ALWAYS,bf=CR0,bit=I.LT,LK=false,labels=labs},an)
277            end            end
278          | stmt(T.CALL{funct, targets, defs, uses, cdefs, cuses, region}, an) =          | stmt(T.CALL{funct, targets, defs, uses, region, ...}, an) =
279            let val defs=cellset(defs)            let val defs=cellset(defs)
280                val uses=cellset(uses)                val uses=cellset(uses)
281             in emit(MTLR(expr funct));             in emit(MTLR(expr funct));
# Line 278  Line 284 
284          | stmt(T.RET flow,an) = mark(RET,an)          | stmt(T.RET flow,an) = mark(RET,an)
285          | stmt(T.STORE(ty,ea,data,mem),an) = store(ty,ea,data,mem,an)          | stmt(T.STORE(ty,ea,data,mem),an) = store(ty,ea,data,mem,an)
286          | stmt(T.FSTORE(ty,ea,data,mem),an) = fstore(ty,ea,data,mem,an)          | stmt(T.FSTORE(ty,ea,data,mem),an) = fstore(ty,ea,data,mem,an)
287          | stmt(T.BCC(ctrl, cc, lab),an) =          | stmt(T.BCC(cc, lab),an) = branch(cc,lab,an)
               branch(cc,lab,an)  
288          | stmt(T.DEFINE l, _) = defineLabel l          | stmt(T.DEFINE l, _) = defineLabel l
289          | stmt(T.ANNOTATION(s,a),an) = stmt(s,a::an)          | stmt(T.ANNOTATION(s,a),an) = stmt(s,a::an)
290          | stmt(s, _) = doStmts(Gen.compileStm s)          | stmt(s, _) = doStmts(Gen.compileStm s)
# Line 539  Line 544 
544        and reduceOpn(I.RegOp r) = r        and reduceOpn(I.RegOp r) = r
545          | reduceOpn opn =          | reduceOpn opn =
546            let val rt = newReg()            let val rt = newReg()
547            in  emit(I.ARITHI{oper=I.ADDI, rt=rt, ra=0, im=opn});            in  emit(I.ARITHI{oper=I.ADDI, rt=rt, ra=zeroR, im=opn});
548                rt                rt
549            end            end
550    
551        (* Reduce an expression, and returns the register that holds        (* Reduce an expression, and returns the register that holds
552         * the value.         * the value.
553         *)         *)
554        and expr(rexp as T.REG(_,80)) =        and expr(rexp as T.REG(_,r)) =
555              if C.sameColor(C.lr, r) then
556            let val rt = newReg()            let val rt = newReg()
557            in  doExpr(rexp, rt, []); rt end            in  doExpr(rexp, rt, []); rt end
558          | expr(T.REG(_,r)) = r            else r
559          | expr(rexp) =          | expr(rexp) =
560            let val rt = newReg()            let val rt = newReg()
561            in  doExpr(rexp, rt, []); rt end            in  doExpr(rexp, rt, []); rt end
# Line 558  Line 564 
564         *    reduce the expression e, assigns it to rd,         *    reduce the expression e, assigns it to rd,
565         *    and annotate the expression with an         *    and annotate the expression with an
566         *)         *)
567        and doExpr(e, 80, an) =        and doExpr(e, rt, an) =
568               if C.sameColor(rt,C.lr) then
569             let val rt = newReg() in doExpr(e,rt,[]); mark(MTLR rt,an) end             let val rt = newReg() in doExpr(e,rt,[]); mark(MTLR rt,an) end
570          | doExpr(e, rt, an) =             else
571             case e of             case e of
572               T.REG(_,80)  => mark(MFLR rt,an)               T.REG(_,rs)  => if C.sameColor(rs,C.lr) then mark(MFLR rt,an)
573             | T.REG(_,rs)  => move(rs,rt,an)                               else move(rs,rt,an)
574             | T.LI i       => loadImmed(i, rt, an)             | T.LI i       => loadImmed(i, rt, an)
575             | T.LI32 w     => loadImmedw(w, rt, an)             | T.LI32 w     => loadImmedw(w, rt, an)
576             | T.LABEL lexp => loadLabel(lexp, rt, an)             | T.LABEL lexp => loadLabel(lexp, rt, an)
# Line 577  Line 584 
584             | T.ANDB(_,e1,T.NOTB(_,e2)) => arith(I.ANDC,e1,e2,rt,an)             | T.ANDB(_,e1,T.NOTB(_,e2)) => arith(I.ANDC,e1,e2,rt,an)
585             | T.ORB(_,e1,T.NOTB(_,e2))  => arith(I.ORC,e1,e2,rt,an)             | T.ORB(_,e1,T.NOTB(_,e2))  => arith(I.ORC,e1,e2,rt,an)
586             | T.XORB(_,e1,T.NOTB(_,e2)) => arith(I.EQV,e1,e2,rt,an)             | T.XORB(_,e1,T.NOTB(_,e2)) => arith(I.EQV,e1,e2,rt,an)
587               | T.EQVB(_,e1,e2)           => arith(I.EQV,e1,e2,rt,an)
588             | T.ANDB(_,T.NOTB(_,e1),e2) => arith(I.ANDC,e2,e1,rt,an)             | T.ANDB(_,T.NOTB(_,e1),e2) => arith(I.ANDC,e2,e1,rt,an)
589             | T.ORB(_,T.NOTB(_,e1),e2)  => arith(I.ORC,e2,e1,rt,an)             | T.ORB(_,T.NOTB(_,e1),e2)  => arith(I.ORC,e2,e1,rt,an)
590             | T.XORB(_,T.NOTB(_,e1),e2) => arith(I.EQV,e2,e1,rt,an)             | T.XORB(_,T.NOTB(_,e1),e2) => arith(I.EQV,e2,e1,rt,an)
# Line 619  Line 627 
627    
628                (* Misc *)                (* Misc *)
629             | T.LET(s,e) => (doStmt s; doExpr(e, rt, an))             | T.LET(s,e) => (doStmt s; doExpr(e, rt, an))
630             | T.MARK(e, a) =>             | T.MARK(e, A.MARKREG f) => (f rt; doExpr(e,rt,an))
631               (case #peek MLRiscAnnotations.MARK_REG a of             | T.MARK(e, a) => doExpr(e,rt,a::an)
                SOME f => (f rt; doExpr(e,rt,an))  
              | NONE => doExpr(e,rt,a::an)  
              )  
632             | e => doExpr(Gen.compileRexp e,rt,an)             | e => doExpr(Gen.compileRexp e,rt,an)
633    
634        (* Generate a floating point load *)        (* Generate a floating point load *)
# Line 709  Line 714 
714            | T.FSQRT(64, e)     => funary(I.FSQRT, e, ft, an)            | T.FSQRT(64, e)     => funary(I.FSQRT, e, ft, an)
715    
716              (* Misc *)              (* Misc *)
717            | T.FMARK(e, a) =>            | T.FMARK(e, A.MARKREG f) => (f ft; doFexpr(e,ft,an))
718              (case #peek MLRiscAnnotations.MARK_REG a of            | T.FMARK(e, a) => doFexpr(e,ft,a::an)
               SOME f => (f ft; doFexpr(e,ft,an))  
             | NONE => doFexpr(e,ft,a::an)  
             )  
719            | _ => error "doFexpr"            | _ => error "doFexpr"
720    
721         and ccExpr(T.CC(_,cc)) = cc         and ccExpr(T.CC(_,cc)) = cc
# Line 741  Line 743 
743            | T.FCMP(fty, fcc, e1, e2) =>            | T.FCMP(fty, fcc, e1, e2) =>
744               mark(I.FCOMPARE{cmp=I.FCMPU, bf=ccd, fa=fexpr e1, fb=fexpr e2},an)               mark(I.FCOMPARE{cmp=I.FCMPU, bf=ccd, fa=fexpr e1, fb=fexpr e2},an)
745            | T.CC(_,cc) => ccmove(cc,ccd,an)            | T.CC(_,cc) => ccmove(cc,ccd,an)
746            | T.CCMARK(cc,a) =>            | T.CCMARK(cc,A.MARKREG f) => (f ccd; doCCexpr(cc,ccd,an))
747              (case #peek MLRiscAnnotations.MARK_REG a of            | T.CCMARK(cc,a) => doCCexpr(cc,ccd,a::an)
               SOME f => (f ccd; doCCexpr(cc,ccd,an))  
             | NONE => doCCexpr(cc,ccd,a::an)  
             )  
748            | _ => error "doCCexpr: Not implemented"            | _ => error "doCCexpr: Not implemented"
749    
750        and emitTrap() = emit(I.TW{to=31,ra=0,si=I.ImmedOp 0})        and emitTrap() = emit(I.TW{to=31,ra=zeroR,si=I.ImmedOp 0})
751    
752          val beginCluster = fn _ => (trapLabel := NONE; beginCluster(0))          val beginCluster = fn _ => (trapLabel := NONE; beginCluster(0))
753          val endCluster = fn a =>          val endCluster = fn a =>
# Line 767  Line 766 
766           entryLabel   = entryLabel,           entryLabel   = entryLabel,
767           comment      = comment,           comment      = comment,
768           annotation   = annotation,           annotation   = annotation,
769           exitBlock    = fn mlrisc => exitBlock(cellset mlrisc),           exitBlock    = fn mlrisc => exitBlock(cellset mlrisc)
          alias        = alias,  
          phi          = phi  
770         }         }
771     end     end
772    

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

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