Commit 9775655d authored by fpizlo@apple.com's avatar fpizlo@apple.com

Rationalize DFG DCE

https://bugs.webkit.org/show_bug.cgi?id=125523

Reviewed by Mark Hahnenberg.
        
Adds the ability to DCE more things. It's now the case that if a node is completely
pure, we clear NodeMustGenerate and the node becomes a DCE candidate.

* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGCSEPhase.cpp:
(JSC::DFG::CSEPhase::performNodeCSE):
* dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* dfg/DFGDCEPhase.cpp:
(JSC::DFG::DCEPhase::cleanVariables):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::clobbersWorld):
* dfg/DFGNodeType.h:
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileAdd):
* dfg/DFGSpeculativeJIT.h:
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileValueAdd):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 04118560
2014-01-01 Filip Pizlo <fpizlo@apple.com>
Rationalize DFG DCE
https://bugs.webkit.org/show_bug.cgi?id=125523
Reviewed by Mark Hahnenberg.
Adds the ability to DCE more things. It's now the case that if a node is completely
pure, we clear NodeMustGenerate and the node becomes a DCE candidate.
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGCSEPhase.cpp:
(JSC::DFG::CSEPhase::performNodeCSE):
* dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* dfg/DFGDCEPhase.cpp:
(JSC::DFG::DCEPhase::cleanVariables):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::clobbersWorld):
* dfg/DFGNodeType.h:
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileAdd):
* dfg/DFGSpeculativeJIT.h:
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileValueAdd):
2014-01-02 Benjamin Poulain <benjamin@webkit.org>
Attempt to fix the build of WebCore's code generator on CMake based system
......
......@@ -340,7 +340,19 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
break;
}
case ValueAdd:
case ValueAdd: {
JSValue left = forNode(node->child1()).value();
JSValue right = forNode(node->child2()).value();
if (left && right && left.isNumber() && right.isNumber()) {
setConstant(node, JSValue(left.asNumber() + right.asNumber()));
break;
}
ASSERT(node->binaryUseKind() == UntypedUse);
clobberWorld(node->codeOrigin, clobberLimit);
forNode(node).setType(SpecString | SpecBytecodeNumber);
break;
}
case ArithAdd: {
JSValue left = forNode(node->child1()).value();
JSValue right = forNode(node->child2()).value();
......@@ -368,9 +380,7 @@ bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimi
forNode(node).setType(SpecDouble);
break;
default:
RELEASE_ASSERT(node->op() == ValueAdd);
clobberWorld(node->codeOrigin, clobberLimit);
forNode(node).setType(SpecString | SpecBytecodeNumber);
RELEASE_ASSERT_NOT_REACHED();
break;
}
break;
......
......@@ -1239,7 +1239,6 @@ private:
// Handle nodes that are conditionally pure: these are pure, and can
// be CSE'd, so long as the prediction is the one we want.
case ValueAdd:
case CompareLess:
case CompareLessEq:
case CompareGreater:
......
......@@ -204,25 +204,11 @@ void clobberize(Graph& graph, Node* node, ReadFunctor& read, WriteFunctor& write
case In:
case GetMyArgumentsLengthSafe:
case GetMyArgumentByValSafe:
case ValueAdd:
read(World);
write(World);
return;
case ValueAdd:
switch (node->binaryUseKind()) {
case Int32Use:
case NumberUse:
case MachineIntUse:
return;
case UntypedUse:
read(World);
write(World);
return;
default:
RELEASE_ASSERT_NOT_REACHED();
return;
}
case GetCallee:
read(AbstractHeap(Variables, JSStack::Callee));
return;
......@@ -579,30 +565,17 @@ void clobberize(Graph& graph, Node* node, ReadFunctor& read, WriteFunctor& write
}
return;
case CompareEq:
case CompareLess:
case CompareLessEq:
case CompareGreater:
case CompareGreaterEq:
if (graph.isPredictedNumerical(node))
if (!node->isBinaryUseKind(UntypedUse))
return;
read(World);
write(World);
return;
case CompareEq:
if (graph.isPredictedNumerical(node)
|| node->isBinaryUseKind(StringUse)
|| node->isBinaryUseKind(StringIdentUse))
return;
if ((node->child1().useKind() == ObjectUse || node->child1().useKind() == ObjectOrOtherUse)
&& (node->child2().useKind() == ObjectUse || node->child2().useKind() == ObjectOrOtherUse))
return;
read(World);
write(World);
return;
case ToString:
switch (node->child1().useKind()) {
case StringObjectUse:
......
......@@ -259,7 +259,7 @@ private:
continue;
if (node->op() == GetLocal) {
node = node->child1().node();
ASSERT(node->op() == Phi);
ASSERT(node->op() == Phi || node->op() == SetArgument);
if (node->shouldGenerate()) {
variables[i] = node;
continue;
......
......@@ -154,11 +154,16 @@ private:
}
case ValueAdd: {
if (attemptToMakeIntegerAdd(node))
if (attemptToMakeIntegerAdd(node)) {
node->setOp(ArithAdd);
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (Node::shouldSpeculateNumberExpectingDefined(node->child1().node(), node->child2().node())) {
fixEdge<NumberUse>(node->child1());
fixEdge<NumberUse>(node->child2());
node->setOp(ArithAdd);
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
......@@ -326,17 +331,20 @@ private:
if (Node::shouldSpeculateInt32(node->child1().node(), node->child2().node())) {
fixEdge<Int32Use>(node->child1());
fixEdge<Int32Use>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (enableInt52()
&& Node::shouldSpeculateMachineInt(node->child1().node(), node->child2().node())) {
fixEdge<MachineIntUse>(node->child1());
fixEdge<MachineIntUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (Node::shouldSpeculateNumber(node->child1().node(), node->child2().node())) {
fixEdge<NumberUse>(node->child1());
fixEdge<NumberUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->op() != CompareEq)
......@@ -344,31 +352,37 @@ private:
if (Node::shouldSpeculateBoolean(node->child1().node(), node->child2().node())) {
fixEdge<BooleanUse>(node->child1());
fixEdge<BooleanUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->child1()->shouldSpeculateStringIdent() && node->child2()->shouldSpeculateStringIdent()) {
fixEdge<StringIdentUse>(node->child1());
fixEdge<StringIdentUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->child1()->shouldSpeculateString() && node->child2()->shouldSpeculateString() && GPRInfo::numberOfRegisters >= 7) {
fixEdge<StringUse>(node->child1());
fixEdge<StringUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObject()) {
fixEdge<ObjectUse>(node->child1());
fixEdge<ObjectUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->child1()->shouldSpeculateObject() && node->child2()->shouldSpeculateObjectOrOther()) {
fixEdge<ObjectUse>(node->child1());
fixEdge<ObjectOrOtherUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
if (node->child1()->shouldSpeculateObjectOrOther() && node->child2()->shouldSpeculateObject()) {
fixEdge<ObjectOrOtherUse>(node->child1());
fixEdge<ObjectUse>(node->child2());
node->clearFlags(NodeMustGenerate | NodeClobbersWorld);
break;
}
break;
......
......@@ -648,13 +648,6 @@ public:
if (!(node->flags() & NodeMightClobber))
return false;
switch (node->op()) {
case ValueAdd:
case CompareLess:
case CompareLessEq:
case CompareGreater:
case CompareGreaterEq:
case CompareEq:
return !isPredictedNumerical(node);
case GetByVal:
case PutByValDirect:
case PutByVal:
......
......@@ -96,12 +96,12 @@ namespace JSC { namespace DFG {
macro(InvalidationPoint, NodeMustGenerate) \
\
/* Nodes for bitwise operations. */\
macro(BitAnd, NodeResultInt32 | NodeMustGenerate) \
macro(BitOr, NodeResultInt32 | NodeMustGenerate) \
macro(BitXor, NodeResultInt32 | NodeMustGenerate) \
macro(BitLShift, NodeResultInt32 | NodeMustGenerate) \
macro(BitRShift, NodeResultInt32 | NodeMustGenerate) \
macro(BitURShift, NodeResultInt32 | NodeMustGenerate) \
macro(BitAnd, NodeResultInt32) \
macro(BitOr, NodeResultInt32) \
macro(BitXor, NodeResultInt32) \
macro(BitLShift, NodeResultInt32) \
macro(BitRShift, NodeResultInt32) \
macro(BitURShift, NodeResultInt32) \
/* Bitwise operators call ToInt32 on their operands. */\
macro(ValueToInt32, NodeResultInt32) \
/* Used to box the result of URShift nodes (result has range 0..2^32-1). */\
......@@ -118,22 +118,22 @@ namespace JSC { namespace DFG {
macro(Int52ToDouble, NodeResultNumber) \
\
/* Nodes for arithmetic operations. */\
macro(ArithAdd, NodeResultNumber | NodeMustGenerate) \
macro(ArithSub, NodeResultNumber | NodeMustGenerate) \
macro(ArithNegate, NodeResultNumber | NodeMustGenerate) \
macro(ArithMul, NodeResultNumber | NodeMustGenerate) \
macro(ArithIMul, NodeResultInt32 | NodeMustGenerate) \
macro(ArithDiv, NodeResultNumber | NodeMustGenerate) \
macro(ArithMod, NodeResultNumber | NodeMustGenerate) \
macro(ArithAbs, NodeResultNumber | NodeMustGenerate) \
macro(ArithMin, NodeResultNumber | NodeMustGenerate) \
macro(ArithMax, NodeResultNumber | NodeMustGenerate) \
macro(ArithSqrt, NodeResultNumber | NodeMustGenerate) \
macro(ArithSin, NodeResultNumber | NodeMustGenerate) \
macro(ArithCos, NodeResultNumber | NodeMustGenerate) \
macro(ArithAdd, NodeResultNumber) \
macro(ArithSub, NodeResultNumber) \
macro(ArithNegate, NodeResultNumber) \
macro(ArithMul, NodeResultNumber) \
macro(ArithIMul, NodeResultInt32) \
macro(ArithDiv, NodeResultNumber) \
macro(ArithMod, NodeResultNumber) \
macro(ArithAbs, NodeResultNumber) \
macro(ArithMin, NodeResultNumber) \
macro(ArithMax, NodeResultNumber) \
macro(ArithSqrt, NodeResultNumber) \
macro(ArithSin, NodeResultNumber) \
macro(ArithCos, NodeResultNumber) \
\
/* Add of values may either be arithmetic, or result in string concatenation. */\
macro(ValueAdd, NodeResultJS | NodeMustGenerate | NodeMightClobber) \
macro(ValueAdd, NodeResultJS | NodeMustGenerate | NodeClobbersWorld) \
\
/* Property access. */\
/* PutByValAlias indicates a 'put' aliases a prior write to the same property. */\
......@@ -208,12 +208,12 @@ namespace JSC { namespace DFG {
macro(StringFromCharCode, NodeResultJS) \
\
/* Nodes for comparison operations. */\
macro(CompareLess, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
macro(CompareLessEq, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
macro(CompareGreater, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
macro(CompareGreaterEq, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
macro(CompareEq, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
macro(CompareEqConstant, NodeResultBoolean | NodeMustGenerate) \
macro(CompareLess, NodeResultBoolean | NodeMustGenerate | NodeClobbersWorld) \
macro(CompareLessEq, NodeResultBoolean | NodeMustGenerate | NodeClobbersWorld) \
macro(CompareGreater, NodeResultBoolean | NodeMustGenerate | NodeClobbersWorld) \
macro(CompareGreaterEq, NodeResultBoolean | NodeMustGenerate | NodeClobbersWorld) \
macro(CompareEq, NodeResultBoolean | NodeMustGenerate | NodeClobbersWorld) \
macro(CompareEqConstant, NodeResultBoolean) \
macro(CompareStrictEq, NodeResultBoolean) \
macro(CompareStrictEqConstant, NodeResultBoolean) \
\
......
......@@ -2685,12 +2685,6 @@ void SpeculativeJIT::compileAdd(Node* node)
return;
}
case UntypedUse: {
RELEASE_ASSERT(node->op() == ValueAdd);
compileValueAdd(node);
return;
}
default:
RELEASE_ASSERT_NOT_REACHED();
break;
......
......@@ -1966,7 +1966,6 @@ public:
void compilePeepHoleObjectToObjectOrOtherEquality(Edge leftChild, Edge rightChild, Node* branchNode);
void compileObjectEquality(Node*);
void compileObjectToObjectOrOtherEquality(Edge leftChild, Edge rightChild);
void compileValueAdd(Node*);
void compileObjectOrOtherLogicalNot(Edge value);
void compileLogicalNot(Node*);
void compileStringEquality(Node*);
......
......@@ -1418,28 +1418,6 @@ void SpeculativeJIT::compileDoubleCompare(Node* node, MacroAssembler::DoubleCond
booleanResult(resultPayload.gpr(), node);
}
void SpeculativeJIT::compileValueAdd(Node* node)
{
JSValueOperand op1(this, node->child1());
JSValueOperand op2(this, node->child2());
GPRReg op1TagGPR = op1.tagGPR();
GPRReg op1PayloadGPR = op1.payloadGPR();
GPRReg op2TagGPR = op2.tagGPR();
GPRReg op2PayloadGPR = op2.payloadGPR();
flushRegisters();
GPRResult2 resultTag(this);
GPRResult resultPayload(this);
if (isKnownNotNumber(node->child1().node()) || isKnownNotNumber(node->child2().node()))
callOperation(operationValueAddNotNumber, resultTag.gpr(), resultPayload.gpr(), op1TagGPR, op1PayloadGPR, op2TagGPR, op2PayloadGPR);
else
callOperation(operationValueAdd, resultTag.gpr(), resultPayload.gpr(), op1TagGPR, op1PayloadGPR, op2TagGPR, op2PayloadGPR);
jsValueResult(resultTag.gpr(), resultPayload.gpr(), node);
}
void SpeculativeJIT::compileObjectOrOtherLogicalNot(Edge nodeUse)
{
JSValueOperand value(this, nodeUse, ManualOperandSpeculation);
......@@ -2072,7 +2050,28 @@ void SpeculativeJIT::compile(Node* node)
break;
}
case ValueAdd:
case ValueAdd: {
JSValueOperand op1(this, node->child1());
JSValueOperand op2(this, node->child2());
GPRReg op1TagGPR = op1.tagGPR();
GPRReg op1PayloadGPR = op1.payloadGPR();
GPRReg op2TagGPR = op2.tagGPR();
GPRReg op2PayloadGPR = op2.payloadGPR();
flushRegisters();
GPRResult2 resultTag(this);
GPRResult resultPayload(this);
if (isKnownNotNumber(node->child1().node()) || isKnownNotNumber(node->child2().node()))
callOperation(operationValueAddNotNumber, resultTag.gpr(), resultPayload.gpr(), op1TagGPR, op1PayloadGPR, op2TagGPR, op2PayloadGPR);
else
callOperation(operationValueAdd, resultTag.gpr(), resultPayload.gpr(), op1TagGPR, op1PayloadGPR, op2TagGPR, op2PayloadGPR);
jsValueResult(resultTag.gpr(), resultPayload.gpr(), node);
break;
}
case ArithAdd:
compileAdd(node);
break;
......
......@@ -1806,25 +1806,6 @@ void SpeculativeJIT::compileDoubleCompare(Node* node, MacroAssembler::DoubleCond
jsValueResult(result.gpr(), node, DataFormatJSBoolean);
}
void SpeculativeJIT::compileValueAdd(Node* node)
{
JSValueOperand op1(this, node->child1());
JSValueOperand op2(this, node->child2());
GPRReg op1GPR = op1.gpr();
GPRReg op2GPR = op2.gpr();
flushRegisters();
GPRResult result(this);
if (isKnownNotNumber(node->child1().node()) || isKnownNotNumber(node->child2().node()))
callOperation(operationValueAddNotNumber, result.gpr(), op1GPR, op2GPR);
else
callOperation(operationValueAdd, result.gpr(), op1GPR, op2GPR);
jsValueResult(result.gpr(), node);
}
void SpeculativeJIT::compileObjectOrOtherLogicalNot(Edge nodeUse)
{
JSValueOperand value(this, nodeUse, ManualOperandSpeculation);
......@@ -2403,7 +2384,25 @@ void SpeculativeJIT::compile(Node* node)
break;
}
case ValueAdd:
case ValueAdd: {
JSValueOperand op1(this, node->child1());
JSValueOperand op2(this, node->child2());
GPRReg op1GPR = op1.gpr();
GPRReg op2GPR = op2.gpr();
flushRegisters();
GPRResult result(this);
if (isKnownNotNumber(node->child1().node()) || isKnownNotNumber(node->child2().node()))
callOperation(operationValueAddNotNumber, result.gpr(), op1GPR, op2GPR);
else
callOperation(operationValueAdd, result.gpr(), op1GPR, op2GPR);
jsValueResult(result.gpr(), node);
break;
}
case ArithAdd:
compileAdd(node);
break;
......
......@@ -261,8 +261,10 @@ private:
case Phantom:
compilePhantom();
break;
case ArithAdd:
case ValueAdd:
compileValueAdd();
break;
case ArithAdd:
compileAddSub();
break;
case ArithSub:
......@@ -763,6 +765,19 @@ private:
DFG_NODE_DO_TO_CHILDREN(m_graph, m_node, speculate);
}
void compileValueAdd()
{
J_JITOperation_EJJ operation;
if (!(m_state.forNode(m_node->child1()).m_type & SpecFullNumber)
&& !(m_state.forNode(m_node->child2()).m_type & SpecFullNumber))
operation = operationValueAddNotNumber;
else
operation = operationValueAdd;
setJSValue(vmCall(
m_out.operation(operation), m_callFrame,
lowJSValue(m_node->child1()), lowJSValue(m_node->child2())));
}
void compileAddSub()
{
bool isSub = m_node->op() == ArithSub;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment