gallivm: Move the global LLVM objects (module, engine, provider, target) into here.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 6 Apr 2010 21:37:08 +0000 (22:37 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 6 Apr 2010 21:52:33 +0000 (22:52 +0100)
src/gallium/auxiliary/Makefile
src/gallium/auxiliary/SConscript
src/gallium/auxiliary/gallivm/lp_bld_init.c [new file with mode: 0644]
src/gallium/auxiliary/gallivm/lp_bld_init.cpp [deleted file]
src/gallium/auxiliary/gallivm/lp_bld_init.h
src/gallium/drivers/llvmpipe/lp_jit.c

index 2258a486616ab24075d101ddd60f06908ee975c8..5beda9267ea59d31f978ba9132f2543cbd8fa145 100644 (file)
@@ -152,6 +152,7 @@ GALLIVM_SOURCES = \
         gallivm/lp_bld_depth.c \
         gallivm/lp_bld_flow.c \
         gallivm/lp_bld_format_soa.c \
+        gallivm/lp_bld_init.c \
         gallivm/lp_bld_interp.c \
         gallivm/lp_bld_intr.c \
         gallivm/lp_bld_logic.c \
@@ -164,8 +165,7 @@ GALLIVM_SOURCES = \
         gallivm/lp_bld_tgsi_soa.c \
         gallivm/lp_bld_type.c
 
-GALLIVM_CPP_SOURCES = \
-        gallivm/lp_bld_init.cpp
+GALLIVM_CPP_SOURCES =
 
 GENERATED_SOURCES = \
        indices/u_indices_gen.c \
index e68b32117336293c2dd0cec08d957ff0fdad765a..ae749acc87ea4559982920fea4a054fcefe74e7f 100644 (file)
@@ -204,7 +204,7 @@ if drawllvm:
     'gallivm/lp_bld_interp.c',
     'gallivm/lp_bld_intr.c',
     'gallivm/lp_bld_logic.c',
-    'gallivm/lp_bld_init.cpp',
+    'gallivm/lp_bld_init.c',
     'gallivm/lp_bld_pack.c',
     'gallivm/lp_bld_printf.c',
     'gallivm/lp_bld_sample.c',
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
new file mode 100644 (file)
index 0000000..de07c22
--- /dev/null
@@ -0,0 +1,78 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "pipe/p_compiler.h"
+#include "util/u_debug.h"
+#include "lp_bld_init.h"
+
+
+LLVMModuleRef lp_build_module = NULL;
+LLVMExecutionEngineRef lp_build_engine = NULL;
+LLVMModuleProviderRef lp_build_provider = NULL;
+LLVMTargetDataRef lp_build_target = NULL;
+
+
+void
+lp_build_init(void)
+{
+   LLVMInitializeNativeTarget();
+
+   LLVMLinkInJIT();
+
+   if (!lp_build_module)
+      lp_build_module = LLVMModuleCreateWithName("gallivm");
+
+   if (!lp_build_provider)
+      lp_build_provider = LLVMCreateModuleProviderForExistingModule(lp_build_module);
+
+   if (!lp_build_engine) {
+      char *error = NULL;
+
+      if (LLVMCreateJITCompiler(&lp_build_engine, lp_build_provider, 1, &error)) {
+         _debug_printf("%s\n", error);
+         LLVMDisposeMessage(error);
+         assert(0);
+      }
+   }
+
+   if (!lp_build_target)
+      lp_build_target = LLVMGetExecutionEngineTargetData(lp_build_engine);
+}
+
+
+/* 
+ * Hack to allow the linking of release LLVM static libraries on a debug build.
+ *
+ * See also:
+ * - http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/7234ea2b-0042-42ed-b4e2-5d8644dfb57d
+ */
+#if defined(_MSC_VER) && defined(_DEBUG)
+#include <crtdefs.h>
+_CRTIMP void __cdecl
+_invalid_parameter_noinfo(void) {}
+#endif
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.cpp b/src/gallium/auxiliary/gallivm/lp_bld_init.cpp
deleted file mode 100644 (file)
index 067397a..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include <llvm/Config/config.h>
-#include <llvm/Target/TargetSelect.h>
-#include <llvm/Target/TargetOptions.h>
-
-#include "pipe/p_config.h"
-
-#include "lp_bld_init.h"
-
-
-extern "C" void LLVMLinkInJIT();
-
-
-extern "C" void
-lp_build_init(void)
-{
-#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86)
-   /*
-    * This is mis-detected on some hardware / software combinations.
-    */
-   llvm::StackAlignment = 4;
-   llvm::RealignStack = true;
-#endif
-
-   /* Same as LLVMInitializeNativeTarget(); */
-   llvm::InitializeNativeTarget();
-
-   LLVMLinkInJIT();
-}
-
-
-/* 
- * Hack to allow the linking of release LLVM static libraries on a debug build.
- *
- * See also:
- * - http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/7234ea2b-0042-42ed-b4e2-5d8644dfb57d
- */
-#if defined(_MSC_VER) && defined(_DEBUG)
-#include <crtdefs.h>
-extern "C" _CRTIMP void __cdecl
-_invalid_parameter_noinfo(void) {}
-#endif
index 07f50d1c43391e2f8040d46b16eba7eb7885deaf..0ec2afcd1be153c35ee04aff64ab7b307071367e 100644 (file)
 #define LP_BLD_INIT_H
 
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "lp_bld.h"
+#include <llvm-c/ExecutionEngine.h>
 
 
-void
-lp_build_init(void);
+extern LLVMModuleRef lp_build_module;
+extern LLVMExecutionEngineRef lp_build_engine;
+extern LLVMModuleProviderRef lp_build_provider;
+extern LLVMTargetDataRef lp_build_target;
 
 
-#ifdef __cplusplus
-}
-#endif
+void
+lp_build_init(void);
 
 
 #endif /* !LP_BLD_INIT_H */
index 927e472ff26a20240147b31301dc084027245a9a..2f804bb11c202e1d6f482280ab7772fcd2d95215 100644 (file)
@@ -166,8 +166,6 @@ lp_jit_screen_cleanup(struct llvmpipe_screen *screen)
 void
 lp_jit_screen_init(struct llvmpipe_screen *screen)
 {
-   char *error = NULL;
-
    util_cpu_detect();
 
 #if 0
@@ -179,17 +177,10 @@ lp_jit_screen_init(struct llvmpipe_screen *screen)
 
    lp_build_init();
 
-   screen->module = LLVMModuleCreateWithName("llvmpipe");
-
-   screen->provider = LLVMCreateModuleProviderForExistingModule(screen->module);
-
-   if (LLVMCreateJITCompiler(&screen->engine, screen->provider, 1, &error)) {
-      _debug_printf("%s\n", error);
-      LLVMDisposeMessage(error);
-      assert(0);
-   }
-
-   screen->target = LLVMGetExecutionEngineTargetData(screen->engine);
+   screen->module = lp_build_module;
+   screen->provider = lp_build_provider;
+   screen->engine = lp_build_engine;
+   screen->target = lp_build_target;
 
    screen->pass = LLVMCreateFunctionPassManager(screen->provider);
    LLVMAddTargetData(screen->target, screen->pass);