on master help sign in
Merge branch 'master' of https://github.com/edwinb/Idris-dev into JavaRepairs
f77551cJan Bessai
idris.cabal+1−1
@@ -273,7 +273,7 @@ Executable idris
273 haskeline>=0.7, split, directory,
273 haskeline>=0.7, split, directory,
274 containers, process, transformers, filepath,
274 containers, process, transformers, filepath,
275 directory, binary, bytestring, text, pretty,
275 directory, binary, bytestring, text, pretty,
276− language-java>=0.2.2, libffi, llvm-general==3.3.3.*,
276+ language-java>=0.2.2, libffi, llvm-general>=3.3.4.1 && <3.3.5,
277 vector, vector-binary-instances
277 vector, vector-binary-instances
278
278
279 Extensions: MultiParamTypeClasses, FunctionalDependencies,
279 Extensions: MultiParamTypeClasses, FunctionalDependencies,
src/IRTS/CodegenLLVM.hs+23−13
@@ -161,6 +161,7 @@ initDefs tgt =
161 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i32" VoidType [ptrI8, ptrI8, IntegerType 32, IntegerType 32, IntegerType 1] False
161 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i32" VoidType [ptrI8, ptrI8, IntegerType 32, IntegerType 32, IntegerType 1] False
162 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i64" VoidType [ptrI8, ptrI8, IntegerType 64, IntegerType 32, IntegerType 1] False
162 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i64" VoidType [ptrI8, ptrI8, IntegerType 64, IntegerType 32, IntegerType 1] False
163 , exfun "memcpy" ptrI8 [ptrI8, ptrI8, intPtr] False
163 , exfun "memcpy" ptrI8 [ptrI8, ptrI8, intPtr] False
164+ , exfun "llvm.invariant.start" (PointerType (StructureType False []) (AddrSpace 0)) [IntegerType 64, ptrI8] False
164 , exfun "snprintf" (IntegerType 32) [ptrI8, intPtr, ptrI8] True
165 , exfun "snprintf" (IntegerType 32) [ptrI8, intPtr, ptrI8] True
165 , exfun "strcmp" (IntegerType 32) [ptrI8, ptrI8] False
166 , exfun "strcmp" (IntegerType 32) [ptrI8, ptrI8] False
166 , exfun "strlen" intPtr [ptrI8] False
167 , exfun "strlen" intPtr [ptrI8] False
@@ -395,6 +396,9 @@ sizeOf ty = ConstantOperand . C.PtrToInt
395 (C.GetElementPtr True (C.Null (PointerType ty (AddrSpace 0))) [C.Int 32 1])
396 (C.GetElementPtr True (C.Null (PointerType ty (AddrSpace 0))) [C.Int 32 1])
396 . IntegerType <$> getWordSize
397 . IntegerType <$> getWordSize
397
398
399+loadInv :: Operand -> Instruction
400+loadInv ptr = Load False ptr Nothing 0 [("invariant.load", MetadataNode [])]
401+
398tgtWordSize :: Target -> Word32
402tgtWordSize :: Target -> Word32
399tgtWordSize (Target { dataLayout = DataLayout { pointerLayouts = l } }) =
403tgtWordSize (Target { dataLayout = DataLayout { pointerLayouts = l } }) =
400 fst . fromJust $ M.lookup (AddrSpace 0) l
404 fst . fromJust $ M.lookup (AddrSpace 0) l
@@ -423,7 +427,8 @@ cgExpr (SCon tag name args) = do
423 case sequence argSlots of
427 case sequence argSlots of
424 Nothing -> return Nothing
428 Nothing -> return Nothing
425 Just argVals -> do
429 Just argVals -> do
426− con <- alloc . conType . fromIntegral . length $ argVals
430+ let ty = conType . fromIntegral . length $ argVals
431+ con <- alloc ty
427 tagPtr <- inst $ GetElementPtr True con [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
432 tagPtr <- inst $ GetElementPtr True con [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
428 inst' $ Store False tagPtr (ConstantOperand (C.Int 32 (fromIntegral tag))) Nothing 0 []
433 inst' $ Store False tagPtr (ConstantOperand (C.Int 32 (fromIntegral tag))) Nothing 0 []
429 forM_ (zip argVals [0..]) $ \(arg, i) -> do
434 forM_ (zip argVals [0..]) $ \(arg, i) -> do
@@ -431,6 +436,8 @@ cgExpr (SCon tag name args) = do
431 , ConstantOperand (C.Int 32 1)
436 , ConstantOperand (C.Int 32 1)
432 , ConstantOperand (C.Int 32 i)] []
437 , ConstantOperand (C.Int 32 i)] []
433 inst' $ Store False ptr arg Nothing 0 []
438 inst' $ Store False ptr arg Nothing 0 []
439+ ptrI8 <- inst $ BitCast con (PointerType (IntegerType 8) (AddrSpace 0)) []
440+ inst' $ simpleCall "llvm.invariant.start" [ConstantOperand $ C.Int 64 (-1), ptrI8]
434 Just <$> inst (BitCast con (PointerType valueType (AddrSpace 0)) [])
441 Just <$> inst (BitCast con (PointerType valueType (AddrSpace 0)) [])
435cgExpr (SCase inspect alts) = do
442cgExpr (SCase inspect alts) = do
436 val <- var inspect
443 val <- var inspect
@@ -449,7 +456,7 @@ cgExpr (SChkCase inspect alts) = do
449 terminate $ CondBr isNull endBBN notNullBBN []
456 terminate $ CondBr isNull endBBN notNullBBN []
450 newBlock notNullBBN
457 newBlock notNullBBN
451 ptr <- inst $ BitCast val (PointerType (IntegerType 32) (AddrSpace 0)) []
458 ptr <- inst $ BitCast val (PointerType (IntegerType 32) (AddrSpace 0)) []
452− flag <- inst $ Load False ptr Nothing 0 []
459+ flag <- inst $ loadInv ptr
453 isVal <- inst $ ICmp IPred.EQ flag (ConstantOperand (C.Int 32 (-1))) []
460 isVal <- inst $ ICmp IPred.EQ flag (ConstantOperand (C.Int 32 (-1))) []
454 conBBN <- getName "constructor"
461 conBBN <- getName "constructor"
455 terminate $ CondBr isVal endBBN conBBN []
462 terminate $ CondBr isVal endBBN conBBN []
@@ -476,7 +483,7 @@ cgExpr (SProj conVar idx) = do
476 , ConstantOperand (C.Int 32 1)
483 , ConstantOperand (C.Int 32 1)
477 , ConstantOperand (C.Int 32 (fromIntegral idx))
484 , ConstantOperand (C.Int 32 (fromIntegral idx))
478 ] []
485 ] []
479− Just <$> inst (Load False ptr Nothing 0 [])
486+ Just <$> inst (loadInv ptr)
480cgExpr (SConst c) = Just <$> cgConst c
487cgExpr (SConst c) = Just <$> cgConst c
481cgExpr (SForeign LANG_C rty fname args) = do
488cgExpr (SForeign LANG_C rty fname args) = do
482 func <- ensureCDecl fname rty (map fst args)
489 func <- ensureCDecl fname rty (map fst args)
@@ -555,7 +562,7 @@ cgPrimCase caseValPtr defExp alts = do
555 SConstCase (TT.Ch _) _ -> IntegerType 32
562 SConstCase (TT.Ch _) _ -> IntegerType 32
556 realPtr <- inst $ BitCast caseValPtr (PointerType (primTy caseTy) (AddrSpace 0)) []
563 realPtr <- inst $ BitCast caseValPtr (PointerType (primTy caseTy) (AddrSpace 0)) []
557 valPtr <- inst $ GetElementPtr True realPtr [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
564 valPtr <- inst $ GetElementPtr True realPtr [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
558− caseVal <- inst $ Load False valPtr Nothing 0 []
565+ caseVal <- inst $ loadInv valPtr
559 defBlockName <- getName "default"
566 defBlockName <- getName "default"
560 exitBlockName <- getName "caseExit"
567 exitBlockName <- getName "caseExit"
561 namedAlts <- mapM (\a -> do n <- nameAlt defBlockName a; return (n, a)) alts
568 namedAlts <- mapM (\a -> do n <- nameAlt defBlockName a; return (n, a)) alts
@@ -568,7 +575,7 @@ cgPrimCase caseValPtr defExp alts = do
568cgConCase :: Operand -> Maybe SExp -> [SAlt] -> Codegen (Maybe Operand)
575cgConCase :: Operand -> Maybe SExp -> [SAlt] -> Codegen (Maybe Operand)
569cgConCase con defExp alts = do
576cgConCase con defExp alts = do
570 tagPtr <- inst $ GetElementPtr True con [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
577 tagPtr <- inst $ GetElementPtr True con [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
571− tag <- inst $ Load False tagPtr Nothing 0 []
578+ tag <- inst $ loadInv tagPtr
572 defBlockName <- getName "default"
579 defBlockName <- getName "default"
573 exitBlockName <- getName "caseExit"
580 exitBlockName <- getName "caseExit"
574 namedAlts <- mapM (\a -> do n <- nameAlt defBlockName a; return (n, a)) alts
581 namedAlts <- mapM (\a -> do n <- nameAlt defBlockName a; return (n, a)) alts
@@ -654,7 +661,7 @@ cgAlt initEnv exitBlockName name destr exp = do
654 do ptr <- inst $ GetElementPtr True con [ ConstantOperand (C.Int 32 0)
661 do ptr <- inst $ GetElementPtr True con [ ConstantOperand (C.Int 32 0)
655 , ConstantOperand (C.Int 32 1)
662 , ConstantOperand (C.Int 32 1)
656 , ConstantOperand (C.Int 32 i)] []
663 , ConstantOperand (C.Int 32 i)] []
657− Just <$> ninst argName (Load False ptr Nothing 0 [])
664+ Just <$> ninst argName (loadInv ptr)
658 altVal <- binds locals $ cgExpr exp
665 altVal <- binds locals $ cgExpr exp
659 altEnv <- gets lexenv
666 altEnv <- gets lexenv
660 altBlock <- gets currentBlockName
667 altBlock <- gets currentBlockName
@@ -690,11 +697,14 @@ nameAlt _ (SConstCase const _) = getName (show const)
690box :: FType -> Operand -> Codegen Operand
697box :: FType -> Operand -> Codegen Operand
691box FUnit _ = return $ ConstantOperand nullValue
698box FUnit _ = return $ ConstantOperand nullValue
692box fty fval = do
699box fty fval = do
700+ let ty = primTy (ftyToTy fty)
693− val <- alloc (primTy (ftyToTy fty))
701+ val <- alloc ty
694 tagptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
702 tagptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
695 valptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
703 valptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
696 inst' $ Store False tagptr (ConstantOperand (C.Int 32 (-1))) Nothing 0 []
704 inst' $ Store False tagptr (ConstantOperand (C.Int 32 (-1))) Nothing 0 []
697 inst' $ Store False valptr fval Nothing 0 []
705 inst' $ Store False valptr fval Nothing 0 []
706+ ptrI8 <- inst $ BitCast val (PointerType (IntegerType 8) (AddrSpace 0)) []
707+ inst' $ simpleCall "llvm.invariant.start" [ConstantOperand $ C.Int 64 (-1), ptrI8]
698 inst $ BitCast val (PointerType valueType (AddrSpace 0)) []
708 inst $ BitCast val (PointerType valueType (AddrSpace 0)) []
699
709
700unbox :: FType -> Operand -> Codegen Operand
710unbox :: FType -> Operand -> Codegen Operand
@@ -702,7 +712,7 @@ unbox FUnit x = return x
702unbox fty bval = do
712unbox fty bval = do
703 val <- inst $ BitCast bval (PointerType (primTy (ftyToTy fty)) (AddrSpace 0)) []
713 val <- inst $ BitCast bval (PointerType (primTy (ftyToTy fty)) (AddrSpace 0)) []
704 fvalptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
714 fvalptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
705− inst $ Load False fvalptr Nothing 0 []
715+ inst $ loadInv fvalptr
706
716
707cgConst' :: TT.Const -> C.Constant
717cgConst' :: TT.Const -> C.Constant
708cgConst' (TT.I i) = C.Int 32 (fromIntegral i)
718cgConst' (TT.I i) = C.Int 32 (fromIntegral i)
@@ -955,7 +965,7 @@ cgOp LStrCons [c,s] = do
955
965
956cgOp LStrHead [c] = do
966cgOp LStrHead [c] = do
957 s <- unbox FString c
967 s <- unbox FString c
958− c <- inst $ Load False s Nothing 0 []
968+ c <- inst $ loadInv s
959 c' <- inst $ ZExt c (IntegerType 32) []
969 c' <- inst $ ZExt c (IntegerType 32) []
960 box (FArith (ATInt ITChar)) c'
970 box (FArith (ATInt ITChar)) c'
961
971
@@ -963,7 +973,7 @@ cgOp LStrIndex [s, i] = do
963 ns <- unbox FString s
973 ns <- unbox FString s
964 ni <- unbox (FArith (ATInt (ITFixed IT32))) i
974 ni <- unbox (FArith (ATInt (ITFixed IT32))) i
965 p <- inst $ GetElementPtr True ns [ni] []
975 p <- inst $ GetElementPtr True ns [ni] []
966− c <- inst $ Load False p Nothing 0 []
976+ c <- inst $ loadInv p
967 c' <- inst $ ZExt c (IntegerType 32) []
977 c' <- inst $ ZExt c (IntegerType 32) []
968 box (FArith (ATInt ITChar)) c'
978 box (FArith (ATInt ITChar)) c'
969
979
@@ -989,15 +999,15 @@ cgOp LReadStr [p] = do
989
999
990cgOp LStdIn [] = do
1000cgOp LStdIn [] = do
991 stdin <- getStdIn
1001 stdin <- getStdIn
992− ptr <- inst $ Load False stdin Nothing 0 []
1002+ ptr <- inst $ loadInv stdin
993 box FPtr ptr
1003 box FPtr ptr
994cgOp LStdOut [] = do
1004cgOp LStdOut [] = do
995 stdout <- getStdOut
1005 stdout <- getStdOut
996− ptr <- inst $ Load False stdout Nothing 0 []
1006+ ptr <- inst $ loadInv stdout
997 box FPtr ptr
1007 box FPtr ptr
998cgOp LStdErr [] = do
1008cgOp LStdErr [] = do
999 stdErr <- getStdErr
1009 stdErr <- getStdErr
1000− ptr <- inst $ Load False stdErr Nothing 0 []
1010+ ptr <- inst $ loadInv stdErr
1001 box FPtr ptr
1011 box FPtr ptr
1002
1012
1003cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("
1013cgOp prim args = ierror $ "Unimplemented primitive: [" ++ show prim ++ "]("