on master help sign in
Communicate invariance of freshly initialized memory to LLVM
commitc8107960f3a3429ea02fc4dd16484dfc7df4c27a authorBenjamin Saunders <besaunde@sfu.ca> dateSun 7 Jul 2013, 17:31 (13 years ago) parent006c8f2
1 file changed+9−2
src/IRTS/CodegenLLVM.hs+9−2
src/IRTS/CodegenLLVM.hs+9−2
@@ -161,6 +161,7 @@ initDefs tgt =
161161 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i32" VoidType [ptrI8, ptrI8, IntegerType 32, IntegerType 32, IntegerType 1] False
162162 -- , exfun "llvm.llvm.memcpy.p0i8.p0i8.i64" VoidType [ptrI8, ptrI8, IntegerType 64, IntegerType 32, IntegerType 1] False
163163 , exfun "memcpy" ptrI8 [ptrI8, ptrI8, intPtr] False
164+ , exfun "llvm.invariant.start" (PointerType (StructureType False []) (AddrSpace 0)) [IntegerType 64, ptrI8] False
164165 , exfun "snprintf" (IntegerType 32) [ptrI8, intPtr, ptrI8] True
165166 , exfun "strcmp" (IntegerType 32) [ptrI8, ptrI8] False
166167 , exfun "strlen" intPtr [ptrI8] False
@@ -423,7 +424,8 @@ cgExpr (SCon tag name args) = do
423424 case sequence argSlots of
424425 Nothing -> return Nothing
425426 Just argVals -> do
426− con <- alloc . conType . fromIntegral . length $ argVals
427+ let ty = conType . fromIntegral . length $ argVals
428+ con <- alloc ty
427429 tagPtr <- inst $ GetElementPtr True con [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
428430 inst' $ Store False tagPtr (ConstantOperand (C.Int 32 (fromIntegral tag))) Nothing 0 []
429431 forM_ (zip argVals [0..]) $ \(arg, i) -> do
@@ -431,6 +433,8 @@ cgExpr (SCon tag name args) = do
431433 , ConstantOperand (C.Int 32 1)
432434 , ConstantOperand (C.Int 32 i)] []
433435 inst' $ Store False ptr arg Nothing 0 []
436+ ptrI8 <- inst $ BitCast con (PointerType (IntegerType 8) (AddrSpace 0)) []
437+ inst' $ simpleCall "llvm.invariant.start" [ConstantOperand $ C.Int 64 (-1), ptrI8]
434438 Just <$> inst (BitCast con (PointerType valueType (AddrSpace 0)) [])
435439cgExpr (SCase inspect alts) = do
436440 val <- var inspect
@@ -690,11 +694,14 @@ nameAlt _ (SConstCase const _) = getName (show const)
690694box :: FType -> Operand -> Codegen Operand
691695box FUnit _ = return $ ConstantOperand nullValue
692696box fty fval = do
693− val <- alloc (primTy (ftyToTy fty))
697+ let ty = primTy (ftyToTy fty)
698+ val <- alloc ty
694699 tagptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 0)] []
695700 valptr <- inst $ GetElementPtr True val [ConstantOperand (C.Int 32 0), ConstantOperand (C.Int 32 1)] []
696701 inst' $ Store False tagptr (ConstantOperand (C.Int 32 (-1))) Nothing 0 []
697702 inst' $ Store False valptr fval Nothing 0 []
703+ ptrI8 <- inst $ BitCast val (PointerType (IntegerType 8) (AddrSpace 0)) []
704+ inst' $ simpleCall "llvm.invariant.start" [ConstantOperand $ C.Int 64 (-1), ptrI8]
698705 inst $ BitCast val (PointerType valueType (AddrSpace 0)) []
699706
700707unbox :: FType -> Operand -> Codegen Operand