DFGVariableAccessData.h [plain text]
#ifndef DFGVariableAccessData_h
#define DFGVariableAccessData_h
#include "DFGDoubleFormatState.h"
#include "DFGNodeFlags.h"
#include "Operands.h"
#include "PredictedType.h"
#include "VirtualRegister.h"
#include <wtf/Platform.h>
#include <wtf/UnionFind.h>
#include <wtf/Vector.h>
namespace JSC { namespace DFG {
class VariableAccessData : public UnionFind<VariableAccessData> {
public:
enum Ballot { VoteValue, VoteDouble };
VariableAccessData()
: m_local(static_cast<VirtualRegister>(std::numeric_limits<int>::min()))
, m_prediction(PredictNone)
, m_argumentAwarePrediction(PredictNone)
, m_flags(0)
, m_doubleFormatState(EmptyDoubleFormatState)
{
clearVotes();
}
VariableAccessData(VirtualRegister local)
: m_local(local)
, m_prediction(PredictNone)
, m_argumentAwarePrediction(PredictNone)
, m_flags(0)
, m_doubleFormatState(EmptyDoubleFormatState)
{
clearVotes();
}
VirtualRegister local()
{
ASSERT(m_local == find()->m_local);
return m_local;
}
int operand()
{
return static_cast<int>(local());
}
bool predict(PredictedType prediction)
{
VariableAccessData* self = find();
bool result = mergePrediction(self->m_prediction, prediction);
if (result)
mergePrediction(m_argumentAwarePrediction, m_prediction);
return result;
}
PredictedType nonUnifiedPrediction()
{
return m_prediction;
}
PredictedType prediction()
{
return find()->m_prediction;
}
PredictedType argumentAwarePrediction()
{
return find()->m_argumentAwarePrediction;
}
bool mergeArgumentAwarePrediction(PredictedType prediction)
{
return mergePrediction(find()->m_argumentAwarePrediction, prediction);
}
void clearVotes()
{
ASSERT(find() == this);
m_votes[VoteValue] = 0;
m_votes[VoteDouble] = 0;
}
void vote(Ballot ballot)
{
ASSERT(static_cast<unsigned>(ballot) < 2);
m_votes[ballot]++;
}
double doubleVoteRatio()
{
ASSERT(find() == this);
return static_cast<double>(m_votes[VoteDouble]) / m_votes[VoteValue];
}
bool shouldUseDoubleFormatAccordingToVote()
{
if (operandIsArgument(operand()))
return false;
if (!isNumberPrediction(prediction()))
return false;
if (isDoublePrediction(prediction()))
return true;
if (flags() & NodeUsedAsInt)
return false;
if (doubleVoteRatio() >= Options::doubleVoteRatioForDoubleFormat)
return true;
return false;
}
DoubleFormatState doubleFormatState()
{
return find()->m_doubleFormatState;
}
bool shouldUseDoubleFormat()
{
ASSERT(isRoot());
return m_doubleFormatState == UsingDoubleFormat;
}
bool tallyVotesForShouldUseDoubleFormat()
{
ASSERT(isRoot());
if (m_doubleFormatState == CantUseDoubleFormat)
return false;
bool newValueOfShouldUseDoubleFormat = shouldUseDoubleFormatAccordingToVote();
if (!newValueOfShouldUseDoubleFormat) {
return false;
}
if (m_doubleFormatState == UsingDoubleFormat)
return false;
return DFG::mergeDoubleFormatState(m_doubleFormatState, UsingDoubleFormat);
}
bool mergeDoubleFormatState(DoubleFormatState doubleFormatState)
{
return DFG::mergeDoubleFormatState(find()->m_doubleFormatState, doubleFormatState);
}
bool makePredictionForDoubleFormat()
{
ASSERT(isRoot());
if (m_doubleFormatState != UsingDoubleFormat)
return false;
return mergePrediction(m_prediction, PredictDouble);
}
NodeFlags flags() const { return m_flags; }
bool mergeFlags(NodeFlags newFlags)
{
newFlags |= m_flags;
if (newFlags == m_flags)
return false;
m_flags = newFlags;
return true;
}
private:
VirtualRegister m_local;
PredictedType m_prediction;
PredictedType m_argumentAwarePrediction;
NodeFlags m_flags;
float m_votes[2];
DoubleFormatState m_doubleFormatState;
};
} }
#endif // DFGVariableAccessData_h