| 1 | /* |
| 2 | * Copyright (C) 2014-2016 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 | #pragma once |
| 27 | |
| 28 | #if ENABLE(DFG_JIT) |
| 29 | |
| 30 | namespace JSC { namespace DFG { |
| 31 | |
| 32 | class AtTailAbstractState; |
| 33 | class Graph; |
| 34 | struct Node; |
| 35 | |
| 36 | // A *very* conservative approximation of whether or not a node could possibly exit. Usually |
| 37 | // returns true except in cases where we obviously don't expect an exit. |
| 38 | |
| 39 | enum ExitMode { |
| 40 | // The node does not exit at all. This means that it's legal to eliminate the first store in a |
| 41 | // program like: |
| 42 | // |
| 43 | // global = 1 // first store |
| 44 | // DoesNotExit(); // let's assume that this also doesn't read "global" |
| 45 | // global = 2 // second store |
| 46 | // |
| 47 | // It's legal to eliminate the first one since nobody will see it; the second store is always |
| 48 | // executed right after. |
| 49 | DoesNotExit, |
| 50 | |
| 51 | // The node will exit, but only by properly throwing exceptions. A proper exception throw will |
| 52 | // divert execution to the matching op_catch and will not reexecute the exit origin. This means |
| 53 | // that the store elimination optimization above would be illegal, but the following would be OK: |
| 54 | // |
| 55 | // SideEffect(..., exit: bc#42) |
| 56 | // ExitsForExceptions(..., exit: #bc42, ExitInvalid) |
| 57 | // |
| 58 | // In particular, it's OK for a node that reports ExitsForExceptions to be executed in a context |
| 59 | // where !Node::origin.exitOK. That's because this node will not exit in a manner that could lead |
| 60 | // to the reexecution of SideEffect(). |
| 61 | ExitsForExceptions, |
| 62 | |
| 63 | // The node will exit to the exit origin. This means that we cannot do store elimination like for |
| 64 | // DoesNotExit and also we cannot place this node in an ExitInvalid context, since this will exit |
| 65 | // in a manner that will cause the reexecution of all previous operations within this exit origin. |
| 66 | Exits |
| 67 | }; |
| 68 | |
| 69 | // FIXME: This currently consumes the Check: flag produced by AI, and will claim that something doesn't |
| 70 | // exit if the Check: flag was cleared. This makes it hard to use mayExit() for things like hoisting |
| 71 | // (for example in LICM), since that wants to know if the node would exit if it was moved somewhere |
| 72 | // else. |
| 73 | // https://bugs.webkit.org/show_bug.cgi?id=148545 |
| 74 | |
| 75 | ExitMode mayExit(Graph&, Node*); |
| 76 | |
| 77 | // Like mayExit(), but instead of using the Check: flag to determine if something exits, it |
| 78 | // evaluates whether it will exit based on the tail state. This is useful for LICM. This *may* also |
| 79 | // use the AtTailAbstractState to return more precise answers for other nodes. |
| 80 | ExitMode mayExit(Graph&, Node*, AtTailAbstractState&); |
| 81 | |
| 82 | } } // namespace JSC::DFG |
| 83 | |
| 84 | namespace WTF { |
| 85 | |
| 86 | class PrintStream; |
| 87 | |
| 88 | void printInternal(PrintStream&, JSC::DFG::ExitMode); |
| 89 | |
| 90 | } // namespace WTF |
| 91 | |
| 92 | #endif // ENABLE(DFG_JIT) |
| 93 | |