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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-il/normalize.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-il/normalize.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2445 - (download) (annotate)
Thu Sep 26 17:40:17 2013 UTC (5 years, 11 months ago) by cchiw
File size: 4196 byte(s)
value numbering?
(* normalize.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Normalize : sig

    val transform : HighIL.program -> HighIL.program

  end = struct

    structure IL = HighIL
    structure Op = HighOps
    structure V = IL.Var
    structure Ty = HighILTypes
    structure ST = Stats
    structure NE = NormalizeEin

(********** Counters for statistics **********)
    val cntInsideScale          = ST.newCounter "high-opt:inside-scale"
    val cntInsideOffset         = ST.newCounter "high-opt:inside-offset"
    val cntInsideNeg            = ST.newCounter "high-opt:inside-meg"
    val cntInsideCurl           = ST.newCounter "high-opt:inside-curl"
    val cntInsideDiff           = ST.newCounter "high-opt:inside-diff"
    val cntProbeAdd             = ST.newCounter "high-opt:probe-add"
    val cntProbeSub             = ST.newCounter "high-opt:probe-sub"
    val cntProbeScale           = ST.newCounter "high-opt:probe-scale"
    val cntProbeOffset          = ST.newCounter "high-opt:probe-offset"
    val cntProbeNeg             = ST.newCounter "high-opt:probe-neg"
    val cntProbeCurl            = ST.newCounter "high-opt:probe-curl"
    val cntDiffField            = ST.newCounter "high-opt:diff-field"
    val cntDiffAdd              = ST.newCounter "high-opt:diff-add"
    val cntDiffScale            = ST.newCounter "high-opt:diff-scale"
    val cntDiffOffset           = ST.newCounter "high-opt:diff-offset"
    val cntDiffNeg              = ST.newCounter "high-opt:diff-neg"
    val cntCurlScale            = ST.newCounter "high-opt:curl-scale"
    val cntCurlNeg              = ST.newCounter "high-opt:curl-neg"
    val cntUnused               = ST.newCounter "high-opt:unused"
    val firstCounter            = cntInsideScale
    val lastCounter             = cntUnused

    structure UnusedElim = UnusedElimFn (
        structure IL = IL
        val cntUnused = cntUnused)

    fun useCount (IL.V{useCnt, ...}) = !useCnt

  (* adjust a variable's use count *)
    fun incUse (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
    fun decUse (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)
    fun use x = (incUse x; x)

    fun getRHS x = (case V.binding x
           of IL.VB_RHS(IL.OP arg) => SOME arg
            | IL.VB_RHS(IL.VAR x') => getRHS x'
        (*    | IL.VB_RHS(IL.EINAPP arg)=> SOME arg*)
            | _ => NONE
          (* end case *))

  (* get the binding of a kernel variable *)
    fun getKernelRHS h = (case getRHS h
           of SOME(Op.Kernel(kernel, k), []) => (kernel, k)
            | _ => raise Fail(concat[
                  "bogus kernel binding ", V.toString h, " = ", IL.vbToString(V.binding h)
                ])
          (* end case *))

  (* optimize the rhs of an assignment, returning NONE if there is no change *)

    fun doRHS _ = NONE

(*
    fun doRHS (lhs, IL.EINAPP (ein, args))=
           SOME[(lhs, IL.EINAPP(NE.normalize(ein), args))]

     | doRHS (lhs, IL.OP rhs) = (case rhs
           of (Op.Inside dim, [pos, f]) => (case getRHS f
                 of SOME(Op.Field _, _) => NONE (* direct inside test does not need rewrite 
                  | SOME(Op.OffsetField, [f', _]) => (
                      ST.tick cntInsideOffset;
                      decUse f;
                      SOME[(lhs, IL.OP(Op.Inside dim, [pos, use f']))])*)
                  | _ => raise Fail(concat[
                        "inside: bogus field binding ", V.toString f, " = ", IL.vbToString(V.binding f)
                      ])
                (* end case *))   
            | _ => NONE
          (* end case *))
      | doRHS _ = NONE
*)

(* (*deleted addfield, subfield, scalefield, negfield, curlfield, and difffield*)
-deleted probe field of Field, addfield, subfield, scalefield OffsetField, negfield, curl, diffield
-deleted diffield of field, addfield, subfield, scalefield, offsetfield
negfield
-deleted curlfield, ...
*)


    structure Rewrite = RewriteFn (
      struct
        structure IL = IL
        val doAssign = doRHS
        fun doMAssign _ = NONE
        val elimUnusedVars = UnusedElim.reduce
      end)

    val transform = Rewrite.transform

  end

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