#ifndef RegisterSet_h
#define RegisterSet_h
#if ENABLE(JIT)
#include "FPRInfo.h"
#include "GPRInfo.h"
#include "MacroAssembler.h"
#include "Reg.h"
#include "TempRegisterSet.h"
#include <wtf/BitVector.h>
namespace JSC {
class RegisterSet {
public:
template<typename... Regs>
explicit RegisterSet(Regs... regs)
{
setMany(regs...);
}
static RegisterSet stackRegisters();
static RegisterSet reservedHardwareRegisters();
static RegisterSet runtimeRegisters();
static RegisterSet specialRegisters(); static RegisterSet calleeSaveRegisters();
static RegisterSet allGPRs();
static RegisterSet allFPRs();
static RegisterSet allRegisters();
void set(Reg reg, bool value = true)
{
ASSERT(!!reg);
m_vector.set(reg.index(), value);
}
void set(JSValueRegs regs)
{
if (regs.tagGPR() != InvalidGPRReg)
set(regs.tagGPR());
set(regs.payloadGPR());
}
void clear(Reg reg)
{
ASSERT(!!reg);
set(reg, false);
}
bool get(Reg reg) const
{
ASSERT(!!reg);
return m_vector.get(reg.index());
}
void merge(const RegisterSet& other) { m_vector.merge(other.m_vector); }
void filter(const RegisterSet& other) { m_vector.filter(other.m_vector); }
void exclude(const RegisterSet& other) { m_vector.exclude(other.m_vector); }
size_t numberOfSetGPRs() const;
size_t numberOfSetFPRs() const;
size_t numberOfSetRegisters() const { return m_vector.bitCount(); }
void dump(PrintStream&) const;
enum EmptyValueTag { EmptyValue };
enum DeletedValueTag { DeletedValue };
RegisterSet(EmptyValueTag)
: m_vector(BitVector::EmptyValue)
{
}
RegisterSet(DeletedValueTag)
: m_vector(BitVector::DeletedValue)
{
}
bool isEmptyValue() const { return m_vector.isEmptyValue(); }
bool isDeletedValue() const { return m_vector.isDeletedValue(); }
bool operator==(const RegisterSet& other) const { return m_vector == other.m_vector; }
unsigned hash() const { return m_vector.hash(); }
private:
void setAny(Reg reg) { set(reg); }
void setAny(const RegisterSet& set) { merge(set); }
void setMany() { }
template<typename RegType, typename... Regs>
void setMany(RegType reg, Regs... regs)
{
setAny(reg);
setMany(regs...);
}
BitVector m_vector;
};
struct RegisterSetHash {
static unsigned hash(const RegisterSet& set) { return set.hash(); }
static bool equal(const RegisterSet& a, const RegisterSet& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = false;
};
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<JSC::RegisterSet> {
typedef JSC::RegisterSetHash Hash;
};
template<typename T> struct HashTraits;
template<> struct HashTraits<JSC::RegisterSet> : public CustomHashTraits<JSC::RegisterSet> { };
}
#endif // ENABLE(JIT)
#endif // RegisterSet_h