BytecodeBasicBlock.h [plain text]
#pragma once
#include "InstructionStream.h"
#include "Opcode.h"
#include <limits.h>
#include <wtf/FastBitVector.h>
#include <wtf/Vector.h>
namespace JSC {
class BytecodeGraph;
class CodeBlock;
class UnlinkedCodeBlock;
class UnlinkedCodeBlockGenerator;
struct Instruction;
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(BytecodeBasicBlock);
class BytecodeBasicBlock {
WTF_MAKE_FAST_ALLOCATED(BytecodeBasicBlock);
WTF_MAKE_NONCOPYABLE(BytecodeBasicBlock);
friend class BytecodeGraph;
public:
using BasicBlockVector = Vector<BytecodeBasicBlock, 0, UnsafeVectorOverflow, 16, BytecodeBasicBlockMalloc>;
static_assert(maxOpcodeLength <= UINT8_MAX);
enum SpecialBlockType { EntryBlock, ExitBlock };
inline BytecodeBasicBlock(const InstructionStream::Ref&, unsigned blockIndex);
inline BytecodeBasicBlock(SpecialBlockType, unsigned blockIndex);
BytecodeBasicBlock(BytecodeBasicBlock&&) = default;
bool isEntryBlock() { return !m_leaderOffset && !m_totalLength; }
bool isExitBlock() { return m_leaderOffset == UINT_MAX && m_totalLength == UINT_MAX; }
unsigned leaderOffset() const { return m_leaderOffset; }
unsigned totalLength() const { return m_totalLength; }
const Vector<uint8_t>& delta() const { return m_delta; }
const Vector<unsigned>& successors() const { return m_successors; }
FastBitVector& in() { return m_in; }
FastBitVector& out() { return m_out; }
unsigned index() const { return m_index; }
explicit operator bool() const { return true; }
private:
static BasicBlockVector compute(CodeBlock*, const InstructionStream& instructions);
static BasicBlockVector compute(UnlinkedCodeBlockGenerator*, const InstructionStream& instructions);
template<typename Block> static BasicBlockVector computeImpl(Block* codeBlock, const InstructionStream& instructions);
void shrinkToFit();
void addSuccessor(BytecodeBasicBlock& block)
{
if (!m_successors.contains(block.index()))
m_successors.append(block.index());
}
inline void addLength(unsigned);
InstructionStream::Offset m_leaderOffset;
unsigned m_totalLength;
unsigned m_index;
Vector<uint8_t> m_delta;
Vector<unsigned> m_successors;
FastBitVector m_in;
FastBitVector m_out;
};
}