#pragma once
#if ENABLE(B3_JIT)
#include "AirBasicBlock.h"
#include "AirCode.h"
#include "AirInst.h"
#include "AirLiveness.h"
#include "RegisterSet.h"
#include <wtf/IndexMap.h>
namespace JSC { namespace B3 { namespace Air {
class RegLiveness {
struct Actions {
Actions() { }
RegisterSet use;
RegisterSet def;
};
typedef Vector<Actions, 0, UnsafeVectorOverflow> ActionsForBoundary;
public:
typedef Reg Thing;
RegLiveness(Code& code);
~RegLiveness();
class LocalCalcBase {
public:
LocalCalcBase(BasicBlock* block)
: m_block(block)
{
}
const RegisterSet& live() const
{
return m_workset;
}
bool isLive(Reg reg) const
{
return m_workset.contains(reg);
}
protected:
BasicBlock* m_block;
RegisterSet m_workset;
};
class LocalCalc : public LocalCalcBase {
public:
LocalCalc(RegLiveness& liveness, BasicBlock* block)
: LocalCalcBase(block)
, m_actions(liveness.m_actions[block])
{
m_workset = liveness.m_liveAtTail[block];
}
void execute(unsigned instIndex)
{
m_workset.exclude(m_actions[instIndex + 1].def);
m_workset.merge(m_actions[instIndex].use);
}
private:
friend class RegLiveness;
ActionsForBoundary& m_actions;
};
class LocalCalcForUnifiedTmpLiveness : public LocalCalcBase {
public:
LocalCalcForUnifiedTmpLiveness(UnifiedTmpLiveness& liveness, BasicBlock* block);
void execute(unsigned instIndex);
private:
Code& m_code;
UnifiedTmpLiveness::ActionsForBoundary& m_actions;
};
const RegisterSet& liveAtHead(BasicBlock* block) const
{
return m_liveAtHead[block];
}
const RegisterSet& liveAtTail(BasicBlock* block) const
{
return m_liveAtTail[block];
}
private:
IndexMap<BasicBlock*, RegisterSet> m_liveAtHead;
IndexMap<BasicBlock*, RegisterSet> m_liveAtTail;
IndexMap<BasicBlock*, ActionsForBoundary> m_actions;
};
} } }
#endif // ENABLE(B3_JIT)