2 * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "DFGStructureRegistrationPhase.h"
31 #include "DFGBasicBlockInlines.h"
34 #include "JSCInlines.h"
36 namespace JSC
{ namespace DFG
{
38 class StructureRegistrationPhase
: public Phase
{
40 StructureRegistrationPhase(Graph
& graph
)
41 : Phase(graph
, "structure registration")
47 // We need to set this before this phase finishes. This phase doesn't do anything
48 // conditioned on this field, except for assertIsRegistered() below. We intend for that
49 // method to behave as if the phase was already finished. So, we set this up here.
50 m_graph
.m_structureRegistrationState
= AllStructuresAreRegistered
;
52 // These are pretty dumb, but needed to placate subsequent assertions. We don't actually
53 // have to watch these because there is no way to transition away from it, but they are
54 // watchable and so we will assert if they aren't watched.
55 registerStructure(m_graph
.m_vm
.structureStructure
.get());
56 registerStructure(m_graph
.m_vm
.stringStructure
.get());
57 registerStructure(m_graph
.m_vm
.getterSetterStructure
.get());
59 for (FrozenValue
* value
: m_graph
.m_frozenValues
)
60 m_graph
.assertIsRegistered(value
->structure());
62 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;) {
63 BasicBlock
* block
= m_graph
.block(blockIndex
);
67 for (unsigned nodeIndex
= 0; nodeIndex
< block
->size(); ++nodeIndex
) {
68 Node
* node
= block
->at(nodeIndex
);
72 registerStructures(node
->structureSet());
76 case ArrayifyToStructure
:
78 registerStructure(node
->structure());
82 case AllocatePropertyStorage
:
83 case ReallocatePropertyStorage
:
84 registerStructure(node
->transition()->previous
);
85 registerStructure(node
->transition()->next
);
88 case MultiGetByOffset
:
89 for (unsigned i
= node
->multiGetByOffsetData().variants
.size(); i
--;) {
90 GetByIdVariant
& variant
= node
->multiGetByOffsetData().variants
[i
];
91 registerStructures(variant
.structureSet());
92 // Don't need to watch anything in the structure chain because that would
93 // have been decomposed into CheckStructure's. Don't need to watch the
94 // callLinkStatus because we wouldn't use MultiGetByOffset if any of the
96 ASSERT(!variant
.callLinkStatus());
100 case MultiPutByOffset
:
101 for (unsigned i
= node
->multiPutByOffsetData().variants
.size(); i
--;) {
102 PutByIdVariant
& variant
= node
->multiPutByOffsetData().variants
[i
];
103 registerStructures(variant
.oldStructure());
104 if (variant
.kind() == PutByIdVariant::Transition
)
105 registerStructure(variant
.newStructure());
111 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->arrayStructureForIndexingTypeDuringAllocation(node
->indexingType()));
115 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->typedArrayStructure(node
->typedArrayType()));
119 case CallStringConstructor
:
120 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->stringObjectStructure());
123 case CreateActivation
:
124 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->activationStructure());
127 case CreateDirectArguments
:
128 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->directArgumentsStructure());
131 case CreateScopedArguments
:
132 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->scopedArgumentsStructure());
136 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->regExpStructure());
140 registerStructure(m_graph
.globalObjectFor(node
->origin
.semantic
)->functionStructure());
153 void registerStructures(const StructureSet
& set
)
155 for (unsigned i
= set
.size(); i
--;)
156 registerStructure(set
[i
]);
159 void registerStructure(Structure
* structure
)
162 m_graph
.registerStructure(structure
);
166 bool performStructureRegistration(Graph
& graph
)
168 SamplingRegion
samplingRegion("DFG Structure Registration Phase");
169 return runPhase
<StructureRegistrationPhase
>(graph
);
172 } } // namespace JSC::DFG
174 #endif // ENABLE(DFG_JIT)