Commit ea39a223 by Olli Etuaho Committed by Commit Bot

Simplify queueReplacement AST transform helper

queueReplacement is always called to replace the node that's currently being visited in the traverser. The currently visited node can be fetched automatically from the traversal path so it can be removed from parameters of queueReplacement. BUG=angleproject:2100 TEST=angle_unittests Change-Id: I62ab6d1cd9c0d2b4c260af9f7c85bc156fb3f349 Reviewed-on: https://chromium-review.googlesource.com/562336Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 145e3cbb
...@@ -117,7 +117,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitFunctionPrototype(Visit visit ...@@ -117,7 +117,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitFunctionPrototype(Visit visit
*replacement->getFunctionSymbolInfo() = *node->getFunctionSymbolInfo(); *replacement->getFunctionSymbolInfo() = *node->getFunctionSymbolInfo();
replacement->setLine(node->getLine()); replacement->setLine(node->getLine());
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
} }
return false; return false;
} }
...@@ -186,7 +186,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitBinary(Visit visit, TIntermBi ...@@ -186,7 +186,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitBinary(Visit visit, TIntermBi
if (rightAgg != nullptr && rightAgg->getOp() == EOpCallFunctionInAST) if (rightAgg != nullptr && rightAgg->getOp() == EOpCallFunctionInAST)
{ {
TIntermAggregate *replacementCall = CreateReplacementCall(rightAgg, node->getLeft()); TIntermAggregate *replacementCall = CreateReplacementCall(rightAgg, node->getLeft());
queueReplacement(node, replacementCall, OriginalNode::IS_DROPPED); queueReplacement(replacementCall, OriginalNode::IS_DROPPED);
} }
} }
return false; return false;
......
...@@ -33,7 +33,7 @@ class ReplaceVariableTraverser : public TIntermTraverser ...@@ -33,7 +33,7 @@ class ReplaceVariableTraverser : public TIntermTraverser
TName &name = node->getName(); TName &name = node->getName();
if (name.getString() == mSymbolName) if (name.getString() == mSymbolName)
{ {
queueReplacement(node, mNewSymbol->deepCopy(), OriginalNode::IS_DROPPED); queueReplacement(mNewSymbol->deepCopy(), OriginalNode::IS_DROPPED);
} }
} }
......
...@@ -71,7 +71,7 @@ void GLFragColorBroadcastTraverser::visitSymbol(TIntermSymbol *node) ...@@ -71,7 +71,7 @@ void GLFragColorBroadcastTraverser::visitSymbol(TIntermSymbol *node)
{ {
if (node->getSymbol() == "gl_FragColor") if (node->getSymbol() == "gl_FragColor")
{ {
queueReplacement(node, constructGLFragDataNode(0), OriginalNode::IS_DROPPED); queueReplacement(constructGLFragDataNode(0), OriginalNode::IS_DROPPED);
mGLFragColorUsed = true; mGLFragColorUsed = true;
} }
} }
......
...@@ -527,7 +527,7 @@ void EmulatePrecision::visitSymbol(TIntermSymbol *node) ...@@ -527,7 +527,7 @@ void EmulatePrecision::visitSymbol(TIntermSymbol *node)
!isLValueRequiredHere()) !isLValueRequiredHere())
{ {
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
queueReplacement(node, replacement, OriginalNode::BECOMES_CHILD); queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
} }
} }
...@@ -575,7 +575,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -575,7 +575,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
break; break;
} }
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
queueReplacement(node, replacement, OriginalNode::BECOMES_CHILD); queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
break; break;
} }
...@@ -587,7 +587,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -587,7 +587,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
node->getRight()->getType().getBuiltInTypeNameString())); node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode( TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "add"); node->getLeft(), node->getRight(), "add");
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
break; break;
} }
case EOpSubAssign: case EOpSubAssign:
...@@ -597,7 +597,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -597,7 +597,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
node->getRight()->getType().getBuiltInTypeNameString())); node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode( TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "sub"); node->getLeft(), node->getRight(), "sub");
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
break; break;
} }
case EOpMulAssign: case EOpMulAssign:
...@@ -611,7 +611,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -611,7 +611,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
node->getRight()->getType().getBuiltInTypeNameString())); node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode( TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "mul"); node->getLeft(), node->getRight(), "mul");
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
break; break;
} }
case EOpDivAssign: case EOpDivAssign:
...@@ -621,7 +621,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -621,7 +621,7 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
node->getRight()->getType().getBuiltInTypeNameString())); node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode( TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "div"); node->getLeft(), node->getRight(), "div");
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
break; break;
} }
default: default:
...@@ -682,7 +682,7 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -682,7 +682,7 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
!ParentConstructorTakesCareOfRounding(parent, node)) !ParentConstructorTakesCareOfRounding(parent, node))
{ {
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
queueReplacement(node, replacement, OriginalNode::BECOMES_CHILD); queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
} }
break; break;
} }
...@@ -705,7 +705,7 @@ bool EmulatePrecision::visitUnary(Visit visit, TIntermUnary *node) ...@@ -705,7 +705,7 @@ bool EmulatePrecision::visitUnary(Visit visit, TIntermUnary *node)
if (canRoundFloat(node->getType()) && visit == PreVisit) if (canRoundFloat(node->getType()) && visit == PreVisit)
{ {
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
queueReplacement(node, replacement, OriginalNode::BECOMES_CHILD); queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
} }
break; break;
} }
......
...@@ -139,7 +139,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -139,7 +139,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
current = div; current = div;
} }
queueReplacement(node, current, OriginalNode::IS_DROPPED); queueReplacement(current, OriginalNode::IS_DROPPED);
mFound = true; mFound = true;
return false; return false;
} }
......
...@@ -699,11 +699,9 @@ void TIntermTraverser::clearReplacementQueue() ...@@ -699,11 +699,9 @@ void TIntermTraverser::clearReplacementQueue()
mInsertions.clear(); mInsertions.clear();
} }
void TIntermTraverser::queueReplacement(TIntermNode *original, void TIntermTraverser::queueReplacement(TIntermNode *replacement, OriginalNode originalStatus)
TIntermNode *replacement,
OriginalNode originalStatus)
{ {
queueReplacementWithParent(getParentNode(), original, replacement, originalStatus); queueReplacementWithParent(getParentNode(), mPath.back(), replacement, originalStatus);
} }
void TIntermTraverser::queueReplacementWithParent(TIntermNode *parent, void TIntermTraverser::queueReplacementWithParent(TIntermNode *parent,
......
...@@ -236,9 +236,10 @@ class TIntermTraverser : angle::NonCopyable ...@@ -236,9 +236,10 @@ class TIntermTraverser : angle::NonCopyable
}; };
void clearReplacementQueue(); void clearReplacementQueue();
void queueReplacement(TIntermNode *original,
TIntermNode *replacement, // Replace the node currently being visited with replacement.
OriginalNode originalStatus); void queueReplacement(TIntermNode *replacement, OriginalNode originalStatus);
// Explicitly specify a node to replace with replacement.
void queueReplacementWithParent(TIntermNode *parent, void queueReplacementWithParent(TIntermNode *parent,
TIntermNode *original, TIntermNode *original,
TIntermNode *replacement, TIntermNode *replacement,
......
...@@ -76,7 +76,7 @@ bool PruneEmptyDeclarationsTraverser::visitDeclaration(Visit, TIntermDeclaration ...@@ -76,7 +76,7 @@ bool PruneEmptyDeclarationsTraverser::visitDeclaration(Visit, TIntermDeclaration
} }
else else
{ {
queueReplacement(node, nullptr, OriginalNode::IS_DROPPED); queueReplacement(nullptr, OriginalNode::IS_DROPPED);
} }
} }
else if (sym->getType().getQualifier() != EvqGlobal && else if (sym->getType().getQualifier() != EvqGlobal &&
......
...@@ -139,7 +139,7 @@ void RecordConstantPrecisionTraverser::visitConstantUnion(TIntermConstantUnion * ...@@ -139,7 +139,7 @@ void RecordConstantPrecisionTraverser::visitConstantUnion(TIntermConstantUnion *
TIntermSequence insertions; TIntermSequence insertions;
insertions.push_back(createTempInitDeclaration(node, EvqConst)); insertions.push_back(createTempInitDeclaration(node, EvqConst));
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
queueReplacement(node, createTempSymbol(node->getType()), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(node->getType()), OriginalNode::IS_DROPPED);
mFoundHigherPrecisionConstant = true; mFoundHigherPrecisionConstant = true;
} }
......
...@@ -493,7 +493,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod ...@@ -493,7 +493,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod
node, tempIndex, createTempSymbol(fieldType), indexedWriteFunctionId); node, tempIndex, createTempSymbol(fieldType), indexedWriteFunctionId);
insertionsAfter.push_back(indexedWriteCall); insertionsAfter.push_back(indexedWriteCall);
insertStatementsInParentBlock(insertionsBefore, insertionsAfter); insertStatementsInParentBlock(insertionsBefore, insertionsAfter);
queueReplacement(node, createTempSymbol(fieldType), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(fieldType), OriginalNode::IS_DROPPED);
mUsedTreeInsertion = true; mUsedTreeInsertion = true;
} }
else else
...@@ -506,7 +506,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod ...@@ -506,7 +506,7 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod
ASSERT(!mRemoveIndexSideEffectsInSubtree); ASSERT(!mRemoveIndexSideEffectsInSubtree);
TIntermAggregate *indexingCall = CreateIndexFunctionCall( TIntermAggregate *indexingCall = CreateIndexFunctionCall(
node, EnsureSignedInt(node->getRight()), indexingFunctionId); node, EnsureSignedInt(node->getRight()), indexingFunctionId);
queueReplacement(node, indexingCall, OriginalNode::IS_DROPPED); queueReplacement(indexingCall, OriginalNode::IS_DROPPED);
} }
} }
} }
......
...@@ -67,7 +67,7 @@ bool RemovePowTraverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -67,7 +67,7 @@ bool RemovePowTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermUnary *exp = new TIntermUnary(EOpExp2, mul); TIntermUnary *exp = new TIntermUnary(EOpExp2, mul);
exp->setLine(node->getLine()); exp->setLine(node->getLine());
queueReplacement(node, exp, OriginalNode::IS_DROPPED); queueReplacement(exp, OriginalNode::IS_DROPPED);
// If the x parameter also needs to be replaced, we need to do that in another traversal, // If the x parameter also needs to be replaced, we need to do that in another traversal,
// since it's parent node will change in a way that's not handled correctly by updateTree(). // since it's parent node will change in a way that's not handled correctly by updateTree().
......
...@@ -139,7 +139,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -139,7 +139,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
texelFetchNode->setLine(node->getLine()); texelFetchNode->setLine(node->getLine());
// Replace the old node by this new node. // Replace the old node by this new node.
queueReplacement(node, texelFetchNode, OriginalNode::IS_DROPPED); queueReplacement(texelFetchNode, OriginalNode::IS_DROPPED);
mFound = true; mFound = true;
return false; return false;
} }
......
...@@ -77,7 +77,7 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node) ...@@ -77,7 +77,7 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
TIntermBinary *sub = new TIntermBinary(EOpSub, zero, fValue); TIntermBinary *sub = new TIntermBinary(EOpSub, zero, fValue);
sub->setLine(fValue->getLine()); sub->setLine(fValue->getLine());
queueReplacement(node, sub, OriginalNode::IS_DROPPED); queueReplacement(sub, OriginalNode::IS_DROPPED);
mFound = true; mFound = true;
return false; return false;
......
...@@ -96,7 +96,7 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node) ...@@ -96,7 +96,7 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
TIntermBinary *add = new TIntermBinary(EOpAdd, bitwiseNot, oneNode); TIntermBinary *add = new TIntermBinary(EOpAdd, bitwiseNot, oneNode);
add->setLine(opr->getLine()); add->setLine(opr->getLine());
queueReplacement(node, add, OriginalNode::IS_DROPPED); queueReplacement(add, OriginalNode::IS_DROPPED);
mFound = true; mFound = true;
return false; return false;
......
...@@ -76,7 +76,7 @@ bool SeparateExpressionsTraverser::visitBinary(Visit visit, TIntermBinary *node) ...@@ -76,7 +76,7 @@ bool SeparateExpressionsTraverser::visitBinary(Visit visit, TIntermBinary *node)
insertions.push_back(createTempInitDeclaration(node->getLeft())); insertions.push_back(createTempInitDeclaration(node->getLeft()));
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
queueReplacement(node, createTempSymbol(node->getType()), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(node->getType()), OriginalNode::IS_DROPPED);
return false; return false;
} }
...@@ -97,7 +97,7 @@ bool SeparateExpressionsTraverser::visitAggregate(Visit visit, TIntermAggregate ...@@ -97,7 +97,7 @@ bool SeparateExpressionsTraverser::visitAggregate(Visit visit, TIntermAggregate
insertions.push_back(createTempInitDeclaration(node->shallowCopy())); insertions.push_back(createTempInitDeclaration(node->shallowCopy()));
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
queueReplacement(node, createTempSymbol(node->getType()), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(node->getType()), OriginalNode::IS_DROPPED);
return false; return false;
} }
......
...@@ -264,7 +264,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) ...@@ -264,7 +264,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node)
ELoopWhile, nullptr, createTempSymbol(conditionInitializer->getType()), nullptr, ELoopWhile, nullptr, createTempSymbol(conditionInitializer->getType()), nullptr,
whileLoopBody); whileLoopBody);
loopScope->getSequence()->push_back(whileLoop); loopScope->getSequence()->push_back(whileLoop);
queueReplacement(node, loopScope, OriginalNode::IS_DROPPED); queueReplacement(loopScope, OriginalNode::IS_DROPPED);
// After this the old body node will be traversed and loops inside it may be // After this the old body node will be traversed and loops inside it may be
// transformed. This is fine, since the old body node will still be in the AST after the // transformed. This is fine, since the old body node will still be in the AST after the
......
...@@ -98,7 +98,7 @@ bool SplitSequenceOperatorTraverser::visitBinary(Visit visit, TIntermBinary *nod ...@@ -98,7 +98,7 @@ bool SplitSequenceOperatorTraverser::visitBinary(Visit visit, TIntermBinary *nod
insertions.push_back(node->getLeft()); insertions.push_back(node->getLeft());
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
// Replace the comma node with its right side operand. // Replace the comma node with its right side operand.
queueReplacement(node, node->getRight(), OriginalNode::IS_DROPPED); queueReplacement(node->getRight(), OriginalNode::IS_DROPPED);
} }
mInsideSequenceOperator--; mInsideSequenceOperator--;
} }
......
...@@ -51,7 +51,7 @@ bool UnfoldShortCircuitAST::visitBinary(Visit visit, TIntermBinary *node) ...@@ -51,7 +51,7 @@ bool UnfoldShortCircuitAST::visitBinary(Visit visit, TIntermBinary *node)
} }
if (replacement) if (replacement)
{ {
queueReplacement(node, replacement, OriginalNode::IS_DROPPED); queueReplacement(replacement, OriginalNode::IS_DROPPED);
} }
return true; return true;
} }
......
...@@ -90,7 +90,7 @@ bool UnfoldShortCircuitTraverser::visitBinary(Visit visit, TIntermBinary *node) ...@@ -90,7 +90,7 @@ bool UnfoldShortCircuitTraverser::visitBinary(Visit visit, TIntermBinary *node)
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
queueReplacement(node, createTempSymbol(boolType), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(boolType), OriginalNode::IS_DROPPED);
return false; return false;
} }
case EOpLogicalAnd: case EOpLogicalAnd:
...@@ -114,7 +114,7 @@ bool UnfoldShortCircuitTraverser::visitBinary(Visit visit, TIntermBinary *node) ...@@ -114,7 +114,7 @@ bool UnfoldShortCircuitTraverser::visitBinary(Visit visit, TIntermBinary *node)
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
queueReplacement(node, createTempSymbol(boolType), OriginalNode::IS_DROPPED); queueReplacement(createTempSymbol(boolType), OriginalNode::IS_DROPPED);
return false; return false;
} }
default: default:
...@@ -157,7 +157,7 @@ bool UnfoldShortCircuitTraverser::visitTernary(Visit visit, TIntermTernary *node ...@@ -157,7 +157,7 @@ bool UnfoldShortCircuitTraverser::visitTernary(Visit visit, TIntermTernary *node
insertStatementsInParentBlock(insertions); insertStatementsInParentBlock(insertions);
TIntermSymbol *ternaryResult = createTempSymbol(node->getType()); TIntermSymbol *ternaryResult = createTempSymbol(node->getType());
queueReplacement(node, ternaryResult, OriginalNode::IS_DROPPED); queueReplacement(ternaryResult, OriginalNode::IS_DROPPED);
return false; return false;
} }
......
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