Skip to content

Commit 1910bc3

Browse files
committed
compiler: Make Specializer visit _func_table of an Operator
1 parent 71259ef commit 1910bc3

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from devito.exceptions import CompilationError
1818
from devito.symbolics import IndexedPointer
1919
from devito.ir.iet.nodes import (Node, Iteration, Expression, ExpressionBundle,
20-
Call, Lambda, BlankLine, Section, ListMajor)
20+
Call, Lambda, BlankLine, Section, ListMajor, MetaCall)
2121
from devito.ir.support.space import Backward
2222
from devito.symbolics import (FieldFromComposite, FieldFromPointer,
2323
ListInitializer, uxreplace)
@@ -1509,7 +1509,8 @@ class Specializer(Uxreplace):
15091509
Note that the Operator is not re-optimized in response to this replacement - this
15101510
transformation could nominally result in expressions of the form `f + 0` in the
15111511
generated code. If one wants to construct an Operator where such expressions are
1512-
considered, then use of `subs=...` is a better choice.
1512+
considered, then use of `subs=...` at construction time is a better choice. However,
1513+
it is likely that such expressions will be optimized away by the C-level compiler.
15131514
"""
15141515

15151516
def __init__(self, mapper, nested=False):
@@ -1554,6 +1555,23 @@ def visit_Operator(self, o, **kwargs):
15541555
state['parameters'] = parameters
15551556
state['body'] = body
15561557

1558+
# TODO: Also rebuild the _func_table for the Operator
1559+
# TODO: This is somewhat incongruent with the visitor and should be refactored
1560+
1561+
func_table = OrderedDict()
1562+
for k, v in o._func_table.items():
1563+
root = v.root
1564+
local = v.local
1565+
1566+
body = self._visit(root.body)
1567+
parameters = tuple(i for i in root.parameters if i not in self.mapper)
1568+
1569+
new_root = root._rebuild(body=body, parameters=parameters)
1570+
1571+
func_table[k] = MetaCall(root=new_root, local=local)
1572+
1573+
state['_func_table'] = func_table
1574+
15571575
try:
15581576
state.pop('ccode')
15591577
except KeyError:

0 commit comments

Comments
 (0)