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 /MLRISC/trunk/amd64/staged-allocation/amd64-svid-fn.sml
ViewVC logotype

Diff of /MLRISC/trunk/amd64/staged-allocation/amd64-svid-fn.sml

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

revision 3082, Tue Jun 17 16:46:05 2008 UTC revision 3083, Tue Jun 17 20:25:00 2008 UTC
# Line 45  Line 45 
45                           datatype location_kind = datatype location_kind                           datatype location_kind = datatype location_kind
46                           val memSize = 8 (* bytes *))                           val memSize = 8 (* bytes *))
47    
48      structure CCs =      structure CCs = AMD64CConventionsFn (
49        struct                        structure SA = SA
50                          type reg = T.reg
51                          val rax = C.rax
52                          val rdi = C.rdi
53                          val rsi = C.rsi
54                          val rdx = C.rdx
55                          val rcx = C.rcx
56                          val r8 = C.r8
57                          val r9 = C.r9
58                          val xmm0 = C.xmm0
59                          val xmm1 = C.xmm1
60                          val xmm2 = C.xmm2
61                          val xmm3 = C.xmm3
62                          val xmm4 = C.xmm4
63                          val xmm5 = C.xmm5
64                          val xmm6 = C.xmm6
65                          val xmm7 = C.xmm7)
66    
67          fun toGpr r = (wordTy, r)          fun toGpr r = (wordTy, r)
68          fun toGprs gprs = List.map toGpr gprs          fun toGprs gprs = List.map toGpr gprs
# Line 59  Line 75 
75          val calleeSaveFRegs = []          val calleeSaveFRegs = []
76    
77          val frameAlignB = 16          val frameAlignB = 16
         val maxAlign = 16  
78    
79        (* conventions for returning arguments *)      val calleeSaveRegs'  = List.map (fn (_, r) => r) calleeSaveRegs
80          val gprRets = toGprs [C.rax, C.rdx]      val calleeSaveFRegs' = List.map (fn (_, r) => r) calleeSaveFRegs
81          val fprRets = toFprs [C.xmm0, C.xmm1]      val callerSaveRegs'  = List.map (fn (_, r) => r) callerSaveRegs
82          val (cRetFpr, ssFloat) = SA.useRegs fprRets      val callerSaveFRegs' = List.map (fn (_, r) => r) callerSaveFRegs
         val (cRetGpr, ssGpr) = SA.useRegs gprRets  
         val cCallStk = SA.freshCounter ()  
         val returnStages = [  
             SA.CHOICE [  
                 (* return in general-purpose register *)  
                   (fn (w, k, str) => k = K_GPR,  
                    SA.SEQ [SA.WIDEN (fn w => Int.max (wordTy, w)), ssGpr]),  
                 (* return in floating-point register *)  
                   (fn (w, k, str) => k = K_FPR,  
                    SA.SEQ [SA.WIDEN (fn w => Int.max (64, w)), ssFloat]),  
                 (* return in a memory location *)  
                   (fn (w, k, str) => k = K_MEM,  
                  (* FIXME! *)  
                    SA.OVERFLOW {counter=cCallStk, blockDirection=SA.UP, maxAlign=maxAlign}) ]  
              ]  
   
       (* conventions for passing arguments *)  
         val gprParams = toGprs [C.rdi, C.rsi, C.rdx, C.rcx, C.r8, C.r9]  
         val fprParams = toFprs [C.xmm0, C.xmm1, C.xmm2, C.xmm3, C.xmm4, C.xmm5, C.xmm6, C.xmm7]  
         val cCallGpr = SA.freshCounter ()  
         val cCallFpr = SA.freshCounter ()  
       (* initial store *)  
   
         val str0 = SA.init [cCallStk, cCallGpr, cCallFpr, cRetFpr, cRetGpr]  
   
         val callStages = [  
               SA.CHOICE [  
               (* pass in general-purpose register *)  
               (fn (w, k, str) => k = K_GPR, SA.SEQ [  
                                             SA.WIDEN (fn w => Int.max (wordTy, w)),  
                                             SA.BITCOUNTER cCallGpr,  
                                             SA.REGS_BY_BITS (cCallGpr, gprParams) ]),  
               (* pass in floating point register *)  
               (fn (w, k, str) => k = K_FPR, SA.SEQ [  
                                             SA.WIDEN (fn w => Int.max (64, w)),  
                                             SA.BITCOUNTER cCallFpr,  
                                             SA.REGS_BY_BITS (cCallFpr, fprParams) ]),  
               (* pass on the stack *)  
               (fn (w, k, str) => k = K_MEM,  
                SA.OVERFLOW {counter=cCallStk, blockDirection=SA.UP, maxAlign=maxAlign})  
               ],  
               SA.OVERFLOW {counter=cCallStk, blockDirection=SA.UP, maxAlign=maxAlign}  
         ]  
   
       end  (* CCs *)  
   
     val calleeSaveRegs : CB.cell list = List.map (fn (_, r) => r) CCs.calleeSaveRegs  
     val calleeSaveFRegs :CB.cell list = List.map (fn (_, r) => r) CCs.calleeSaveFRegs  
     val callerSaveRegs : CB.cell list = List.map (fn (_, r) => r) CCs.callerSaveRegs  
     val callerSaveFRegs :CB.cell list = List.map (fn (_, r) => r) CCs.callerSaveFRegs  
83    
84    (* convert a list of C types to a list of eight bytes *)    (* convert a list of C types to a list of eight bytes *)
85      fun eightBytesOfCTys ([], [], ebs) = List.rev (List.map List.rev ebs)      fun eightBytesOfCTys ([], [], ebs) = List.rev (List.map List.rev ebs)
# Line 225  Line 190 
190             val (paramLocss, str) = layoutCall(str, paramTys)             val (paramLocss, str) = layoutCall(str, paramTys)
191           (* number of bytes allocated for the call *)           (* number of bytes allocated for the call *)
192             val frameSzB = SA.find(str, CCs.cCallStk)             val frameSzB = SA.find(str, CCs.cCallStk)
193             val argMem = {szb=CSizes.alignAddr(frameSzB, CCs.frameAlignB), align=CCs.frameAlignB}             val argMem = {szb=CSizes.alignAddr(frameSzB, frameAlignB), align=frameAlignB}
194             in             in
195                {argLocs=paramLocss, argMem=argMem, structRetLoc=structRetLoc, resLocs=resLocs}                {argLocs=paramLocss, argMem=argMem, structRetLoc=structRetLoc, resLocs=resLocs}
196             end             end
# Line 256  Line 221 
221          val (copyArgs, gprUses, fprUses) = CCall.copyArgs(args, argLocs)          val (copyArgs, gprUses, fprUses) = CCall.copyArgs(args, argLocs)
222         (* the defined registers of the call depend on the calling convention *)         (* the defined registers of the call depend on the calling convention *)
223          val defs = (case #conv proto          val defs = (case #conv proto
224              of "ccall" => List.map (gpr o #2) CCs.callerSaveRegs @ List.map fpr CCs.callerSaveFRegs              of "ccall" => List.map (gpr o #2) callerSaveRegs @ List.map fpr callerSaveFRegs
225               | "ccall-bare" => []               | "ccall-bare" => []
226               | conv => raise Fail (concat [               | conv => raise Fail (concat [
227                          "unknown calling convention \"", String.toString conv, "\""                          "unknown calling convention \"", String.toString conv, "\""

Legend:
Removed from v.3082  
changed lines
  Added in v.3083

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