]> git.saurik.com Git - apple/javascriptcore.git/blame - jit/JITDriver.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / jit / JITDriver.h
CommitLineData
6fe7ccc8
A
1/*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef JITDriver_h
27#define JITDriver_h
28
29#include <wtf/Platform.h>
30
31#if ENABLE(JIT)
32
33#include "BytecodeGenerator.h"
34#include "DFGDriver.h"
35#include "JIT.h"
36#include "LLIntEntrypoints.h"
37
38namespace JSC {
39
40template<typename CodeBlockType>
93a37866 41inline bool jitCompileIfAppropriate(ExecState* exec, OwnPtr<CodeBlockType>& codeBlock, JITCode& jitCode, JITCode::JITType jitType, unsigned bytecodeIndex, JITCompilationEffort effort)
6fe7ccc8 42{
93a37866
A
43 VM& vm = exec->vm();
44
6fe7ccc8
A
45 if (jitType == codeBlock->getJITType())
46 return true;
47
93a37866 48 if (!vm.canUseJIT())
6fe7ccc8
A
49 return true;
50
51 codeBlock->unlinkIncomingCalls();
52
53 JITCode oldJITCode = jitCode;
54
55 bool dfgCompiled = false;
56 if (jitType == JITCode::DFGJIT)
93a37866 57 dfgCompiled = DFG::tryCompile(exec, codeBlock.get(), jitCode, bytecodeIndex);
6fe7ccc8
A
58 if (dfgCompiled) {
59 if (codeBlock->alternative())
60 codeBlock->alternative()->unlinkIncomingCalls();
61 } else {
62 if (codeBlock->alternative()) {
63 codeBlock = static_pointer_cast<CodeBlockType>(codeBlock->releaseAlternative());
64 jitCode = oldJITCode;
65 return false;
66 }
93a37866 67 jitCode = JIT::compile(&vm, codeBlock.get(), effort);
6fe7ccc8
A
68 if (!jitCode) {
69 jitCode = oldJITCode;
70 return false;
71 }
72 }
73 codeBlock->setJITCode(jitCode, MacroAssemblerCodePtr());
74
75 return true;
76}
77
93a37866 78inline bool jitCompileFunctionIfAppropriate(ExecState* exec, OwnPtr<FunctionCodeBlock>& codeBlock, JITCode& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, JITCode::JITType jitType, unsigned bytecodeIndex, JITCompilationEffort effort)
6fe7ccc8 79{
93a37866
A
80 VM& vm = exec->vm();
81
6fe7ccc8
A
82 if (jitType == codeBlock->getJITType())
83 return true;
84
93a37866 85 if (!vm.canUseJIT())
6fe7ccc8
A
86 return true;
87
88 codeBlock->unlinkIncomingCalls();
89
90 JITCode oldJITCode = jitCode;
91 MacroAssemblerCodePtr oldJITCodeWithArityCheck = jitCodeWithArityCheck;
92
93 bool dfgCompiled = false;
94 if (jitType == JITCode::DFGJIT)
93a37866 95 dfgCompiled = DFG::tryCompileFunction(exec, codeBlock.get(), jitCode, jitCodeWithArityCheck, bytecodeIndex);
6fe7ccc8
A
96 if (dfgCompiled) {
97 if (codeBlock->alternative())
98 codeBlock->alternative()->unlinkIncomingCalls();
99 } else {
100 if (codeBlock->alternative()) {
101 codeBlock = static_pointer_cast<FunctionCodeBlock>(codeBlock->releaseAlternative());
6fe7ccc8
A
102 jitCode = oldJITCode;
103 jitCodeWithArityCheck = oldJITCodeWithArityCheck;
104 return false;
105 }
93a37866 106 jitCode = JIT::compile(&vm, codeBlock.get(), effort, &jitCodeWithArityCheck);
6fe7ccc8
A
107 if (!jitCode) {
108 jitCode = oldJITCode;
109 jitCodeWithArityCheck = oldJITCodeWithArityCheck;
110 return false;
111 }
112 }
113 codeBlock->setJITCode(jitCode, jitCodeWithArityCheck);
114
115 return true;
116}
117
118} // namespace JSC
119
120#endif // ENABLE(JIT)
121
122#endif // JITDriver_h
123