blob: 9228001cc5397315a7dd1c6ea27d6f56a48e0331 [file] [log] [blame]
fpizlo@apple.comd84425d2013-10-30 19:58:08 +00001/*
fpizlo@apple.com631f30d2014-09-04 21:08:38 +00002 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
fpizlo@apple.comd84425d2013-10-30 19:58:08 +00003 *
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"
ossy@webkit.orgbeb0de42014-02-17 19:00:03 +000027#include "DFGInvalidationPointInjectionPhase.h"
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000028
29#if ENABLE(DFG_JIT)
30
fpizlo@apple.com631f30d2014-09-04 21:08:38 +000031#include "DFGBlockSetInlines.h"
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000032#include "DFGClobberize.h"
fpizlo@apple.com0bef2a12014-02-10 19:26:29 +000033#include "DFGGraph.h"
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000034#include "DFGInsertionSet.h"
35#include "DFGPhase.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000036#include "JSCInlines.h"
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000037
38namespace JSC { namespace DFG {
39
40class InvalidationPointInjectionPhase : public Phase {
41 static const bool verbose = false;
42
43public:
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
fpizlo@apple.com0bfc7302014-08-28 19:23:02 +000054 BlockSet blocksThatNeedInvalidationPoints;
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000055
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--;)
fpizlo@apple.com0bfc7302014-08-28 19:23:02 +000067 blocksThatNeedInvalidationPoints.add(block->successor(i));
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000068 }
69
70 m_insertionSet.execute(block);
71 }
fpizlo@apple.com0bfc7302014-08-28 19:23:02 +000072
fpizlo@apple.com631f30d2014-09-04 21:08:38 +000073 for (BasicBlock* block : blocksThatNeedInvalidationPoints.iterable(m_graph)) {
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000074 insertInvalidationCheck(0, block->at(0));
75 m_insertionSet.execute(block);
76 }
77
78 return true;
79 }
80
81private:
82 void handle(unsigned nodeIndex, Node* node)
83 {
fpizlo@apple.com6793a322014-02-12 05:42:32 +000084 if (m_originThatHadFire.isSet() && m_originThatHadFire != node->origin.forExit) {
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000085 insertInvalidationCheck(nodeIndex, node);
86 m_originThatHadFire = CodeOrigin();
87 }
88
89 if (writesOverlap(m_graph, node, Watchpoint_fire))
fpizlo@apple.com6793a322014-02-12 05:42:32 +000090 m_originThatHadFire = node->origin.forExit;
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000091 }
92
93 void insertInvalidationCheck(unsigned nodeIndex, Node* node)
94 {
fpizlo@apple.com6793a322014-02-12 05:42:32 +000095 m_insertionSet.insertNode(nodeIndex, SpecNone, InvalidationPoint, node->origin);
fpizlo@apple.comd84425d2013-10-30 19:58:08 +000096 }
97
98 CodeOrigin m_originThatHadFire;
99 InsertionSet m_insertionSet;
100};
101
102bool 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