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/instructions/shuffle.sml
 [smlnj] / MLRISC / trunk / instructions / shuffle.sml

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

revision 412, Fri Sep 3 00:25:03 1999 UTC revision 579, Wed Mar 22 06:33:08 2000 UTC
# Line 19  Line 19
19          -> I.instruction list          -> I.instruction list
20    end =    end =
21  struct  struct
22    datatype reg = REG of int | TEMP    fun equal (r1 : int, r2 : int) = r1 = r2
fun equal (REG r1, REG r2) = r1 = r2
| equal (TEMP, TEMP) = true
| equal _ = false
23
24    fun shuffle{mvInstr, ea} {regmap, tmp, dst, src} = let    fun shuffle{mvInstr, ea} {regmap, tmp, dst, src} = let
25      val mv = rev o mvInstr      fun mv{dst, src, instrs} = List.revAppend(mvInstr{dst=dst,src=src}, instrs)
26      fun opnd (REG dst) = ea dst      val TEMP = ~1
27        | opnd TEMP = Option.valOf tmp      fun opnd dst = if dst = TEMP then Option.valOf tmp else ea dst
28
29      (* perform unconstrained moves *)      (* perform unconstrained moves *)
30      fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =      fun loop((p as (rd,rs))::rest, changed, used, done, instrs) =
31          if List.exists (fn r => equal(r, rd)) used then          if List.exists (fn r => equal(r, rd)) used then
32             loop(rest, changed, used, p::done, instrs)             loop(rest, changed, used, p::done, instrs)
33          else loop(rest, true, used, done,          else loop(rest, true, used, done,
34                    mv{dst=opnd rd, src=opnd rs}@instrs)                    mv{dst=opnd rd, src=opnd rs, instrs=instrs})
35        | loop([], changed, _, done, instrs) = (changed, done, instrs)        | loop([], changed, _, done, instrs) = (changed, done, instrs)
36
37      fun cycle([], instrs) = instrs      fun cycle([], instrs) = instrs
# Line 45  Line 42
42             | (false, (rd,rs)::acc, instrs) => let             | (false, (rd,rs)::acc, instrs) => let
43                 fun rename(p as (a,b)) = if equal(rd, b) then (a, TEMP) else p                 fun rename(p as (a,b)) = if equal(rd, b) then (a, TEMP) else p
44                 val acc' = (rd, rs) :: map rename acc                 val acc' = (rd, rs) :: map rename acc
45                 val instrs' = mv{dst=Option.valOf tmp, src=opnd rd}@instrs                 val instrs' = mv{dst=Option.valOf tmp,src=opnd rd,instrs=instrs}
46                 val (_, acc'', instrs'') =                 val (_, acc'', instrs'') =
47                   loop(acc', false, map #2 acc', [], instrs')                   loop(acc', false, map #2 acc', [], instrs')
48               in cycle(acc'', instrs'')               in cycle(acc'', instrs'')
# Line 53  Line 50
50           (*esac*))           (*esac*))
51
52      (* remove moves that have been coalesced. *)      (* remove moves that have been coalesced. *)
53      fun rmvCoalesced(rd::rds, rs::rss) = let      fun rmvCoalesced(rd::rds, rs::rss, mvs) = let
54            val dst = regmap rd            val dst = regmap rd
55            val src = regmap rs            val src = regmap rs
56          in          in
57            if dst = src then rmvCoalesced(rds, rss)            if dst = src then rmvCoalesced(rds, rss, mvs)
58            else (REG dst, REG src)::rmvCoalesced(rds, rss)            else rmvCoalesced(rds, rss, (dst, src)::mvs)
59          end          end
60        | rmvCoalesced([], []) = []        | rmvCoalesced([], [], mvs) = mvs
61    in rev (cycle (rmvCoalesced(dst, src), []))    in rev (cycle (rmvCoalesced(dst, src, []), []))
62    end    end
63  end  end
64

Legend:
 Removed from v.412 changed lines Added in v.579

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