Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Diff of /trunk/sml3d/src/particles/compiler/specialized.sml
ViewVC logotype

Diff of /trunk/sml3d/src/particles/compiler/specialized.sml

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

revision 905, Sun May 30 20:35:18 2010 UTC revision 906, Wed Jun 2 21:13:39 2010 UTC
# Line 35  Line 35 
35        gProgramChanged := true;        gProgramChanged := true;
36        IR.PRIM(v, p, vl, s))        IR.PRIM(v, p, vl, s))
37    
38        fun optimizeBlock(IR.BLK{id, params, body, visited, refCount}) = let
39      fun optimizeStmt(IR.PRIM(v, p, vl, s)) = (case p      fun optimizeStmt(IR.PRIM(v, p, vl, s)) = (case p
40        of IR.DOT => let        of IR.DOT => let
41    
# Line 109  Line 110 
110            IR.PRIM(v, p, vl, optimizeStmt(s))            IR.PRIM(v, p, vl, optimizeStmt(s))
111          end          end
112    
113             | IR.ADD => let
114               val fltOne = List.nth(vl, 0)
115               val fltTwo = List.nth(vl, 1)
116              in
117               if checkMatchFloat(fltOne, 0.0) then
118                mkOptStmt(v, IR.COPY, [fltTwo], optimizeStmt(s))
119               else if checkMatchFloat(fltTwo, 0.0) then
120                mkOptStmt(v, IR.COPY, [fltOne], optimizeStmt(s))
121               else
122                IR.PRIM(v, p, vl, optimizeStmt(s))
123              end
124    
125             | IR.MULT => let
126               val fltOne = List.nth(vl, 0)
127               val fltTwo = List.nth(vl, 1)
128              in
129               if checkMatchFloat(fltOne, 0.0) orelse checkMatchFloat(fltTwo, 0.0) then
130                mkOptStmt(v, IR.COPY, [IR.newConst("opt", IR.C_FLOAT(0.0))], optimizeStmt(s))
131               else if checkMatchFloat(fltOne, 1.0) then
132                mkOptStmt(v, IR.COPY, [fltTwo], optimizeStmt(s))
133               else if checkMatchFloat(fltTwo, 1.0) then
134                mkOptStmt(v, IR.COPY, [fltOne], optimizeStmt(s))
135               else
136                IR.PRIM(v, p, vl, optimizeStmt(s))
137              end
138    
139             | IR.DIV => let
140               val fltOne = List.nth(vl, 0)
141               val fltTwo = List.nth(vl, 1)
142              in
143               if checkMatchFloat(fltTwo, 1.0) then
144                mkOptStmt(v, IR.COPY, [fltOne], optimizeStmt(s))
145               else
146                IR.PRIM(v, p, vl, optimizeStmt(s))
147              end
148    
149             | IR.SUB => let
150               val fltOne = List.nth(vl, 0)
151               val fltTwo = List.nth(vl, 1)
152              in
153               if checkMatchFloat(fltTwo, 0.0) then
154                mkOptStmt(v, IR.COPY, [fltOne], optimizeStmt(s))
155               else
156                IR.PRIM(v, p, vl, optimizeStmt(s))
157              end
158    
159         | _ => IR.PRIM(v, p, vl, optimizeStmt(s))         | _ => IR.PRIM(v, p, vl, optimizeStmt(s))
160        (* end case *))        (* end case *))
161    
# Line 125  Line 172 
172          (* end case *))          (* end case *))
173    
174        (* Gotos, discards, and returns cannot be optimized here... *)        (* Gotos, discards, and returns cannot be optimized here... *)
175            | optimizeStmt(IR.GOTO(nextBlk, vl)) = IR.GOTO(optimizeBlock(nextBlk), vl)
176        | optimizeStmt(x) = x        | optimizeStmt(x) = x
177    
     fun optimizeBlock(IR.BLK{id, params, body, visited, refCount}) = let  
178        val _ = gProgramChanged := false        val _ = gProgramChanged := false
179        val newBlk = IR.BLK{id=id, params=params, body=optimizeStmt(body), visited=visited, refCount=refCount}        val newBlk = IR.BLK{id=id, params=params, body=optimizeStmt(body), visited=visited, refCount=refCount}
180       in       in
# Line 139  Line 186 
186    
187      fun optimize(IR.PGM{emitter, physics, render}) =      fun optimize(IR.PGM{emitter, physics, render}) =
188        IR.PGM{        IR.PGM{
189          emitter = optimizeBlock(emitter),          emitter = optimizeBlock emitter,
190          physics = List.map optimizeBlock physics,          physics = optimizeBlock physics,
191          render = render          render = render
192        }        }
193    

Legend:
Removed from v.905  
changed lines
  Added in v.906

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