@@ -25,6 +25,8 @@ class CTemp(Temp):
2525 """
2626 A cluster-level Temp, similar to Temp, ensured to have different priority
2727 """
28+ is_CTemp = True
29+
2830 ordering_of_classes .insert (ordering_of_classes .index ('Temp' ) + 1 , 'CTemp' )
2931
3032
@@ -220,13 +222,39 @@ def _compact(exprs, exclude):
220222 `for (i = ...) { a = b; for (j = a ...) ... }`. Hence, this routine
221223 only targets CTemps.
222224 """
225+ # FIXME: Can use is_CTemp rather than isinstance
223226 candidates = [e for e in exprs
224227 if isinstance (e .lhs , CTemp ) and e .lhs not in exclude ]
225228
226229 mapper = {e .lhs : e .rhs for e in candidates if q_leaf (e .rhs )}
227230
228- mapper .update ({e .lhs : e .rhs for e in candidates
229- if sum ([i .rhs .count (e .lhs ) for i in exprs ]) == 1 })
231+ # FIXME: Move this to searches as retrieve_ctemps
232+ from devito .symbolics .search import search
233+
234+ def q_ctemp (expr ):
235+ try :
236+ return expr .is_CTemp
237+ except AttributeError :
238+ return False
239+
240+ # Find all the CTemps in expressions without removing duplicates
241+ # ctemps = search(exprs, q_ctemp, 'all', 'dfs')
242+ # I think it was more like
243+ ctemps = search ([e .rhs for e in exprs ], q_ctemp , 'all' , 'dfs' )
244+
245+ # print(ctemps, len(ctemps), len(set(ctemps)), len(candidates))
246+
247+ # FIXME: This line is kinda slow. I should find some way to replace it.
248+ # FIXME: Specifically sum([i.rhs.count(e.lhs) for i in exprs]) == 1 is slow as hell
249+ # mapper.update({e.lhs: e.rhs for e in candidates
250+ # if sum([i.rhs.count(e.lhs) for i in exprs]) == 1})
251+
252+ # If there are ctemps in the expressions, then add any to the mapper which only
253+ # appear once
254+ # TODO: Double check this is exactly the prior behaviour?
255+ if ctemps :
256+ mapper .update ({e .lhs : e .rhs for e in candidates
257+ if ctemps .count (e .lhs ) == 1 })
230258
231259 processed = []
232260 for e in exprs :
0 commit comments