2 * Copyright (C) 2011 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 #ifndef DFGCapabilities_h
27 #define DFGCapabilities_h
29 #include "Intrinsic.h"
31 #include "Executable.h"
33 #include "Interpreter.h"
34 #include <wtf/Platform.h>
36 namespace JSC
{ namespace DFG
{
39 // Fast check functions; if they return true it is still necessary to
41 inline bool mightCompileEval(CodeBlock
* codeBlock
)
43 return codeBlock
->instructionCount() <= Options::maximumOptimizationCandidateInstructionCount
;
45 inline bool mightCompileProgram(CodeBlock
* codeBlock
)
47 return codeBlock
->instructionCount() <= Options::maximumOptimizationCandidateInstructionCount
;
49 inline bool mightCompileFunctionForCall(CodeBlock
* codeBlock
)
51 return codeBlock
->instructionCount() <= Options::maximumOptimizationCandidateInstructionCount
;
53 inline bool mightCompileFunctionForConstruct(CodeBlock
* codeBlock
)
55 return codeBlock
->instructionCount() <= Options::maximumOptimizationCandidateInstructionCount
;
58 inline bool mightInlineFunctionForCall(CodeBlock
* codeBlock
)
60 return codeBlock
->instructionCount() <= Options::maximumFunctionForCallInlineCandidateInstructionCount
61 && !codeBlock
->ownerExecutable()->needsActivation();
63 inline bool mightInlineFunctionForConstruct(CodeBlock
* codeBlock
)
65 return codeBlock
->instructionCount() <= Options::maximumFunctionForConstructInlineCandidateInstructionCount
66 && !codeBlock
->ownerExecutable()->needsActivation();
70 inline bool canCompileOpcode(OpcodeID opcodeID
)
93 #if ENABLE(DEBUG_WITH_BREAKPOINT)
97 case op_check_has_instance
:
118 case op_method_check
:
119 case op_get_scoped_var
:
120 case op_put_scoped_var
:
123 case op_put_by_id_transition_direct
:
124 case op_put_by_id_transition_normal
:
125 case op_get_global_var
:
126 case op_put_global_var
:
131 case op_loop_if_true
:
132 case op_loop_if_false
:
144 case op_loop_if_less
:
145 case op_loop_if_lesseq
:
146 case op_loop_if_greater
:
147 case op_loop_if_greatereq
:
150 case op_call_put_result
:
152 case op_resolve_base
:
153 case op_resolve_global
:
156 case op_new_array_buffer
:
158 case op_to_primitive
:
160 case op_throw_reference_error
:
164 case op_init_lazy_reg
:
165 case op_create_activation
:
166 case op_tear_off_activation
:
168 case op_new_func_exp
:
176 inline bool canInlineOpcode(OpcodeID opcodeID
)
180 // These opcodes would be easy to support with inlining, but we currently don't do it.
181 // The issue is that the scope chain will not be set correctly.
182 case op_get_scoped_var
:
183 case op_put_scoped_var
:
185 case op_resolve_base
:
186 case op_resolve_global
:
188 // Constant buffers aren't copied correctly. This is easy to fix, but for
189 // now we just disable inlining for functions that use them.
190 case op_new_array_buffer
:
192 // Inlining doesn't correctly remap regular expression operands.
196 // We don't support inlining code that creates activations or has nested functions.
197 case op_init_lazy_reg
:
198 case op_create_activation
:
199 case op_tear_off_activation
:
201 case op_new_func_exp
:
205 return canCompileOpcode(opcodeID
);
209 bool canCompileOpcodes(CodeBlock
*);
210 bool canInlineOpcodes(CodeBlock
*);
211 #else // ENABLE(DFG_JIT)
212 inline bool mightCompileEval(CodeBlock
*) { return false; }
213 inline bool mightCompileProgram(CodeBlock
*) { return false; }
214 inline bool mightCompileFunctionForCall(CodeBlock
*) { return false; }
215 inline bool mightCompileFunctionForConstruct(CodeBlock
*) { return false; }
216 inline bool mightInlineFunctionForCall(CodeBlock
*) { return false; }
217 inline bool mightInlineFunctionForConstruct(CodeBlock
*) { return false; }
219 inline bool canCompileOpcode(OpcodeID
) { return false; }
220 inline bool canInlineOpcode(OpcodeID
) { return false; }
221 inline bool canCompileOpcodes(CodeBlock
*) { return false; }
222 inline bool canInlineOpcodes(CodeBlock
*) { return false; }
223 #endif // ENABLE(DFG_JIT)
225 inline bool canCompileEval(CodeBlock
* codeBlock
)
227 return mightCompileEval(codeBlock
) && canCompileOpcodes(codeBlock
);
230 inline bool canCompileProgram(CodeBlock
* codeBlock
)
232 return mightCompileProgram(codeBlock
) && canCompileOpcodes(codeBlock
);
235 inline bool canCompileFunctionForCall(CodeBlock
* codeBlock
)
237 return mightCompileFunctionForCall(codeBlock
) && canCompileOpcodes(codeBlock
);
240 inline bool canCompileFunctionForConstruct(CodeBlock
* codeBlock
)
242 return mightCompileFunctionForConstruct(codeBlock
) && canCompileOpcodes(codeBlock
);
245 inline bool canInlineFunctionForCall(CodeBlock
* codeBlock
)
247 return mightInlineFunctionForCall(codeBlock
) && canInlineOpcodes(codeBlock
);
250 inline bool canInlineFunctionForConstruct(CodeBlock
* codeBlock
)
252 return mightInlineFunctionForConstruct(codeBlock
) && canInlineOpcodes(codeBlock
);
255 inline bool mightInlineFunctionFor(CodeBlock
* codeBlock
, CodeSpecializationKind kind
)
257 if (kind
== CodeForCall
)
258 return mightInlineFunctionForCall(codeBlock
);
259 ASSERT(kind
== CodeForConstruct
);
260 return mightInlineFunctionForConstruct(codeBlock
);
263 inline bool canInlineFunctionFor(CodeBlock
* codeBlock
, CodeSpecializationKind kind
)
265 if (kind
== CodeForCall
)
266 return canInlineFunctionForCall(codeBlock
);
267 ASSERT(kind
== CodeForConstruct
);
268 return canInlineFunctionForConstruct(codeBlock
);
271 } } // namespace JSC::DFG
273 #endif // DFGCapabilities_h