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/instructions/shuffle.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/instructions/shuffle.sml

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

revision 651, Thu Jun 1 18:34:03 2000 UTC revision 744, Fri Dec 8 04:11:42 2000 UTC
# Line 10  Line 10 
10    sig    sig
11      val shuffle :      val shuffle :
12        {mvInstr : {dst:I.ea, src:I.ea} -> I.instruction list,        {mvInstr : {dst:I.ea, src:I.ea} -> I.instruction list,
13         ea : int -> I.ea}         ea : I.C.cell -> I.ea}
14        ->        ->
15          {regmap: int -> int,          {tmp : I.ea option,
16           tmp : I.ea option,           dst : I.C.cell list,
17           dst : int list,           src : I.C.cell list}
          src : int list}  
18          -> I.instruction list          -> I.instruction list
19    end =    end =
20  struct  struct
21    fun equal (r1 : int, r2 : int) = r1 = r2    structure C = I.C
22    
23    fun shuffle{mvInstr, ea} {regmap, tmp, dst, src} = let    datatype obj = TEMP | CELL of C.cell
24    
25      fun equal (r1, r2) = C.sameColor(r1,r2)
26    
27      fun equalObj (TEMP, TEMP) = true
28        | equalObj (CELL u, CELL v) = equal(u, v)
29        | equalObj _ = false
30    
31      fun shuffle{mvInstr, ea} {tmp, dst, src} = let
32      fun mv{dst, src, instrs} = List.revAppend(mvInstr{dst=dst,src=src}, instrs)      fun mv{dst, src, instrs} = List.revAppend(mvInstr{dst=dst,src=src}, instrs)
33      val TEMP = ~1  
34      fun valOf(SOME x) = x      fun valOf(SOME x) = x
35        | valOf NONE = raise Option        | valOf NONE = raise Option
36      fun opnd dst = if dst = TEMP then valOf tmp else ea dst  
37        fun opnd dst = case dst of
38                         TEMP     => valOf tmp
39                       | CELL dst => ea dst
40    
41      (* perform unconstrained moves *)      (* perform unconstrained moves *)
42      fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =      fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =
43          if List.exists (fn r => equal(r, rd)) used then          if List.exists (fn r => equalObj(r, rd)) used then
44             loop(rest, changed, used, p::done, instrs)             loop(rest, changed, used, p::done, instrs)
45          else loop(rest, true, used, done,          else loop(rest, true, used, done,
46                    mv{dst=opnd rd, src=opnd rs, instrs=instrs})                    mv{dst=opnd rd, src=opnd rs, instrs=instrs})
# Line 42  Line 52 
52            of (_, [], instrs) => instrs            of (_, [], instrs) => instrs
53             | (true, acc, instrs) => cycle(acc, instrs)             | (true, acc, instrs) => cycle(acc, instrs)
54             | (false, (rd,rs)::acc, instrs) => let             | (false, (rd,rs)::acc, instrs) => let
55                 fun rename(p as (a,b)) = if equal(rd, b) then (a, TEMP) else p                 fun rename(p as (a,b)) =
56                       if equalObj(rd, b) then (a, TEMP) else p
57                 val acc' = (rd, rs) :: map rename acc                 val acc' = (rd, rs) :: map rename acc
58                 val instrs' = mv{dst=valOf tmp,src=opnd rd,instrs=instrs}                 val instrs' = mv{dst=valOf tmp,src=opnd rd,instrs=instrs}
59                 val (_, acc'', instrs'') =                 val (_, acc'', instrs'') =
# Line 52  Line 63 
63           (*esac*))           (*esac*))
64    
65      (* remove moves that have been coalesced. *)      (* remove moves that have been coalesced. *)
66      fun rmvCoalesced(rd::rds, rs::rss, mvs) = let      fun rmvCoalesced(rd::rds, rs::rss, mvs) =
67            val dst = regmap rd          if equal(rd, rs) then rmvCoalesced(rds, rss, mvs)
68            val src = regmap rs          else rmvCoalesced(rds, rss, (CELL rd, CELL rs)::mvs)
         in  
           if dst = src then rmvCoalesced(rds, rss, mvs)  
           else rmvCoalesced(rds, rss, (dst, src)::mvs)  
         end  
69        | rmvCoalesced([], [], mvs) = mvs        | rmvCoalesced([], [], mvs) = mvs
70    in rev (cycle (rmvCoalesced(dst, src, []), []))    in rev (cycle (rmvCoalesced(dst, src, []), []))
71    end    end

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

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