Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding LLVM3.0 specific functions (conditionally compiling removed ones) #29

Merged
merged 8 commits into from

5 participants

@scottgw

The old version seemed to not work at all with LLVM3.0, it compiled but because functions were removed from the LLVM library at runtime some symbols were not found (such as LLVMBuildUnwind). It will likely be very messy to continue to try to support both pre-3.0 and 3.0 in the same codebase.

For llvm-base: this patch conditionally compiles the removed functions as well as the new ones introduced in LLVM 3.0.

For llvm: comments out the removed functions from llvm-base. I don't know how to conditionally compile them based on whether llvm-base was compiled with 3.0 or < 3.0.

I suggest that llvm-base in the future track directly the LLVM version, without backwards compatibility. Let the interface changes be represented in the llvm-base version numbering, and let the dependent packages (llvm, maybe others) select accordingly. I think this is likely the best policy as otherwise

  1. there is a tangle of conditional compilation, and
  2. the llvm-base version number is a lie anyway: eg, unwind is both available and unavailable within the same version: ruh-oh.
scottgw added some commits
@scottgw scottgw Adding initial shared library support. 5a73333
@scottgw scottgw Merge remote-tracking branch 'upstream/master' ef9f0f8
@scottgw scottgw Adding struct as a FunctionArg instance
Export StructFields from Core/Types so it can be used in CodeGen.
88887ae
@scottgw scottgw Remove DatatypeContexts, as advised by a warning. eb03ce3
@scottgw scottgw LowerSetJmp was removed as a pass from LLVM 3.0 769aa4e
@scottgw scottgw Initial pass at updating to LLVM 3.0.
Had to remove quite a few functions, not sure how severe it is yet.
The type functions have changed, the new type functions have not yet
been added.
c44a75a
@scottgw scottgw Merge git://github.com/bos/llvm
Conflicts:
	base/cbits/extra.cpp
	base/configure.ac
	cbits/support.cpp
23b0171
@scottgw scottgw Adding LLVM3.0 functions to Core.hsc.
This adds the new exception and new type creation functions.
It also conditionally comments out the old removed functions.
84160d8
@ohjames

Installed this with cabal and my code works again against llvm 3.0.

@leoncamel

+1 llvm-3.0 works again on my Macbook. Cool

@jhance

It would be very nice to get this into hackage...

@bos bos merged commit 84160d8 into bos:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 21, 2011
  1. @scottgw
Commits on Oct 1, 2011
  1. @scottgw
  2. @scottgw

    Adding struct as a FunctionArg instance

    scottgw authored
    Export StructFields from Core/Types so it can be used in CodeGen.
  3. @scottgw
Commits on Oct 2, 2011
  1. @scottgw
  2. @scottgw

    Initial pass at updating to LLVM 3.0.

    scottgw authored
    Had to remove quite a few functions, not sure how severe it is yet.
    The type functions have changed, the new type functions have not yet
    been added.
Commits on Feb 4, 2012
  1. @scottgw

    Merge git://github.com/bos/llvm

    scottgw authored
    Conflicts:
    	base/cbits/extra.cpp
    	base/configure.ac
    	cbits/support.cpp
  2. @scottgw

    Adding LLVM3.0 functions to Core.hsc.

    scottgw authored
    This adds the new exception and new type creation functions.
    It also conditionally comments out the old removed functions.
This page is out of date. Refresh to see the latest.
View
2  LLVM/Core/CodeGen.hs
@@ -281,6 +281,8 @@ instance FunctionArgs (IO Word64) (FA Word64) Word64 where
instance FunctionArgs (IO ()) (FA ()) () where apArgs _ _ g = g
instance (Pos n, IsPrimitive a) =>
FunctionArgs (IO (Vector n a)) (FA (Vector n a)) (Vector n a) where apArgs _ _ g = g
+instance StructFields as =>
+ FunctionArgs (IO (Struct as)) (FA (Struct as)) (Struct as) where apArgs _ _ g = g
instance (IsType a) =>
FunctionArgs (IO (Ptr a)) (FA (Ptr a)) (Ptr a) where apArgs _ _ g = g
instance FunctionArgs (IO (StablePtr a)) (FA (StablePtr a)) (StablePtr a) where apArgs _ _ g = g
View
12 LLVM/Core/Instructions.hs
@@ -8,7 +8,8 @@ module LLVM.Core.Instructions(
br,
switch,
invoke, invokeWithConv,
- unwind,
+ -- Removed in LLVM_3.0
+ -- unwind,
unreachable,
-- * Arithmetic binary operations
-- | Arithmetic operations with the normal semantics.
@@ -276,12 +277,13 @@ switch (Value val) (BasicBlock dflt) arms = do
--------------------------------------
+-- Removed in LLVM_3.0
-- |Unwind the call stack until a function call performed with 'invoke' is reached.
-- I.e., throw a non-local exception.
-unwind :: CodeGenFunction r Terminate
-unwind = do
- withCurrentBuilder_ FFI.buildUnwind
- return terminate
+-- unwind :: CodeGenFunction r Terminate
+-- unwind = do
+-- withCurrentBuilder_ FFI.buildUnwind
+-- return terminate
-- |Inform the code generator that this code can never be reached.
unreachable :: CodeGenFunction r Terminate
View
2  LLVM/Core/Type.hs
@@ -10,6 +10,8 @@
module LLVM.Core.Type(
-- * Type classifier
IsType(..),
+ -- * StructFields classifier
+ StructFields,
-- ** Special type classifiers
Nat,
Pos,
View
79 base/LLVM/FFI/Core.hsc
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls, DeriveDataTypeable #-}
+{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls, DeriveDataTypeable, CPP #-}
-- |
-- Module: LLVM.FFI.Core
@@ -35,9 +35,10 @@ module LLVM.FFI.Core
-- * Types
, Type
, TypeRef
+#if HS_LLVM_VERSION < 300
, addTypeName
, deleteTypeName
-
+#endif
, getTypeKind
, TypeKind(..)
@@ -67,7 +68,9 @@ module LLVM.FFI.Core
-- ** Other types
, voidType
, labelType
+#if HS_LLVM_VERSION < 300
, opaqueType
+#endif
-- ** Array, pointer, and vector types
, arrayType
@@ -83,13 +86,20 @@ module LLVM.FFI.Core
, countStructElementTypes
, getStructElementTypes
, isPackedStruct
+#if HS_LLVM_VERSION >= 300
+ , structCreateNamed
+ , getStructName
+ , structSetBody
+#endif
-- * Type handles
+#if HS_LLVM_VERSION < 300
, TypeHandleRef
, createTypeHandle
, refineType
, resolveTypeHandle
, disposeTypeHandle
+#endif
-- * Values
, Value
@@ -288,9 +298,18 @@ module LLVM.FFI.Core
, buildCondBr
, buildSwitch
, buildInvoke
+#if HS_LLVM_VERSION < 300
, buildUnwind
+#endif
, buildUnreachable
+#if HS_LLVM_VERSION >= 300
+ -- ** Landing pad
+ , buildLandingPad
+ , addClause
+ , setCleanup
+#endif
+
-- ** Arithmetic
, buildAdd
, buildSub
@@ -460,7 +479,9 @@ module LLVM.FFI.Core
, int8TypeInContext
, intTypeInContext
, labelTypeInContext
+#if HS_LLVM_VERSION < 300
, opaqueTypeInContext
+#endif
, pPCFP128TypeInContext
, structTypeInContext
, voidTypeInContext
@@ -638,11 +659,13 @@ foreign import ccall unsafe "LLVMVectorType" vectorType
-> CUInt -- ^ element count
-> TypeRef
+#if HS_LLVM_VERSION < 300
foreign import ccall unsafe "LLVMAddTypeName" addTypeName
:: ModuleRef -> CString -> TypeRef -> IO CInt
foreign import ccall unsafe "LLVMDeleteTypeName" deleteTypeName
:: ModuleRef -> CString -> IO ()
+#endif
-- | Get the type of a sequential type's elements.
foreign import ccall unsafe "LLVMGetElementType" getElementType
@@ -1084,11 +1107,24 @@ foreign import ccall unsafe "LLVMBuildSwitch" buildSwitch
foreign import ccall unsafe "LLVMBuildInvoke" buildInvoke
:: BuilderRef -> ValueRef -> Ptr ValueRef -> CUInt
-> BasicBlockRef -> BasicBlockRef -> CString -> IO ValueRef
+#if HS_LLVM_VERSION < 300
foreign import ccall unsafe "LLVMBuildUnwind" buildUnwind
:: BuilderRef -> IO ValueRef
+#endif
+
foreign import ccall unsafe "LLVMBuildUnreachable" buildUnreachable
:: BuilderRef -> IO ValueRef
+#if HS_LLVM_VERSION >= 300
+-- New landing pad instructions for LLVM 3.0
+foreign import ccall unsafe "LLVMBuildLandingPad" buildLandingPad
+ :: BuilderRef -> TypeRef -> ValueRef -> CUInt -> CString -> IO ValueRef
+foreign import ccall unsafe "LLVMAddClause" addClause
+ :: ValueRef -> ValueRef -> IO ()
+foreign import ccall unsafe "LLVMSetCleanup" setCleanup
+ :: ValueRef -> CUInt -> IO ()
+#endif
+
foreign import ccall unsafe "LLVMBuildAdd" buildAdd
:: BuilderRef -> ValueRef -> ValueRef -> CString -> IO ValueRef
foreign import ccall unsafe "LLVMBuildSub" buildSub
@@ -1221,9 +1257,11 @@ data MemoryBuffer
deriving (Typeable)
type MemoryBufferRef = Ptr MemoryBuffer
+#if HS_LLVM_VERSION < 300
data TypeHandle
deriving (Typeable)
type TypeHandleRef = Ptr TypeHandle
+#endif
data TypeKind
= VoidTypeKind
@@ -1249,14 +1287,10 @@ foreign import ccall unsafe "LLVMCreateMemoryBufferWithContentsOfFile" createMem
:: CString -> Ptr MemoryBufferRef -> Ptr CString -> IO CInt
foreign import ccall unsafe "LLVMCreateMemoryBufferWithSTDIN" createMemoryBufferWithSTDIN
:: Ptr MemoryBufferRef -> Ptr CString -> IO CInt
-foreign import ccall unsafe "LLVMCreateTypeHandle" createTypeHandle
- :: TypeRef -> IO TypeHandleRef
foreign import ccall unsafe "LLVMDisposeMemoryBuffer" disposeMemoryBuffer
:: MemoryBufferRef -> IO ()
foreign import ccall unsafe "LLVMDisposeMessage" disposeMessage
:: CString -> IO ()
-foreign import ccall unsafe "LLVMDisposeTypeHandle" disposeTypeHandle
- :: TypeHandleRef -> IO ()
foreign import ccall unsafe "LLVMGetArrayLength" getArrayLength
:: TypeRef -> IO CUInt
foreign import ccall unsafe "LLVMGetIntTypeWidth" getIntTypeWidth
@@ -1269,15 +1303,29 @@ foreign import ccall unsafe "LLVMGetTypeKind" getTypeKindCUInt
:: TypeRef -> IO CUInt
foreign import ccall unsafe "LLVMGetVectorSize" getVectorSize
:: TypeRef -> IO CUInt
-foreign import ccall unsafe "LLVMRefineType" refineType
- :: TypeRef -> TypeRef -> IO ()
-foreign import ccall unsafe "LLVMResolveTypeHandle" resolveTypeHandle
- :: TypeHandleRef -> IO TypeRef
foreign import ccall unsafe "LLVMSetTarget" setTarget
:: ModuleRef -> CString -> IO ()
foreign import ccall unsafe "LLVMSizeOf" sizeOf
:: TypeRef -> IO ValueRef
+#if HS_LLVM_VERSION < 300
+foreign import ccall unsafe "LLVMCreateTypeHandle" createTypeHandle
+ :: TypeRef -> IO TypeHandleRef
+foreign import ccall unsafe "LLVMDisposeTypeHandle" disposeTypeHandle
+ :: TypeHandleRef -> IO ()
+foreign import ccall unsafe "LLVMRefineType" refineType
+ :: TypeRef -> TypeRef -> IO ()
+foreign import ccall unsafe "LLVMResolveTypeHandle" resolveTypeHandle
+ :: TypeHandleRef -> IO TypeRef
+#else
+foreign import ccall unsafe "LLVMStructCreateNamed" structCreateNamed
+ :: ContextRef -> CString -> IO TypeRef
+foreign import ccall unsafe "LLVMGetStructName" getStructName
+ :: TypeRef -> IO CString
+foreign import ccall unsafe "LLVMStructSetBody" structSetBody
+ :: TypeRef -> Ptr TypeRef -> CUInt -> CUInt -> IO ()
+#endif
+
data Attribute
= ZExtAttribute
| SExtAttribute
@@ -1424,8 +1472,6 @@ foreign import ccall unsafe "LLVMInitializeFunctionPassManager" initializeFuncti
:: PassManagerRef -> IO CInt
foreign import ccall unsafe "LLVMLabelType" labelType
:: TypeRef
-foreign import ccall unsafe "LLVMOpaqueType" opaqueType
- :: TypeRef
foreign import ccall unsafe "LLVMPositionBuilder" positionBuilder
:: BuilderRef -> BasicBlockRef -> ValueRef -> IO ()
foreign import ccall unsafe "LLVMRunFunctionPassManager" runFunctionPassManager
@@ -1437,6 +1483,13 @@ foreign import ccall unsafe "LLVMSetInstrParamAlignment" setInstrParamAlignment
foreign import ccall unsafe "LLVMSetParamAlignment" setParamAlignment
:: ValueRef -> CUInt -> IO ()
+#if HS_LLVM_VERSION < 300
+foreign import ccall unsafe "LLVMOpaqueType" opaqueType
+ :: TypeRef
+foreign import ccall unsafe "LLVMOpaqueTypeInContext" opaqueTypeInContext
+ :: ContextRef -> IO TypeRef
+#endif
+
data Context
deriving (Typeable)
@@ -1570,8 +1623,6 @@ foreign import ccall unsafe "LLVMLabelTypeInContext" labelTypeInContext
:: ContextRef -> IO TypeRef
foreign import ccall unsafe "LLVMModuleCreateWithNameInContext" moduleCreateWithNameInContext
:: CString -> ContextRef -> IO ModuleRef
-foreign import ccall unsafe "LLVMOpaqueTypeInContext" opaqueTypeInContext
- :: ContextRef -> IO TypeRef
foreign import ccall unsafe "LLVMPPCFP128TypeInContext" pPCFP128TypeInContext
:: ContextRef -> IO TypeRef
foreign import ccall unsafe "LLVMRemoveFunctionAttr" removeFunctionAttr
View
5 base/LLVM/FFI/Target.hsc
@@ -39,8 +39,9 @@ foreign import ccall unsafe "LLVMElementAtOffset" elementAtOffset
:: TargetDataRef -> TypeRef -> CULLong -> CUInt
foreign import ccall unsafe "LLVMIntPtrType" intPtrType
:: TargetDataRef -> TypeRef
-foreign import ccall unsafe "LLVMInvalidateStructLayout" invalidateStructLayout
- :: TargetDataRef -> TypeRef -> IO ()
+-- Removed in LLVM_3.0 ?
+-- foreign import ccall unsafe "LLVMInvalidateStructLayout" invalidateStructLayout
+-- :: TargetDataRef -> TypeRef -> IO ()
foreign import ccall unsafe "LLVMOffsetOfElement" offsetOfElement
:: TargetDataRef -> TypeRef -> CUInt -> CULLong
foreign import ccall unsafe "LLVMPointerSize" pointerSize
View
9 base/LLVM/Target/Native.hs
@@ -1,18 +1,23 @@
-{-# LANGUAGE CPP #-}
+{-# LANGUAGE CPP, ForeignFunctionInterface #-}
module LLVM.Target.Native(initializeNativeTarget) where
import Control.Monad
import Control.Concurrent.MVar
import System.IO.Unsafe
+import Foreign.C.Types
+
-- TARGET is expanded by CPP to the native target architecture.
import LLVM.Target.TARGET
+foreign import ccall unsafe "LLVMInitNativeTarget"
+ llvmInitializeNativeTarget :: IO CUInt
+
-- | Initialize jitter to the native target.
-- The operation is idempotent.
initializeNativeTarget :: IO ()
initializeNativeTarget = do
done <- takeMVar refDone
- when (not done) initializeTarget
+ when (not done) (llvmInitializeNativeTarget >> return ()) -- initializeTarget
putMVar refDone True
-- UNSAFE: global variable to keep track of initialization state.
View
8 base/cbits/extra.cpp
@@ -89,6 +89,11 @@
//using namespace llvm;
+unsigned LLVMInitNativeTarget()
+{
+ return LLVMInitializeNativeTarget();
+}
+
char *LLVMDumpModuleToString(LLVMModuleRef module)
{
std::string s;
@@ -516,7 +521,8 @@ void LLVMAdd ## P ## Pass (LLVMPassManagerRef passmgr) { \
define_pass( AAEval )
define_pass( AliasAnalysisCounter )
define_pass( AlwaysInliner )
-define_pass( BasicAliasAnalysis )
+// Name conflicts with those in LLVM proper, have a safer prefix?
+// define_pass( BasicAliasAnalysis )
define_pass( BlockPlacement )
define_pass( BreakCriticalEdges )
define_pass( CodeGenPrepare )
View
22 base/configure.ac
@@ -80,24 +80,31 @@ llvm_ldflags="`$llvm_config --ldflags`"
llvm_all_libs="`$llvm_config --libs all`"
llvm_target="`$llvm_config --libs engine | sed 's/.*LLVM\(.[[^ ]]*\)CodeGen.*/\1/'`"
+CPPFLAGS="$llvm_cppflags $CPPFLAGS $TARGET_CPPFLAGS"
+LDFLAGS="$llvm_ldflags $LDFLAGS $TARGET_LDFLAGS"
+
+llvm_extra_ghci_libs=""
+
+AC_SEARCH_LIBS([LLVMModuleCreateWithName],[LLVM-2.7 LLVM-2.8 LLVM-2.9 LLVM-3.0])
+if test "$ac_cv_search_LLVMModuleCreateWithName" = "no"; then
+ llvm_all_libs="`$llvm_config --libs all`"
+else
+ llvm_extra_ghci_libs="LLVM-$llvm_version"
+ llvm_all_libs="$LIBS"
+fi
+
dnl We need to separate libraries that need to be linked from other linker options.
llvm_extra_libs=""
llvm_extra_libdirs=""
-llvm_extra_ghci_libs=""
llvm_ldoptions=""
for opt in $llvm_all_libs $llvm_ldflags; do
case $opt in
-l*) llvm_extra_libs="$llvm_extra_libs `echo $opt | sed 's/^-l//'`";;
-L*) llvm_extra_libdirs="$llvm_extra_libdirs `echo $opt | sed 's/^-L//'`";;
- */lib*.so|*/lib*.dylib)
- llvm_extra_ghci_libs="$llvm_extra_ghci_libs `echo $opt | sed -e 's,^.*/lib\([^/]*\),\1,' -e 's/\.so$//' -e 's/\.dylib$//'`";;
*) llvm_ldoptions="$llvm_ldoptions $opt";;
esac
done
-CPPFLAGS="$llvm_cppflags $CPPFLAGS $TARGET_CPPFLAGS"
-LDFLAGS="$llvm_ldflags $LDFLAGS $TARGET_LDFLAGS"
-
AC_CHECK_HEADERS([llvm-c/Core.h], [],
[AC_MSG_ERROR(could not find LLVM C bindings)])
@@ -108,7 +115,7 @@ AC_CHECK_HEADERS([llvm/Support/DynamicLibrary.h], [], [],
#endif])
save_LIBS="$LIBS"
-LIBS="-lLLVMSupport -lLLVMSystem -lpthread -ldl $LIBS"
+LIBS="-lLLVMSupport -lpthread -ldl $LIBS"
AC_CHECK_LIB(LLVMCore, LLVMModuleCreateWithName, [], [])
if test "$ac_cv_lib_LLVMCore_LLVMModuleCreateWithName" = "no"; then
@@ -122,6 +129,7 @@ llvm_num_version="`echo $llvm_version | tr . 0`"
AC_DEFINE_UNQUOTED([HS_LLVM_VERSION], [$llvm_num_version],
[Define to the version of LLVM, e.g. 209 for 2.9.])
+AC_SUBST([llvm_num_version])
AC_SUBST([llvm_version])
AC_SUBST([llvm_cppflags])
AC_SUBST([llvm_extra_libs])
View
5 base/include/extra.h
@@ -46,6 +46,11 @@ extern "C" {
* indicated in the comments. Where it is not indicated, DO NOT call dispose.
*/
+
+/* Wraps the LLVMInitializeTarget macro from Target.h */
+unsigned LLVMInitNativeTarget(void);
+
+
/* Wraps llvm::Module::print(). Dispose the returned string after use, via
* LLVMDisposeMessage(). */
char *LLVMDumpModuleToString(LLVMModuleRef module);
View
3  base/include/hs_llvm_config.h.in
@@ -54,6 +54,9 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
/* Define to the version of this package. */
#undef PACKAGE_VERSION
View
2  base/llvm-base.buildinfo.in
@@ -1,4 +1,4 @@
-cpp-options: @llvm_cppflags@ -DTARGET=@llvm_target@
+cpp-options: @llvm_cppflags@ -DTARGET=@llvm_target@ -DHS_LLVM_VERSION=@llvm_num_version@
ghc-options: -pgml @CXX@
extra-libraries: @llvm_extra_libs@ stdc++
extra-lib-dirs: @llvm_extra_libdirs@
Something went wrong with that request. Please try again.