@@ -41,10 +41,14 @@ def _drop_reduction_halospots(iet):
4141
4242 # If all HaloSpot reads pertain to reductions, then the HaloSpot is useless
4343 for hs , expressions in MapNodes (HaloSpot , Expression ).visit (iet ).items ():
44- scope = Scope (i .expr for i in expressions )
45- for f , v in scope .reads .items ():
46- if f in hs .fmapper and all (i .is_reduction for i in v ):
47- mapper [hs ].add (f )
44+ scope = Scope .maybe_cached (tuple (i .expr for i in expressions ))
45+ for k , v in hs .fmapper .items ():
46+ f = v .bundle or k
47+ if f not in scope .reads :
48+ continue
49+ v = scope .reads [f ]
50+ if all (i .is_reduction for i in v ):
51+ mapper [hs ].add (k )
4852
4953 # Transform the IET introducing the "reduced" HaloSpots
5054 mapper = {hs : hs ._rebuild (halo_scheme = hs .halo_scheme .drop (mapper [hs ]))
@@ -79,7 +83,7 @@ def _hoist_redundant_from_conditionals(iet):
7983
8084 mapper = HaloSpotMapper ()
8185 for it , halo_spots in iter_mapper .items ():
82- scope = Scope ( e .expr for e in FindNodes (Expression ).visit (it ))
86+ scope = Scope . maybe_cached ( tuple ( e .expr for e in FindNodes (Expression ).visit (it ) ))
8387
8488 for hs0 in halo_spots :
8589 conditions = cond_mapper [hs0 ]
@@ -279,7 +283,7 @@ def _mark_overlappable(iet):
279283 if not expressions :
280284 continue
281285
282- scope = Scope ( i .expr for i in expressions )
286+ scope = Scope . maybe_cached ( tuple ( i .expr for i in expressions ) )
283287
284288 # Comp/comm overlaps is legal only if the OWNED regions can grow
285289 # arbitrarly, which means all of the dependences must be carried
@@ -459,7 +463,7 @@ def _derive_scope(it, hs0, hs1):
459463 and ends at the HaloSpot `hs1`.
460464 """
461465 expressions = FindWithin (Expression , hs0 , stop = hs1 ).visit (it )
462- return Scope ( e .expr for e in expressions )
466+ return Scope . maybe_cached ( tuple ( e .expr for e in expressions ) )
463467
464468
465469def _check_control_flow (hs0 , hs1 , cond_mapper ):
0 commit comments