diff options
| author | Roman Leshchinskiy <rl@cse.unsw.edu.au> | 2007-08-30 01:42:57 +0000 |
|---|---|---|
| committer | Roman Leshchinskiy <rl@cse.unsw.edu.au> | 2007-08-30 01:42:57 +0000 |
| commit | 9f695847ad2ace19c5fd0b937c34015af9735863 (patch) | |
| tree | 224b965b21f2e5644c0e1f28260e7acc642b4e85 /compiler/vectorise/VectUtils.hs | |
| parent | 8e3058a518acedf74306f95f06a7e78cc1145ca6 (diff) | |
| download | haskell-9f695847ad2ace19c5fd0b937c34015af9735863.tar.gz | |
Add code for looking up PA methods of primitive TyCons
Diffstat (limited to 'compiler/vectorise/VectUtils.hs')
| -rw-r--r-- | compiler/vectorise/VectUtils.hs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/compiler/vectorise/VectUtils.hs b/compiler/vectorise/VectUtils.hs index 709a3c018d..3c9d921aa5 100644 --- a/compiler/vectorise/VectUtils.hs +++ b/compiler/vectorise/VectUtils.hs @@ -221,27 +221,45 @@ paDFunApply dfun tys dicts <- mapM paDictOfType tys return $ mkApps (mkTyApps dfun tys) dicts -paMethod :: (Builtins -> Var) -> Type -> VM CoreExpr -paMethod method ty +type PAMethod = (Builtins -> Var, String) + +pa_length = (lengthPAVar, "lengthPA") +pa_replicate = (replicatePAVar, "replicatePA") +pa_empty = (emptyPAVar, "emptyPA") + +paMethod :: PAMethod -> Type -> VM CoreExpr +paMethod (method, name) ty + | Just (tycon, []) <- splitTyConApp_maybe ty + , isPrimTyCon tycon + = do + fn <- traceMaybeV "paMethod" (ppr tycon <+> text name) + $ lookupPrimMethod tycon name + return (Var fn) + +paMethod (method, name) ty = do fn <- builtin method dict <- paDictOfType ty return $ mkApps (Var fn) [Type ty, dict] mkPR :: Type -> VM CoreExpr -mkPR = paMethod mkPRVar +mkPR ty + = do + fn <- builtin mkPRVar + dict <- paDictOfType ty + return $ mkApps (Var fn) [Type ty, dict] lengthPA :: CoreExpr -> VM CoreExpr -lengthPA x = liftM (`App` x) (paMethod lengthPAVar ty) +lengthPA x = liftM (`App` x) (paMethod pa_length ty) where ty = splitPArrayTy (exprType x) replicatePA :: CoreExpr -> CoreExpr -> VM CoreExpr replicatePA len x = liftM (`mkApps` [len,x]) - (paMethod replicatePAVar (exprType x)) + (paMethod pa_replicate (exprType x)) emptyPA :: Type -> VM CoreExpr -emptyPA = paMethod emptyPAVar +emptyPA = paMethod pa_empty liftPA :: CoreExpr -> VM CoreExpr liftPA x |
