Skip to content

Commit

Permalink
Handle infinite loops in migration table.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Jul 20, 2023
1 parent 3298c56 commit 2ce2241
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Futhark/Optimise/ReduceDeviceSyncs/MigrationTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Data.IntMap.Strict qualified as IM
import Data.IntSet qualified as IS
import Data.List qualified as L
import Data.Map.Strict qualified as M
import Data.Maybe (fromJust, fromMaybe, isJust, isNothing)
import Data.Maybe (fromMaybe, isJust, isNothing)
import Data.Sequence qualified as SQ
import Data.Set (Set, (\\))
import Data.Set qualified as S
Expand Down Expand Up @@ -700,7 +700,7 @@ graphLoop (b : bs) params lform body = do
unless may_migrate $ case lform of
ForLoop _ _ (Var n) _ -> connectToSink (nameToId n)
WhileLoop n
| (_, p, _, res) <- loopValueFor n -> do
| Just (_, p, _, res) <- loopValueFor n -> do
connectToSink p
case res of
Var v -> connectToSink (nameToId v)
Expand Down Expand Up @@ -741,8 +741,9 @@ graphLoop (b : bs) params lform body = do
ForLoop _ _ n _ ->
onlyGraphedScalarSubExp n >>= addEdges (ToNodes bindings Nothing)
WhileLoop n
| (_, _, arg, _) <- loopValueFor n ->
| Just (_, _, arg, _) <- loopValueFor n ->
onlyGraphedScalarSubExp arg >>= addEdges (ToNodes bindings Nothing)
_ -> pure ()
where
subgraphId :: Id
subgraphId = fst b
Expand All @@ -759,9 +760,8 @@ graphLoop (b : bs) params lform body = do
bindings :: IdSet
bindings = IS.fromList $ map (\((i, _), _, _, _) -> i) loopValues

loopValueFor :: VName -> LoopValue
loopValueFor n =
fromJust $ find (\(_, p, _, _) -> p == nameToId n) loopValues
find (\(_, p, _, _) -> p == nameToId n) loopValues

graphTheLoop :: Grapher ()
graphTheLoop = do
Expand Down

0 comments on commit 2ce2241

Please sign in to comment.