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

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

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

revision 743, Thu Dec 7 15:31:24 2000 UTC revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 51  Line 51 
51    structure P  = PseudoInstrs    structure P  = PseudoInstrs
52    structure A  = MLRiscAnnotations    structure A  = MLRiscAnnotations
53    
54    type instrStream = (I.instruction,C.regmap,C.cellset) T.stream    type instrStream = (I.instruction,C.cellset) T.stream
55    type mltreeStream = (T.stm,C.regmap,T.mlrisc list) T.stream    type mltreeStream = (T.stm,T.mlrisc list) T.stream
56    
57    val intTy = if V9 then 64 else 32    val intTy = if V9 then 64 else 32
58    structure Gen = MLTreeGen(structure T = T    structure Gen = MLTreeGen(structure T = T
# Line 153  Line 153 
153    
154    fun error msg = MLRiscErrorMsg.error("Sparc",msg)    fun error msg = MLRiscErrorMsg.error("Sparc",msg)
155    
156    
157    
158    fun selectInstructions    fun selectInstructions
159         (instrStream as         (instrStream as
160          S.STREAM{emit,defineLabel,entryLabel,pseudoOp,annotation,          S.STREAM{emit,defineLabel,entryLabel,pseudoOp,annotation,
161                   beginCluster,endCluster,exitBlock,alias,phi,comment,...}) =                   beginCluster,endCluster,exitBlock,comment,...}) =
162    let    let
163        (* Flags *)        (* Flags *)
164        val useBR          = !useBR        val useBR          = !useBR
# Line 164  Line 166 
166    
167        val trap32 = PseudoInstrs.overflowtrap32        val trap32 = PseudoInstrs.overflowtrap32
168        val trap64 = PseudoInstrs.overflowtrap64        val trap64 = PseudoInstrs.overflowtrap64
169          val zeroR   = C.r0
170        val newReg = C.newReg        val newReg = C.newReg
171        val newFreg = C.newFreg        val newFreg = C.newFreg
172        fun immed13 n = ~4096 <= n andalso n < 4096        fun immed13 n = ~4096 <= n andalso n < 4096
# Line 173  Line 176 
176        fun split n  = splitw(W.fromInt n)        fun split n  = splitw(W.fromInt n)
177    
178    
179        val zeroOpn = I.REG 0 (* zero value operand *)        val zeroOpn = I.REG zeroR (* zero value operand *)
       val _ = if C.psr <> 65 then error "Wrong encoding for psr" else ()  
180    
181        fun cond T.LT  = I.BL        fun cond T.LT  = I.BL
182          | cond T.LTU = I.BCS          | cond T.LTU = I.BCS
# Line 186  Line 188 
188          | cond T.GEU = I.BCC          | cond T.GEU = I.BCC
189          | cond T.GT  = I.BG          | cond T.GT  = I.BG
190          | cond T.GTU = I.BGU          | cond T.GTU = I.BGU
191            | cond _     = error "cond"
192    
193        fun rcond T.LT  = I.RLZ        fun rcond T.LT  = I.RLZ
194          | rcond T.LE  = I.RLEZ          | rcond T.LE  = I.RLEZ
# Line 221  Line 224 
224    
225        (* convert an operand into a register *)        (* convert an operand into a register *)
226        fun reduceOpn(I.REG r) = r        fun reduceOpn(I.REG r) = r
227          | reduceOpn(I.IMMED 0) = 0          | reduceOpn(I.IMMED 0) = zeroR
228          | reduceOpn i =          | reduceOpn i =
229            let val d = newReg()            let val d = newReg()
230            in  emit(I.ARITH{a=I.OR,r=0,i=i,d=d}); d end            in  emit(I.ARITH{a=I.OR,r=zeroR,i=i,d=d}); d end
231    
232        (* emit parallel copies *)        (* emit parallel copies *)
233        fun copy(dst,src,an) =        fun copy(dst,src,an) =
# Line 238  Line 241 
241    
242        (* move register s to register d *)        (* move register s to register d *)
243        fun move(s,d,an) =        fun move(s,d,an) =
244            if s = d orelse d = 0 then ()            if C.sameColor(s,d) orelse C.registerId d = 0 then ()
245            else mark(I.COPY{dst=[d],src=[s],tmp=NONE,impl=ref NONE},an)            else mark(I.COPY{dst=[d],src=[s],tmp=NONE,impl=ref NONE},an)
246    
247        (* move floating point register s to register d *)        (* move floating point register s to register d *)
248        fun fmoved(s,d,an) =        fun fmoved(s,d,an) =
249            if s = d then ()            if C.sameColor(s,d) then ()
250            else mark(I.FCOPY{dst=[d],src=[s],tmp=NONE,impl=ref NONE},an)            else mark(I.FCOPY{dst=[d],src=[s],tmp=NONE,impl=ref NONE},an)
251        fun fmoves(s,d,an) = fmoved(s,d,an) (* error "fmoves" for now!!! XXX *)        fun fmoves(s,d,an) = fmoved(s,d,an) (* error "fmoves" for now!!! XXX *)
252        fun fmoveq(s,d,an) = error "fmoveq"        fun fmoveq(s,d,an) = error "fmoveq"
# Line 252  Line 255 
255        fun loadImmedw(w,d,cc,an) =        fun loadImmedw(w,d,cc,an) =
256        let val or = if cc <> REG then I.ORCC else I.OR        let val or = if cc <> REG then I.ORCC else I.OR
257        in  if immed13w w then        in  if immed13w w then
258               mark(I.ARITH{a=or,r=0,i=I.IMMED(W.toIntX w),d=d},an)               mark(I.ARITH{a=or,r=zeroR,i=I.IMMED(W.toIntX w),d=d},an)
259            else let val {hi,lo} = splitw w            else let val {hi,lo} = splitw w
260                 in  if lo = 0 then                 in  if lo = 0 then
261                        (mark(I.SETHI{i=hi,d=d},an); genCmp0(cc,d))                        (mark(I.SETHI{i=hi,d=d},an); genCmp0(cc,d))
# Line 266  Line 269 
269        (* load immediate *)        (* load immediate *)
270        and loadImmed(n,d,cc,an) =        and loadImmed(n,d,cc,an) =
271        let val or = if cc <> REG then I.ORCC else I.OR        let val or = if cc <> REG then I.ORCC else I.OR
272        in  if immed13 n then mark(I.ARITH{a=or,r=0,i=I.IMMED n,d=d},an)        in  if immed13 n then mark(I.ARITH{a=or,r=zeroR,i=I.IMMED n,d=d},an)
273            else let val {hi,lo} = split n            else let val {hi,lo} = split n
274                 in  if lo = 0 then                 in  if lo = 0 then
275                        (mark(I.SETHI{i=hi,d=d},an); genCmp0(cc,d))                        (mark(I.SETHI{i=hi,d=d},an); genCmp0(cc,d))
# Line 280  Line 283 
283        (* load label expression *)        (* load label expression *)
284        and loadLabel(lab,d,cc,an) =        and loadLabel(lab,d,cc,an) =
285        let val or = if cc <> REG then I.ORCC else I.OR        let val or = if cc <> REG then I.ORCC else I.OR
286        in  mark(I.ARITH{a=or,r=0,i=I.LAB lab,d=d},an) end        in  mark(I.ARITH{a=or,r=zeroR,i=I.LAB lab,d=d},an) end
287    
288        (* emit an arithmetic op *)        (* emit an arithmetic op *)
289        and arith(a,acc,e1,e2,d,cc,comm,trap,an) =        and arith(a,acc,e1,e2,d,cc,comm,trap,an) =
290        let val (a,d) = case cc of        let val (a,d) = case cc of
291                           REG    => (a,d)                           REG    => (a,d)
292                        |  CC     => (acc,0)                        |  CC     => (acc,zeroR)
293                        |  CC_REG => (acc,d)                        |  CC_REG => (acc,d)
294        in  case (opn e1,opn e2,comm) of        in  case (opn e1,opn e2,comm) of
295              (i,I.REG r,COMMUTE)=> mark(I.ARITH{a=a,r=r,i=i,d=d},an)              (i,I.REG r,COMMUTE)=> mark(I.ARITH{a=a,r=r,i=i,d=d},an)
# Line 393  Line 396 
396          | addr(T.ADD(_,T.LABEL l,e)) = (expr e,I.LAB l)          | addr(T.ADD(_,T.LABEL l,e)) = (expr e,I.LAB l)
397          | addr(T.ADD(_,e1,e2))       = (expr e1,I.REG(expr e2))          | addr(T.ADD(_,e1,e2))       = (expr e1,I.REG(expr e2))
398          | addr(T.SUB(ty,e,T.LI n))   = addr(T.ADD(ty,e,T.LI(~n)))          | addr(T.SUB(ty,e,T.LI n))   = addr(T.ADD(ty,e,T.LI(~n)))
399          | addr(T.LABEL l)            = (0,I.LAB l)          | addr(T.LABEL l)            = (zeroR,I.LAB l)
400          | addr a                     = (expr a,zeroOpn)          | addr a                     = (expr a,zeroOpn)
401    
402        (* emit an integer load *)        (* emit an integer load *)
# Line 426  Line 429 
429        (* convert mlrisc to cellset *)        (* convert mlrisc to cellset *)
430        and cellset mlrisc =        and cellset mlrisc =
431        let fun g([],set) = set        let fun g([],set) = set
432              | g(T.GPR(T.REG(_,r))::regs,set) = g(regs,C.addReg(r,set))              | g(T.GPR(T.REG(_,r))::regs,set) = g(regs,C.CellSet.add(r,set))
433              | g(T.FPR(T.FREG(_,f))::regs,set) = g(regs,C.addFreg(f,set))              | g(T.FPR(T.FREG(_,f))::regs,set) = g(regs,C.CellSet.add(f,set))
434              | g(T.CCR(T.CC(_,65))::regs,set) = g(regs,C.addPSR(65,set))              | g(T.CCR(T.CC(_,cc))::regs,set) = g(regs,C.CellSet.add(cc,set))
             | g(T.CCR(T.CC(_,cc))::regs,set) = g(regs,C.addReg(cc,set))  
435              | g(_::regs, set) = g(regs,set)              | g(_::regs, set) = g(regs,set)
436        in  g(mlrisc, C.empty) end        in  g(mlrisc, C.empty) end
437    
# Line 438  Line 440 
440        let val (r,i) = addr a        let val (r,i) = addr a
441            val defs=cellset(defs)            val defs=cellset(defs)
442            val uses=cellset(uses)            val uses=cellset(uses)
443        in  case (r,i) of        in  case (C.registerId r,i) of
444              (0,I.LAB(LE.LABEL l)) =>              (0,I.LAB(LE.LABEL l)) =>
445               mark(I.CALL{label=l,defs=C.addReg(C.linkReg,defs),uses=uses,               mark(I.CALL{label=l,defs=C.addReg(C.linkReg,defs),uses=uses,
446                           mem=mem,nop=true},an)                           mem=mem,nop=true},an)
# Line 447  Line 449 
449        end        end
450    
451        (* emit an integer branch instruction *)        (* emit an integer branch instruction *)
452        and branch(ctrl,T.CMP(ty,cond,a,b),lab,an) =        and branch(T.CMP(ty,cond,a,b),lab,an) =
453            let val (cond,a,b) =            let val (cond,a,b) =
454                    case a of                    case a of
455                      (T.LI _ | T.LI32 _ | T.CONST _ | T.LABEL _) =>                      (T.LI _ | T.LI32 _ | T.CONST _ | T.LABEL _) =>
# Line 458  Line 460 
460                else                else
461                   (doExpr(T.SUB(ty,a,b),newReg(),CC,[]); br(cond,lab,an))                   (doExpr(T.SUB(ty,a,b),newReg(),CC,[]); br(cond,lab,an))
462            end            end
463          | branch(ctrl,T.CC(cond,65),lab,an) = br(cond,lab,an)          | branch(T.CC(cond,r),lab,an) =
464          | branch(ctrl,T.CC(cond,r),lab,an) = (genCmp0(CC,r); br(cond,lab,an))                if C.sameCell(r, C.psr) then br(cond,lab,an)
465          | branch(ctrl,T.FCMP(fty,cond,a,b),lab,an) =                else (genCmp0(CC,r); br(cond,lab,an))
466            | branch(T.FCMP(fty,cond,a,b),lab,an) =
467            let val cmp = case fty of            let val cmp = case fty of
468                            32 => I.FCMPs                            32 => I.FCMPs
469                          | 64 => I.FCMPd                          | 64 => I.FCMPd
# Line 500  Line 503 
503          | stmt(T.CCMV(d,e),an) = doCCexpr(e,d,an)          | stmt(T.CCMV(d,e),an) = doCCexpr(e,d,an)
504          | stmt(T.COPY(_,dst,src),an) = copy(dst,src,an)          | stmt(T.COPY(_,dst,src),an) = copy(dst,src,an)
505          | stmt(T.FCOPY(_,dst,src),an) = fcopy(dst,src,an)          | stmt(T.FCOPY(_,dst,src),an) = fcopy(dst,src,an)
506          | stmt(T.JMP(ctrl,T.LABEL(LE.LABEL l),_),an) =          | stmt(T.JMP(T.LABEL(LE.LABEL l),_),an) =
507              mark(I.Bicc{b=I.BA,a=true,label=l,nop=false},an)              mark(I.Bicc{b=I.BA,a=true,label=l,nop=false},an)
508          | stmt(T.JMP(ctrl,e,labs),an) = jmp(e,labs,an)          | stmt(T.JMP(e,labs),an) = jmp(e,labs,an)
509          | stmt(T.CALL{funct,targets,defs,uses,cdefs,cuses,region},an) =          | stmt(T.CALL{funct,targets,defs,uses,region,...},an) =
510              call(funct,targets,defs,uses,region,an)              call(funct,targets,defs,uses,region,an)
511          | stmt(T.RET _,an) = mark(I.RET{leaf=not registerwindow,nop=true},an)          | stmt(T.RET _,an) = mark(I.RET{leaf=not registerwindow,nop=true},an)
512          | stmt(T.STORE(8,a,d,mem),an)   = store(I.STB,a,d,mem,an)          | stmt(T.STORE(8,a,d,mem),an)   = store(I.STB,a,d,mem,an)
# Line 513  Line 516 
516               store(if V9 then I.STX else I.STD,a,d,mem,an)               store(if V9 then I.STX else I.STD,a,d,mem,an)
517          | stmt(T.FSTORE(32,a,d,mem),an) = fstore(I.STF,a,d,mem,an)          | stmt(T.FSTORE(32,a,d,mem),an) = fstore(I.STF,a,d,mem,an)
518          | stmt(T.FSTORE(64,a,d,mem),an) = fstore(I.STDF,a,d,mem,an)          | stmt(T.FSTORE(64,a,d,mem),an) = fstore(I.STDF,a,d,mem,an)
519          | stmt(T.BCC(ctrl,cc,lab),an) = branch(ctrl,cc,lab,an)          | stmt(T.BCC(cc,lab),an) = branch(cc,lab,an)
520          | stmt(T.DEFINE l,_) = defineLabel l          | stmt(T.DEFINE l,_) = defineLabel l
521          | stmt(T.ANNOTATION(s,a),an) = stmt(s,a::an)          | stmt(T.ANNOTATION(s,a),an) = stmt(s,a::an)
522          | stmt(T.EXT s,an) = ExtensionComp.compileSext(reducer()) {stm=s, an=an}          | stmt(T.EXT s,an) = ExtensionComp.compileSext(reducer()) {stm=s, an=an}
# Line 525  Line 528 
528    
529            (* convert an expression into a register *)            (* convert an expression into a register *)
530        and expr(T.REG(_,r)) = r        and expr(T.REG(_,r)) = r
531          | expr(T.LI 0)     = 0          | expr(T.LI 0)     = zeroR
532          | expr(T.LI32 0w0) = 0          | expr(T.LI32 0w0) = zeroR
533          | expr e           = let val d = newReg()          | expr e           = let val d = newReg()
534                               in  doExpr(e,d,REG,[]); d end                               in  doExpr(e,d,REG,[]); d end
535    
# Line 606  Line 609 
609    
610                (* loads *)                (* loads *)
611            | T.LOAD(8,a,mem) => load(I.LDUB,a,d,mem,cc,an)            | T.LOAD(8,a,mem) => load(I.LDUB,a,d,mem,cc,an)
612            | T.CVTI2I(_,T.SIGN_EXTEND,_,T.LOAD(8,a,mem)) =>            | T.SX(_,_,T.LOAD(8,a,mem)) => load(I.LDSB,a,d,mem,cc,an)
               load(I.LDSB,a,d,mem,cc,an)  
613            | T.LOAD(16,a,mem) => load(I.LDUH,a,d,mem,cc,an)            | T.LOAD(16,a,mem) => load(I.LDUH,a,d,mem,cc,an)
614            | T.CVTI2I(_,T.SIGN_EXTEND,_,T.LOAD(16,a,mem)) =>            | T.SX(_,_,T.LOAD(16,a,mem)) => load(I.LDSH,a,d,mem,cc,an)
                load(I.LDSH,a,d,mem,cc,an)  
615            | T.LOAD(32,a,mem) => load(I.LD,a,d,mem,cc,an)            | T.LOAD(32,a,mem) => load(I.LD,a,d,mem,cc,an)
616            | T.LOAD(64,a,mem) =>            | T.LOAD(64,a,mem) =>
617                 load(if V9 then I.LDX else I.LDD,a,d,mem,cc,an)                 load(if V9 then I.LDX else I.LDD,a,d,mem,cc,an)
# Line 628  Line 629 
629    
630           (* generate a comparison with zero *)           (* generate a comparison with zero *)
631        and genCmp0(REG,_) = ()        and genCmp0(REG,_) = ()
632          | genCmp0(_,d) = emit(I.ARITH{a=I.SUBCC,r=d,i=zeroOpn,d=0})          | genCmp0(_,d) = emit(I.ARITH{a=I.SUBCC,r=d,i=zeroOpn,d=zeroR})
633    
634            (* convert an expression into a floating point register *)            (* convert an expression into a floating point register *)
635        and fexpr(T.FREG(_,r)) = r        and fexpr(T.FREG(_,r)) = r
# Line 695  Line 696 
696            | T.FEXT e => ExtensionComp.compileFext (reducer()) {e=e, fd=d, an=an}            | T.FEXT e => ExtensionComp.compileFext (reducer()) {e=e, fd=d, an=an}
697            | e => doFexpr(Gen.compileFexp e,d,an)            | e => doFexpr(Gen.compileFexp e,d,an)
698    
699        and doCCexpr(T.CMP(ty,cond,e1,e2),65,an) =        and doCCexpr(T.CMP(ty,cond,e1,e2),cc,an) =
700                 if C.sameCell(cc,C.psr) then
701              doExpr(T.SUB(ty,e1,e2),newReg(),CC,an)              doExpr(T.SUB(ty,e1,e2),newReg(),CC,an)
702          | doCCexpr(T.CMP _,d,an) = error "doCCexpr"               else error "doCCexpr"
703          | doCCexpr(_,65,an) = error "doCCexpr"          | doCCexpr(T.CC(_,r),d,an) =
704          | doCCexpr(T.CC(_,65),d,an) = error "doCCexpr"               if C.sameColor(r,C.psr) then error "doCCexpr"
705          | doCCexpr(T.CC(_,r),d,an) = move(r,d,an)               else move(r,d,an)
706          | doCCexpr(T.CCMARK(e,A.MARKREG f),d,an) = (f d; doCCexpr(e,d,an))          | doCCexpr(T.CCMARK(e,A.MARKREG f),d,an) = (f d; doCCexpr(e,d,an))
707          | doCCexpr(T.CCMARK(e,a),d,an) = doCCexpr(e,d,a::an)          | doCCexpr(T.CCMARK(e,a),d,an) = doCCexpr(e,d,a::an)
708          | doCCexpr(T.CCEXT e,d,an) =          | doCCexpr(T.CCEXT e,d,an) =
# Line 741  Line 743 
743              entryLabel  = entryLabel,              entryLabel  = entryLabel,
744              comment     = comment,              comment     = comment,
745              annotation  = annotation,              annotation  = annotation,
746              exitBlock   = fn regs => exitBlock(cellset regs),              exitBlock   = fn regs => exitBlock(cellset regs)
             alias       = alias,  
             phi         = phi  
747            }            }
748    in  self()    in  self()
749    end    end

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

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