fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011, 2013 Apple Inc. All rights reserved. |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +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 | #ifndef DFGBasicBlock_h |
| 27 | #define DFGBasicBlock_h |
| 28 | |
| 29 | #if ENABLE(DFG_JIT) |
| 30 | |
| 31 | #include "DFGAbstractValue.h" |
fpizlo@apple.com | 367a110 | 2012-11-10 23:33:29 +0000 | [diff] [blame] | 32 | #include "DFGBranchDirection.h" |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 33 | #include "DFGFlushedAt.h" |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 34 | #include "DFGNode.h" |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 35 | #include "DFGVariadicFunction.h" |
fpizlo@apple.com | 9cf1981 | 2012-03-25 23:35:07 +0000 | [diff] [blame] | 36 | #include "Operands.h" |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 37 | #include <wtf/HashMap.h> |
| 38 | #include <wtf/HashSet.h> |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 39 | #include <wtf/OwnPtr.h> |
| 40 | #include <wtf/Vector.h> |
| 41 | |
| 42 | namespace JSC { namespace DFG { |
| 43 | |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 44 | class Graph; |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 45 | class InsertionSet; |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 46 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 47 | typedef Vector<BasicBlock*, 2> PredecessorList; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 48 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 49 | struct BasicBlock : RefCounted<BasicBlock> { |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 50 | BasicBlock(unsigned bytecodeBegin, unsigned numArguments, unsigned numLocals); |
| 51 | ~BasicBlock(); |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 52 | |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 53 | void ensureLocals(unsigned newNumLocals); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 54 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 55 | size_t size() const { return m_nodes.size(); } |
| 56 | bool isEmpty() const { return !size(); } |
| 57 | Node*& at(size_t i) { return m_nodes[i]; } |
| 58 | Node* at(size_t i) const { return m_nodes[i]; } |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 59 | Node*& operator[](size_t i) { return at(i); } |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 60 | Node* operator[](size_t i) const { return at(i); } |
| 61 | Node* last() const { return at(size() - 1); } |
| 62 | void resize(size_t size) { m_nodes.resize(size); } |
| 63 | void grow(size_t size) { m_nodes.grow(size); } |
| 64 | |
| 65 | void append(Node* node) { m_nodes.append(node); } |
oliver@apple.com | e17632e | 2013-07-25 04:05:31 +0000 | [diff] [blame] | 66 | void insertBeforeLast(Node* node) |
| 67 | { |
| 68 | append(last()); |
| 69 | at(size() - 2) = node; |
| 70 | } |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 71 | |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 72 | size_t numNodes() const { return phis.size() + size(); } |
fpizlo@apple.com | 8ff092f | 2013-01-29 08:01:03 +0000 | [diff] [blame] | 73 | Node* node(size_t i) const |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 74 | { |
| 75 | if (i < phis.size()) |
| 76 | return phis[i]; |
| 77 | return at(i - phis.size()); |
| 78 | } |
| 79 | bool isPhiIndex(size_t i) const { return i < phis.size(); } |
| 80 | |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 81 | bool isInPhis(Node* node) const; |
| 82 | bool isInBlock(Node* myNode) const; |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 83 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 84 | unsigned numSuccessors() { return last()->numSuccessors(); } |
| 85 | |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 86 | BasicBlock*& successor(unsigned index) |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 87 | { |
| 88 | return last()->successor(index); |
| 89 | } |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 90 | BasicBlock*& successorForCondition(bool condition) |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 91 | { |
| 92 | return last()->successorForCondition(condition); |
| 93 | } |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 94 | |
| 95 | void removePredecessor(BasicBlock* block); |
| 96 | void replacePredecessor(BasicBlock* from, BasicBlock* to); |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 97 | |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 98 | #define DFG_DEFINE_APPEND_NODE(templatePre, templatePost, typeParams, valueParamsComma, valueParams, valueArgs) \ |
fpizlo@apple.com | 06f82b5 | 2013-03-06 02:27:16 +0000 | [diff] [blame] | 99 | templatePre typeParams templatePost Node* appendNode(Graph&, SpeculatedType valueParamsComma valueParams); |
fpizlo@apple.com | f45e88b | 2013-01-20 19:29:50 +0000 | [diff] [blame] | 100 | DFG_VARIADIC_TEMPLATE_FUNCTION(DFG_DEFINE_APPEND_NODE) |
| 101 | #undef DFG_DEFINE_APPEND_NODE |
| 102 | |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 103 | #define DFG_DEFINE_APPEND_NODE(templatePre, templatePost, typeParams, valueParamsComma, valueParams, valueArgs) \ |
| 104 | templatePre typeParams templatePost Node* appendNonTerminal(Graph&, SpeculatedType valueParamsComma valueParams); |
| 105 | DFG_VARIADIC_TEMPLATE_FUNCTION(DFG_DEFINE_APPEND_NODE) |
| 106 | #undef DFG_DEFINE_APPEND_NODE |
| 107 | |
| 108 | void dump(PrintStream& out) const; |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 109 | |
fpizlo@apple.com | 41f5c95 | 2011-10-17 23:54:41 +0000 | [diff] [blame] | 110 | // This value is used internally for block linking and OSR entry. It is mostly meaningless |
| 111 | // for other purposes due to inlining. |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 112 | unsigned bytecodeBegin; |
fpizlo@apple.com | 41f5c95 | 2011-10-17 23:54:41 +0000 | [diff] [blame] | 113 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 114 | BlockIndex index; |
| 115 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 116 | bool isOSRTarget; |
| 117 | bool cfaHasVisited; |
| 118 | bool cfaShouldRevisit; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 119 | bool cfaFoundConstants; |
fpizlo@apple.com | edcb7a9 | 2012-07-13 05:31:05 +0000 | [diff] [blame] | 120 | bool cfaDidFinish; |
fpizlo@apple.com | 367a110 | 2012-11-10 23:33:29 +0000 | [diff] [blame] | 121 | BranchDirection cfaBranchDirection; |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 122 | #if !ASSERT_DISABLED |
| 123 | bool isLinked; |
| 124 | #endif |
| 125 | bool isReachable; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 126 | |
fpizlo@apple.com | 8ff092f | 2013-01-29 08:01:03 +0000 | [diff] [blame] | 127 | Vector<Node*> phis; |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 128 | PredecessorList predecessors; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 129 | |
fpizlo@apple.com | 8ff092f | 2013-01-29 08:01:03 +0000 | [diff] [blame] | 130 | Operands<Node*, NodePointerTraits> variablesAtHead; |
| 131 | Operands<Node*, NodePointerTraits> variablesAtTail; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 132 | |
| 133 | Operands<AbstractValue> valuesAtHead; |
| 134 | Operands<AbstractValue> valuesAtTail; |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 135 | |
oliver@apple.com | 4fe26de | 2013-07-25 04:04:51 +0000 | [diff] [blame] | 136 | // These fields are reserved for NaturalLoops. |
| 137 | static const unsigned numberOfInnerMostLoopIndices = 2; |
| 138 | unsigned innerMostLoopIndices[numberOfInnerMostLoopIndices]; |
| 139 | |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 140 | struct SSAData { |
fpizlo@apple.com | a62d482 | 2013-10-06 04:22:43 +0000 | [diff] [blame] | 141 | Operands<FlushedAt> flushAtHead; |
| 142 | Operands<FlushedAt> flushAtTail; |
oliver@apple.com | 827d2cf | 2013-07-25 04:04:45 +0000 | [diff] [blame] | 143 | Operands<Node*> availabilityAtHead; |
| 144 | Operands<Node*> availabilityAtTail; |
| 145 | HashSet<Node*> liveAtHead; |
| 146 | HashSet<Node*> liveAtTail; |
| 147 | HashMap<Node*, AbstractValue> valuesAtHead; |
| 148 | HashMap<Node*, AbstractValue> valuesAtTail; |
| 149 | |
| 150 | SSAData(BasicBlock*); |
| 151 | ~SSAData(); |
| 152 | }; |
| 153 | OwnPtr<SSAData> ssa; |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 154 | |
| 155 | private: |
| 156 | friend class InsertionSet; |
| 157 | Vector<Node*, 8> m_nodes; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 160 | struct UnlinkedBlock { |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 161 | BasicBlock* m_block; |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 162 | bool m_needsNormalLinking; |
| 163 | bool m_needsEarlyReturnLinking; |
| 164 | |
| 165 | UnlinkedBlock() { } |
| 166 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 167 | explicit UnlinkedBlock(BasicBlock* block) |
| 168 | : m_block(block) |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 169 | , m_needsNormalLinking(true) |
| 170 | , m_needsEarlyReturnLinking(false) |
| 171 | { |
| 172 | } |
| 173 | }; |
| 174 | |
oliver@apple.com | 426f5b0 | 2013-07-25 04:04:27 +0000 | [diff] [blame] | 175 | static inline unsigned getBytecodeBeginForBlock(BasicBlock** basicBlock) |
| 176 | { |
| 177 | return (*basicBlock)->bytecodeBegin; |
| 178 | } |
| 179 | |
| 180 | static inline BasicBlock* blockForBytecodeOffset(Vector<BasicBlock*>& linkingTargets, unsigned bytecodeBegin) |
| 181 | { |
| 182 | return *binarySearch<BasicBlock*, unsigned>(linkingTargets, linkingTargets.size(), bytecodeBegin, getBytecodeBeginForBlock); |
| 183 | } |
| 184 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 185 | } } // namespace JSC::DFG |
| 186 | |
| 187 | #endif // ENABLE(DFG_JIT) |
| 188 | |
| 189 | #endif // DFGBasicBlock_h |
| 190 | |