Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/high-opt/normalize.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/high-opt/normalize.sml

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

revision 3978, Wed Jun 15 19:07:40 2016 UTC revision 4138, Fri Jul 1 14:46:08 2016 UTC
# Line 31  Line 31 
31      fun decUse (IR.V{useCnt, ...}) = (useCnt := !useCnt - 1)      fun decUse (IR.V{useCnt, ...}) = (useCnt := !useCnt - 1)
32      fun use x = (incUse x; x)      fun use x = (incUse x; x)
33    
34    (*** OLD VERSION
35      fun getEinApp x = (case V.getDef x      fun getEinApp x = (case V.getDef x
36             of IR.EINAPP(e, arg) => SOME(e, arg)             of IR.EINAPP(e, arg) => SOME(e, arg)
37              | _ => NONE              | _ => NONE
38            (* end case *))            (* end case *))
39    ****)
40      (* get the EIN application that "x" is bound to (if any).  Note that we are conservative
41       * on following globals so as to avoid duplicating computation.
42       *)
43        fun getEinApp x = let
44              fun getEinRHS (IR.EINAPP app) = SOME app
45                | getEinRHS _ = NONE
46              in
47                case V.ty x
48                 of HighTypes.KernelTy => getEinRHS(V.getDef x)
49                  | HighTypes.FieldTy => getEinRHS(V.getDef x)
50                  | _ => getEinRHS(V.getLocalDef x)
51                (* end case *)
52              end
53    
54   (* doNormalize : EIN -> EIN   (* doNormalize : EIN -> EIN
55    * Orders EIN, normalizes it, then cleans the summation    * Orders EIN, normalizes it, then cleans the summation
56    *)    *)
57      fun doNormalize e' = let      fun doNormalize e' = let
58    val _ =print(String.concat["\n\n\n do normalize:", EinPP.toString(e')])
59            val ordered = Reorder.transform e'            val ordered = Reorder.transform e'
60            in            in
61              case NormalizeEin.transform ordered              case NormalizeEin.transform ordered
62               of NONE => ordered               of NONE => ordered
63              | SOME e => EinSums.clean e  | SOME e => (print(String.concat["\n transform :=>", EinPP.toString(e)]) ; EinSums.clean e)
64              (* end case *)              (* end case *)
65            end            end
66    
# Line 57  Line 73 
73     *)     *)
74      fun rewriteEin (params, place, changed, newE, newArgs, done, newEinApp, orig, lhs) = (      fun rewriteEin (params, place, changed, newE, newArgs, done, newEinApp, orig, lhs) = (
75            case List.nth(params, place)            case List.nth(params, place)
76             of Ein.TEN(false, _) => (changed, orig, place+1, done@[newEinApp])             of Ein.TEN(false, _) => (
77                    incUse lhs; incUse newEinApp;
78                    (changed, orig, place+1, done@[newEinApp]))
79              | _ => let              | _ => let
80                  val rtnArgs = done @ newArgs                  val rtnArgs = done @ newArgs
81                  val (c, subst) = Apply.apply(orig, place, newE)                  val (c, subst) = Apply.apply(orig, place, newE)
82    val _ =print(String.concat["\n\n\n after substition:", EinPP.toString(subst)])
83                  in                  in
84                    if c                    if c
85                      then (true, subst, place + length newArgs, rtnArgs)                      then (true, subst, place + length newArgs, rtnArgs)
# Line 70  Line 89 
89                  end                  end
90            (* end case *))            (* end case *))
91    
92    (* FIXME: it would be much more efficient to do all of the substitutions in one go,
93     * instead of repeatedly rewriting the term for each argument.
94     *)
95    (* doRHS: HighIR.var * rhs -> (var * rhs) list option    (* doRHS: HighIR.var * rhs -> (var * rhs) list option
96     * Looks at each argument to the original EINAPP.     * Looks at each argument to the original EINAPP.
97     * If it is another EIN APP calls rewriteEin to do application     * If it is another EIN APP calls rewriteEin to do application
# Line 77  Line 99 
99     * Keeps track of the place of the argument in substitution.     * Keeps track of the place of the argument in substitution.
100     *)     *)
101      fun doRHS (lhs, IR.EINAPP(ein, args)) = let      fun doRHS (lhs, IR.EINAPP(ein, args)) = let
102    val _ =print(String.concat["\n\n\n doRHS:", EinPP.toString(ein)])
103            fun rewrite (false, _, _, [], _) = NONE            fun rewrite (false, _, _, [], _) = NONE
104              | rewrite (true, orig, _, [], args') =              | rewrite (true, orig, _, [], args') =
105                  SOME[(lhs, IR.EINAPP(doNormalize orig, args'))]                  SOME[(lhs, IR.EINAPP(doNormalize orig, args'))]
# Line 108  Line 131 
131    
132      val transform = Promote.transform o Rewrite.transform      val transform = Promote.transform o Rewrite.transform
133    
134    (*DEBUG*
135    fun transform prog = let
136          val prog = Rewrite.transform prog
137          val _ = HighPP.output(Log.logFile(), "AFTER REWRITE", prog)
138          val prog = Promote.transform prog
139          val _ = HighPP.output(Log.logFile(), "AFTER PROMOTE", prog)
140          in
141            prog
142          end
143    *DEBUG*)
144    
145    end    end

Legend:
Removed from v.3978  
changed lines
  Added in v.4138

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