fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 631f30d | 2014-09-04 21:08:38 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 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" |
ossy@webkit.org | beb0de4 | 2014-02-17 19:00:03 +0000 | [diff] [blame] | 27 | #include "DFGInvalidationPointInjectionPhase.h" |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 28 | |
| 29 | #if ENABLE(DFG_JIT) |
| 30 | |
fpizlo@apple.com | 631f30d | 2014-09-04 21:08:38 +0000 | [diff] [blame] | 31 | #include "DFGBlockSetInlines.h" |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 32 | #include "DFGClobberize.h" |
fpizlo@apple.com | 0bef2a1 | 2014-02-10 19:26:29 +0000 | [diff] [blame] | 33 | #include "DFGGraph.h" |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 34 | #include "DFGInsertionSet.h" |
| 35 | #include "DFGPhase.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 36 | #include "JSCInlines.h" |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 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 | |
fpizlo@apple.com | 0bfc730 | 2014-08-28 19:23:02 +0000 | [diff] [blame] | 54 | BlockSet blocksThatNeedInvalidationPoints; |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 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--;) |
fpizlo@apple.com | 0bfc730 | 2014-08-28 19:23:02 +0000 | [diff] [blame] | 67 | blocksThatNeedInvalidationPoints.add(block->successor(i)); |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | m_insertionSet.execute(block); |
| 71 | } |
fpizlo@apple.com | 0bfc730 | 2014-08-28 19:23:02 +0000 | [diff] [blame] | 72 | |
fpizlo@apple.com | 631f30d | 2014-09-04 21:08:38 +0000 | [diff] [blame] | 73 | for (BasicBlock* block : blocksThatNeedInvalidationPoints.iterable(m_graph)) { |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 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 | { |
fpizlo@apple.com | 6793a32 | 2014-02-12 05:42:32 +0000 | [diff] [blame] | 84 | if (m_originThatHadFire.isSet() && m_originThatHadFire != node->origin.forExit) { |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 85 | insertInvalidationCheck(nodeIndex, node); |
| 86 | m_originThatHadFire = CodeOrigin(); |
| 87 | } |
| 88 | |
| 89 | if (writesOverlap(m_graph, node, Watchpoint_fire)) |
fpizlo@apple.com | 6793a32 | 2014-02-12 05:42:32 +0000 | [diff] [blame] | 90 | m_originThatHadFire = node->origin.forExit; |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void insertInvalidationCheck(unsigned nodeIndex, Node* node) |
| 94 | { |
fpizlo@apple.com | 6793a32 | 2014-02-12 05:42:32 +0000 | [diff] [blame] | 95 | m_insertionSet.insertNode(nodeIndex, SpecNone, InvalidationPoint, node->origin); |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 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 | |