revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / gallium / auxiliary / gallivm / lp_bld_misc.cpp
blob85fabc574b22be88ce0303ef860e6e94e7997724
1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
26 **************************************************************************/
29 #ifndef __STDC_LIMIT_MACROS
30 #define __STDC_LIMIT_MACROS
31 #endif
33 #ifndef __STDC_CONSTANT_MACROS
34 #define __STDC_CONSTANT_MACROS
35 #endif
37 #include <llvm-c/Core.h>
38 #include <llvm-c/ExecutionEngine.h>
39 #include <llvm/Target/TargetOptions.h>
40 #include <llvm/ExecutionEngine/ExecutionEngine.h>
41 #include <llvm/ExecutionEngine/JITEventListener.h>
42 #include <llvm/Support/CommandLine.h>
43 #include <llvm/Support/PrettyStackTrace.h>
45 #include "pipe/p_config.h"
46 #include "util/u_debug.h"
49 /**
50 * Register the engine with oprofile.
52 * This allows to see the LLVM IR function names in oprofile output.
54 * To actually work LLVM needs to be built with the --with-oprofile configure
55 * option.
57 * Also a oprofile:oprofile user:group is necessary. Which is not created by
58 * default on some distributions.
60 extern "C" void
61 lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE)
63 llvm::unwrap(EE)->RegisterJITEventListener(llvm::createOProfileJITEventListener());
67 extern "C" void
68 lp_set_target_options(void)
70 #if defined(DEBUG)
71 #if HAVE_LLVM >= 0x0207
72 llvm::JITEmitDebugInfo = true;
73 #endif
74 #endif
77 * LLVM revision 123367 switched the default stack alignment to 16 bytes on
78 * Linux (and several other Unices in later revisions), to match recent gcc
79 * versions.
81 * However our drivers can be loaded by old binary applications, still
82 * maintaining a 4 bytes stack alignment. Therefore we must tell LLVM here
83 * to only assume a 4 bytes alignment for backwards compatibility.
85 #if defined(PIPE_ARCH_X86)
86 #if HAVE_LLVM >= 0x0300
87 llvm::StackAlignmentOverride = 4;
88 #else
89 llvm::StackAlignment = 4;
90 #endif
91 #endif
93 #if defined(DEBUG) || defined(PROFILE)
94 llvm::NoFramePointerElim = true;
95 #endif
97 llvm::NoExcessFPPrecision = false;
99 /* XXX: Investigate this */
100 #if 0
101 llvm::UnsafeFPMath = true;
102 #endif
104 #if HAVE_LLVM < 0x0209
106 * LLVM will generate MMX instructions for vectors <= 64 bits, leading to
107 * innefficient code, and in 32bit systems, to the corruption of the FPU
108 * stack given that it expects the user to generate the EMMS instructions.
110 * See also:
111 * - http://llvm.org/bugs/show_bug.cgi?id=3287
112 * - http://l4.me.uk/post/2009/06/07/llvm-wrinkle-3-configuration-what-configuration/
114 * The -disable-mmx global option can be specified only once since we
115 * dynamically link against LLVM it will reside in a separate shared object,
116 * which may or not be delete when this shared object is, so we use the
117 * llvm::DisablePrettyStackTrace variable (which we set below and should
118 * reside in the same shared library) to determine whether the -disable-mmx
119 * option has been set or not.
121 * Thankfully this ugly hack is not necessary on LLVM 2.9 onwards.
123 if (!llvm::DisablePrettyStackTrace) {
124 static boolean first = TRUE;
125 static const char* options[] = {
126 "prog",
127 "-disable-mmx"
129 assert(first);
130 llvm::cl::ParseCommandLineOptions(2, const_cast<char**>(options));
131 first = FALSE;
133 #endif
136 * By default LLVM adds a signal handler to output a pretty stack trace.
137 * This signal handler is never removed, causing problems when unloading the
138 * shared object where the gallium driver resides.
140 llvm::DisablePrettyStackTrace = true;
144 extern "C" void
145 lp_func_delete_body(LLVMValueRef FF)
147 llvm::Function *func = llvm::unwrap<llvm::Function>(FF);
148 func->deleteBody();
152 extern "C"
153 LLVMValueRef
154 lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
155 const char *Name)
157 return llvm::wrap(llvm::unwrap(B)->CreateLoad(llvm::unwrap(PointerVal), true, Name));