[enable storage analysis to enable allocation on the stack
John Meacham <john@repetae.net>**20090905112613
 Ignore-this: 698cba1f286da15511ab00db0f641348
] hunk ./src/C/FromGrin2.hs 419
-convertBody (BaseOp (StoreNode b)  [n@NodeC {}])  = newNode (bool b wptr_t sptr_t) n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
---convertBody (Return [n@NodeC {}])  = newNode wptr_t n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
---convertBody (Store  n@NodeC {})  = newNode sptr_t n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
---convertBody (Return [n@NodeC {}])  = newNode wptr_t n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
+convertBody (BaseOp (StoreNode b)  [n@NodeC {}])  = newNode region_heap (bool b wptr_t sptr_t) n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
+convertBody (BaseOp (StoreNode b)  [n@NodeC {},region]) = newNode region (bool b wptr_t sptr_t) n >>= \(x,y) -> simpleRet y >>= \v -> return (x & v)
hunk ./src/C/FromGrin2.hs 567
-        (nns, nn) <- newNode fptr_t tn
+        (nns, nn) <- newNode region_heap fptr_t tn
hunk ./src/C/FromGrin2.hs 764
-newNode ty ~(NodeC t as) = do
+newNode region ty ~(NodeC t as) = do
hunk ./src/C/FromGrin2.hs 776
---            nonPtr (TyTup xs) = all nonPtr xs
+            nonPtr TyINode = False
hunk ./src/C/FromGrin2.hs 778
-        (dtmp,tmp) <- ty `newTmpVar` malloc
+        (dtmp,tmp) <- case region == region_stack of
+            True -> do
+                v <- newVar st
+                return (mempty,v)
+            False -> do ty `newTmpVar` malloc
+        tmp <- if region == region_stack then return (reference tmp) else return tmp
hunk ./src/C/Generate.hs 408
+massign a b = if isEmptyExpression b then toStatement a else assign a b
hunk ./src/C/Generate.hs 414
-            va <- draw (variable n `assign` e)
+            va <- draw (variable n `massign` e)
hunk ./src/C/Generate.hs 421
-            va <- draw (variable n `assign` e)
+            va <- draw (variable n `massign` e)
hunk ./src/Grin/Grin.hs 617
+
hunk ./src/Grin/StorageAnalysis.hs 3
+import Control.Monad.Identity
hunk ./src/Grin/StorageAnalysis.hs 8
-import Support.FreeVars
-import Support.CanType
+import Grin.Grin
hunk ./src/Grin/StorageAnalysis.hs 10
+import Grin.Noodle
+import Grin.Val
hunk ./src/Grin/StorageAnalysis.hs 13
+import Support.CanType
+import Support.FreeVars
hunk ./src/Grin/StorageAnalysis.hs 16
-import Util.UniqueMonad
-import Util.UnionSolve
-import Grin.Grin
-import Grin.Noodle
hunk ./src/Grin/StorageAnalysis.hs 17
+import Util.UnionSolve
+import Util.UniqueMonad
hunk ./src/Grin/StorageAnalysis.hs 55
-    dumpGrin "storeAnalyze1" grin
+    --dumpGrin "storeAnalyze1" grin
hunk ./src/Grin/StorageAnalysis.hs 57
-    dumpGrin "storeAnalyze2" grin'
-    --(rm,res) <- solve (const $ return ()) cs
-    (rm,res) <- solve putStrLn cs
-    putStrLn "----------------------------"
-    mapM_ (\ (x,y) -> putStrLn $ show x ++ " -> " ++ show y) (Map.toList rm)
-    putStrLn "----------------------------"
-    mapM_ print (Map.elems res)
-    putStrLn "----------------------------"
-    let cmap = Map.map (lower . fromJust . flip Map.lookup res) rm
+    --dumpGrin "storeAnalyze2" grin'
+    (rm,res) <- solve (const $ return ()) cs
+ --   (rm,res) <- solve putStrLn cs
+ --   putStrLn "----------------------------"
+ --   mapM_ (\ (x,y) -> putStrLn $ show x ++ " -> " ++ show y) (Map.toList rm)
+ --   putStrLn "----------------------------"
+ --   mapM_ print (Map.elems res)
+ --   putStrLn "----------------------------"
+    let cmap = Map.filterWithKey fm $ Map.map (lower . fromJust . flip Map.lookup res) rm
hunk ./src/Grin/StorageAnalysis.hs 68
+        fm _ E = False
+        fm (Vr _) _ = True
+        fm (Va _ _) _ = True
+        fm _ _ = False
hunk ./src/Grin/StorageAnalysis.hs 73
-    return grin'
+    let grin'' = runIdentity $ tickleM (lastLam cmap) grin'
+    return grin''
hunk ./src/Grin/StorageAnalysis.hs 99
+            f wtd e@(BaseOp Overwrite [Var v _,n]) = do tell $ mconcat [ Left (Vb v) `islte` Left r | r <- concat $ toVs [n] ] ; return e
hunk ./src/Grin/StorageAnalysis.hs 107
-            f wtd e = return e
+            f wtd e =  do
+                let zs = Set.toList (Set.map (Vb . fst) $ Set.filter (isHeap . snd) (freeVars e))
+                tell $ mconcat [ Right E `islte` Left r | r <- zs ];
+                return e
hunk ./src/Grin/StorageAnalysis.hs 128
+lastLam :: Map.Map Vr T -> Lam -> Identity Lam
+lastLam cmap  lam = tickleM f lam where
+    f (BaseOp (StoreNode sh) [n,Var r TyRegion]) = do
+        case Map.lookup (Vr r) cmap of
+            Just S -> return (BaseOp (StoreNode sh) [n,region_stack])
+            _ ->  return (BaseOp (StoreNode sh) [n])
+    f e = tickleM f e
+
+
+
+
hunk ./src/Grin/Val.hs 11
+    region_stack,
hunk ./src/Main.hs 678
---    x <- storeAnalyze x
+    x <- storeAnalyze x