blob: 441e2e75e9dc2a1bba98fb7c4738a258439244bc [file] [log] [blame]
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +00001/*
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.com9cf19812012-03-25 23:35:07 +000033#include "Operands.h"
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +000034#include <wtf/OwnPtr.h>
35#include <wtf/Vector.h>
36
37namespace JSC { namespace DFG {
38
39typedef Vector <BlockIndex, 2> PredecessorList;
40
yuqiang.xian@intel.com861d9182012-03-01 07:39:31 +000041struct BasicBlock : Vector<NodeIndex, 8> {
42 BasicBlock(unsigned bytecodeBegin, unsigned numArguments, unsigned numLocals)
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +000043 : bytecodeBegin(bytecodeBegin)
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +000044 , isOSRTarget(false)
45 , cfaHasVisited(false)
46 , cfaShouldRevisit(false)
fpizlo@apple.com3187c922012-05-18 21:47:53 +000047 , cfaFoundConstants(false)
fpizlo@apple.comedcb7a92012-07-13 05:31:05 +000048 , cfaDidFinish(true)
fpizlo@apple.comd9ded3b2011-10-22 01:22:46 +000049#if !ASSERT_DISABLED
50 , isLinked(false)
51#endif
52 , isReachable(false)
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +000053 , variablesAtHead(numArguments, numLocals)
54 , variablesAtTail(numArguments, numLocals)
55 , valuesAtHead(numArguments, numLocals)
56 , valuesAtTail(numArguments, numLocals)
57 {
58 }
fpizlo@apple.comd9ded3b2011-10-22 01:22:46 +000059
fpizlo@apple.com79c51ee2012-05-18 22:30:24 +000060 ~BasicBlock()
61 {
62 }
63
fpizlo@apple.comd9ded3b2011-10-22 01:22:46 +000064 void ensureLocals(unsigned newNumLocals)
65 {
66 variablesAtHead.ensureLocals(newNumLocals);
67 variablesAtTail.ensureLocals(newNumLocals);
68 valuesAtHead.ensureLocals(newNumLocals);
69 valuesAtTail.ensureLocals(newNumLocals);
70 }
fpizlo@apple.com79c51ee2012-05-18 22:30:24 +000071
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.com4ffd3952011-10-12 02:05:53 +000098
fpizlo@apple.com41f5c952011-10-17 23:54:41 +000099 // This value is used internally for block linking and OSR entry. It is mostly meaningless
100 // for other purposes due to inlining.
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +0000101 unsigned bytecodeBegin;
fpizlo@apple.com41f5c952011-10-17 23:54:41 +0000102
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +0000103 bool isOSRTarget;
104 bool cfaHasVisited;
105 bool cfaShouldRevisit;
fpizlo@apple.com3187c922012-05-18 21:47:53 +0000106 bool cfaFoundConstants;
fpizlo@apple.comedcb7a92012-07-13 05:31:05 +0000107 bool cfaDidFinish;
fpizlo@apple.comd9ded3b2011-10-22 01:22:46 +0000108#if !ASSERT_DISABLED
109 bool isLinked;
110#endif
111 bool isReachable;
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +0000112
yuqiang.xian@intel.comfa12f4e2012-03-07 04:56:05 +0000113 Vector<NodeIndex> phis;
fpizlo@apple.com4ffd3952011-10-12 02:05:53 +0000114 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.comd9ded3b2011-10-22 01:22:46 +0000123struct 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.com4ffd3952011-10-12 02:05:53 +0000138} } // namespace JSC::DFG
139
140#endif // ENABLE(DFG_JIT)
141
142#endif // DFGBasicBlock_h
143