blob: 5c5c60ebc8bcb4b200e35dfdf4dc4206c150f9e8 [file] [log] [blame]
fpizlo@apple.comb41e6822014-07-25 20:55:17 +00001/*
fpizlo@apple.com8fefdd32015-02-18 19:55:47 +00002 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
fpizlo@apple.comb41e6822014-07-25 20:55:17 +00003 *
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#include "config.h"
27#include "DFGMayExit.h"
28
fpizlo@apple.com55b13b32014-07-25 22:43:19 +000029#if ENABLE(DFG_JIT)
30
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000031#include "DFGGraph.h"
32#include "DFGNode.h"
33#include "Operations.h"
34
35namespace JSC { namespace DFG {
36
37namespace {
38
39class EdgeMayExit {
40public:
41 EdgeMayExit()
42 : m_result(false)
43 {
44 }
45
46 void operator()(Node*, Edge edge)
47 {
fpizlo@apple.comb0d28362015-08-27 23:41:59 +000048 // FIXME: Maybe this should call mayHaveTypeCheck(edge.useKind()) instead.
49 // https://bugs.webkit.org/show_bug.cgi?id=148545
mark.lam@apple.com88fb7ac2015-04-25 15:43:45 +000050 if (edge.willHaveCheck()) {
51 m_result = true;
52 return;
53 }
54
55 switch (edge.useKind()) {
fpizlo@apple.com07e90782015-05-13 17:39:02 +000056 // These are shady because nodes that have these use kinds will typically exit for
57 // unrelated reasons. For example CompareEq doesn't usually exit, but if it uses ObjectUse
58 // then it will.
mark.lam@apple.com88fb7ac2015-04-25 15:43:45 +000059 case ObjectUse:
60 case ObjectOrOtherUse:
fpizlo@apple.com07e90782015-05-13 17:39:02 +000061 m_result = true;
62 break;
63
64 // These are shady because they check the structure even if the type of the child node
65 // passes the StringObject type filter.
mark.lam@apple.com88fb7ac2015-04-25 15:43:45 +000066 case StringObjectUse:
67 case StringOrStringObjectUse:
68 m_result = true;
69 break;
fpizlo@apple.com07e90782015-05-13 17:39:02 +000070
mark.lam@apple.com88fb7ac2015-04-25 15:43:45 +000071 default:
72 break;
73 }
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000074 }
75
76 bool result() const { return m_result; }
77
78private:
79 bool m_result;
80};
81
82} // anonymous namespace
83
fpizlo@apple.comf29186e2015-08-26 19:24:41 +000084ExitMode mayExit(Graph& graph, Node* node)
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000085{
fpizlo@apple.comf29186e2015-08-26 19:24:41 +000086 ExitMode result = DoesNotExit;
87
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000088 switch (node->op()) {
fpizlo@apple.com60de9f62015-04-21 20:16:18 +000089 // This is a carefully curated list of nodes that definitely do not exit. We try to be very
90 // conservative when maintaining this list, because adding new node types to it doesn't
fpizlo@apple.comf29186e2015-08-26 19:24:41 +000091 // generally make things a lot better but it might introduce subtle bugs.
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000092 case SetArgument:
93 case JSConstant:
94 case DoubleConstant:
fpizlo@apple.com024424c2016-03-09 05:16:47 +000095 case LazyJSConstant:
fpizlo@apple.comb41e6822014-07-25 20:55:17 +000096 case Int52Constant:
97 case MovHint:
98 case SetLocal:
99 case Flush:
100 case Phantom:
101 case Check:
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000102 case Identity:
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000103 case GetLocal:
104 case LoopHint:
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000105 case Phi:
106 case Upsilon:
107 case ZombieHint:
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000108 case ExitOK:
fpizlo@apple.comfc70ba62014-09-26 03:59:33 +0000109 case BottomValue:
fpizlo@apple.com8ff74712015-03-17 15:50:44 +0000110 case PutHint:
fpizlo@apple.comfc70ba62014-09-26 03:59:33 +0000111 case PhantomNewObject:
fpizlo@apple.combcfd8eb2015-02-26 19:51:52 +0000112 case PutStack:
113 case KillStack:
114 case GetStack:
fpizlo@apple.coma3bf6012015-02-02 23:36:45 +0000115 case GetCallee:
fpizlo@apple.comda834ae2015-03-26 04:28:43 +0000116 case GetArgumentCount:
sbarati@apple.com855d5602015-11-30 20:36:54 +0000117 case GetRestLength:
fpizlo@apple.coma3bf6012015-02-02 23:36:45 +0000118 case GetScope:
119 case PhantomLocal:
fpizlo@apple.com8fefdd32015-02-18 19:55:47 +0000120 case CountExecution:
fpizlo@apple.com747f4af2015-04-23 20:47:31 +0000121 case Jump:
122 case Branch:
123 case Unreachable:
fpizlo@apple.com74254192015-04-27 18:31:26 +0000124 case DoubleRep:
125 case Int52Rep:
126 case ValueRep:
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000127 case ExtractOSREntryLocal:
128 case LogicalNot:
129 case NotifyWrite:
130 case PutStructure:
131 case StoreBarrier:
132 case PutByOffset:
133 case PutClosureVar:
fpizlo@apple.com280ef002016-04-05 22:13:16 +0000134 case RecordRegExpCachedResult:
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000135 break;
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000136
137 case StrCat:
138 case Call:
139 case Construct:
140 case CallVarargs:
141 case ConstructVarargs:
142 case CallForwardVarargs:
143 case ConstructForwardVarargs:
144 case MaterializeCreateActivation:
145 case MaterializeNewObject:
146 case NewFunction:
utatane.tea@gmail.com9d9fd322015-12-17 10:33:08 +0000147 case NewGeneratorFunction:
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000148 case NewStringObject:
149 case CreateActivation:
150 result = ExitsForExceptions;
151 break;
152
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000153 default:
154 // If in doubt, return true.
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000155 return Exits;
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000156 }
157
158 EdgeMayExit functor;
159 DFG_NODE_DO_TO_CHILDREN(graph, node, functor);
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000160 if (functor.result())
161 result = Exits;
162
163 return result;
fpizlo@apple.comb41e6822014-07-25 20:55:17 +0000164}
165
166} } // namespace JSC::DFG
167
fpizlo@apple.comf29186e2015-08-26 19:24:41 +0000168namespace WTF {
169
170using namespace JSC::DFG;
171
172void printInternal(PrintStream& out, ExitMode mode)
173{
174 switch (mode) {
175 case DoesNotExit:
176 out.print("DoesNotExit");
177 return;
178 case ExitsForExceptions:
179 out.print("ExitsForExceptions");
180 return;
181 case Exits:
182 out.print("Exits");
183 return;
184 }
185 RELEASE_ASSERT_NOT_REACHED();
186}
187
188} // namespace WTF
189
fpizlo@apple.com55b13b32014-07-25 22:43:19 +0000190#endif // ENABLE(DFG_JIT)