From 21fe1d7731a5fd66a1530ed6895b091b0f93f989 Mon Sep 17 00:00:00 2001
From: Marcel Koch <marcel.koch@uni-muenster.de>
Date: Wed, 3 Apr 2019 15:00:44 +0200
Subject: [PATCH] move alias declaration into preamble

---
 .../codegen/blockstructured/accumulation.py   |  9 +++----
 .../dune/codegen/blockstructured/argument.py  | 25 ++++++++++---------
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/python/dune/codegen/blockstructured/accumulation.py b/python/dune/codegen/blockstructured/accumulation.py
index 9af9759d..1f26d3ca 100644
--- a/python/dune/codegen/blockstructured/accumulation.py
+++ b/python/dune/codegen/blockstructured/accumulation.py
@@ -1,5 +1,5 @@
 from dune.codegen.blockstructured.tools import sub_element_inames
-from dune.codegen.generation import accumulation_mixin, instruction
+from dune.codegen.generation import accumulation_mixin, instruction, preamble
 from dune.codegen.loopy.target import dtype_floatingpoint
 from dune.codegen.options import get_form_option
 from dune.codegen.pdelab.geometry import world_dimension, name_intersection_geometry_wrapper
@@ -28,16 +28,13 @@ def name_accumulation_alias(container, accumspace):
     k = get_form_option("number_of_blocks")
     p = accumspace.element.degree()
 
+    @preamble
     def _add_alias_insn(name):
         dim = world_dimension()
         element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim))
         index_stride = tuple((p * k + 1)**i for i in range(0, dim))
         globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True)
-        code = "auto {} = &{}.container()({},0);".format(name, container, accumspace.lfs.name)
-        instruction(within_inames=frozenset(),
-                    code=code,
-                    read_variables=frozenset({container}),
-                    assignees=frozenset({name}))
+        return "auto {} = &{}.container()({},0);".format(name, container, accumspace.lfs.name)
 
     _add_alias_insn(name)
     _add_alias_insn(name_tail)
diff --git a/python/dune/codegen/blockstructured/argument.py b/python/dune/codegen/blockstructured/argument.py
index 420773e8..0cc7bd17 100644
--- a/python/dune/codegen/blockstructured/argument.py
+++ b/python/dune/codegen/blockstructured/argument.py
@@ -1,5 +1,5 @@
 from dune.codegen.generation import (kernel_cached,
-                                     valuearg, instruction, globalarg)
+                                     valuearg, globalarg, preamble)
 from dune.codegen.options import get_form_option
 from dune.codegen.pdelab.argument import CoefficientAccess
 from dune.codegen.blockstructured.tools import micro_index_to_macro_index, sub_element_inames
@@ -10,17 +10,18 @@ import pymbolic.primitives as prim
 
 def name_alias(container, lfs, element):
     name = container + "_" + lfs.name + "_alias"
-    k = get_form_option("number_of_blocks")
-    p = element.degree()
-    dim = world_dimension()
-    element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim))
-    index_stride = tuple((p * k + 1)**i for i in range(0, dim))
-    globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True)
-    code = "const auto {} = &{}({},0);".format(name, container, lfs.name)
-    instruction(within_inames=frozenset(),
-                code=code,
-                read_variables=frozenset({container}),
-                assignees=frozenset({name}))
+
+    @preamble
+    def _add_alias_insn(name):
+        k = get_form_option("number_of_blocks")
+        p = element.degree()
+        dim = world_dimension()
+        element_stride = tuple(p * (p * k + 1)**i for i in range(0, dim))
+        index_stride = tuple((p * k + 1)**i for i in range(0, dim))
+        globalarg(name, shape=(k,) * dim + (p + 1,) * dim, strides=element_stride + index_stride, managed=True)
+        return "const auto {} = &{}({},0);".format(name, container, lfs.name)
+
+    _add_alias_insn(name)
     return name
 
 
-- 
GitLab