Add support for z13 processor
[mono.git] / mono / mini / llvm-jit.cpp
index fe876b4ba30907b73c1c8ff6de883b433676c1b9..e10f65766c97c3db26ecd53d7415bbc893ff44c2 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2009-2011 Novell, Inc.
 // Copyright 2011-2015 Xamarin, Inc (http://www.xamarin.com)
 //
-
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 //
 // Mono's internal header files are not C++ clean, so avoid including them if 
 // possible
 #include "mini-llvm-cpp.h"
 #include "llvm-jit.h"
 
-extern "C" {
-#include <mono/utils/mono-dl.h>
-}
-
 #if !defined(MONO_CROSS_COMPILE) && LLVM_API_VERSION > 100
 
 /*
@@ -31,12 +27,18 @@ extern "C" {
 #include <llvm/Support/raw_ostream.h>
 #include <llvm/Support/Host.h>
 #include <llvm/Support/TargetSelect.h>
+#include <llvm/IR/Mangler.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
-#include "llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h"
+
+#include <cstdlib>
+
+extern "C" {
+#include <mono/utils/mono-dl.h>
+}
 
 using namespace llvm;
 using namespace llvm::orc;
@@ -64,6 +66,58 @@ void bzero (void *to, size_t count) { memset (to, 0, count); }
 
 #endif
 
+static AllocCodeMemoryCb *alloc_code_mem_cb;
+
+class MonoJitMemoryManager : public RTDyldMemoryManager
+{
+public:
+       ~MonoJitMemoryManager() override;
+
+       uint8_t *allocateDataSection(uintptr_t Size,
+                                                                unsigned Alignment,
+                                                                unsigned SectionID,
+                                                                StringRef SectionName,
+                                                                bool IsReadOnly) override;
+
+       uint8_t *allocateCodeSection(uintptr_t Size,
+                                                                unsigned Alignment,
+                                                                unsigned SectionID,
+                                                                StringRef SectionName) override;
+
+       bool finalizeMemory(std::string *ErrMsg = nullptr) override;
+};
+
+MonoJitMemoryManager::~MonoJitMemoryManager()
+{
+}
+
+uint8_t *
+MonoJitMemoryManager::allocateDataSection(uintptr_t Size,
+                                                                                 unsigned Alignment,
+                                                                                 unsigned SectionID,
+                                                                                 StringRef SectionName,
+                                                                                 bool IsReadOnly) {
+       uint8_t *res = (uint8_t*)malloc (Size);
+       assert (res);
+       memset (res, 0, Size);
+       return res;
+}
+
+uint8_t *
+MonoJitMemoryManager::allocateCodeSection(uintptr_t Size,
+                                                                                 unsigned Alignment,
+                                                                                 unsigned SectionID,
+                                                                                 StringRef SectionName)
+{
+       return alloc_code_mem_cb (NULL, Size);
+}
+
+bool
+MonoJitMemoryManager::finalizeMemory(std::string *ErrMsg)
+{
+       return false;
+}
+
 class MonoLLVMJIT {
 public:
        /* We use our own trampoline infrastructure instead of the Orc one */
@@ -105,7 +159,7 @@ public:
                                          } );
 
                return CompileLayer.addModuleSet(singletonSet(M),
-                                                                                 make_unique<SectionMemoryManager>(),
+                                                                                 make_unique<MonoJitMemoryManager>(),
                                                                                  std::move(Resolver));
        }
 
@@ -166,6 +220,8 @@ static MonoLLVMJIT *jit;
 MonoEERef
 mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb, LLVMExecutionEngineRef *ee)
 {
+       alloc_code_mem_cb = alloc_cb;
+
        InitializeNativeTarget ();
        InitializeNativeTargetAsmPrinter();
 
@@ -474,7 +530,11 @@ static void
 force_pass_linking (void)
 {
        // Make sure the rest is linked in, but never executed
-       if (g_getenv ("FOO") != (char*)-1)
+       char *foo = g_getenv ("FOO");
+       gboolean ret = (foo != (char*)-1);
+       g_free (foo);
+
+       if (ret) 
                return;
 
        // This is a subset of the passes in LinkAllPasses.h
@@ -760,6 +820,13 @@ mono_llvm_optimize_method (MonoEERef eeref, LLVMValueRef method)
        g_assert_not_reached ();
 }
 
+gpointer
+mono_llvm_compile_method (MonoEERef mono_ee, LLVMValueRef method, int nvars, LLVMValueRef *callee_vars, gpointer *callee_addrs, gpointer *eh_frame)
+{
+       g_assert_not_reached ();
+       return NULL;
+}
+
 void
 mono_llvm_dispose_ee (MonoEERef *eeref)
 {