darcs-all: allow relative path for repo in local fs
[ghc-hetmet.git] / compiler / vectorise / VectUtils.hs
index 5cd0471..199ef68 100644 (file)
@@ -2,7 +2,9 @@ module VectUtils (
   collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg,
   splitClosureTy,
   mkPADictType, mkPArrayType,
-  paDictArgType, paDictOfType
+  paDictArgType, paDictOfType,
+  lookupPArrayFamInst,
+  hoistExpr, takeHoisted
 ) where
 
 #include "HsVersions.h"
@@ -10,6 +12,7 @@ module VectUtils (
 import VectMonad
 
 import CoreSyn
+import CoreUtils
 import Type
 import TypeRep
 import TyCon
@@ -17,6 +20,7 @@ import Var
 import PrelNames
 
 import Outputable
+import FastString
 
 import Control.Monad         ( liftM )
 
@@ -104,3 +108,21 @@ paDFunApply dfun tys
       dicts <- mapM paDictOfType tys
       return $ mkApps (mkTyApps dfun tys) dicts
 
+lookupPArrayFamInst :: Type -> VM (TyCon, [Type])
+lookupPArrayFamInst ty = builtin parrayTyCon >>= (`lookupFamInst` [ty])
+
+hoistExpr :: FastString -> CoreExpr -> VM Var
+hoistExpr fs expr
+  = do
+      var <- newLocalVar fs (exprType expr)
+      updGEnv $ \env ->
+        env { global_bindings = (var, expr) : global_bindings env }
+      return var
+
+takeHoisted :: VM [(Var, CoreExpr)]
+takeHoisted
+  = do
+      env <- readGEnv id
+      setGEnv $ env { global_bindings = [] }
+      return $ global_bindings env
+