2 * Copyright (C) 2013, 2014 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 "DFGInvalidationPointInjectionPhase.h"
31 #include "DFGBlockSetInlines.h"
32 #include "DFGClobberize.h"
34 #include "DFGInsertionSet.h"
36 #include "JSCInlines.h"
38 namespace JSC
{ namespace DFG
{
40 class InvalidationPointInjectionPhase
: public Phase
{
41 static const bool verbose
= false;
44 InvalidationPointInjectionPhase(Graph
& graph
)
45 : Phase(graph
, "invalidation point injection")
46 , m_insertionSet(graph
)
52 ASSERT(m_graph
.m_form
!= SSA
);
54 BlockSet blocksThatNeedInvalidationPoints
;
56 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;) {
57 BasicBlock
* block
= m_graph
.block(blockIndex
);
61 for (unsigned nodeIndex
= 0; nodeIndex
< block
->size(); ++nodeIndex
)
62 handle(nodeIndex
, block
->at(nodeIndex
));
64 // Note: this assumes that control flow occurs at bytecode instruction boundaries.
65 if (m_originThatHadFire
.isSet()) {
66 for (unsigned i
= block
->numSuccessors(); i
--;)
67 blocksThatNeedInvalidationPoints
.add(block
->successor(i
));
70 m_insertionSet
.execute(block
);
73 for (BasicBlock
* block
: blocksThatNeedInvalidationPoints
.iterable(m_graph
)) {
74 insertInvalidationCheck(0, block
->at(0));
75 m_insertionSet
.execute(block
);
82 void handle(unsigned nodeIndex
, Node
* node
)
84 if (m_originThatHadFire
.isSet() && m_originThatHadFire
!= node
->origin
.forExit
) {
85 insertInvalidationCheck(nodeIndex
, node
);
86 m_originThatHadFire
= CodeOrigin();
89 if (writesOverlap(m_graph
, node
, Watchpoint_fire
))
90 m_originThatHadFire
= node
->origin
.forExit
;
93 void insertInvalidationCheck(unsigned nodeIndex
, Node
* node
)
95 m_insertionSet
.insertNode(nodeIndex
, SpecNone
, InvalidationPoint
, node
->origin
);
98 CodeOrigin m_originThatHadFire
;
99 InsertionSet m_insertionSet
;
102 bool performInvalidationPointInjection(Graph
& graph
)
104 SamplingRegion
samplingRegion("DFG Invalidation Point Injection Phase");
105 return runPhase
<InvalidationPointInjectionPhase
>(graph
);
108 } } // namespace JSC::DFG
110 #endif // ENABLE(DFG_JIT)