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 | #include "CodeOrigin.h" |
31 | #include "DFGClobbersExitState.h" |
32 | |
33 | namespace JSC { namespace DFG { |
34 | |
35 | class Graph; |
36 | struct Node; |
37 | |
38 | struct NodeOrigin { |
39 | NodeOrigin() { } |
40 | |
41 | NodeOrigin(CodeOrigin semantic, CodeOrigin forExit, bool exitOK) |
42 | : semantic(semantic) |
43 | , forExit(forExit) |
44 | , exitOK(exitOK) |
45 | { |
46 | } |
47 | |
48 | bool isSet() const |
49 | { |
50 | ASSERT(semantic.isSet() == forExit.isSet()); |
51 | return semantic.isSet(); |
52 | } |
53 | |
54 | NodeOrigin withSemantic(CodeOrigin semantic) const |
55 | { |
56 | if (!isSet()) |
57 | return NodeOrigin(); |
58 | |
59 | NodeOrigin result = *this; |
60 | if (semantic.isSet()) |
61 | result.semantic = semantic; |
62 | return result; |
63 | } |
64 | |
65 | NodeOrigin withForExitAndExitOK(CodeOrigin forExit, bool exitOK) const |
66 | { |
67 | if (!isSet()) |
68 | return NodeOrigin(); |
69 | |
70 | NodeOrigin result = *this; |
71 | if (forExit.isSet()) |
72 | result.forExit = forExit; |
73 | result.exitOK = exitOK; |
74 | return result; |
75 | } |
76 | |
77 | NodeOrigin withExitOK(bool value) const |
78 | { |
79 | NodeOrigin result = *this; |
80 | result.exitOK = value; |
81 | return result; |
82 | } |
83 | |
84 | NodeOrigin withInvalidExit() const |
85 | { |
86 | return withExitOK(false); |
87 | } |
88 | |
89 | NodeOrigin takeValidExit(bool& canExit) const |
90 | { |
91 | return withExitOK(exitOK & std::exchange(canExit, false)); |
92 | } |
93 | |
94 | NodeOrigin withWasHoisted() const |
95 | { |
96 | NodeOrigin result = *this; |
97 | result.wasHoisted = true; |
98 | return result; |
99 | } |
100 | |
101 | NodeOrigin forInsertingAfter(Graph& graph, Node* node) const |
102 | { |
103 | NodeOrigin result = *this; |
104 | if (exitOK && clobbersExitState(graph, node)) |
105 | result.exitOK = false; |
106 | return result; |
107 | } |
108 | |
109 | bool operator==(const NodeOrigin& other) const |
110 | { |
111 | return semantic == other.semantic |
112 | && forExit == other.forExit |
113 | && exitOK == other.exitOK; |
114 | } |
115 | |
116 | bool operator!=(const NodeOrigin& other) const |
117 | { |
118 | return !(*this == other); |
119 | } |
120 | |
121 | void dump(PrintStream&) const; |
122 | |
123 | // Used for determining what bytecode this came from. This is important for |
124 | // debugging, exceptions, and even basic execution semantics. |
125 | CodeOrigin semantic; |
126 | // Code origin for where the node exits to. |
127 | CodeOrigin forExit; |
128 | // Whether or not it is legal to exit here. |
129 | bool exitOK { false }; |
130 | // Whether or not the node has been hoisted. |
131 | bool wasHoisted { false }; |
132 | }; |
133 | |
134 | } } // namespace JSC::DFG |
135 | |
136 | #endif // ENABLE(DFG_JIT) |
137 | |