]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGInvalidationPointInjectionPhase.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGInvalidationPointInjectionPhase.cpp
1 /*
2 * Copyright (C) 2013, 2014 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 "DFGInvalidationPointInjectionPhase.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGBlockSetInlines.h"
32 #include "DFGClobberize.h"
33 #include "DFGGraph.h"
34 #include "DFGInsertionSet.h"
35 #include "DFGPhase.h"
36 #include "JSCInlines.h"
37
38 namespace JSC { namespace DFG {
39
40 class InvalidationPointInjectionPhase : public Phase {
41 static const bool verbose = false;
42
43 public:
44 InvalidationPointInjectionPhase(Graph& graph)
45 : Phase(graph, "invalidation point injection")
46 , m_insertionSet(graph)
47 {
48 }
49
50 bool run()
51 {
52 ASSERT(m_graph.m_form != SSA);
53
54 BlockSet blocksThatNeedInvalidationPoints;
55
56 for (BlockIndex blockIndex = m_graph.numBlocks(); blockIndex--;) {
57 BasicBlock* block = m_graph.block(blockIndex);
58 if (!block)
59 continue;
60
61 for (unsigned nodeIndex = 0; nodeIndex < block->size(); ++nodeIndex)
62 handle(nodeIndex, block->at(nodeIndex));
63
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));
68 }
69
70 m_insertionSet.execute(block);
71 }
72
73 for (BasicBlock* block : blocksThatNeedInvalidationPoints.iterable(m_graph)) {
74 insertInvalidationCheck(0, block->at(0));
75 m_insertionSet.execute(block);
76 }
77
78 return true;
79 }
80
81 private:
82 void handle(unsigned nodeIndex, Node* node)
83 {
84 if (m_originThatHadFire.isSet() && m_originThatHadFire != node->origin.forExit) {
85 insertInvalidationCheck(nodeIndex, node);
86 m_originThatHadFire = CodeOrigin();
87 }
88
89 if (writesOverlap(m_graph, node, Watchpoint_fire))
90 m_originThatHadFire = node->origin.forExit;
91 }
92
93 void insertInvalidationCheck(unsigned nodeIndex, Node* node)
94 {
95 m_insertionSet.insertNode(nodeIndex, SpecNone, InvalidationPoint, node->origin);
96 }
97
98 CodeOrigin m_originThatHadFire;
99 InsertionSet m_insertionSet;
100 };
101
102 bool performInvalidationPointInjection(Graph& graph)
103 {
104 SamplingRegion samplingRegion("DFG Invalidation Point Injection Phase");
105 return runPhase<InvalidationPointInjectionPhase>(graph);
106 }
107
108 } } // namespace JSC::DFG
109
110 #endif // ENABLE(DFG_JIT)
111