on master help sign in
Vector operation support in LLVM codegen
commit5067d7e70ca8da73a4d25eee3b103d09235da9b6 authorBenjamin Saunders <besaunde@sfu.ca> dateTue 2 Jul 2013, 19:16 (13 years ago) parent115ad2f
1 file changed+39−2
src/IRTS/CodegenLLVM.hs+39−2
src/IRTS/CodegenLLVM.hs+39−2
@@ -29,6 +29,7 @@ import Data.Maybe
2929import Data.Word
3030import Data.Set (Set)
3131import qualified Data.Set as S
32+import qualified Data.Vector.Unboxed as V
3233import Control.Applicative
3334import Control.Monad.RWS
3435import Control.Monad.Writer
@@ -679,6 +680,11 @@ cgConst' (TT.B8 i) = C.Int 8 (fromIntegral i)
679680cgConst' (TT.B16 i) = C.Int 16 (fromIntegral i)
680681cgConst' (TT.B32 i) = C.Int 32 (fromIntegral i)
681682cgConst' (TT.B64 i) = C.Int 64 (fromIntegral i)
683+cgConst' (TT.B8V v) = C.Vector (map ((C.Int 8) . fromIntegral) . V.toList $ v)
684+cgConst' (TT.B16V v) = C.Vector (map ((C.Int 16) . fromIntegral) . V.toList $ v)
685+cgConst' (TT.B32V v) = C.Vector (map ((C.Int 32) . fromIntegral) . V.toList $ v)
686+cgConst' (TT.B64V v) = C.Vector (map ((C.Int 64) . fromIntegral) . V.toList $ v)
687+
682688cgConst' (TT.BI i) = C.Array (IntegerType 8) (map (C.Int 8 . fromIntegral . fromEnum) (show i) ++ [C.Int 8 0])
683689cgConst' (TT.Fl f) = C.Float (F.Double f)
684690cgConst' (TT.Ch c) = C.Int 32 . fromIntegral . fromEnum $ c
@@ -691,6 +697,10 @@ cgConst c@(TT.B8 _) = box (FArith (ATInt (ITFixed IT8))) (ConstantOperand $ cgC
691697cgConst c@(TT.B16 _) = box (FArith (ATInt (ITFixed IT16))) (ConstantOperand $ cgConst' c)
692698cgConst c@(TT.B32 _) = box (FArith (ATInt (ITFixed IT32))) (ConstantOperand $ cgConst' c)
693699cgConst c@(TT.B64 _) = box (FArith (ATInt (ITFixed IT64))) (ConstantOperand $ cgConst' c)
700+cgConst c@(TT.B8V v) = box (FArith (ATInt (ITVec IT8 (V.length v)))) (ConstantOperand $ cgConst' c)
701+cgConst c@(TT.B16V v) = box (FArith (ATInt (ITVec IT16 (V.length v)))) (ConstantOperand $ cgConst' c)
702+cgConst c@(TT.B32V v) = box (FArith (ATInt (ITVec IT32 (V.length v)))) (ConstantOperand $ cgConst' c)
703+cgConst c@(TT.B64V v) = box (FArith (ATInt (ITVec IT64 (V.length v)))) (ConstantOperand $ cgConst' c)
694704cgConst c@(TT.Fl _) = box (FArith ATFloat) (ConstantOperand $ cgConst' c)
695705cgConst c@(TT.Ch _) = box FChar (ConstantOperand $ cgConst' c)
696706cgConst c@(TT.Str s) = do
@@ -752,6 +762,8 @@ ftyToTy :: FType -> Type
752762ftyToTy (FArith (ATInt ITNative)) = IntegerType 32
753763ftyToTy (FArith (ATInt ITBig)) = PointerType mpzTy (AddrSpace 0)
754764ftyToTy (FArith (ATInt (ITFixed ty))) = IntegerType (fromIntegral $ nativeTyWidth ty)
765+ftyToTy (FArith (ATInt (ITVec e c)))
766+ = VectorType (fromIntegral c) (IntegerType (fromIntegral $ nativeTyWidth e))
755767ftyToTy FChar = IntegerType 32
756768ftyToTy FString = PointerType (IntegerType 8) (AddrSpace 0)
757769ftyToTy FUnit = VoidType
@@ -831,6 +843,27 @@ cgOp (LSHL ity) [x,y] = ibin ity x y (Shl False False)
831843cgOp (LLSHR ity) [x,y] = ibin ity x y (LShr False)
832844cgOp (LASHR ity) [x,y] = ibin ity x y (AShr False)
833845
846+cgOp (LMkVec ety c) xs | c == length xs = do
847+ nxs <- mapM (unbox (FArith (ATInt (ITFixed ety)))) xs
848+ vec <- foldM (\v (e, i) -> inst $ InsertElement v e (ConstantOperand (C.Int 32 i)) [])
849+ (ConstantOperand $ C.Vector (replicate c (C.Undef (IntegerType . fromIntegral $ nativeTyWidth ety))))
850+ (zip nxs [0..])
851+ box (FArith (ATInt (ITVec ety c))) vec
852+
853+cgOp (LIdxVec ety c) [v,i] = do
854+ nv <- unbox (FArith (ATInt (ITVec ety c))) v
855+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
856+ elt <- inst $ ExtractElement nv ni []
857+ box (FArith (ATInt (ITFixed ety))) elt
858+
859+cgOp (LUpdateVec ety c) [v,i,e] = do
860+ let fty = FArith (ATInt (ITVec ety c))
861+ nv <- unbox fty v
862+ ni <- unbox (FArith (ATInt (ITFixed IT32))) i
863+ ne <- unbox (FArith (ATInt (ITFixed ety))) e
864+ nv' <- inst $ InsertElement nv ne ni []
865+ box fty nv'
866+
834867cgOp LStrEq [x,y] = do
835868 x' <- unbox FString x
836869 y' <- unbox FString y
@@ -981,8 +1014,12 @@ iCmp ity pred x y = do
9811014 nx <- unbox (FArith (ATInt ity)) x
9821015 ny <- unbox (FArith (ATInt ity)) y
9831016 nr <- inst $ ICmp pred nx ny []
984− nr' <- inst $ ZExt nr (IntegerType 32) []
985− box (FArith (ATInt (ITFixed IT32))) nr'
1017+ nr' <- inst $ SExt nr (ftyToTy $ cmpResultTy ity) []
1018+ box (cmpResultTy ity) nr'
1019+
1020+cmpResultTy :: IntTy -> FType
1021+cmpResultTy v@(ITVec _ _) = FArith (ATInt v)
1022+cmpResultTy _ = FArith (ATInt (ITFixed IT32))
9861023
9871024mpzBin :: String -> Operand -> Operand -> Codegen Operand
9881025mpzBin name x y = do