changeset 17031:38bcfd413db0

Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2 * configure.ac: Call LLVM API incoherence checks. * jit-typeinfo.cc: Check new defines. * pt-jit.cc: Check new defines. * m4/acinclude.m4: Add LLVM API incoherence checks.
author LYH <lyh.kernel@gmail.com>
date Wed, 01 May 2013 17:54:56 +0800
parents 05b8ad3b7d12
children 53d6166f7867
files configure.ac libinterp/corefcn/jit-typeinfo.cc libinterp/corefcn/pt-jit.cc m4/acinclude.m4
diffstat 4 files changed, 212 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sun Jul 21 17:26:39 2013 -0400
+++ b/configure.ac	Wed May 01 17:54:56 2013 +0800
@@ -766,6 +766,11 @@
     AC_CHECK_HEADER([llvm/Support/TargetSelect.h], [
       warn_llvm=
       XTRA_CXXFLAGS="$XTRA_CXXFLAGS $LLVM_CXXFLAGS $LLVM_CPPFLAGS"])
+    OCTAVE_LLVM_IRBUILDER_HEADER
+    OCTAVE_LLVM_DATALAYOUT_HEADER
+    OCTAVE_LLVM_FUNCTION_ADDATTRIBUTE_API
+    OCTAVE_LLVM_FUNCTION_ADDFNATTR_API
+    OCTAVE_LLVM_CALLINST_ADDATTRIBUTE_API
     AC_LANG_POP(C++)
     CPPFLAGS="$save_CPPFLAGS"
     CXXFLAGS="$save_CXXFLAGS"
--- a/libinterp/corefcn/jit-typeinfo.cc	Sun Jul 21 17:26:39 2013 -0400
+++ b/libinterp/corefcn/jit-typeinfo.cc	Wed May 01 17:54:56 2013 +0800
@@ -41,7 +41,11 @@
 #include <llvm/Function.h>
 #include <llvm/Instructions.h>
 #include <llvm/Intrinsics.h>
+#ifdef IRBUILDER_HEADER_IN_SUPPORT_DIR
 #include <llvm/Support/IRBuilder.h>
+#else
+#include <llvm/IRBuilder.h>
+#endif
 #include <llvm/Support/raw_os_ostream.h>
 
 #include "jit-ir.h"
@@ -579,10 +583,23 @@
                                           aname, module);
 
   if (sret ())
-    llvm_function->addAttribute (1, llvm::Attribute::StructRet);
+    {
+#ifdef FUNCTION_ADDATTRIBUTE_ARG_IS_ATTRIBUTES
+      llvm::AttrBuilder attr_builder;
+      attr_builder.addAttribute (llvm::Attributes::StructRet);
+      llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder);
+      llvm_function->addAttribute (1, attrs);
+#else
+      llvm_function->addAttribute (1, llvm::Attribute::StructRet);
+#endif
+    }
 
   if (call_conv == jit_convention::internal)
+#ifdef FUNCTION_ADDFNATTR_ARG_IS_ATTRIBUTES
+    llvm_function->addFnAttr (llvm::Attributes::AlwaysInline);
+#else
     llvm_function->addFnAttr (llvm::Attribute::AlwaysInline);
+#endif
 }
 
 jit_function::jit_function (const jit_function& fn, jit_type *aresult,
@@ -685,7 +702,14 @@
 
   if (sret ())
     {
+#ifdef CALLINST_ADDATTRIBUTE_ARG_IS_ATTRIBUTES
+      llvm::AttrBuilder attr_builder;
+      attr_builder.addAttribute(llvm::Attributes::StructRet);
+      llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder); 
+      callinst->addAttribute (1, attrs);
+#else
       callinst->addAttribute (1, llvm::Attribute::StructRet);
+#endif
       ret = builder.CreateLoad (sret_mem);
     }
 
--- a/libinterp/corefcn/pt-jit.cc	Sun Jul 21 17:26:39 2013 -0400
+++ b/libinterp/corefcn/pt-jit.cc	Wed May 01 17:54:56 2013 +0800
@@ -55,10 +55,18 @@
 #include <llvm/ExecutionEngine/JIT.h>
 #include <llvm/Module.h>
 #include <llvm/PassManager.h>
+#ifdef IRBUILDER_HEADER_IN_SUPPORT_DIR
 #include <llvm/Support/IRBuilder.h>
+#else
+#include <llvm/IRBuilder.h>
+#endif
 #include <llvm/Support/raw_os_ostream.h>
 #include <llvm/Support/TargetSelect.h>
+#ifdef HAVE_DATALAYOUT
+#include <llvm/DataLayout.h>
+#else
 #include <llvm/Target/TargetData.h>
+#endif
 #include <llvm/Transforms/IPO.h>
 #include <llvm/Transforms/Scalar.h>
 
@@ -1864,7 +1872,11 @@
   module_pass_manager->add (llvm::createAlwaysInlinerPass ());
 
   pass_manager = new llvm::FunctionPassManager (module);
-  pass_manager->add (new llvm::TargetData(*engine->getTargetData ()));
+#if HAVE_DATALAYOUT
+  pass_manager->add (new llvm::DataLayout (*engine->getDataLayout ()));
+#else
+  pass_manager->add (new llvm::TargetData (*engine->getTargetData ()));
+#endif
   pass_manager->add (llvm::createCFGSimplificationPass ());
   pass_manager->add (llvm::createBasicAliasAnalysisPass ());
   pass_manager->add (llvm::createPromoteMemoryToRegisterPass ());
--- a/m4/acinclude.m4	Sun Jul 21 17:26:39 2013 -0400
+++ b/m4/acinclude.m4	Wed May 01 17:54:56 2013 +0800
@@ -1882,6 +1882,175 @@
       [Define to 1 if unordered_map requires the use of tr1 namespace.])
   fi
 ])
+dnl
+dnl Check whether IRBuilder.h is in Support directory.
+dnl
+AC_DEFUN([OCTAVE_LLVM_IRBUILDER_HEADER], [
+  AC_CHECK_HEADER([llvm/IRBuilder.h], [
+    octave_irbuilder_header_in_support_dir=no], [
+    AC_CHECK_HEADER([llvm/Support/IRBuilder.h], [
+      octave_irbuilder_header_in_support_dir=yes], [
+      AC_MSG_ERROR("IRBuilder.h is required.")
+    ])
+  ])
+  if test $octave_irbuilder_header_in_support_dir = yes; then
+    AC_DEFINE(IRBUILDER_HEADER_IN_SUPPORT_DIR, 1, 
+      [Define to 1 if IRBuilder.h in Support directory.])
+  fi
+])
+dnl
+dnl Detect TargetData.h or DataLayout.h.
+dnl
+AC_DEFUN([OCTAVE_LLVM_DATALAYOUT_HEADER], [
+  AC_CHECK_HEADER([llvm/DataLayout.h], [
+    octave_is_datalayout_header=yes], [
+    AC_CHECK_HEADER([llvm/Target/TargetData.h], [
+      octave_is_datalayout_header=no], [
+      AC_MSG_ERROR("DataLayout.h or Target/TargetData.h is required.")
+    ])
+  ])
+  if test $octave_is_datalayout_header = yes; then
+    AC_DEFINE(HAVE_DATALAYOUT, 1, 
+      [Define to 1 if DataLayout.h exist.])
+  fi
+])
+dnl
+dnl Check for Function::addAttribute API
+dnl
+AC_DEFUN([OCTAVE_LLVM_FUNCTION_ADDATTRIBUTE_API], [
+  AC_CACHE_CHECK([check llvm::Function::addAttribute arg type is llvm::Attributes], 
+    [octave_cv_function_addattribute_arg_is_attributes],
+    [AC_LANG_PUSH(C++)
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[
+          #include <llvm/Function.h>
+          #include <llvm/Attributes.h>
+          #include <llvm/LLVMContext.h>
+          ]], [[
+          llvm::Function *llvm_function;
+          llvm::AttrBuilder attr_builder;
+          attr_builder.addAttribute(llvm::Attributes::StructRet);
+          llvm::Attributes attrs = llvm::Attributes::get(llvm::getGlobalContext(), attr_builder);
+          llvm_function->addAttribute (1, attrs);
+        ]])],
+        octave_cv_function_addattribute_arg_is_attributes=yes, 
+        octave_cv_function_addattribute_arg_is_attributes=no)
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_function_addattribute_arg_is_attributes = yes; then
+    AC_DEFINE(FUNCTION_ADDATTRIBUTE_ARG_IS_ATTRIBUTES, 1, 
+      [Define to 1 if llvm::Function:addAttribute arg type is llvm::Attributes.])
+  else
+    AC_CACHE_CHECK([check llvm::Function::addAttribute arg type is llvm::Attribute], 
+      [octave_cv_function_addattribute_arg_is_attribute],
+      [AC_LANG_PUSH(C++)
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM([[
+            #include <llvm/Function.h>
+            #include <llvm/Attributes.h>
+            ]], [[
+            llvm::Function *llvm_function;
+            llvm_function->addAttribute (1, llvm::Attribute::StructRet);
+          ]])],
+          octave_cv_function_addattribute_arg_is_attribute=yes, 
+          octave_cv_function_addattribute_arg_is_attribute=no)
+      AC_LANG_POP(C++)
+    ])
+    if test $octave_cv_function_addattribute_arg_is_attribute = no; then
+      AC_MSG_ERROR("llvm::Function::addAttribute is required.")      
+    fi
+  fi
+])
+dnl
+dnl Check for Function::addFnAttr API
+dnl
+AC_DEFUN([OCTAVE_LLVM_FUNCTION_ADDFNATTR_API], [
+  AC_CACHE_CHECK([check LLVM::Function::addFnAttr arg type is llvm::Attributes], 
+    [octave_cv_function_addfnattr_arg_is_attributes],
+    [AC_LANG_PUSH(C++)
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[
+          #include <llvm/Function.h>
+          #include <llvm/Attributes.h>
+          ]], [[
+          llvm::Function *llvm_function;
+          llvm_function->addFnAttr (llvm::Attributes::AlwaysInline);
+        ]])],
+        octave_cv_function_addfnattr_arg_is_attributes=yes, 
+        octave_cv_function_addfnattr_arg_is_attributes=no)
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_function_addfnattr_arg_is_attributes = yes; then
+    AC_DEFINE(FUNCTION_ADDFNATTR_ARG_IS_ATTRIBUTES, 1, 
+      [Define to 1 if llvm::Function:addFnAttr arg type is llvm::Attributes.])
+  else
+    AC_CACHE_CHECK([check llvm::Function::addFnAttr arg type is llvm::Attribute], 
+      [octave_cv_function_addfnattr_arg_is_attribute],
+      [AC_LANG_PUSH(C++)
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM([[
+            #include <llvm/Function.h>
+            #include <llvm/Attributes.h>
+            ]], [[
+            llvm::Function *llvm_function;
+            llvm_function->addFnAttr (llvm::Attribute::AlwaysInline);
+          ]])],
+          octave_cv_function_addfnattr_arg_is_attribute=yes, 
+          octave_cv_function_addfnattr_arg_is_attribute=no)
+      AC_LANG_POP(C++)
+    ])
+    if test $octave_cv_function_addfnattr_arg_is_attribute = no; then
+      AC_MSG_ERROR("llvm::Function::addFnAttr is required.")      
+    fi
+  fi
+])
+dnl
+dnl Check for CallInst::addAttribute API
+dnl
+AC_DEFUN([OCTAVE_LLVM_CALLINST_ADDATTRIBUTE_API], [
+  AC_CACHE_CHECK([check LLVM::CallInst::addAttribute arg type is llvm::Attributes], 
+    [octave_cv_callinst_addattribute_arg_is_attributes],
+    [AC_LANG_PUSH(C++)
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM([[
+          #include <llvm/Instructions.h>
+          #include <llvm/Attributes.h>
+          #include <llvm/LLVMContext.h>
+          ]], [[
+          llvm::CallInst *callinst;
+          llvm::AttrBuilder attr_builder;
+          attr_builder.addAttribute(llvm::Attributes::StructRet);
+          llvm::Attributes attrs = llvm::Attributes::get(llvm::getGlobalContext(), attr_builder); 
+          callinst->addAttribute (1, attrs);
+        ]])],
+        octave_cv_callinst_addattribute_arg_is_attributes=yes, 
+        octave_cv_callinst_addattribute_arg_is_attributes=no)
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_callinst_addattribute_arg_is_attributes = yes; then
+    AC_DEFINE(CALLINST_ADDATTRIBUTE_ARG_IS_ATTRIBUTES, 1, 
+      [Define to 1 if llvm::CallInst:addAttribute arg type is llvm::Attributes.])
+  else
+    AC_CACHE_CHECK([check LLVM::CallInst::addAttribute arg type is llvm::Attribute], 
+      [octave_cv_callinst_addattribute_arg_is_attribute],
+      [AC_LANG_PUSH(C++)
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM([[
+            #include <llvm/Instructions.h>
+            #include <llvm/Attributes.h>
+            ]], [[
+            llvm::CallInst *callinst;
+            callinst->addAttribute (1, llvm::Attribute::StructRet);
+          ]])],
+          octave_cv_callinst_addattribute_arg_is_attribute=yes, 
+          octave_cv_callinst_addattribute_arg_is_attribute=no)
+      AC_LANG_POP(C++)
+    ])
+    if test $octave_cv_callinst_addattribute_arg_is_attribute = no; then
+      AC_MSG_ERROR("llvm::CallInst::addAttribute is required.")      
+    fi    
+  fi
+])
 
 dnl         End of macros written by Octave developers
 dnl ------------------------------------------------------------