]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2013-2015 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 | #include "config.h" | |
27 | #include "DFGWatchpointCollectionPhase.h" | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "ArrayPrototype.h" | |
32 | #include "DFGClobberize.h" | |
33 | #include "DFGGraph.h" | |
34 | #include "DFGPhase.h" | |
35 | #include "JSCInlines.h" | |
36 | ||
37 | // FIXME: Remove this phase entirely by moving the addLazily() calls into either the backend or | |
38 | // into the phase that performs the optimization. Moving the calls into the backend makes the most | |
39 | // sense when the intermediate phases don't need to know that the watchpoint was set. Moving the | |
40 | // calls earlier usually only makes sense if the node's only purpose was to convey the need for | |
41 | // the watchpoint (like VarInjectionWatchpoint). But, it can also make sense if the fact that the | |
42 | // watchpoint was set enables other optimizations. | |
43 | // https://bugs.webkit.org/show_bug.cgi?id=144669 | |
44 | ||
45 | namespace JSC { namespace DFG { | |
46 | ||
47 | class WatchpointCollectionPhase : public Phase { | |
48 | static const bool verbose = false; | |
49 | ||
50 | public: | |
51 | WatchpointCollectionPhase(Graph& graph) | |
52 | : Phase(graph, "watchpoint collection") | |
53 | { | |
54 | } | |
55 | ||
56 | bool run() | |
57 | { | |
58 | for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) { | |
59 | BasicBlock* block = m_graph.block(blockIndex); | |
60 | if (!block) | |
61 | continue; | |
62 | ||
63 | for (unsigned nodeIndex = block->size(); nodeIndex--;) { | |
64 | m_node = block->at(nodeIndex); | |
65 | handle(); | |
66 | } | |
67 | } | |
68 | ||
69 | return true; | |
70 | } | |
71 | ||
72 | private: | |
73 | void handle() | |
74 | { | |
75 | switch (m_node->op()) { | |
76 | case CompareEqConstant: | |
77 | case IsUndefined: | |
78 | handleMasqueradesAsUndefined(); | |
79 | break; | |
80 | ||
81 | case CompareEq: | |
82 | if (m_node->isBinaryUseKind(ObjectUse) | |
83 | || (m_node->child1().useKind() == ObjectUse && m_node->child2().useKind() == ObjectOrOtherUse) | |
84 | || (m_node->child1().useKind() == ObjectOrOtherUse && m_node->child2().useKind() == ObjectUse)) | |
85 | handleMasqueradesAsUndefined(); | |
86 | break; | |
87 | ||
88 | case LogicalNot: | |
89 | case Branch: | |
90 | switch (m_node->child1().useKind()) { | |
91 | case ObjectOrOtherUse: | |
92 | case UntypedUse: | |
93 | handleMasqueradesAsUndefined(); | |
94 | break; | |
95 | default: | |
96 | break; | |
97 | } | |
98 | break; | |
99 | ||
100 | case NewArray: | |
101 | case NewArrayWithSize: | |
102 | case NewArrayBuffer: | |
103 | if (!globalObject()->isHavingABadTime() && !hasAnyArrayStorage(m_node->indexingType())) | |
104 | addLazily(globalObject()->havingABadTimeWatchpoint()); | |
105 | break; | |
106 | ||
107 | case VarInjectionWatchpoint: | |
108 | addLazily(globalObject()->varInjectionWatchpoint()); | |
109 | break; | |
110 | ||
111 | default: | |
112 | break; | |
113 | } | |
114 | } | |
115 | ||
116 | void handleMasqueradesAsUndefined() | |
117 | { | |
118 | if (m_graph.masqueradesAsUndefinedWatchpointIsStillValid(m_node->origin.semantic)) | |
119 | addLazily(globalObject()->masqueradesAsUndefinedWatchpoint()); | |
120 | } | |
121 | ||
122 | void addLazily(WatchpointSet* set) | |
123 | { | |
124 | m_graph.watchpoints().addLazily(set); | |
125 | } | |
126 | void addLazily(InlineWatchpointSet& set) | |
127 | { | |
128 | m_graph.watchpoints().addLazily(set); | |
129 | } | |
130 | ||
131 | JSGlobalObject* globalObject() | |
132 | { | |
133 | return m_graph.globalObjectFor(m_node->origin.semantic); | |
134 | } | |
135 | ||
136 | Node* m_node; | |
137 | }; | |
138 | ||
139 | bool performWatchpointCollection(Graph& graph) | |
140 | { | |
141 | SamplingRegion samplingRegion("DFG Watchpoint Collection Phase"); | |
142 | return runPhase<WatchpointCollectionPhase>(graph); | |
143 | } | |
144 | ||
145 | } } // namespace JSC::DFG | |
146 | ||
147 | #endif // ENABLE(DFG_JIT) | |
148 |