2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "config_llvm.h"
31 #include "LLVMTrapCallback.h"
33 // Include some extra LLVM C++ headers. This is the only place where including LLVM C++
34 // headers is OK, since this module lives inside of the LLVM dylib we make and so can see
35 // otherwise private things. But to include those headers, we need to do some weird things
36 // first. Anyway, we should keep LLVM C++ includes to a minimum if possible.
38 #define __STDC_LIMIT_MACROS
39 #define __STDC_CONSTANT_MACROS
42 #pragma clang diagnostic push
43 #pragma clang diagnostic ignored "-Wmissing-noreturn"
44 #pragma clang diagnostic ignored "-Wunused-parameter"
45 #endif // COMPILER(CLANG)
47 #include <llvm/Support/CommandLine.h>
50 #pragma clang diagnostic pop
51 #endif // COMPILER(CLANG)
53 #undef __STDC_LIMIT_MACROS
54 #undef __STDC_CONSTANT_MACROS
56 static void llvmCrash(const char*) NO_RETURN
;
57 extern "C" WTF_EXPORT_PRIVATE
JSC::LLVMAPI
* initializeAndGetJSCLLVMAPI(
58 void (*)(const char*, ...) NO_RETURN
, bool* enableFastISel
);
60 static void llvmCrash(const char* reason
)
62 g_llvmTrapCallback("LLVM fatal error: %s", reason
);
65 template<typename
... Args
>
66 void initCommandLine(Args
... args
)
68 const char* theArgs
[] = { args
... };
69 llvm::cl::ParseCommandLineOptions(sizeof(theArgs
) / sizeof(const char*), theArgs
);
72 extern "C" JSC::LLVMAPI
* initializeAndGetJSCLLVMAPI(
73 void (*callback
)(const char*, ...) NO_RETURN
,
76 g_llvmTrapCallback
= callback
;
78 LLVMInstallFatalErrorHandler(llvmCrash
);
80 if (!LLVMStartMultithreaded())
81 callback("Could not start LLVM multithreading");
85 // You think you want to call LLVMInitializeNativeTarget()? Think again. This presumes that
86 // LLVM was ./configured correctly, which won't be the case in cross-compilation situations.
89 LLVMInitializeX86TargetInfo();
90 LLVMInitializeX86Target();
91 LLVMInitializeX86TargetMC();
92 LLVMInitializeX86AsmPrinter();
93 LLVMInitializeX86Disassembler();
95 #if (__IPHONE_OS_VERSION_MIN_REQUIRED > 80200) || OS(LINUX)
96 LLVMInitializeAArch64TargetInfo();
97 LLVMInitializeAArch64Target();
98 LLVMInitializeAArch64TargetMC();
99 LLVMInitializeAArch64AsmPrinter();
100 LLVMInitializeAArch64Disassembler();
102 LLVMInitializeARM64TargetInfo();
103 LLVMInitializeARM64Target();
104 LLVMInitializeARM64TargetMC();
105 LLVMInitializeARM64AsmPrinter();
106 LLVMInitializeARM64Disassembler();
109 UNREACHABLE_FOR_PLATFORM();
112 #if LLVM_VERSION_MAJOR >= 4 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6)
113 // It's OK to have fast ISel, if it was requested.
115 // We don't have enough support for fast ISel. Disable it.
116 *enableFastISel
= false;
120 initCommandLine("llvmForJSC.dylib", "-enable-misched=false", "-regalloc=basic");
122 initCommandLine("llvmForJSC.dylib", "-enable-patchpoint-liveness=true");
124 JSC::LLVMAPI
* result
= new JSC::LLVMAPI
;
126 // Initialize the whole thing to null.
127 memset(result
, 0, sizeof(*result
));
129 #define LLVM_API_FUNCTION_ASSIGNMENT(returnType, name, signature) \
130 result->name = LLVM##name;
131 FOR_EACH_LLVM_API_FUNCTION(LLVM_API_FUNCTION_ASSIGNMENT
);
132 #undef LLVM_API_FUNCTION_ASSIGNMENT
134 // Handle conditionally available functions.
135 #if LLVM_VERSION_MAJOR >= 4 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6)
136 result
->AddLowerSwitchPass
= LLVMAddLowerSwitchPass
;
144 // Create a dummy initializeAndGetJSCLLVMAPI to placate the build system.
145 extern "C" WTF_EXPORT_PRIVATE
void initializeAndGetJSCLLVMAPI();
146 extern "C" void initializeAndGetJSCLLVMAPI() { }