Commit 2768bc8a by Olli Etuaho Committed by Commit Bot

Clean up creating constant folded nodes

It's not necessary to set the qualifier on folded nodes separately, they always use the qualifier of the node being folded. BUG=angleproject:1490 TEST=angle_unittests Change-Id: Id2581ef4cae42d7137fbe0caf18c3fcacbf954c6 Reviewed-on: https://chromium-review.googlesource.com/847553 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 4728bdc8
...@@ -95,16 +95,12 @@ float VectorDotProduct(const TConstantUnion *paramArray1, ...@@ -95,16 +95,12 @@ float VectorDotProduct(const TConstantUnion *paramArray1,
return result; return result;
} }
TIntermTyped *CreateFoldedNode(const TConstantUnion *constArray, TIntermTyped *CreateFoldedNode(const TConstantUnion *constArray, const TIntermTyped *originalNode)
const TIntermTyped *originalNode,
TQualifier qualifier)
{ {
if (constArray == nullptr) ASSERT(constArray != nullptr);
{ // Note that we inherit whatever qualifier the folded node had. Nodes may be constant folded
return nullptr; // without being qualified as constant.
}
TIntermTyped *folded = new TIntermConstantUnion(constArray, originalNode->getType()); TIntermTyped *folded = new TIntermConstantUnion(constArray, originalNode->getType());
folded->getTypePointer()->setQualifier(qualifier);
folded->setLine(originalNode->getLine()); folded->setLine(originalNode->getLine());
return folded; return folded;
} }
...@@ -1302,7 +1298,7 @@ TIntermTyped *TIntermSwizzle::fold() ...@@ -1302,7 +1298,7 @@ TIntermTyped *TIntermSwizzle::fold()
{ {
constArray[i] = *operandConstant->foldIndexing(mSwizzleOffsets.at(i)); constArray[i] = *operandConstant->foldIndexing(mSwizzleOffsets.at(i));
} }
return CreateFoldedNode(constArray, this, mType.getQualifier()); return CreateFoldedNode(constArray, this);
} }
TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics) TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics)
...@@ -1333,7 +1329,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics) ...@@ -1333,7 +1329,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics)
{ {
return this; return this;
} }
return CreateFoldedNode(constArray, this, mType.getQualifier()); return CreateFoldedNode(constArray, this);
} }
case EOpIndexDirectStruct: case EOpIndexDirectStruct:
{ {
...@@ -1351,7 +1347,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics) ...@@ -1351,7 +1347,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics)
} }
const TConstantUnion *constArray = leftConstant->getUnionArrayPointer(); const TConstantUnion *constArray = leftConstant->getUnionArrayPointer();
return CreateFoldedNode(constArray + previousFieldsSize, this, mType.getQualifier()); return CreateFoldedNode(constArray + previousFieldsSize, this);
} }
case EOpIndexIndirect: case EOpIndexIndirect:
case EOpIndexDirectInterfaceBlock: case EOpIndexDirectInterfaceBlock:
...@@ -1369,9 +1365,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics) ...@@ -1369,9 +1365,7 @@ TIntermTyped *TIntermBinary::fold(TDiagnostics *diagnostics)
{ {
return this; return this;
} }
return CreateFoldedNode(constArray, this);
// Nodes may be constant folded without being qualified as constant.
return CreateFoldedNode(constArray, this, mType.getQualifier());
} }
} }
} }
...@@ -1427,9 +1421,7 @@ TIntermTyped *TIntermUnary::fold(TDiagnostics *diagnostics) ...@@ -1427,9 +1421,7 @@ TIntermTyped *TIntermUnary::fold(TDiagnostics *diagnostics)
{ {
return this; return this;
} }
return CreateFoldedNode(constArray, this);
// Nodes may be constant folded without being qualified as constant.
return CreateFoldedNode(constArray, this, mType.getQualifier());
} }
TIntermTyped *TIntermAggregate::fold(TDiagnostics *diagnostics) TIntermTyped *TIntermAggregate::fold(TDiagnostics *diagnostics)
...@@ -1444,12 +1436,15 @@ TIntermTyped *TIntermAggregate::fold(TDiagnostics *diagnostics) ...@@ -1444,12 +1436,15 @@ TIntermTyped *TIntermAggregate::fold(TDiagnostics *diagnostics)
} }
TConstantUnion *constArray = nullptr; TConstantUnion *constArray = nullptr;
if (isConstructor()) if (isConstructor())
{
constArray = TIntermConstantUnion::FoldAggregateConstructor(this); constArray = TIntermConstantUnion::FoldAggregateConstructor(this);
}
else else
{
ASSERT(CanFoldAggregateBuiltInOp(mOp));
constArray = TIntermConstantUnion::FoldAggregateBuiltIn(this, diagnostics); constArray = TIntermConstantUnion::FoldAggregateBuiltIn(this, diagnostics);
}
// Nodes may be constant folded without being qualified as constant. return CreateFoldedNode(constArray, this);
return CreateFoldedNode(constArray, this, getQualifier());
} }
// //
......
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