#ifndef DFGNodeOrigin_h
#define DFGNodeOrigin_h
#if ENABLE(DFG_JIT)
#include "CodeOrigin.h"
#include "DFGClobbersExitState.h"
namespace JSC { namespace DFG {
class Graph;
struct Node;
struct NodeOrigin {
NodeOrigin() { }
NodeOrigin(CodeOrigin semantic, CodeOrigin forExit, bool exitOK)
: semantic(semantic)
, forExit(forExit)
, exitOK(exitOK)
{
}
bool isSet() const
{
ASSERT(semantic.isSet() == forExit.isSet());
return semantic.isSet();
}
NodeOrigin withSemantic(CodeOrigin semantic) const
{
if (!isSet())
return NodeOrigin();
NodeOrigin result = *this;
if (semantic.isSet())
result.semantic = semantic;
return result;
}
NodeOrigin withForExitAndExitOK(CodeOrigin forExit, bool exitOK) const
{
if (!isSet())
return NodeOrigin();
NodeOrigin result = *this;
if (forExit.isSet())
result.forExit = forExit;
result.exitOK = exitOK;
return result;
}
NodeOrigin withExitOK(bool value) const
{
NodeOrigin result = *this;
result.exitOK = value;
return result;
}
NodeOrigin withInvalidExit() const
{
return withExitOK(false);
}
NodeOrigin takeValidExit(bool& canExit) const
{
return withExitOK(exitOK & std::exchange(canExit, false));
}
NodeOrigin withWasHoisted() const
{
NodeOrigin result = *this;
result.wasHoisted = true;
return result;
}
NodeOrigin forInsertingAfter(Graph& graph, Node* node) const
{
NodeOrigin result = *this;
if (exitOK && clobbersExitState(graph, node))
result.exitOK = false;
return result;
}
bool operator==(const NodeOrigin& other) const
{
return semantic == other.semantic
&& forExit == other.forExit
&& exitOK == other.exitOK;
}
bool operator!=(const NodeOrigin& other) const
{
return !(*this == other);
}
void dump(PrintStream&) const;
CodeOrigin semantic;
CodeOrigin forExit;
bool exitOK { false };
bool wasHoisted { false };
};
} }
#endif // ENABLE(DFG_JIT)
#endif // DFGNodeOrigin_h