From 3e64635f9560cb67b593a4988c26798e89ef7fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Thu, 3 Nov 2011 00:43:36 +0100 Subject: [PATCH] optimize the control at the end to maximize profit Indeed, some examples showed that memory allocation could trigger a profit-full deadcode removal for the control. See Downscaler.down avec -flatten. --- compiler/obc/main/obc_compiler.ml | 5 ++-- test/image_filters/downscale.ept | 44 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/image_filters/downscale.ept diff --git a/compiler/obc/main/obc_compiler.ml b/compiler/obc/main/obc_compiler.ml index 43a6788..65bf8a3 100644 --- a/compiler/obc/main/obc_compiler.ml +++ b/compiler/obc/main/obc_compiler.ml @@ -14,8 +14,6 @@ open Compiler_options let pp p = if !verbose then Obc_printer.print stdout p let compile_program p = - (*Control optimization*) - let p = pass "Control optimization" true Control.program p pp in (* Memory allocation application *) let p = pass "Application of Memory Allocation" @@ -25,4 +23,7 @@ let compile_program p = let p = pass "Dead code removal" (!do_mem_alloc or !do_linear_typing) Deadcode.program p pp in + (*Control optimization*) + let p = pass "Control optimization" true Control.program p pp in + p diff --git a/test/image_filters/downscale.ept b/test/image_filters/downscale.ept new file mode 100644 index 0000000..519472b --- /dev/null +++ b/test/image_filters/downscale.ept @@ -0,0 +1,44 @@ + +type pixel = float^3 + +node nat() returns (n :int) +let + n = 0 fby n+1 +tel + +fun pix_sum(x1,x2 :pixel) returns (r :pixel) +let + r = map<<3>> (+.) (x1,x2); +tel + +fun pix_div(x :pixel; c :float) returns (r :pixel) +let + r = map<<3>> (/.) (x, c^3); +tel + +node counter(res :bool) returns (cpt :int) +let + reset + cpt = (0 fby cpt) + 1 + every res +tel + +(* down par region +node down(x :pixel; out :bool) returns (r :pixel) +var cpt :float; sum :pixel; +let + reset + cpt = (0.0 fby cpt) +. 1.0; + sum = x -> pix_sum(pre sum, x); + every out; + r = pix_div(sum when out, cpt when out); +tel +*) + +node down(x :pixel; out :bool) returns (r :pixel :: . on out) +var x1, x2 : pixel; +let + x1 = x fby x; + x2 = x fby x1; + r = pix_div(pix_sum(x when out, pix_sum(x1 when out, x2 when out)), 3.0 ); +tel