s390x-codegen.h : Fix instruction definition and add instruction format variant
[mono.git] / mono / mini / mini-llvm-cpp.cpp
index dca376a9daa721568f76d383f6b9749f3d8aa62b..f11db19bc9620eabc37089ab0ddecd5f7fb1f77d 100644 (file)
 //
 
 #include "config.h"
-//undef those as llvm defines them on its own config.h as well.
-#undef PACKAGE_BUGREPORT
-#undef PACKAGE_NAME
-#undef PACKAGE_STRING
-#undef PACKAGE_TARNAME
-#undef PACKAGE_VERSION
 
 #include <stdint.h>
 
 #include <llvm/Support/raw_ostream.h>
+#include <llvm/Support/Host.h>
 #include <llvm/PassManager.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
 #include <llvm/ExecutionEngine/JITMemoryManager.h>
 
 #include "mini-llvm-cpp.h"
 
-#define LLVM_CHECK_VERSION(major,minor) \
-       ((LLVM_MAJOR_VERSION > (major)) ||                                                                      \
-        ((LLVM_MAJOR_VERSION == (major)) && (LLVM_MINOR_VERSION >= (minor))))
-
 // extern "C" void LLVMInitializeARMTargetInfo();
 // extern "C" void LLVMInitializeARMTarget ();
 // extern "C" void LLVMInitializeARMTargetMC ();
@@ -327,9 +318,25 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty,
 
 LLVMValueRef 
 mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
-                                         const char *Name, gboolean is_volatile)
+                                         const char *Name, gboolean is_volatile, BarrierKind barrier)
 {
-       return wrap(unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name));
+       LoadInst *ins = unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name);
+
+       switch (barrier) {
+       case LLVM_BARRIER_NONE:
+               break;
+       case LLVM_BARRIER_ACQ:
+               ins->setOrdering(Acquire);
+               break;
+       case LLVM_BARRIER_SEQ:
+               ins->setOrdering(SequentiallyConsistent);
+               break;
+       default:
+               g_assert_not_reached ();
+               break;
+       }
+
+       return wrap(ins);
 }
 
 LLVMValueRef 
@@ -346,9 +353,25 @@ mono_llvm_build_aligned_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
 
 LLVMValueRef 
 mono_llvm_build_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
-                                         gboolean is_volatile)
+                                         gboolean is_volatile, BarrierKind barrier)
 {
-       return wrap(unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile));
+       StoreInst *ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile);
+
+       switch (barrier) {
+       case LLVM_BARRIER_NONE:
+               break;
+       case LLVM_BARRIER_REL:
+               ins->setOrdering(Release);
+               break;
+       case LLVM_BARRIER_SEQ:
+               ins->setOrdering(SequentiallyConsistent);
+               break;
+       default:
+               g_assert_not_reached ();
+               break;
+       }
+
+       return wrap(ins);
 }
 
 LLVMValueRef 
@@ -394,16 +417,34 @@ mono_llvm_build_atomic_rmw (LLVMBuilderRef builder, AtomicRMWOp op, LLVMValueRef
                break;
        }
 
-       ins = unwrap (builder)->CreateAtomicRMW (aop, unwrap (ptr), unwrap (val), AcquireRelease);
+       ins = unwrap (builder)->CreateAtomicRMW (aop, unwrap (ptr), unwrap (val), SequentiallyConsistent);
        return wrap (ins);
 }
 
 LLVMValueRef
-mono_llvm_build_fence (LLVMBuilderRef builder)
+mono_llvm_build_fence (LLVMBuilderRef builder, BarrierKind kind)
 {
        FenceInst *ins;
+       AtomicOrdering ordering;
+
+       g_assert (kind != LLVM_BARRIER_NONE);
 
-       ins = unwrap (builder)->CreateFence (AcquireRelease);
+       switch (kind) {
+       case LLVM_BARRIER_ACQ:
+               ordering = Acquire;
+               break;
+       case LLVM_BARRIER_REL:
+               ordering = Release;
+               break;
+       case LLVM_BARRIER_SEQ:
+               ordering = SequentiallyConsistent;
+               break;
+       default:
+               g_assert_not_reached ();
+               break;
+       }
+
+       ins = unwrap (builder)->CreateFence (ordering);
        return wrap (ins);
 }
 
@@ -605,12 +646,34 @@ mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, Func
   TargetOptions opts;
   opts.JITExceptionHandling = 1;
 
-  EngineBuilder b (unwrap (MP));
+#if LLVM_API_VERSION >= 2
+  StringRef cpu_name = sys::getHostCPUName ();
+
+  // EngineBuilder no longer has a copy assignment operator (?)
+  std::unique_ptr<Module> Owner(unwrap(MP));
+  EngineBuilder b (std::move(Owner));
 #ifdef TARGET_AMD64
-  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setCodeModel (CodeModel::Large).setAllocateGVsWithCode (true).create ();
+  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true).setMCPU (cpu_name).setCodeModel (CodeModel::Large).create ();
 #else
-  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true).create ();
+  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true).setMCPU (cpu_name).create ();
 #endif
+
+#else
+
+  EngineBuilder b (unwrap (MP));
+  EngineBuilder &eb = b;
+  eb = eb.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true);
+#if LLVM_API_VERSION >= 1
+  StringRef cpu_name = sys::getHostCPUName ();
+  eb = eb.setMCPU (cpu_name);
+#endif
+#ifdef TARGET_AMD64
+  eb = eb.setCodeModel (CodeModel::Large);
+#endif
+
+  ExecutionEngine *EE = eb.create ();
+#endif
+
   g_assert (EE);
   mono_ee->EE = EE;