fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014, 2015 Apple Inc. All rights reserved. |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 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 | #include "config.h" |
| 27 | #include "DFGMayExit.h" |
| 28 | |
fpizlo@apple.com | 55b13b3 | 2014-07-25 22:43:19 +0000 | [diff] [blame] | 29 | #if ENABLE(DFG_JIT) |
| 30 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 31 | #include "DFGGraph.h" |
| 32 | #include "DFGNode.h" |
| 33 | #include "Operations.h" |
| 34 | |
| 35 | namespace JSC { namespace DFG { |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | class EdgeMayExit { |
| 40 | public: |
| 41 | EdgeMayExit() |
| 42 | : m_result(false) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void operator()(Node*, Edge edge) |
| 47 | { |
fpizlo@apple.com | b0d2836 | 2015-08-27 23:41:59 +0000 | [diff] [blame] | 48 | // FIXME: Maybe this should call mayHaveTypeCheck(edge.useKind()) instead. |
| 49 | // https://bugs.webkit.org/show_bug.cgi?id=148545 |
mark.lam@apple.com | 88fb7ac | 2015-04-25 15:43:45 +0000 | [diff] [blame] | 50 | if (edge.willHaveCheck()) { |
| 51 | m_result = true; |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | switch (edge.useKind()) { |
fpizlo@apple.com | 07e9078 | 2015-05-13 17:39:02 +0000 | [diff] [blame] | 56 | // 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.com | 88fb7ac | 2015-04-25 15:43:45 +0000 | [diff] [blame] | 59 | case ObjectUse: |
| 60 | case ObjectOrOtherUse: |
fpizlo@apple.com | 07e9078 | 2015-05-13 17:39:02 +0000 | [diff] [blame] | 61 | 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.com | 88fb7ac | 2015-04-25 15:43:45 +0000 | [diff] [blame] | 66 | case StringObjectUse: |
| 67 | case StringOrStringObjectUse: |
| 68 | m_result = true; |
| 69 | break; |
fpizlo@apple.com | 07e9078 | 2015-05-13 17:39:02 +0000 | [diff] [blame] | 70 | |
mark.lam@apple.com | 88fb7ac | 2015-04-25 15:43:45 +0000 | [diff] [blame] | 71 | default: |
| 72 | break; |
| 73 | } |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | bool result() const { return m_result; } |
| 77 | |
| 78 | private: |
| 79 | bool m_result; |
| 80 | }; |
| 81 | |
| 82 | } // anonymous namespace |
| 83 | |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 84 | ExitMode mayExit(Graph& graph, Node* node) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 85 | { |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 86 | ExitMode result = DoesNotExit; |
| 87 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 88 | switch (node->op()) { |
fpizlo@apple.com | 60de9f6 | 2015-04-21 20:16:18 +0000 | [diff] [blame] | 89 | // 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.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 91 | // generally make things a lot better but it might introduce subtle bugs. |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 92 | case SetArgument: |
| 93 | case JSConstant: |
| 94 | case DoubleConstant: |
fpizlo@apple.com | 024424c | 2016-03-09 05:16:47 +0000 | [diff] [blame] | 95 | case LazyJSConstant: |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 96 | case Int52Constant: |
| 97 | case MovHint: |
| 98 | case SetLocal: |
| 99 | case Flush: |
| 100 | case Phantom: |
| 101 | case Check: |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 102 | case Identity: |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 103 | case GetLocal: |
| 104 | case LoopHint: |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 105 | case Phi: |
| 106 | case Upsilon: |
| 107 | case ZombieHint: |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 108 | case ExitOK: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 109 | case BottomValue: |
fpizlo@apple.com | 8ff7471 | 2015-03-17 15:50:44 +0000 | [diff] [blame] | 110 | case PutHint: |
fpizlo@apple.com | fc70ba6 | 2014-09-26 03:59:33 +0000 | [diff] [blame] | 111 | case PhantomNewObject: |
fpizlo@apple.com | bcfd8eb | 2015-02-26 19:51:52 +0000 | [diff] [blame] | 112 | case PutStack: |
| 113 | case KillStack: |
| 114 | case GetStack: |
fpizlo@apple.com | a3bf601 | 2015-02-02 23:36:45 +0000 | [diff] [blame] | 115 | case GetCallee: |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 116 | case GetArgumentCount: |
sbarati@apple.com | 855d560 | 2015-11-30 20:36:54 +0000 | [diff] [blame] | 117 | case GetRestLength: |
fpizlo@apple.com | a3bf601 | 2015-02-02 23:36:45 +0000 | [diff] [blame] | 118 | case GetScope: |
| 119 | case PhantomLocal: |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 120 | case CountExecution: |
fpizlo@apple.com | 747f4af | 2015-04-23 20:47:31 +0000 | [diff] [blame] | 121 | case Jump: |
| 122 | case Branch: |
| 123 | case Unreachable: |
fpizlo@apple.com | 7425419 | 2015-04-27 18:31:26 +0000 | [diff] [blame] | 124 | case DoubleRep: |
| 125 | case Int52Rep: |
| 126 | case ValueRep: |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 127 | case ExtractOSREntryLocal: |
| 128 | case LogicalNot: |
| 129 | case NotifyWrite: |
| 130 | case PutStructure: |
| 131 | case StoreBarrier: |
| 132 | case PutByOffset: |
| 133 | case PutClosureVar: |
fpizlo@apple.com | 280ef00 | 2016-04-05 22:13:16 +0000 | [diff] [blame] | 134 | case RecordRegExpCachedResult: |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 135 | break; |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 136 | |
| 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.com | 9d9fd32 | 2015-12-17 10:33:08 +0000 | [diff] [blame] | 147 | case NewGeneratorFunction: |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 148 | case NewStringObject: |
| 149 | case CreateActivation: |
| 150 | result = ExitsForExceptions; |
| 151 | break; |
| 152 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 153 | default: |
| 154 | // If in doubt, return true. |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 155 | return Exits; |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | EdgeMayExit functor; |
| 159 | DFG_NODE_DO_TO_CHILDREN(graph, node, functor); |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 160 | if (functor.result()) |
| 161 | result = Exits; |
| 162 | |
| 163 | return result; |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | } } // namespace JSC::DFG |
| 167 | |
fpizlo@apple.com | f29186e | 2015-08-26 19:24:41 +0000 | [diff] [blame] | 168 | namespace WTF { |
| 169 | |
| 170 | using namespace JSC::DFG; |
| 171 | |
| 172 | void 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.com | 55b13b3 | 2014-07-25 22:43:19 +0000 | [diff] [blame] | 190 | #endif // ENABLE(DFG_JIT) |