clover: Fix build after llvm r325155 and r325160
authorJan Vesely <jan.vesely@rutgers.edu>
Thu, 15 Feb 2018 19:00:38 +0000 (14:00 -0500)
committerJan Vesely <jan.vesely@rutgers.edu>
Thu, 15 Feb 2018 23:18:53 +0000 (18:18 -0500)
r325155 ("Pass a reference to a module to the bitcode writer.")
and
r325160 ("Pass module reference to CloneModule")

change function interface from pointer to reference.

v2: Fix indentation (tab instead of spaces)

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
src/gallium/state_trackers/clover/llvm/codegen/native.cpp
src/gallium/state_trackers/clover/llvm/compat.hpp

index 679ecd87580b386da5e5c4903fc40662ac956527..40bb426218d1f1b8ed4ad94afe4bf3897f60fc75 100644 (file)
@@ -66,7 +66,7 @@ namespace {
    emit_code(const ::llvm::Module &mod) {
       ::llvm::SmallVector<char, 1024> data;
       ::llvm::raw_svector_ostream os { data };
-      WriteBitcodeToFile(&mod, os);
+      compat::write_bitcode_to_file(mod, os);
       return { os.str().begin(), os.str().end() };
    }
 }
index 12c83a92b663bf5ea83bb765abc252900ddcc85c..409f8ac32f0ea566a8345478c2900d5bf53d68ad 100644 (file)
@@ -156,7 +156,7 @@ clover::llvm::print_module_native(const ::llvm::Module &mod,
                                   const target &target) {
    std::string log;
    try {
-      std::unique_ptr< ::llvm::Module> cmod { CloneModule(&mod) };
+      std::unique_ptr< ::llvm::Module> cmod { compat::clone_module(mod) };
       return as_string(emit_code(*cmod, target,
                                  TargetMachine::CGFT_AssemblyFile, log));
    } catch (...) {
index 6fc75fb2502a8ccf03696d615957581b8bd71588..19528a0133f05d73ca2c8ca4481907eaf31ca089 100644 (file)
 
 #include "util/algorithm.hpp"
 
+#if HAVE_LLVM < 0x0400
+#include <llvm/Bitcode/ReaderWriter.h>
+#else
+#include <llvm/Bitcode/BitcodeReader.h>
+#include <llvm/Bitcode/BitcodeWriter.h>
+#endif
+
 #include <llvm/IR/LLVMContext.h>
 #include <llvm/Linker/Linker.h>
 #include <llvm/Transforms/IPO.h>
+#include <llvm/Transforms/Utils/Cloning.h>
 #include <llvm/Target/TargetMachine.h>
 #if HAVE_LLVM >= 0x0400
 #include <llvm/Support/Error.h>
@@ -217,6 +225,26 @@ namespace clover {
            ctx.setDiagnosticHandler(diagnostic_handler, data);
 #endif
         }
+
+       inline std::unique_ptr< ::llvm::Module>
+       clone_module(const ::llvm::Module &mod)
+       {
+#if HAVE_LLVM >= 0x0700
+               return ::llvm::CloneModule(mod);
+#else
+               return ::llvm::CloneModule(&mod);
+#endif
+       }
+
+       template<typename T> void
+       write_bitcode_to_file(const ::llvm::Module &mod, T &os)
+       {
+#if HAVE_LLVM >= 0x0700
+               ::llvm::WriteBitcodeToFile(mod, os);
+#else
+               ::llvm::WriteBitcodeToFile(&mod, os);
+#endif
+       }
       }
    }
 }