Remove NewArrowFunction from DFG IR
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGStructureRegistrationPhase.cpp
1 /*
2  * Copyright (C) 2014, 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 "DFGStructureRegistrationPhase.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGBasicBlockInlines.h"
32 #include "DFGGraph.h"
33 #include "DFGPhase.h"
34 #include "JSCInlines.h"
35
36 namespace JSC { namespace DFG {
37
38 class StructureRegistrationPhase : public Phase {
39 public:
40     StructureRegistrationPhase(Graph& graph)
41         : Phase(graph, "structure registration")
42     {
43     }
44     
45     bool run()
46     {
47         // FIXME: This phase shouldn't exist. We should have registered all structures by now, since
48         // we may already have done optimizations that rely on structures having been registered.
49         // Currently, we still have places where we don't register structures prior to this phase,
50         // but structures don't end up being used for optimization prior to this phase. That's a
51         // pretty fragile situation and we should fix it eventually.
52         // https://bugs.webkit.org/show_bug.cgi?id=147889
53         
54         // We need to set this before this phase finishes. This phase doesn't do anything
55         // conditioned on this field, except for assertIsRegistered() below. We intend for that
56         // method to behave as if the phase was already finished. So, we set this up here.
57         m_graph.m_structureRegistrationState = AllStructuresAreRegistered;
58         
59         // These are pretty dumb, but needed to placate subsequent assertions. We don't actually
60         // have to watch these because there is no way to transition away from it, but they are
61         // watchable and so we will assert if they aren't watched.
62         registerStructure(m_graph.m_vm.structureStructure.get());
63         registerStructure(m_graph.m_vm.stringStructure.get());
64         registerStructure(m_graph.m_vm.symbolStructure.get());
65         registerStructure(m_graph.m_vm.getterSetterStructure.get());
66         
67         for (FrozenValue* value : m_graph.m_frozenValues)
68             assertIsRegistered(value->structure());
69         
70         for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
71             BasicBlock* block = m_graph.block(blockIndex);
72             if (!block)
73                 continue;
74         
75             for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex) {
76                 Node* node = block->at(nodeIndex);
77             
78                 switch (node->op()) {
79                 case CheckStructure:
80                     assertAreRegistered(node->structureSet());
81                     break;
82                 
83                 case NewObject:
84                 case ArrayifyToStructure:
85                 case NewStringObject:
86                     registerStructure(node->structure());
87                     break;
88                 
89                 case PutStructure:
90                 case AllocatePropertyStorage:
91                 case ReallocatePropertyStorage:
92                     registerStructure(node->transition()->previous);
93                     registerStructure(node->transition()->next);
94                     break;
95                     
96                 case MultiGetByOffset:
97                     for (const MultiGetByOffsetCase& getCase : node->multiGetByOffsetData().cases)
98                         registerStructures(getCase.set());
99                     break;
100                     
101                 case MultiPutByOffset:
102                     for (unsigned i = node->multiPutByOffsetData().variants.size(); i--;) {
103                         PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
104                         registerStructures(variant.oldStructure());
105                         if (variant.kind() == PutByIdVariant::Transition)
106                             registerStructure(variant.newStructure());
107                     }
108                     break;
109                     
110                 case NewArray:
111                 case NewArrayBuffer:
112                 case NewArrayWithSize: {
113                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
114                     registerStructure(globalObject->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
115                     registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithSlowPutArrayStorage));
116                     break;
117                 }
118                     
119                 case NewTypedArray:
120                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->typedArrayStructure(node->typedArrayType()));
121                     break;
122                     
123                 case ToString:
124                 case CallStringConstructor:
125                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->stringObjectStructure());
126                     break;
127                     
128                 case CreateActivation:
129                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->activationStructure());
130                     break;
131                     
132                 case CreateDirectArguments:
133                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->directArgumentsStructure());
134                     break;
135                     
136                 case CreateScopedArguments:
137                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->scopedArgumentsStructure());
138                     break;
139
140                 case CreateClonedArguments:
141                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->clonedArgumentsStructure());
142                     break;
143
144                 case NewRegexp:
145                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->regExpStructure());
146                     break;
147                 case NewFunction:
148                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->functionStructure());
149                     break;
150                 case NewGeneratorFunction:
151                     registerStructure(m_graph.globalObjectFor(node->origin.semantic)->generatorFunctionStructure());
152                     break;
153
154                 default:
155                     break;
156                 }
157             }
158         }
159         
160         return true;
161     }
162
163 private:
164     void registerStructures(const StructureSet& set)
165     {
166         for (Structure* structure : set)
167             registerStructure(structure);
168     }
169     
170     void registerStructure(Structure* structure)
171     {
172         if (structure)
173             m_graph.registerStructure(structure);
174     }
175
176     void assertAreRegistered(const StructureSet& set)
177     {
178         for (Structure* structure : set)
179             assertIsRegistered(structure);
180     }
181
182     void assertIsRegistered(Structure* structure)
183     {
184         if (structure)
185             m_graph.assertIsRegistered(structure);
186     }
187 };
188
189 bool performStructureRegistration(Graph& graph)
190 {
191     return runPhase<StructureRegistrationPhase>(graph);
192 }
193
194 } } // namespace JSC::DFG
195
196 #endif // ENABLE(DFG_JIT)
197