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

SCM Repository

[smlnj] View of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml
ViewVC logotype

View of /sml/trunk/src/MLRISC/ppc/ra/ppcRewrite.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1003 - (download) (annotate)
Fri Dec 7 02:45:32 2001 UTC (18 years, 1 month ago) by george
File size: 6365 byte(s)
Changed the representation of instructions from being fully abstract
to being partially concrete. That is to say:

  from
	type instruction

  to
	type instr				(* machine instruction *)

	datatype instruction =
	    LIVE of {regs: C.cellset, spilled: C.cellset}
          | KILL of {regs: C.cellset, spilled: C.cellset}
          | COPYXXX of {k: CB.cellkind, dst: CB.cell list, src: CB.cell list}
          | ANNOTATION of {i: instruction, a: Annotations.annotation}
          | INSTR of instr

This makes the handling of certain special instructions that appear on
all architectures easier and uniform.

LIVE and KILL say that a list of registers are live or killed at the
program point where they appear. No spill code is generated when an
element of the 'regs' field is spilled, but the register is moved to
the 'spilled' (which is present, more for debugging than anything else).

LIVE replaces the (now deprecated) DEFFREG instruction on the alpha.
We used to generate:

	DEFFREG f1
	f1 := f2 + f3
        trapb

but now generate:

	f1 := f2 + f3
	trapb
	LIVE {regs=[f1,f2,f3], spilled=[]}

Furthermore, the DEFFREG (hack) required that all floating point instruction
use all registers mentioned in the instruction. Therefore f1 := f2 + f3,
defines f1 and uses [f1,f2,f3]! This hack is no longer required resulting
in a cleaner alpha implementation. (Hopefully, intel will not get rid of
this architecture).

COPYXXX is intended to replace the parallel COPY and FCOPY  available on
all the architectures. This will result in further simplification of the
register allocator that must be aware of them for coalescing purposes, and
will also simplify certain aspects of the machine description that provides
callbacks related to parallel copies.

ANNOTATION should be obvious, and now INSTR represents the honest to God
machine instruction set!

The <arch>/instructions/<arch>Instr.sml files define certain utility
functions for making porting easier -- essentially converting upper case
to lower case. All machine instructions (of type instr) are in upper case,
and the lower case form generates an MLRISC instruction. For example on
the alpha we have:

  datatype instr =
     LDA of {r:cell, b:cell, d:operand}
   | ...

  val lda : {r:cell, b:cell, d:operand} -> instruction
    ...

where lda is just (INSTR o LDA), etc.
functor PPCRewrite(Instr : PPCINSTR) = struct
  structure I = Instr
  structure C = I.C
  structure CB = CellsBasis
  structure CS = CB.CellSet

  fun error msg = MLRiscErrorMsg.error ("PPCRewrite", msg)

  fun ea(NONE, _, _) = NONE
    | ea(e as SOME(I.Direct r), rs, rt) =
       if CB.sameColor(r,rs) then SOME(I.Direct rt) else e 
    | ea(e as SOME(I.FDirect r), rs, rt) = 
       if CB.sameColor(r,rs) then SOME(I.FDirect rt) else e 
    | ea(e as SOME(I.Displace{base, disp}), rs, rt) =
       if CB.sameColor(base,rs) then SOME(I.Displace{base=rt, disp=disp}) 
       else e 

  fun rewriteUse(instr, rs, rt) = let
    fun ppcUse(instr) = let
      fun rplac r = if CB.sameColor(r,rs) then rt else r
      fun rwOperand(opnd as I.RegOp r) = 
	   if CB.sameColor(r,rs) then I.RegOp rt else opnd
	| rwOperand opnd = opnd
    in
      case instr
      of I.L {ld, rt, ra, d, mem} =>
	  I.L{ld=ld, rt=rt, ra=rplac ra, d=rwOperand d, mem=mem}
       | I.LF {ld, ft, ra, d, mem} =>
	  I.LF{ld=ld, ft=ft, ra=rplac ra, d=rwOperand d, mem=mem}
       | I.ST {st, rs, ra, d, mem} => 
	  I.ST{st=st, rs=rplac rs, ra=rplac ra, d=rwOperand d, mem=mem}
       | I.STF {st, fs, ra, d, mem} => 
	  I.STF{st=st, fs=fs, ra=rplac ra, d=rwOperand d, mem=mem}
       | I.UNARY {oper, rt, ra, Rc, OE} =>
	  I.UNARY{oper=oper, rt=rt, ra=rplac ra, Rc=Rc, OE=OE}
       | I.ARITH{oper, rt, ra, rb, Rc, OE} => 
	  I.ARITH{oper=oper, rt=rt, ra=rplac ra, rb=rplac rb, Rc=Rc, OE=OE}
       | I.ARITHI{oper, rt, ra, im} => 
	  I.ARITHI{oper=oper, rt=rt, ra=rplac ra, im=rwOperand im}
       | I.ROTATE {oper, ra, rs, sh, mb, me} =>
	  I.ROTATE{oper=oper, ra=ra, rs=rplac rs, sh=rplac sh, mb=mb, me=me}
       | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
	  I.ROTATEI{oper=oper, ra=ra, rs=rplac rs, sh=rwOperand sh, mb=mb, me=me}
       | I.COMPARE {cmp, bf, l, ra, rb} =>
	  I.COMPARE{cmp=cmp, bf=bf, l=l, ra=rplac ra, rb=rwOperand rb}
       | I.MTSPR{rs, spr} => I.MTSPR{rs=rplac rs, spr=spr}
       | I.TW {to, ra, si} => I.TW{to=to, ra=rplac ra, si=rwOperand si}
       | I.TD {to, ra, si} => I.TD{to=to, ra=rplac ra, si=rwOperand si}
       | I.CALL {def, use, cutsTo, mem} => 
	    I.CALL{def=def, use=CS.map {from=rs,to=rt} use, 
		   cutsTo=cutsTo, mem=mem}
       | I.COPY{dst, src, impl, tmp} =>
	  I.COPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
       | I.FCOPY{dst, src, impl, tmp} =>
	  I.FCOPY{dst=dst, src=src, impl=impl, tmp=ea(tmp, rs, rt)}
       | _ => instr
    end
  in
      case instr
       of (I.ANNOTATION{i, ...}) => rewriteUse(i, rs, rt)
        | I.INSTR(i) => I.INSTR(ppcUse(i))
	| I.LIVE{regs, spilled} => 
	    I.LIVE{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
	| _ => error "rewriteUse"
  end


  fun rewriteDef(instr, rs, rt) = let
    fun ppcDef(instr) = let
      fun rplac r = if CB.sameColor(r,rs) then rt else r
    in
      case instr
      of I.L {ld, rt, ra, d, mem} =>
	  I.L{ld=ld, rt=rplac rt, ra=ra, d=d, mem=mem}
       | I.UNARY {oper, rt, ra, Rc, OE} =>
	  I.UNARY{oper=oper, rt=rplac rt, ra=ra, Rc=Rc, OE=OE}
       | I.ARITH {oper, rt, ra, rb, Rc, OE} =>
	  I.ARITH{oper=oper, rt=rplac rt, ra=ra, rb=rb, Rc=Rc, OE=OE}
       | I.ARITHI {oper, rt, ra, im} =>
	  I.ARITHI {oper=oper, rt=rplac rt, ra=ra, im=im}
       | I.ROTATE {oper, ra, rs, sh, mb, me} =>
	  I.ROTATE {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
       | I.ROTATEI {oper, ra, rs, sh, mb, me} =>
	  I.ROTATEI {oper=oper, ra=rplac ra, rs=rs, sh=sh, mb=mb, me=me}
       | I.MFSPR {rt, spr} => I.MFSPR{rt=rplac rt, spr=spr}
       | I.CALL {def, use, cutsTo, mem} => 
	  I.CALL{def=CS.map {from=rs,to=rt} def, use=use, 
		 cutsTo=cutsTo, mem=mem}
       | I.COPY {dst, src, impl, tmp} =>
	  I.COPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,rs,rt)}
       | _ => instr
    end
  in 
      case instr
       of (I.ANNOTATION{i, ...}) => rewriteDef(i, rs, rt)
        | I.INSTR(i) => I.INSTR(ppcDef(i))
	| I.KILL{regs, spilled} => 
	   I.KILL{regs=C.addReg(rt, C.rmvReg(rs, regs)), spilled=spilled}
	| _ => error "rewriteDef"
  end


  fun frewriteUse(instr, fs, ft) = let
    fun ppcUse(instr) = let
      fun rplac r = if CB.sameColor(r,fs) then ft else r
    in
      case instr
      of I.STF {st, fs, ra, d, mem} =>
	   I.STF{st=st, fs=rplac fs, ra=ra, d=d, mem=mem}
       | I.CALL{def, use, cutsTo, mem} => 
	   I.CALL{def=def, use=CS.map {from=fs,to=ft} use, 
		  cutsTo=cutsTo, mem=mem}
       | I.FCOMPARE {cmp, bf, fa, fb} =>
	   I.FCOMPARE{cmp=cmp, bf=bf, fa=rplac fa, fb=rplac fb}
       | I.FUNARY {oper, ft, fb, Rc} =>
	   I.FUNARY{oper=oper, ft=ft, fb=rplac fb, Rc=Rc}
       | I.FARITH {oper, ft, fa, fb, Rc} =>
	   I.FARITH{oper=oper, ft=ft, fa=rplac fa, fb=rplac fb, Rc=Rc}
       | I.FARITH3 {oper, ft, fa, fb, fc, Rc} =>
	   I.FARITH3{oper=oper,ft=ft,fa=rplac fa, fb=rplac fb, fc=rplac fc,Rc=Rc}
       | I.FCOPY {dst, src, impl, tmp} =>
	   I.FCOPY{dst=dst, src=map rplac src, impl=impl, tmp=tmp}
       | _ => instr
    end
  in
      case instr
       of (I.ANNOTATION{i, ...}) => frewriteUse(i, fs, ft)
        | I.INSTR(i) => I.INSTR(ppcUse(i))
	| I.LIVE{regs, spilled} => 
	    I.LIVE{regs=C.addFreg(ft, C.rmvFreg(fs, regs)), spilled=spilled}
	| _ => error "frewriteUse"

  end

  fun frewriteDef(instr, fs, ft) = let
    fun ppcDef(instr) = let
      fun rplac r = if CB.sameColor(r,fs) then ft else r
    in
      case instr
      of I.LF{ld, ft, ra, d, mem} =>
	  I.LF{ld=ld, ft=rplac ft, ra=ra, d=d, mem=mem}
       | I.FUNARY {oper, ft, fb, Rc} =>
	  I.FUNARY{oper=oper, ft=rplac ft, fb=fb, Rc=Rc}
       | I.FARITH{oper, ft, fa, fb, Rc} =>
	  I.FARITH{oper=oper, ft=rplac ft, fa=fa, fb=fb, Rc=Rc}
       | I.FARITH3{oper, ft, fa, fb, fc, Rc} =>
	  I.FARITH3{oper=oper, ft=rplac ft, fa=fa, fb=fb, fc=fc, Rc=Rc}
      (* CALL = BCLR {bo=ALWAYS, bf=0, bit=0, LK=true, labels=[] *)
       | I.CALL{def, use, cutsTo, mem} => 
	  I.CALL{def=CS.map {from=fs,to=ft} def, use=use, 
		 cutsTo=cutsTo, mem=mem}
       | I.FCOPY {dst, src, impl, tmp} =>
	  I.FCOPY{dst=map rplac dst, src=src, impl=impl, tmp=ea(tmp,fs,ft)}
       | _ => instr
    end
  in
      case instr
       of (I.ANNOTATION{i, ...}) => frewriteDef(i, fs, ft)
        | I.INSTR(i) => I.INSTR(ppcDef(i))
        | I.KILL{regs, spilled} => 
	   I.KILL{regs=C.addFreg(ft, C.rmvFreg(fs, regs)), spilled=spilled}
	| _ => error "frewriteDef"
  end
end


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