Commits

Anonymous committed 5daac82 Merge

Merge remote-tracking branch 'upstream/master'

Comments (0)

Files changed (8)

 e9629c390317a2fa35c823b7d20a46ac5b3f2e50 0_4_1_0
 f7e21a44f034e01c8f0e88641ff97363bb1401fe 0_8_0_2
 ff95e98f68eb0cc681dbc0f6803a2325fb98fb8c 0_0_1
+94ee9e340ca7c09184b2d894a5783d5b65608368 0.10.0.0
+b4ff2b1c45b868666c2e91f22a35fdd9bcf7e5d0 0.10.0.1
     BasicBlock, newBasicBlock, newNamedBasicBlock, defineBasicBlock, createBasicBlock, getCurrentBasicBlock,
     getBasicBlocks,              
     fromLabel, toLabel,
-    getInstructions, getOperands,
+    getInstructions, getOperands, hasUsers, getUsers, getUses, getUser, isChildOf, getDep,
     -- * Misc
     addAttributes, Attribute(..),
     castVarArgs,

LLVM/Core/Instructions.hs

     -- * Conversions
     trunc, zext, sext,
     fptrunc, fpext,
-    fptoui, fptosi,
-    uitofp, sitofp,
+    fptoui, fptosi, fptoint,
+    uitofp, sitofp, inttofp,
     ptrtoint, inttoptr,
     bitcast, bitcastUnify,
     -- * Comparison
       => Value a -> CodeGenFunction r (Value b)
 fpext = convert FFI.buildFPExt
 
+{-# DEPRECATED fptoui "use fptoint since it is type-safe with respect to signs" #-}
 -- | Convert a floating point value to an unsigned integer.
 fptoui :: (IsFloating a, IsInteger b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 fptoui = convert FFI.buildFPToUI
 
+{-# DEPRECATED fptosi "use fptoint since it is type-safe with respect to signs" #-}
 -- | Convert a floating point value to a signed integer.
 fptosi :: (IsFloating a, IsInteger b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 fptosi = convert FFI.buildFPToSI
 
+-- | Convert a floating point value to an integer.
+-- It is mapped to @fptosi@ or @fptoui@ depending on the type @a@.
+fptoint :: forall r n a b. (IsFloating a, IsInteger b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
+fptoint =
+   if isSigned (undefined :: b)
+     then convert FFI.buildFPToSI
+     else convert FFI.buildFPToUI
+
+
+{-# DEPRECATED uitofp "use inttofp since it is type-safe with respect to signs" #-}
 -- | Convert an unsigned integer to a floating point value.
 uitofp :: (IsInteger a, IsFloating b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 uitofp = convert FFI.buildUIToFP
 
+{-# DEPRECATED sitofp "use inttofp since it is type-safe with respect to signs" #-}
 -- | Convert a signed integer to a floating point value.
 sitofp :: (IsInteger a, IsFloating b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 sitofp = convert FFI.buildSIToFP
 
+-- | Convert an integer to a floating point value.
+-- It is mapped to @sitofp@ or @uitofp@ depending on the type @a@.
+inttofp :: forall r n a b. (IsInteger a, IsFloating b, NumberOfElements n a, NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
+inttofp =
+   if isSigned (undefined :: a)
+     then convert FFI.buildSIToFP
+     else convert FFI.buildUIToFP
+
+
 -- | Convert a pointer to an integer.
 ptrtoint :: (IsInteger b, IsPrimitive b) => Value (Ptr a) -> CodeGenFunction r (Value b)
 ptrtoint = convert FFI.buildPtrToInt
     makeCall, makeInvoke,
     makeCallWithCc, makeInvokeWithCc,
     withValue, getInstructions, getOperands,
+    -- * Uses and Users
+    hasUsers, getUsers, getUses, getUser, isChildOf, getDep,
     -- * Misc
     CString, withArrayLen,
     withEmptyCString,
 import Control.Monad(liftM, filterM, when)
 import Foreign.C.String (withCString, withCStringLen, CString, peekCString)
 import Foreign.ForeignPtr (ForeignPtr, newForeignPtr, newForeignPtr_, withForeignPtr)
-import Foreign.Ptr (nullPtr)
+import Foreign.Ptr (Ptr, nullPtr)
 import Foreign.Marshal.Array (withArrayLen, withArray, allocaArray, peekArray)
 import Foreign.Marshal.Alloc (alloca)
 import Foreign.Storable (Storable(..))
 
 getValueNameU :: Value -> IO String
 getValueNameU a = do
+    -- sometimes void values need explicit names too
     cs <- FFI.getValueName a
-    peekCString cs
+    str <- peekCString cs
+    if str == "" then return (show a) else return str
 
+getObjList :: (t1 -> (t2 -> IO [Ptr a]) -> t) -> (t2 -> IO (Ptr a))
+           -> (Ptr a -> IO (Ptr a)) -> t1 -> t
 getObjList withF firstF nextF obj = do
     withF obj $ \ objPtr -> do
       ofst <- firstF objPtr 
 isIntrinsic :: Value -> IO Bool
 isIntrinsic v = do
   if FFI.getIntrinsicID v == 0 then return True else return False
+
+--------------------------------------
+
+type Use = FFI.UseRef
+
+hasUsers :: Value -> IO Bool
+hasUsers v = do
+  nU <- FFI.getNumUses v
+  if nU == 0 then return False else return True
+
+getUses :: Value -> IO [Use]
+getUses = getObjList withValue FFI.getFirstUse FFI.getNextUse
+
+getUsers :: [Use] -> IO [(String, Value)]
+getUsers us = mapM FFI.getUser us >>= annotateValueList
+
+getUser :: Use -> IO Value
+getUser = FFI.getUser
+
+isChildOf :: BasicBlock -> Value -> IO Bool
+isChildOf bb v = do
+  bb2 <- FFI.getInstructionParent v
+  if bb == bb2 then return True else return False
+
+getDep :: Use -> IO (String, String)
+getDep u = do
+  producer <- FFI.getUsedValue u >>= getValueNameU
+  consumer <- FFI.getUser u >>= getValueNameU
+  return (producer, consumer)
     , UseRef
     , getFirstUse
     , getNextUse
+    , getNumUses
     , getUsedValue
     , getUser
+    , isUsedInBasicBlock
 
     ) where
 import Data.Typeable(Typeable)
 foreign import ccall unsafe "LLVMGetUnionElementTypes" getUnionElementTypes
     :: TypeRef -> (Ptr TypeRef) -> IO ()
 -}
+foreign import ccall unsafe "LLVMValueIsUsedInBasicBlock" isUsedInBasicBlock
+    :: BasicBlockRef -> ValueRef -> IO CInt
+foreign import ccall unsafe "LLVMValueGetNumUses" getNumUses
+    :: ValueRef -> IO CUInt
 foreign import ccall unsafe "LLVMGetUsedValue" getUsedValue
     :: UseRef -> IO ValueRef
 foreign import ccall unsafe "LLVMGetUser" getUser
     return n;
 }
 
+unsigned LLVMValueIsUsedInBasicBlock(LLVMValueRef value, LLVMBasicBlockRef bb)
+{
+    llvm::Value *valuep = llvm::unwrap(value);
+    assert(valuep);
+    llvm::BasicBlock *bbp = llvm::unwrap(bb);
+    assert(bbp);
+    return valuep->isUsedInBasicBlock(bbp);
+}
+
 void LLVMDisposeValueRefArray(LLVMValueRef *refs)
 {
     assert(refs);
  * subsequent call to LLVMDisposeValueRefArray(). */
 unsigned LLVMValueGetUses(LLVMValueRef value, LLVMValueRef **refs);
 
+/* Wraps llvm::Value::isUsedInBasicBlock(). */
+unsigned LLVMValueIsUsedInBasicBlock(LLVMValueRef value, LLVMBasicBlockRef bb);
 /* See above. */
 void LLVMDisposeValueRefArray(LLVMValueRef *refs);
 
 name:          llvm
-version:       0.10.0.0
+version:       0.10.0.1
 license:       BSD3
 license-file:  LICENSE
 synopsis:      Bindings to the LLVM compiler toolkit.
     *.md
     Makefile
     configure.ac
+    configure
     examples/*.c
     examples/*.hs
     include/extra.h