Commit ef8dbf84 authored by fpizlo@apple.com's avatar fpizlo@apple.com

FTL: Soft-link LLVM as a workaround for LLVM's static initializers and exit-time destructors

https://bugs.webkit.org/show_bug.cgi?id=122566

Source/JavaScriptCore: 

Reviewed by Mark Rowe.
        
The JSC project now builds a libllvmForJSC.dylib. If FTL is enabled, this
gets copied into JavaScriptCore.framework/Versions/A/Libraries. JSC will
load the dylib by finding it using NSBundle APIs and then doing dlopen().
That will only happen lazily, when something happens that requires LLVM.
        
This mostly takes care of LLVM static initialization overhead by deferring
it until it's really needed.
        
This takes care of LLVM's exit-time destructors because inside
libllvmForJSC.dylib, we override __cxa_atexit.
        
* Configurations/JavaScriptCore.xcconfig:
* Configurations/LLVMForJSC.xcconfig: Added.
* JavaScriptCore.xcodeproj/project.pbxproj:
* dfg/DFGPlan.cpp:
(JSC::DFG::Plan::compileInThreadImpl):
* disassembler/LLVMDisassembler.cpp:
(JSC::tryToDisassembleWithLLVM):
* ftl/FTLAbbreviatedTypes.h:
* ftl/FTLAbbreviations.h:
(JSC::FTL::voidType):
(JSC::FTL::int1Type):
(JSC::FTL::int8Type):
(JSC::FTL::int16Type):
(JSC::FTL::int32Type):
(JSC::FTL::int64Type):
(JSC::FTL::intPtrType):
(JSC::FTL::floatType):
(JSC::FTL::doubleType):
(JSC::FTL::pointerType):
(JSC::FTL::structType):
(JSC::FTL::functionType):
(JSC::FTL::typeOf):
(JSC::FTL::mdKindID):
(JSC::FTL::mdString):
(JSC::FTL::mdNode):
(JSC::FTL::setMetadata):
(JSC::FTL::addFunction):
(JSC::FTL::setLinkage):
(JSC::FTL::setFunctionCallingConv):
(JSC::FTL::getParam):
(JSC::FTL::constInt):
(JSC::FTL::constReal):
(JSC::FTL::constIntToPtr):
(JSC::FTL::constBitCast):
(JSC::FTL::appendBasicBlock):
(JSC::FTL::insertBasicBlock):
(JSC::FTL::buildPhi):
(JSC::FTL::addIncoming):
(JSC::FTL::buildAlloca):
(JSC::FTL::buildAdd):
(JSC::FTL::buildSub):
(JSC::FTL::buildMul):
(JSC::FTL::buildDiv):
(JSC::FTL::buildRem):
(JSC::FTL::buildNeg):
(JSC::FTL::buildFAdd):
(JSC::FTL::buildFSub):
(JSC::FTL::buildFMul):
(JSC::FTL::buildFDiv):
(JSC::FTL::buildFRem):
(JSC::FTL::buildFNeg):
(JSC::FTL::buildAnd):
(JSC::FTL::buildOr):
(JSC::FTL::buildXor):
(JSC::FTL::buildShl):
(JSC::FTL::buildAShr):
(JSC::FTL::buildLShr):
(JSC::FTL::buildNot):
(JSC::FTL::buildLoad):
(JSC::FTL::buildStore):
(JSC::FTL::buildSExt):
(JSC::FTL::buildZExt):
(JSC::FTL::buildFPToSI):
(JSC::FTL::buildFPToUI):
(JSC::FTL::buildSIToFP):
(JSC::FTL::buildUIToFP):
(JSC::FTL::buildIntCast):
(JSC::FTL::buildFPCast):
(JSC::FTL::buildIntToPtr):
(JSC::FTL::buildPtrToInt):
(JSC::FTL::buildBitCast):
(JSC::FTL::buildICmp):
(JSC::FTL::buildFCmp):
(JSC::FTL::buildCall):
(JSC::FTL::setTailCall):
(JSC::FTL::buildExtractValue):
(JSC::FTL::buildSelect):
(JSC::FTL::buildBr):
(JSC::FTL::buildCondBr):
(JSC::FTL::buildSwitch):
(JSC::FTL::addCase):
(JSC::FTL::buildRet):
(JSC::FTL::buildUnreachable):
(JSC::FTL::dumpModule):
(JSC::FTL::verifyModule):
* ftl/FTLCompile.cpp:
(JSC::FTL::compile):
* ftl/FTLFail.cpp:
(JSC::FTL::fail):
* ftl/FTLJITCode.h:
* ftl/FTLJITFinalizer.h:
* ftl/FTLLink.cpp:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::lower):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::Output):
(JSC::FTL::Output::~Output):
* ftl/FTLOutput.h:
(JSC::FTL::Output::appendTo):
* ftl/FTLState.cpp:
(JSC::FTL::State::State):
(JSC::FTL::State::~State):
* ftl/WebKitLLVMLibraryAnchor.cpp: Removed.
* jsc.cpp:
(jscmain):
* llvm: Added.
* llvm/InitializeLLVM.cpp: Added.
(JSC::initializeLLVM):
* llvm/InitializeLLVM.h: Added.
* llvm/InitializeLLVMMac.mm: Added.
(JSC::initializeLLVMImpl):
* llvm/InitializeLLVMPOSIX.cpp: Added.
(JSC::initializeLLVMPOSIX):
* llvm/InitializeLLVMPOSIX.h: Added.
* llvm/LLVMAPI.cpp: Added.
* llvm/LLVMAPI.h: Added.
* llvm/LLVMAPIFunctions.h: Added.
* llvm/LLVMHeaders.h: Added.
* llvm/library: Added.
* llvm/library/LLVMAnchor.cpp: Added.
* llvm/library/LLVMExports.cpp: Added.
(initializeAndGetJSCLLVMAPI):
* llvm/library/LLVMOverrides.cpp: Added.
(__cxa_atexit):
* llvm/library/config_llvm.h: Added.
* runtime/InitializeThreading.cpp:
(JSC::initializeThreadingOnce):
* runtime/Options.h:

Source/WTF: 

Reviewed by Mark Rowe.
        
Remove all LLVM stuff from WTF since to get LLVM you need to soft-link and it's
entirely the responsibility of JSC to do that.
        
Also fixed an export goof that I found after fixing the weak thingy script in JSC.

* WTF.xcodeproj/project.pbxproj:
* wtf/LLVMHeaders.h: Removed.
* wtf/text/CString.h:
(WTF::CStringHash::hash):

Tools: 

Reviewed by Mark Rowe.

* Scripts/configure-llvm:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157260 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c89afb6d
2013-10-09 Filip Pizlo <fpizlo@apple.com>
FTL: Soft-link LLVM as a workaround for LLVM's static initializers and exit-time destructors
https://bugs.webkit.org/show_bug.cgi?id=122566
Reviewed by Mark Rowe.
The JSC project now builds a libllvmForJSC.dylib. If FTL is enabled, this
gets copied into JavaScriptCore.framework/Versions/A/Libraries. JSC will
load the dylib by finding it using NSBundle APIs and then doing dlopen().
That will only happen lazily, when something happens that requires LLVM.
This mostly takes care of LLVM static initialization overhead by deferring
it until it's really needed.
This takes care of LLVM's exit-time destructors because inside
libllvmForJSC.dylib, we override __cxa_atexit.
* Configurations/JavaScriptCore.xcconfig:
* Configurations/LLVMForJSC.xcconfig: Added.
* JavaScriptCore.xcodeproj/project.pbxproj:
* dfg/DFGPlan.cpp:
(JSC::DFG::Plan::compileInThreadImpl):
* disassembler/LLVMDisassembler.cpp:
(JSC::tryToDisassembleWithLLVM):
* ftl/FTLAbbreviatedTypes.h:
* ftl/FTLAbbreviations.h:
(JSC::FTL::voidType):
(JSC::FTL::int1Type):
(JSC::FTL::int8Type):
(JSC::FTL::int16Type):
(JSC::FTL::int32Type):
(JSC::FTL::int64Type):
(JSC::FTL::intPtrType):
(JSC::FTL::floatType):
(JSC::FTL::doubleType):
(JSC::FTL::pointerType):
(JSC::FTL::structType):
(JSC::FTL::functionType):
(JSC::FTL::typeOf):
(JSC::FTL::mdKindID):
(JSC::FTL::mdString):
(JSC::FTL::mdNode):
(JSC::FTL::setMetadata):
(JSC::FTL::addFunction):
(JSC::FTL::setLinkage):
(JSC::FTL::setFunctionCallingConv):
(JSC::FTL::getParam):
(JSC::FTL::constInt):
(JSC::FTL::constReal):
(JSC::FTL::constIntToPtr):
(JSC::FTL::constBitCast):
(JSC::FTL::appendBasicBlock):
(JSC::FTL::insertBasicBlock):
(JSC::FTL::buildPhi):
(JSC::FTL::addIncoming):
(JSC::FTL::buildAlloca):
(JSC::FTL::buildAdd):
(JSC::FTL::buildSub):
(JSC::FTL::buildMul):
(JSC::FTL::buildDiv):
(JSC::FTL::buildRem):
(JSC::FTL::buildNeg):
(JSC::FTL::buildFAdd):
(JSC::FTL::buildFSub):
(JSC::FTL::buildFMul):
(JSC::FTL::buildFDiv):
(JSC::FTL::buildFRem):
(JSC::FTL::buildFNeg):
(JSC::FTL::buildAnd):
(JSC::FTL::buildOr):
(JSC::FTL::buildXor):
(JSC::FTL::buildShl):
(JSC::FTL::buildAShr):
(JSC::FTL::buildLShr):
(JSC::FTL::buildNot):
(JSC::FTL::buildLoad):
(JSC::FTL::buildStore):
(JSC::FTL::buildSExt):
(JSC::FTL::buildZExt):
(JSC::FTL::buildFPToSI):
(JSC::FTL::buildFPToUI):
(JSC::FTL::buildSIToFP):
(JSC::FTL::buildUIToFP):
(JSC::FTL::buildIntCast):
(JSC::FTL::buildFPCast):
(JSC::FTL::buildIntToPtr):
(JSC::FTL::buildPtrToInt):
(JSC::FTL::buildBitCast):
(JSC::FTL::buildICmp):
(JSC::FTL::buildFCmp):
(JSC::FTL::buildCall):
(JSC::FTL::setTailCall):
(JSC::FTL::buildExtractValue):
(JSC::FTL::buildSelect):
(JSC::FTL::buildBr):
(JSC::FTL::buildCondBr):
(JSC::FTL::buildSwitch):
(JSC::FTL::addCase):
(JSC::FTL::buildRet):
(JSC::FTL::buildUnreachable):
(JSC::FTL::dumpModule):
(JSC::FTL::verifyModule):
* ftl/FTLCompile.cpp:
(JSC::FTL::compile):
* ftl/FTLFail.cpp:
(JSC::FTL::fail):
* ftl/FTLJITCode.h:
* ftl/FTLJITFinalizer.h:
* ftl/FTLLink.cpp:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::lower):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::Output):
(JSC::FTL::Output::~Output):
* ftl/FTLOutput.h:
(JSC::FTL::Output::appendTo):
* ftl/FTLState.cpp:
(JSC::FTL::State::State):
(JSC::FTL::State::~State):
* ftl/WebKitLLVMLibraryAnchor.cpp: Removed.
* jsc.cpp:
(jscmain):
* llvm: Added.
* llvm/InitializeLLVM.cpp: Added.
(JSC::initializeLLVM):
* llvm/InitializeLLVM.h: Added.
* llvm/InitializeLLVMMac.mm: Added.
(JSC::initializeLLVMImpl):
* llvm/InitializeLLVMPOSIX.cpp: Added.
(JSC::initializeLLVMPOSIX):
* llvm/InitializeLLVMPOSIX.h: Added.
* llvm/LLVMAPI.cpp: Added.
* llvm/LLVMAPI.h: Added.
* llvm/LLVMAPIFunctions.h: Added.
* llvm/LLVMHeaders.h: Added.
* llvm/library: Added.
* llvm/library/LLVMAnchor.cpp: Added.
* llvm/library/LLVMExports.cpp: Added.
(initializeAndGetJSCLLVMAPI):
* llvm/library/LLVMOverrides.cpp: Added.
(__cxa_atexit):
* llvm/library/config_llvm.h: Added.
* runtime/InitializeThreading.cpp:
(JSC::initializeThreadingOnce):
* runtime/Options.h:
2013-10-10 Mark Hahnenberg <mhahnenberg@apple.com>
currentThis and currentArguments crash if called from outside a callback
......@@ -35,15 +35,11 @@ JSVALUE_MODEL_x86_64 = 64;
// Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol -Wl,__ZTISt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTISt9exception -Wl,-unexported_symbol -Wl,__ZTSSt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTSSt9exception -Wl,-unexported_symbol -Wl,__ZdlPvS_ -Wl,-unexported_symbol -Wl,__ZnwmPv -Wl,-all_load;
OTHER_LDFLAGS_LLVM = $(OTHER_LDFLAGS_LLVM_$(ENABLE_FTL_JIT));
OTHER_LDFLAGS_LLVM_ = ;
OTHER_LDFLAGS_LLVM_ENABLE_FTL_JIT = -lpthread -lm -lLLVMTableGen -lLLVMDebugInfo -lLLVMOption -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMIRReader -lLLVMAsmParser -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInstrumentation -lLLVMBitReader -lLLVMInterpreter -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMBitWriter -lLLVMMCJIT -lLLVMJIT -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport;
OTHER_LDFLAGS_BASE = -lobjc -Wl,-Y,3 $(OTHER_LDFLAGS_HIDE_SYMBOLS);
OTHER_LDFLAGS = $(inherited) $(OTHER_LDFLAGS_$(PLATFORM_NAME));
OTHER_LDFLAGS_iphoneos = $(OTHER_LDFLAGS_BASE);
OTHER_LDFLAGS_iphonesimulator = $(OTHER_LDFLAGS_iphoneos);
OTHER_LDFLAGS_macosx = $(OTHER_LDFLAGS_BASE) $(OTHER_LDFLAGS_LLVM) -sub_library libobjc -framework CoreServices;
OTHER_LDFLAGS_macosx = $(OTHER_LDFLAGS_BASE) -sub_library libobjc -framework CoreServices;
GCC_PREFIX_HEADER = JavaScriptCorePrefix.h;
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
HEADER_SEARCH_PATHS = "${BUILT_PRODUCTS_DIR}/DerivedSources/JavaScriptCore" $(HEADER_SEARCH_PATHS);
......
// Copyright (C) 2013 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FeatureDefines.xcconfig"
#include "Version.xcconfig"
// Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol -Wl,__ZTISt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTISt9exception -Wl,-unexported_symbol -Wl,__ZTSSt9bad_alloc -Wl,-unexported_symbol -Wl,__ZTSSt9exception -Wl,-unexported_symbol -Wl,__ZdlPvS_ -Wl,-unexported_symbol -Wl,__ZnwmPv -Wl,-all_load;
OTHER_LDFLAGS_LLVM = $(OTHER_LDFLAGS_LLVM_$(ENABLE_FTL_JIT));
OTHER_LDFLAGS_LLVM_ = ;
OTHER_LDFLAGS_LLVM_ENABLE_FTL_JIT = -lpthread -lm -lLLVMTableGen -lLLVMDebugInfo -lLLVMOption -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMIRReader -lLLVMAsmParser -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInstrumentation -lLLVMBitReader -lLLVMInterpreter -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMBitWriter -lLLVMMCJIT -lLLVMJIT -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport;
OTHER_LDFLAGS_BASE = -lobjc -Wl,-Y,3 $(OTHER_LDFLAGS_HIDE_SYMBOLS);
OTHER_LDFLAGS = $(inherited) $(OTHER_LDFLAGS_$(PLATFORM_NAME));
OTHER_LDFLAGS_iphoneos = $(OTHER_LDFLAGS_BASE);
OTHER_LDFLAGS_iphonesimulator = $(OTHER_LDFLAGS_iphoneos);
OTHER_LDFLAGS_macosx = $(OTHER_LDFLAGS_BASE) $(OTHER_LDFLAGS_LLVM)
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore" $(HEADER_SEARCH_PATHS);
PRODUCT_NAME = llvmForJSC;
EXECUTABLE_PREFIX = lib;
......@@ -67,6 +67,7 @@
#include "FTLLink.h"
#include "FTLLowerDFGToLLVM.h"
#include "FTLState.h"
#include "InitializeLLVM.h"
#endif
namespace JSC { namespace DFG {
......@@ -255,8 +256,7 @@ Plan::CompilationPath Plan::compileInThreadImpl(LongLivedState& longLivedState)
dumpAndVerifyGraph(dfg, "Graph just before FTL lowering:");
// FIXME: Support OSR entry.
// https://bugs.webkit.org/show_bug.cgi?id=113625
initializeLLVM();
FTL::State state(dfg);
FTL::lowerDFGToLLVM(state);
......
......@@ -28,8 +28,9 @@
#if USE(LLVM_DISASSEMBLER)
#include "InitializeLLVM.h"
#include "LLVMAPI.h"
#include "MacroAssemblerCodeRef.h"
#include <wtf/LLVMHeaders.h>
namespace JSC {
......@@ -79,6 +80,8 @@ bool tryToDisassembleWithLLVM(
const MacroAssemblerCodePtr& codePtr, size_t size, const char* prefix, PrintStream& out,
InstructionSubsetHint)
{
initializeLLVM();
const char* triple;
#if CPU(X86_64)
triple = "x86_64-apple-darwin";
......@@ -91,7 +94,7 @@ bool tryToDisassembleWithLLVM(
char symbolString[symbolStringSize];
LLVMDisasmContextRef disassemblyContext =
LLVMCreateDisasm(triple, symbolString, 0, 0, symbolLookupCallback);
llvm->CreateDisasm(triple, symbolString, 0, 0, symbolLookupCallback);
RELEASE_ASSERT(disassemblyContext);
char pcString[20];
......@@ -105,7 +108,7 @@ bool tryToDisassembleWithLLVM(
pcString, sizeof(pcString), "0x%lx",
static_cast<unsigned long>(bitwise_cast<uintptr_t>(pc)));
size_t instructionSize = LLVMDisasmInstruction(
size_t instructionSize = llvm->DisasmInstruction(
disassemblyContext, pc, end - pc, bitwise_cast<uintptr_t>(pc),
instructionString, sizeof(instructionString));
......@@ -117,7 +120,7 @@ bool tryToDisassembleWithLLVM(
out.printf("%s%16s: %s\n", prefix, pcString, instructionString);
}
LLVMDisasmDispose(disassemblyContext);
llvm->DisasmDispose(disassemblyContext);
return true;
}
......
......@@ -30,7 +30,7 @@
#if ENABLE(FTL_JIT)
#include <wtf/LLVMHeaders.h>
#include "LLVMAPI.h"
namespace JSC { namespace FTL {
......
......@@ -37,9 +37,9 @@
#include "FTLJITCode.h"
#include "FTLThunks.h"
#include "JITStubs.h"
#include "LLVMAPI.h"
#include "LinkBuffer.h"
#include "RepatchBuffer.h"
#include <wtf/LLVMHeaders.h>
namespace JSC { namespace FTL {
......@@ -155,52 +155,52 @@ void compile(State& state)
char* error = 0;
LLVMMCJITCompilerOptions options;
LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
llvm->InitializeMCJITCompilerOptions(&options, sizeof(options));
options.OptLevel = Options::llvmBackendOptimizationLevel();
options.NoFramePointerElim = true;
if (Options::useLLVMSmallCodeModel())
options.CodeModel = LLVMCodeModelSmall;
options.EnableFastISel = Options::enableLLVMFastISel();
options.MCJMM = LLVMCreateSimpleMCJITMemoryManager(
options.MCJMM = llvm->CreateSimpleMCJITMemoryManager(
&state, mmAllocateCodeSection, mmAllocateDataSection, mmApplyPermissions, mmDestroy);
LLVMExecutionEngineRef engine;
if (LLVMCreateMCJITCompilerForModule(&engine, state.module, &options, sizeof(options), &error)) {
if (llvm->CreateMCJITCompilerForModule(&engine, state.module, &options, sizeof(options), &error)) {
dataLog("FATAL: Could not create LLVM execution engine: ", error, "\n");
CRASH();
}
LLVMPassManagerBuilderRef passBuilder = LLVMPassManagerBuilderCreate();
LLVMPassManagerBuilderSetOptLevel(passBuilder, Options::llvmOptimizationLevel());
LLVMPassManagerBuilderSetSizeLevel(passBuilder, Options::llvmSizeLevel());
LLVMPassManagerBuilderRef passBuilder = llvm->PassManagerBuilderCreate();
llvm->PassManagerBuilderSetOptLevel(passBuilder, Options::llvmOptimizationLevel());
llvm->PassManagerBuilderSetSizeLevel(passBuilder, Options::llvmSizeLevel());
LLVMPassManagerRef functionPasses = LLVMCreateFunctionPassManagerForModule(state.module);
LLVMPassManagerRef modulePasses = LLVMCreatePassManager();
LLVMPassManagerRef functionPasses = llvm->CreateFunctionPassManagerForModule(state.module);
LLVMPassManagerRef modulePasses = llvm->CreatePassManager();
LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), modulePasses);
llvm->AddTargetData(llvm->GetExecutionEngineTargetData(engine), modulePasses);
LLVMPassManagerBuilderPopulateFunctionPassManager(passBuilder, functionPasses);
LLVMPassManagerBuilderPopulateModulePassManager(passBuilder, modulePasses);
llvm->PassManagerBuilderPopulateFunctionPassManager(passBuilder, functionPasses);
llvm->PassManagerBuilderPopulateModulePassManager(passBuilder, modulePasses);
LLVMPassManagerBuilderDispose(passBuilder);
llvm->PassManagerBuilderDispose(passBuilder);
LLVMInitializeFunctionPassManager(functionPasses);
for (LValue function = LLVMGetFirstFunction(state.module); function; function = LLVMGetNextFunction(function))
LLVMRunFunctionPassManager(functionPasses, function);
LLVMFinalizeFunctionPassManager(functionPasses);
llvm->InitializeFunctionPassManager(functionPasses);
for (LValue function = llvm->GetFirstFunction(state.module); function; function = llvm->GetNextFunction(function))
llvm->RunFunctionPassManager(functionPasses, function);
llvm->FinalizeFunctionPassManager(functionPasses);
LLVMRunPassManager(modulePasses, state.module);
llvm->RunPassManager(modulePasses, state.module);
if (DFG::shouldShowDisassembly() || DFG::verboseCompilationEnabled())
state.dumpState("after optimization");
// FIXME: Need to add support for the case where JIT memory allocation failed.
// https://bugs.webkit.org/show_bug.cgi?id=113620
state.generatedFunction = reinterpret_cast<GeneratedFunction>(LLVMGetPointerToGlobal(engine, state.function));
LLVMDisposePassManager(functionPasses);
LLVMDisposePassManager(modulePasses);
LLVMDisposeExecutionEngine(engine);
state.generatedFunction = reinterpret_cast<GeneratedFunction>(llvm->GetPointerToGlobal(engine, state.function));
llvm->DisposePassManager(functionPasses);
llvm->DisposePassManager(modulePasses);
llvm->DisposeExecutionEngine(engine);
if (shouldShowDisassembly()) {
for (unsigned i = 0; i < state.jitCode->handles().size(); ++i) {
......
......@@ -30,7 +30,7 @@
#include "DFGFailedFinalizer.h"
#include "FTLJITCode.h"
#include <wtf/LLVMHeaders.h>
#include "LLVMAPI.h"
namespace JSC { namespace FTL {
......@@ -41,7 +41,7 @@ void fail(State& state)
state.graph.m_plan.finalizer = adoptPtr(new FailedFinalizer(state.graph.m_plan));
if (state.module)
LLVMDisposeModule(state.module);
llvm->DisposeModule(state.module);
}
} } // namespace JSC::FTL
......
......@@ -34,7 +34,7 @@
#include "FTLOSRExit.h"
#include "FTLStackMaps.h"
#include "JITCode.h"
#include <wtf/LLVMHeaders.h>
#include "LLVMAPI.h"
#include <wtf/RefCountedArray.h>
namespace JSC { namespace FTL {
......
......@@ -33,9 +33,9 @@
#include "DFGFinalizer.h"
#include "FTLGeneratedFunction.h"
#include "FTLJITCode.h"
#include "LLVMAPI.h"
#include "LinkBuffer.h"
#include "MacroAssembler.h"
#include <wtf/LLVMHeaders.h>
namespace JSC { namespace FTL {
......
......@@ -35,9 +35,9 @@
#include "FTLJITCode.h"
#include "JITOperations.h"
#include "JITStubs.h"
#include "LLVMAPI.h"
#include "LinkBuffer.h"
#include "VirtualRegister.h"
#include <wtf/LLVMHeaders.h>
namespace JSC { namespace FTL {
......
......@@ -97,7 +97,7 @@ public:
m_graph.m_dominators.computeIfNecessary(m_graph);
m_ftlState.module =
LLVMModuleCreateWithNameInContext(name.data(), m_ftlState.context);
llvm->ModuleCreateWithNameInContext(name.data(), m_ftlState.context);
m_ftlState.function = addFunction(
m_ftlState.module, name.data(), functionType(m_out.int64, m_out.intPtr));
......
......@@ -34,7 +34,7 @@ Output::Output(LContext context)
: IntrinsicRepository(context)
, m_function(0)
, m_heaps(0)
, m_builder(LLVMCreateBuilderInContext(m_context))
, m_builder(llvm->CreateBuilderInContext(m_context))
, m_block(0)
, m_nextBlock(0)
{
......@@ -42,7 +42,7 @@ Output::Output(LContext context)
Output::~Output()
{
LLVMDisposeBuilder(m_builder);
llvm->DisposeBuilder(m_builder);
}
} } // namespace JSC::FTL
......
......@@ -94,7 +94,7 @@ public:
{
m_block = block;
LLVMPositionBuilderAtEnd(m_builder, block);
llvm->PositionBuilderAtEnd(m_builder, block);
}
LBasicBlock newBlock(const char* name = "")
{
......
......@@ -39,7 +39,7 @@ using namespace DFG;
State::State(Graph& graph)
: graph(graph)
, context(LLVMContextCreate())
, context(llvm->ContextCreate())
, module(0)
, function(0)
, generatedFunction(0)
......@@ -67,7 +67,7 @@ State::State(Graph& graph)
State::~State()
{
LLVMContextDispose(context);
llvm->ContextDispose(context);
}
void State::dumpState(const char* when)
......
......@@ -846,10 +846,10 @@ int jscmain(int argc, char** argv)
// Note that the options parsing can affect VM creation, and thus
// comes first.
CommandLine options(argc, argv);
RefPtr<VM> vm = VM::create(LargeHeap);
VM* vm = VM::create(LargeHeap).leakRef();
int result;
{
APIEntryShim shim(vm.get());
APIEntryShim shim(vm);
if (options.m_profile && !vm->m_perBytecodeProfiler)
vm->m_perBytecodeProfiler = adoptPtr(new Profiler::Database(*vm));
......@@ -870,14 +870,6 @@ int jscmain(int argc, char** argv)
}
}
if (Options::neverDeleteVMInCommandLine()) {
JSC::VM* temp = vm.release().leakRef();
UNUSED_PARAM(temp);
} else {
JSLockHolder lock(*vm);
vm.clear();
}
return result;
}
......
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "InitializeLLVM.h"
#if HAVE(LLVM)
#include <pthread.h>
namespace JSC {
static pthread_once_t initializeLLVMOnceKey = PTHREAD_ONCE_INIT;
void initializeLLVM()
{
pthread_once(&initializeLLVMOnceKey, initializeLLVMImpl);
}
} // namespace JSC
#endif // HAVE(LLVM)
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef InitializeLLVM_h
#define InitializeLLVM_h
#include <wtf/Platform.h>
#if HAVE(LLVM)
namespace JSC {
void initializeLLVMImpl();
void initializeLLVM(); // It's safe to call this multiple times.
} // namespace JSC
#endif // HAVE(LLVM)
#endif // InitializeLLVM_h
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "InitializeLLVM.h"
#if HAVE(LLVM)
#import "InitializeLLVMPOSIX.h"
#import <Foundation/Foundation.h>
// Use the "JS" prefix to make check-for-inappropriate-objc-class-names happy. I
// think this is better than hacking that script.
@interface JSJavaScriptCoreBundleFinder : NSObject
@end
@implementation JSJavaScriptCoreBundleFinder
@end
namespace JSC {
void initializeLLVMImpl()
{
@autoreleasepool {
NSBundle *myBundle = [NSBundle bundleForClass:[JSJavaScriptCoreBundleFinder class]];
NSString *path = [[myBundle bundlePath] stringByAppendingPathComponent:@"Libraries/libllvmForJSC.dylib"];
initializeLLVMPOSIX([path UTF8String]);
}
}
} // namespace JSC
#endif // HAVE(LLVM)
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright