summaryrefslogtreecommitdiff
path: root/libre/openshadinglanguage/llvm.patch
diff options
context:
space:
mode:
Diffstat (limited to 'libre/openshadinglanguage/llvm.patch')
-rw-r--r--libre/openshadinglanguage/llvm.patch331
1 files changed, 331 insertions, 0 deletions
diff --git a/libre/openshadinglanguage/llvm.patch b/libre/openshadinglanguage/llvm.patch
new file mode 100644
index 000000000..a63b91e0d
--- /dev/null
+++ b/libre/openshadinglanguage/llvm.patch
@@ -0,0 +1,331 @@
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/cmake/externalpackages.cmake OpenShadingLanguage-Release-1.3.3/src/cmake/externalpackages.cmake
+--- OpenShadingLanguage-Release-1.3.3.orig/src/cmake/externalpackages.cmake 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/cmake/externalpackages.cmake 2014-02-04 18:09:20.236025178 -0200
+@@ -185,9 +185,9 @@
+ find_library ( LLVM_LIBRARY
+ NAMES LLVM-${LLVM_VERSION}
+ PATHS ${LLVM_LIB_DIR})
++message (STATUS "LLVM version = ${LLVM_VERSION}")
++message (STATUS "LLVM dir = ${LLVM_DIRECTORY}")
+ if (VERBOSE)
+- message (STATUS "LLVM version = ${LLVM_VERSION}")
+- message (STATUS "LLVM dir = ${LLVM_DIRECTORY}")
+ message (STATUS "LLVM includes = ${LLVM_INCLUDES}")
+ message (STATUS "LLVM library = ${LLVM_LIBRARY}")
+ message (STATUS "LLVM lib dir = ${LLVM_LIB_DIR}")
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/CMakeLists.txt OpenShadingLanguage-Release-1.3.3/src/liboslexec/CMakeLists.txt
+--- OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/CMakeLists.txt 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/liboslexec/CMakeLists.txt 2014-02-04 18:07:21.960947198 -0200
+@@ -51,49 +51,64 @@
+ MESSAGE (STATUS "LLVM_COMPILE cpp=${llvm_bc_cpp}")
+ endif ()
+ SET ( ${srclist} ${${srclist}} ${llvm_bc_cpp} )
+- EXEC_PROGRAM ( ${LLVM_DIRECTORY}/bin/llvm-config ARGS --cxxflags OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
+- set (LLVM_COMPILE_FLAGS "${LLVM_COMPILE_FLAGS} -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O3 --combine")
+- LIST (APPEND LLVM_COMPILE_FLAGS "-I${ILMBASE_INCLUDE_DIR}")
++ SET (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-I${ILMBASE_INCLUDE_DIR}")
+ if (OSL_NAMESPACE)
+- LIST (APPEND LLVM_COMPILE_FLAGS "-DOSL_NAMESPACE=${OSL_NAMESPACE}")
++ SET (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-DOSL_NAMESPACE=${OSL_NAMESPACE}")
+ endif ()
+ if (OPENIMAGEIO_NAMESPACE)
+- LIST (APPEND LLVM_COMPILE_FLAGS "-DOPENIMAGEIO_NAMESPACE=${OPENIMAGEIO_NAMESPACE}")
++ SET (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-DOPENIMAGEIO_NAMESPACE=${OPENIMAGEIO_NAMESPACE}")
+ endif ()
+ get_property (CURRENT_DEFINITIONS DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+ if (VERBOSE)
+ message (STATUS "Current #defines are ${CURRENT_DEFINITIONS}")
+ endif ()
+ foreach (def ${CURRENT_DEFINITIONS})
+- LIST (APPEND LLVM_COMPILE_FLAGS "-D${def}")
++ SET (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-D${def}")
+ endforeach()
+
+- # First try looking in their build (clang++ first, then llvm-g++)
+- FIND_PROGRAM(LLVM_BC_GENERATOR NAMES "clang++" "llvm-g++" PATHS ${LLVM_DIRECTORY}/bin NO_DEFAULT_PATH NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH)
++ # Figure out what program we will use to make the bitcode.
++ if (NOT LLVM_BC_GENERATOR)
++ FIND_PROGRAM(LLVM_BC_GENERATOR NAMES "clang++" PATHS "${LLVM_DIRECTORY}/bin" NO_DEFAULT_PATH NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH)
++ endif ()
++ # If that didn't work, look anywhere
++ if (NOT LLVM_BC_GENERATOR)
++ # Wasn't in their build, look anywhere
++ FIND_PROGRAM(LLVM_BC_GENERATOR NAMES clang++ llvm-g++)
++ endif ()
+
+- if(NOT LLVM_BC_GENERATOR)
+- # Wasn't in their build, look anywhere
+- FIND_PROGRAM(LLVM_BC_GENERATOR NAMES clang++ llvm-g++)
++ if (NOT LLVM_BC_GENERATOR)
++ message (FATAL_ERROR "You must have a valid llvm bitcode generator (clang++) somewhere.")
++ endif ()
++ if (VERBOSE)
++ message (STATUS "Using ${LLVM_BC_GENERATOR} to generate bitcode.")
+ endif()
+
+- if(NOT LLVM_BC_GENERATOR)
+- message (FATAL_ERROR "You must have a valid llvm bitcode generator (either llvm-g++ or clang++) somewhere.")
+- else()
+- if (VERBOSE)
+- message (STATUS "Using ${LLVM_BC_GENERATOR} to generate bitcode.")
+- endif ()
+- endif()
++ # Fix specific problem I had on new Apple systems (e.g. Mavericks) with
++ # LLVM/libc++ installed -- for some reason, LLVM 3.4 wasn't finding it,
++ # so in that specific case, append another -I to point it in the right
++ # direction.
++ if (APPLE AND ${LLVM_BC_GENERATOR} MATCHES ".*clang.*")
++ EXEC_PROGRAM ( "${LLVM_BC_GENERATOR}" ARGS --version OUTPUT_VARIABLE MY_CLANG_VERSION )
++ string (REGEX REPLACE "clang version ([0-9][.][0-9]+).*" "\\1" MY_CLANG_VERSION "${MY_CLANG_VERSION}")
++ if ((${MY_CLANG_VERSION} VERSION_GREATER "3.3")
++ AND (EXISTS "/usr/lib/libc++.dylib")
++ AND (EXISTS "/Library/Developer/CommandLineTools/usr/lib/c++/v1"))
++ set (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-I/Library/Developer/CommandLineTools/usr/lib/c++/v1")
++ endif ()
++ endif ()
+
+ # Command to turn the .cpp file into LLVM assembly language .s, into
+ # LLVM bitcode .bc, then back into a C++ file with the bc embedded!
+ ADD_CUSTOM_COMMAND ( OUTPUT ${llvm_bc_cpp}
+- COMMAND ${LLVM_BC_GENERATOR} ${LLVM_COMPILE_FLAGS}
+- -I${CMAKE_CURRENT_SOURCE_DIR}
+- -I${CMAKE_SOURCE_DIR}/include
+- -I${CMAKE_BINARY_DIR}/include
+- -I${OPENIMAGEIO_INCLUDES} -I${ILMBASE_INCLUDE_DIR}
+- -I${Boost_INCLUDE_DIRS} -O3 -S -emit-llvm -o ${llvm_asm} ${llvm_src}
+-
++ COMMAND ${LLVM_BC_GENERATOR}
++ ${LLVM_COMPILE_FLAGS}
++ "-I${CMAKE_CURRENT_SOURCE_DIR}"
++ "-I${CMAKE_SOURCE_DIR}/src/include"
++ "-I${CMAKE_BINARY_DIR}/include"
++ "-I${OPENIMAGEIO_INCLUDES}"
++ "-I${ILMBASE_INCLUDE_DIR}"
++ "-I${Boost_INCLUDE_DIRS}"
++ -O3 -S -emit-llvm -o ${llvm_asm} ${llvm_src}
+ COMMAND ${LLVM_DIRECTORY}/bin/llvm-as -f -o ${llvm_bc} ${llvm_asm}
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/serialize-bc.bash ${llvm_bc} ${llvm_bc_cpp}
+ MAIN_DEPENDENCY ${llvm_src}
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/llvm_headers.h OpenShadingLanguage-Release-1.3.3/src/liboslexec/llvm_headers.h
+--- OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/llvm_headers.h 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/liboslexec/llvm_headers.h 2014-02-04 19:28:31.349811104 -0200
+@@ -33,7 +33,27 @@
+ namespace llvm = LLVM_NAMESPACE;
+ #endif
+
+-#if OSL_LLVM_VERSION >= 33
++#if OSL_LLVM_VERSION >= 34
++
++# include <llvm/IR/Constants.h>
++# include <llvm/IR/DerivedTypes.h>
++# include <llvm/IR/Instructions.h>
++# include <llvm/IR/Intrinsics.h>
++# include <llvm/IR/Module.h>
++# include <llvm/IR/LLVMContext.h>
++# include <llvm/IR/IRBuilder.h>
++# include <llvm/IR/DataLayout.h>
++# include <llvm/Bitcode/ReaderWriter.h>
++# include <llvm/ExecutionEngine/GenericValue.h>
++# include <llvm/ExecutionEngine/JIT.h>
++# include <llvm/ExecutionEngine/JITMemoryManager.h>
++# include <llvm/Linker.h>
++# include <llvm/IR/LegacyPassManager.h>
++# include <llvm/Support/ManagedStatic.h>
++# include <llvm/Support/MemoryBuffer.h>
++# include <llvm/Support/raw_ostream.h>
++
++#elif OSL_LLVM_VERSION >= 33
+
+ # include <llvm/IR/Constants.h>
+ # include <llvm/IR/DerivedTypes.h>
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/llvm_instance.cpp OpenShadingLanguage-Release-1.3.3/src/liboslexec/llvm_instance.cpp
+--- OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/llvm_instance.cpp 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/liboslexec/llvm_instance.cpp 2014-02-04 20:08:23.574948459 -0200
+@@ -992,6 +992,7 @@
+ virtual void deallocateFunctionBody(void *Body) {
+ // DON'T DEALLOCATE mm->deallocateFunctionBody (Body);
+ }
++#if OSL_LLVM_VERSION <= 33
+ virtual uint8_t* startExceptionTable(const llvm::Function* F,
+ uintptr_t &ActualSize) {
+ return mm->startExceptionTable (F, ActualSize);
+@@ -1003,6 +1004,7 @@
+ virtual void deallocateExceptionTable(void *ET) {
+ // DON'T DEALLOCATE mm->deallocateExceptionTable(ET);
+ }
++#endif
+ virtual bool CheckInvariants(std::string &s) {
+ return mm->CheckInvariants(s);
+ }
+@@ -1018,7 +1020,41 @@
+ virtual unsigned GetNumCodeSlabs() { return mm->GetNumCodeSlabs(); }
+ virtual unsigned GetNumDataSlabs() { return mm->GetNumDataSlabs(); }
+ virtual unsigned GetNumStubSlabs() { return mm->GetNumStubSlabs(); }
+-#if OSL_LLVM_VERSION >= 31
++
++#if OSL_LLVM_VERSION >= 34
++
++ virtual void *getPointerToNamedFunction(const std::string &Name,
++ bool AbortOnFailure = true) {
++ return mm->getPointerToNamedFunction (Name, AbortOnFailure);
++ }
++ virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
++ unsigned SectionID, llvm::StringRef SectionName) {
++ return mm->allocateCodeSection(Size, Alignment, SectionID, SectionName);
++ }
++ virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
++ unsigned SectionID, llvm::StringRef SectionName,
++ bool IsReadOnly) {
++ return mm->allocateDataSection(Size, Alignment, SectionID,
++ SectionName, IsReadOnly);
++ }
++ virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) {
++ mm->registerEHFrames (Addr, LoadAddr, Size);
++ }
++ virtual void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) {
++ mm->deregisterEHFrames(Addr, LoadAddr, Size);
++ }
++ virtual uint64_t getSymbolAddress(const std::string &Name) {
++ return mm->getSymbolAddress (Name);
++ }
++ virtual void notifyObjectLoaded(llvm::ExecutionEngine *EE, const llvm::ObjectImage *oi) {
++ mm->notifyObjectLoaded (EE, oi);
++ }
++ virtual bool finalizeMemory(std::string *ErrMsg = 0) {
++ return mm->finalizeMemory (ErrMsg);
++ }
++
++#elif OSL_LLVM_VERSION == 33
++
+ virtual void *getPointerToNamedFunction(const std::string &Name,
+ bool AbortOnFailure = true) {
+ return mm->getPointerToNamedFunction (Name, AbortOnFailure);
+@@ -1027,7 +1063,6 @@
+ unsigned SectionID) {
+ return mm->allocateCodeSection(Size, Alignment, SectionID);
+ }
+-#if OSL_LLVM_VERSION >= 33
+ virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID, bool IsReadOnly) {
+ return mm->allocateDataSection(Size, Alignment, SectionID, IsReadOnly);
+@@ -1035,12 +1070,22 @@
+ virtual bool applyPermissions(std::string *ErrMsg = 0) {
+ return mm->applyPermissions(ErrMsg);
+ }
+-#else
++
++#elif OSL_LLVM_VERSION == 32 || OSL_LLVM_VERSION == 31
++
++ virtual void *getPointerToNamedFunction(const std::string &Name,
++ bool AbortOnFailure = true) {
++ return mm->getPointerToNamedFunction (Name, AbortOnFailure);
++ }
++ virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
++ unsigned SectionID) {
++ return mm->allocateCodeSection(Size, Alignment, SectionID);
++ }
+ virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID) {
+ return mm->allocateDataSection(Size, Alignment, SectionID);
+ }
+-#endif
++
+ #endif
+ };
+
+@@ -1155,7 +1200,7 @@
+ m_shadingsys.m_stat_empty_groups += 1;
+ m_shadingsys.m_stat_empty_instances += 1; // the one layer is empty
+ } else {
+- m_llvm_passes->run (*llvm_module());
++ m_llvm_module_passes->run (*llvm_module());
+ }
+
+ m_stat_llvm_opt_time += timer.lap();
+@@ -1290,7 +1335,12 @@
+ // Some global LLVM initialization for the first thread that
+ // gets here.
+ info ("Setting up LLVM");
++
++#if OSL_LLVM_VERSION <= 33
++ // Starting with LLVM 3.4, the pretty stack trace was opt-in rather
++ // than opt-out, and the following variable was removed.
+ llvm::DisablePrettyStackTrace = true;
++#endif
+ llvm::llvm_start_multithreaded (); // enable it to be thread-safe
+ llvm::InitializeNativeTarget();
+ done = true;
+@@ -1301,12 +1351,17 @@
+ void
+ RuntimeOptimizer::llvm_setup_optimization_passes ()
+ {
+- ASSERT (m_llvm_passes == NULL && m_llvm_func_passes == NULL);
++ ASSERT (m_llvm_module_passes == NULL && m_llvm_func_passes == NULL);
+
+ // Specify per-function passes
+ //
++#if OSL_LLVM_VERSION >= 34
++ m_llvm_func_passes = new llvm::legacy::FunctionPassManager(llvm_module());
++ llvm::legacy::FunctionPassManager &fpm (*m_llvm_func_passes);
++#else
+ m_llvm_func_passes = new llvm::FunctionPassManager(llvm_module());
+ llvm::FunctionPassManager &fpm (*m_llvm_func_passes);
++#endif
+ #if OSL_LLVM_VERSION >= 32
+ fpm.add (new llvm::DataLayout(llvm_module()));
+ #else
+@@ -1315,8 +1370,13 @@
+
+ // Specify module-wide (interprocedural optimization) passes
+ //
+- m_llvm_passes = new llvm::PassManager;
+- llvm::PassManager &passes (*m_llvm_passes);
++#if OSL_LLVM_VERSION >= 34
++ m_llvm_module_passes = new llvm::legacy::PassManager;
++ llvm::legacy::PassManager &passes (*m_llvm_module_passes);
++#else
++ m_llvm_module_passes = new llvm::PassManager;
++ llvm::PassManager &passes (*m_llvm_module_passes);
++#endif
+ #if OSL_LLVM_VERSION >= 32
+ passes.add (new llvm::DataLayout(llvm_module()));
+ #else
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/runtimeoptimize.cpp OpenShadingLanguage-Release-1.3.3/src/liboslexec/runtimeoptimize.cpp
+--- OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/runtimeoptimize.cpp 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/liboslexec/runtimeoptimize.cpp 2014-02-04 19:37:02.660353625 -0200
+@@ -107,7 +107,7 @@
+ m_stat_llvm_jit_time(0),
+ m_llvm_context(NULL), m_llvm_module(NULL),
+ m_llvm_exec(NULL), m_builder(NULL),
+- m_llvm_passes(NULL), m_llvm_func_passes(NULL)
++ m_llvm_module_passes(NULL), m_llvm_func_passes(NULL)
+ {
+ set_debug ();
+ memset (&m_shaderglobals, 0, sizeof(ShaderGlobals));
+@@ -119,7 +119,7 @@
+ RuntimeOptimizer::~RuntimeOptimizer ()
+ {
+ delete m_builder;
+- delete m_llvm_passes;
++ delete m_llvm_module_passes;
+ delete m_llvm_func_passes;
+ }
+
+diff -Nur OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/runtimeoptimize.h OpenShadingLanguage-Release-1.3.3/src/liboslexec/runtimeoptimize.h
+--- OpenShadingLanguage-Release-1.3.3.orig/src/liboslexec/runtimeoptimize.h 2013-07-11 20:01:18.000000000 -0300
++++ OpenShadingLanguage-Release-1.3.3/src/liboslexec/runtimeoptimize.h 2014-02-04 19:52:30.207956999 -0200
+@@ -934,8 +934,13 @@
+ llvm::Type *m_llvm_type_closure_component_attr; // LLVM type for ClosureMeta::Attr
+ llvm::PointerType *m_llvm_type_prepare_closure_func;
+ llvm::PointerType *m_llvm_type_setup_closure_func;
+- llvm::PassManager *m_llvm_passes;
++#if OSL_LLVM_VERSION >= 34
++ llvm::legacy::PassManager *m_llvm_module_passes;
++ llvm::legacy::FunctionPassManager *m_llvm_func_passes;
++#else
++ llvm::PassManager *m_llvm_module_passes;
+ llvm::FunctionPassManager *m_llvm_func_passes;
++#endif
+ int m_llvm_local_mem; // Amount of memory we use for locals
+
+ // Persistant data shared between layers