2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef BytecodeBasicBlock_h
27 #define BytecodeBasicBlock_h
30 #include <wtf/FastBitVector.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/RefCounted.h>
33 #include <wtf/Vector.h>
39 class BytecodeBasicBlock
: public RefCounted
<BytecodeBasicBlock
> {
41 enum SpecialBlockType
{ EntryBlock
, ExitBlock
};
42 BytecodeBasicBlock(unsigned start
, unsigned length
);
43 BytecodeBasicBlock(SpecialBlockType
);
45 bool isEntryBlock() { return !m_leaderBytecodeOffset
&& !m_totalBytecodeLength
; }
46 bool isExitBlock() { return m_leaderBytecodeOffset
== UINT_MAX
&& m_totalBytecodeLength
== UINT_MAX
; }
48 unsigned leaderBytecodeOffset() { return m_leaderBytecodeOffset
; }
49 unsigned totalBytecodeLength() { return m_totalBytecodeLength
; }
51 Vector
<unsigned>& bytecodeOffsets() { return m_bytecodeOffsets
; }
52 void addBytecodeLength(unsigned);
54 void addPredecessor(BytecodeBasicBlock
* block
) { m_predecessors
.append(block
); }
55 void addSuccessor(BytecodeBasicBlock
* block
) { m_successors
.append(block
); }
57 Vector
<BytecodeBasicBlock
*>& predecessors() { return m_predecessors
; }
58 Vector
<BytecodeBasicBlock
*>& successors() { return m_successors
; }
60 FastBitVector
& in() { return m_in
; }
61 FastBitVector
& out() { return m_out
; }
64 unsigned m_leaderBytecodeOffset
;
65 unsigned m_totalBytecodeLength
;
67 Vector
<unsigned> m_bytecodeOffsets
;
69 Vector
<BytecodeBasicBlock
*> m_predecessors
;
70 Vector
<BytecodeBasicBlock
*> m_successors
;
76 void computeBytecodeBasicBlocks(CodeBlock
*, Vector
<RefPtr
<BytecodeBasicBlock
> >&);
78 inline BytecodeBasicBlock::BytecodeBasicBlock(unsigned start
, unsigned length
)
79 : m_leaderBytecodeOffset(start
)
80 , m_totalBytecodeLength(length
)
82 m_bytecodeOffsets
.append(m_leaderBytecodeOffset
);
85 inline BytecodeBasicBlock::BytecodeBasicBlock(BytecodeBasicBlock::SpecialBlockType blockType
)
86 : m_leaderBytecodeOffset(blockType
== BytecodeBasicBlock::EntryBlock
? 0 : UINT_MAX
)
87 , m_totalBytecodeLength(blockType
== BytecodeBasicBlock::EntryBlock
? 0 : UINT_MAX
)
91 inline void BytecodeBasicBlock::addBytecodeLength(unsigned bytecodeLength
)
93 m_bytecodeOffsets
.append(m_leaderBytecodeOffset
+ m_totalBytecodeLength
);
94 m_totalBytecodeLength
+= bytecodeLength
;
99 #endif // BytecodeBasicBlock_h