fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #ifndef DFGBasicBlock_h |
| 27 | #define DFGBasicBlock_h |
| 28 | |
| 29 | #if ENABLE(DFG_JIT) |
| 30 | |
| 31 | #include "DFGAbstractValue.h" |
| 32 | #include "DFGNode.h" |
fpizlo@apple.com | 9cf1981 | 2012-03-25 23:35:07 +0000 | [diff] [blame] | 33 | #include "Operands.h" |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 34 | #include <wtf/OwnPtr.h> |
| 35 | #include <wtf/Vector.h> |
| 36 | |
| 37 | namespace JSC { namespace DFG { |
| 38 | |
| 39 | typedef Vector <BlockIndex, 2> PredecessorList; |
| 40 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 41 | struct BasicBlock : Vector<NodeIndex, 8> { |
| 42 | BasicBlock(unsigned bytecodeBegin, unsigned numArguments, unsigned numLocals) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 43 | : bytecodeBegin(bytecodeBegin) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 44 | , isOSRTarget(false) |
| 45 | , cfaHasVisited(false) |
| 46 | , cfaShouldRevisit(false) |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 47 | , cfaFoundConstants(false) |
fpizlo@apple.com | edcb7a9 | 2012-07-13 05:31:05 +0000 | [diff] [blame^] | 48 | , cfaDidFinish(true) |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 49 | #if !ASSERT_DISABLED |
| 50 | , isLinked(false) |
| 51 | #endif |
| 52 | , isReachable(false) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 53 | , variablesAtHead(numArguments, numLocals) |
| 54 | , variablesAtTail(numArguments, numLocals) |
| 55 | , valuesAtHead(numArguments, numLocals) |
| 56 | , valuesAtTail(numArguments, numLocals) |
| 57 | { |
| 58 | } |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 59 | |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 60 | ~BasicBlock() |
| 61 | { |
| 62 | } |
| 63 | |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 64 | void ensureLocals(unsigned newNumLocals) |
| 65 | { |
| 66 | variablesAtHead.ensureLocals(newNumLocals); |
| 67 | variablesAtTail.ensureLocals(newNumLocals); |
| 68 | valuesAtHead.ensureLocals(newNumLocals); |
| 69 | valuesAtTail.ensureLocals(newNumLocals); |
| 70 | } |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 71 | |
| 72 | size_t numNodes() const { return phis.size() + size(); } |
| 73 | NodeIndex nodeIndex(size_t i) const |
| 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 | |
| 81 | bool isInPhis(NodeIndex nodeIndex) const |
| 82 | { |
| 83 | for (size_t i = 0; i < phis.size(); ++i) { |
| 84 | if (phis[i] == nodeIndex) |
| 85 | return true; |
| 86 | } |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | bool isInBlock(NodeIndex index) const |
| 91 | { |
| 92 | for (size_t i = 0; i < numNodes(); ++i) { |
| 93 | if (nodeIndex(i) == index) |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 98 | |
fpizlo@apple.com | 41f5c95 | 2011-10-17 23:54:41 +0000 | [diff] [blame] | 99 | // This value is used internally for block linking and OSR entry. It is mostly meaningless |
| 100 | // for other purposes due to inlining. |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 101 | unsigned bytecodeBegin; |
fpizlo@apple.com | 41f5c95 | 2011-10-17 23:54:41 +0000 | [diff] [blame] | 102 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 103 | bool isOSRTarget; |
| 104 | bool cfaHasVisited; |
| 105 | bool cfaShouldRevisit; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 106 | bool cfaFoundConstants; |
fpizlo@apple.com | edcb7a9 | 2012-07-13 05:31:05 +0000 | [diff] [blame^] | 107 | bool cfaDidFinish; |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 108 | #if !ASSERT_DISABLED |
| 109 | bool isLinked; |
| 110 | #endif |
| 111 | bool isReachable; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 112 | |
yuqiang.xian@intel.com | fa12f4e | 2012-03-07 04:56:05 +0000 | [diff] [blame] | 113 | Vector<NodeIndex> phis; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 114 | PredecessorList m_predecessors; |
| 115 | |
| 116 | Operands<NodeIndex, NodeIndexTraits> variablesAtHead; |
| 117 | Operands<NodeIndex, NodeIndexTraits> variablesAtTail; |
| 118 | |
| 119 | Operands<AbstractValue> valuesAtHead; |
| 120 | Operands<AbstractValue> valuesAtTail; |
| 121 | }; |
| 122 | |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 123 | struct UnlinkedBlock { |
| 124 | BlockIndex m_blockIndex; |
| 125 | bool m_needsNormalLinking; |
| 126 | bool m_needsEarlyReturnLinking; |
| 127 | |
| 128 | UnlinkedBlock() { } |
| 129 | |
| 130 | explicit UnlinkedBlock(BlockIndex blockIndex) |
| 131 | : m_blockIndex(blockIndex) |
| 132 | , m_needsNormalLinking(true) |
| 133 | , m_needsEarlyReturnLinking(false) |
| 134 | { |
| 135 | } |
| 136 | }; |
| 137 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 138 | } } // namespace JSC::DFG |
| 139 | |
| 140 | #endif // ENABLE(DFG_JIT) |
| 141 | |
| 142 | #endif // DFGBasicBlock_h |
| 143 | |