[llvm] Detect the cpu architecture and pass it to EngineBuilder, recent llvm versions...
authorZoltan Varga <vargaz@gmail.com>
Tue, 20 May 2014 13:00:23 +0000 (15:00 +0200)
committerZoltan Varga <vargaz@gmail.com>
Tue, 20 May 2014 13:00:35 +0000 (15:00 +0200)
mono/mini/mini-llvm-cpp.cpp

index dca376a9daa721568f76d383f6b9749f3d8aa62b..1f4775368c90fd71af4a0090a8327ef6a09f07e9 100644 (file)
@@ -31,6 +31,7 @@
 #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>
@@ -606,11 +607,17 @@ mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, Func
   opts.JITExceptionHandling = 1;
 
   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
-  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setCodeModel (CodeModel::Large).setAllocateGVsWithCode (true).create ();
-#else
-  ExecutionEngine *EE = b.setJITMemoryManager (mono_mm).setTargetOptions (opts).setAllocateGVsWithCode (true).create ();
+  eb = eb.setCodeModel (CodeModel::Large);
 #endif
+
+  ExecutionEngine *EE = eb.create ();
   g_assert (EE);
   mono_ee->EE = EE;