Thread lifting context implicitly in the vectorisation monad
[ghc-hetmet.git] / compiler / vectorise / VectMonad.hs
index 86b1cb7..a991b8c 100644 (file)
@@ -39,6 +39,7 @@ import Id
 import OccName
 import Name
 import NameEnv
+import TysPrim       ( intPrimTy )
 
 import DsMonad
 import PrelNames
@@ -69,6 +70,7 @@ data Builtins = Builtins {
                 , lengthPAVar      :: Var
                 , replicatePAVar   :: Var
                 , emptyPAVar       :: Var
+                , liftingContext   :: Var
                 }
 
 paDictTyCon :: Builtins -> TyCon
@@ -92,6 +94,9 @@ initBuiltins
       replicatePAVar   <- dsLookupGlobalId replicatePAName
       emptyPAVar       <- dsLookupGlobalId emptyPAName
 
+      liftingContext <- liftM (\u -> mkSysLocal FSLIT("lc") u intPrimTy)
+                              newUnique
+
       return $ Builtins {
                  parrayTyCon      = parrayTyCon
                , paClass          = paClass
@@ -103,6 +108,7 @@ initBuiltins
                , lengthPAVar      = lengthPAVar
                , replicatePAVar   = replicatePAVar
                , emptyPAVar       = emptyPAVar
+               , liftingContext   = liftingContext
                }
 
 data GlobalEnv = GlobalEnv {
@@ -213,6 +219,9 @@ instance Monad VM where
 noV :: VM a
 noV = VM $ \_ _ _ -> return No
 
+traceNoV :: String -> SDoc -> VM a
+traceNoV s d = pprTrace s d noV
+
 tryV :: VM a -> VM (Maybe a)
 tryV (VM p) = VM $ \bi genv lenv ->
   do
@@ -224,6 +233,9 @@ tryV (VM p) = VM $ \bi genv lenv ->
 maybeV :: VM (Maybe a) -> VM a
 maybeV p = maybe noV return =<< p
 
+traceMaybeV :: String -> SDoc -> VM (Maybe a) -> VM a
+traceMaybeV s d p = maybe (traceNoV s d) return =<< p
+
 orElseV :: VM a -> VM a -> VM a
 orElseV p q = maybe q return =<< tryV p
 
@@ -336,7 +348,8 @@ lookupVar v
       case r of
         Just e  -> return (Local e)
         Nothing -> liftM Global
-                 $  maybeV (readGEnv $ \env -> lookupVarEnv (global_vars env) v)
+                 $  traceMaybeV "lookupVar" (ppr v)
+                                (readGEnv $ \env -> lookupVarEnv (global_vars env) v)
 
 lookupTyCon :: TyCon -> VM (Maybe TyCon)
 lookupTyCon tc
@@ -393,7 +406,7 @@ lookupInst cls tys
              where
                inst_tys'  = [ty | Right ty <- inst_tys]
                noFlexiVar = all isRight inst_tys
-          _other         -> noV
+          _other         -> traceNoV "lookupInst" (ppr cls <+> ppr tys)
        }
   where
     isRight (Left  _) = False