on master help sign in
Vector operation support in LLVM codegen
commit8709754e5c315f495e41eb9db1d1414d02c9288e authorBenjamin Saunders <besaunde@sfu.ca> dateTue 2 Jul 2013, 19:16 (13 years ago) parent702141b
1 file changed+39−2
src/IRTS/CodegenLLVM.hs+39−2
src/IRTS/CodegenLLVM.hs+39−2
@@ -36,6 +36,7 @@ import Data.Word
3636import Data.Set (Set)
3737import qualified Data.Set as S
3838import qualified Data.Map as M
39+import qualified Data.Vector.Unboxed as V
3940import Control.Applicative
4041import Control.Monad.RWS
4142import Control.Monad.Writer
@@ -709,6 +710,11 @@ cgConst' (TT.B8 i) = C.Int 8 (fromIntegral i)
709710cgConst' (TT.B16 i) = C.Int 16 (fromIntegral i)
710711cgConst' (TT.B32 i) = C.Int 32 (fromIntegral i)
711712cgConst' (TT.B64 i) = C.Int 64 (fromIntegral i)
713+cgConst' (TT.B8V v) = C.Vector (map ((C.Int 8) . fromIntegral) . V.toList $ v)
714+cgConst' (TT.B16V v) = C.Vector (map ((C.Int 16) . fromIntegral) . V.toList $ v)
715+cgConst' (TT.B32V v) = C.Vector (map ((C.Int 32) . fromIntegral) . V.toList $ v)
716+cgConst' (TT.B64V v) = C.Vector (map ((C.Int 64) . fromIntegral) . V.toList $ v)
717+
712718cgConst' (TT.BI i) = C.Array (IntegerType 8) (map (C.Int 8 . fromIntegral . fromEnum) (show i) ++ [C.Int 8 0])
713719cgConst' (TT.Fl f) = C.Float (F.Double f)
714720cgConst' (TT.Ch c) = C.Int 32 . fromIntegral . fromEnum $ c
@@ -721,6 +727,10 @@ cgConst c@(TT.B8 _) = box (FArith (ATInt (ITFixed IT8))) (ConstantOperand $ cgC
721727cgConst c@(TT.B16 _) = box (FArith (ATInt (ITFixed IT16))) (ConstantOperand $ cgConst' c)
722728cgConst c@(TT.B32 _) = box (FArith (ATInt (ITFixed IT32))) (ConstantOperand $ cgConst' c)
723729cgConst c@(TT.B64 _) = box (FArith (ATInt (ITFixed IT64))) (ConstantOperand $ cgConst' c)
730+cgConst c@(TT.B8V v) = box (FArith (ATInt (ITVec IT8 (V.length v)))) (ConstantOperand $ cgConst' c)
731+cgConst c@(TT.B16V v) = box (FArith (ATInt (ITVec IT16 (V.length v)))) (ConstantOperand $ cgConst' c)
732+cgConst c@(TT.B32V v) = box (FArith (ATInt (ITVec IT32 (V.length v)))) (ConstantOperand $ cgConst' c)
733+cgConst c@(TT.B64V v) = box (FArith (ATInt (ITVec IT64 (V.length v)))) (ConstantOperand $ cgConst' c)
724734cgConst c@(TT.Fl _) = box (FArith ATFloat) (ConstantOperand $ cgConst' c)
725735cgConst c@(TT.Ch _) = box FChar (ConstantOperand $ cgConst' c)
726736cgConst c@(TT.Str s) = do
@@ -782,6 +792,8 @@ ftyToTy :: FType -> Type
782792ftyToTy (FArith (ATInt ITNative)) = IntegerType 32
783793ftyToTy (FArith (ATInt ITBig)) = PointerType mpzTy (AddrSpace 0)
784794ftyToTy (FArith (ATInt (ITFixed ty))) = IntegerType (fromIntegral $ nativeTyWidth ty)
795+ftyToTy (FArith (ATInt (ITVec e c)))
796+ = VectorType (fromIntegral c) (IntegerType (fromIntegral $ nativeTyWidth e))
785797ftyToTy FChar = IntegerType 32
786798ftyToTy FString = PointerType (IntegerType 8) (AddrSpace 0)
787799ftyToTy FUnit = VoidType
@@ -863,6 +875,27 @@ cgOp (LASHR ity) [x,y] = ibin ity x y (AShr False)
863875
864876cgOp LNoOp xs = return $ last xs
865877
878+cgOp (LMkVec ety c) xs | c == length xs = do
879+ nxs <- mapM (unbox (FArith (ATInt (ITFixed ety)))) xs
880+ vec <- foldM (\v (e, i) -> inst $ InsertElement v e (ConstantOperand (C.Int 32 i)) [])
881+ (ConstantOperand $ C.Vector (replicate c (C.Undef (IntegerType . fromIntegral $ nativeTyWidth ety))))
882+ (zip nxs [0..])
883+ box (FArith (ATInt (ITVec ety c))) vec
884+
885+cgOp (LIdxVec ety c) [v,i] = do
886+ nv <- unbox (FArith (ATInt (ITVec ety c))) v
887+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
888+ elt <- inst $ ExtractElement nv ni []
889+ box (FArith (ATInt (ITFixed ety))) elt
890+
891+cgOp (LUpdateVec ety c) [v,i,e] = do
892+ let fty = FArith (ATInt (ITVec ety c))
893+ nv <- unbox fty v
894+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
895+ ne <- unbox (FArith (ATInt (ITFixed ety))) e
896+ nv' <- inst $ InsertElement nv ne ni []
897+ box fty nv'
898+
866899cgOp LStrEq [x,y] = do
867900 x' <- unbox FString x
868901 y' <- unbox FString y
@@ -1015,8 +1048,12 @@ iCmp ity pred x y = do
10151048 nx <- unbox (FArith (ATInt ity)) x
10161049 ny <- unbox (FArith (ATInt ity)) y
10171050 nr <- inst $ ICmp pred nx ny []
1018− nr' <- inst $ ZExt nr (IntegerType 32) []
1019− box (FArith (ATInt (ITFixed IT32))) nr'
1051+ nr' <- inst $ SExt nr (ftyToTy $ cmpResultTy ity) []
1052+ box (cmpResultTy ity) nr'
1053+
1054+cmpResultTy :: IntTy -> FType
1055+cmpResultTy v@(ITVec _ _) = FArith (ATInt v)
1056+cmpResultTy _ = FArith (ATInt (ITFixed IT32))
10201057
10211058mpzBin :: String -> Operand -> Operand -> Codegen Operand
10221059mpzBin name x y = do