Commit 2cb7b835 by Olli Etuaho Committed by Zhenyao Mo

Clean up binary operation constant folding code

Fix mixed up comments, remove unnecessary type conversions, clarify variable names and improve formatting in a few places. TEST=angle_unittests, WebGL conformance tests BUG=angleproject:913 Change-Id: Ice8fe3682d8e97f42747752302a1fba116132df4 Reviewed-on: https://chromium-review.googlesource.com/266843Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent a8c414ba
...@@ -666,7 +666,7 @@ bool TIntermBinary::promote(TInfoSink &infoSink) ...@@ -666,7 +666,7 @@ bool TIntermBinary::promote(TInfoSink &infoSink)
// Returns the node to keep using, which may or may not be the node passed in. // Returns the node to keep using, which may or may not be the node passed in.
// //
TIntermTyped *TIntermConstantUnion::fold( TIntermTyped *TIntermConstantUnion::fold(
TOperator op, TIntermTyped *constantNode, TInfoSink &infoSink) TOperator op, TIntermConstantUnion *rightNode, TInfoSink &infoSink)
{ {
ConstantUnion *unionArray = getUnionArrayPointer(); ConstantUnion *unionArray = getUnionArrayPointer();
...@@ -675,39 +675,38 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -675,39 +675,38 @@ TIntermTyped *TIntermConstantUnion::fold(
size_t objectSize = getType().getObjectSize(); size_t objectSize = getType().getObjectSize();
if (constantNode) if (rightNode)
{ {
// binary operations // binary operations
TIntermConstantUnion *node = constantNode->getAsConstantUnion(); ConstantUnion *rightUnionArray = rightNode->getUnionArrayPointer();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
TType returnType = getType(); TType returnType = getType();
if (!rightUnionArray) if (!rightUnionArray)
return nullptr; return nullptr;
// for a case like float f = 1.2 + vec4(2,3,4,5); // for a case like float f = vec4(2, 3, 4, 5) + 1.2;
if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) if (rightNode->getType().getObjectSize() == 1 && objectSize > 1)
{ {
rightUnionArray = new ConstantUnion[objectSize]; rightUnionArray = new ConstantUnion[objectSize];
for (size_t i = 0; i < objectSize; ++i) for (size_t i = 0; i < objectSize; ++i)
{ {
rightUnionArray[i] = *node->getUnionArrayPointer(); rightUnionArray[i] = *rightNode->getUnionArrayPointer();
} }
returnType = getType(); returnType = getType();
} }
else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) else if (rightNode->getType().getObjectSize() > 1 && objectSize == 1)
{ {
// for a case like float f = vec4(2,3,4,5) + 1.2; // for a case like float f = 1.2 + vec4(2, 3, 4, 5);
unionArray = new ConstantUnion[constantNode->getType().getObjectSize()]; unionArray = new ConstantUnion[rightNode->getType().getObjectSize()];
for (size_t i = 0; i < constantNode->getType().getObjectSize(); ++i) for (size_t i = 0; i < rightNode->getType().getObjectSize(); ++i)
{ {
unionArray[i] = *getUnionArrayPointer(); unionArray[i] = *getUnionArrayPointer();
} }
returnType = node->getType(); returnType = rightNode->getType();
objectSize = constantNode->getType().getObjectSize(); objectSize = rightNode->getType().getObjectSize();
} }
ConstantUnion *tempConstArray = NULL; ConstantUnion *tempConstArray = nullptr;
TIntermConstantUnion *tempNode; TIntermConstantUnion *tempNode;
bool boolNodeFlag = false; bool boolNodeFlag = false;
...@@ -735,7 +734,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -735,7 +734,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpMatrixTimesMatrix: case EOpMatrixTimesMatrix:
{ {
if (getType().getBasicType() != EbtFloat || if (getType().getBasicType() != EbtFloat ||
node->getBasicType() != EbtFloat) rightNode->getBasicType() != EbtFloat)
{ {
infoSink.info.message( infoSink.info.message(
EPrefixInternalError, getLine(), EPrefixInternalError, getLine(),
...@@ -745,12 +744,12 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -745,12 +744,12 @@ TIntermTyped *TIntermConstantUnion::fold(
const int leftCols = getCols(); const int leftCols = getCols();
const int leftRows = getRows(); const int leftRows = getRows();
const int rightCols = constantNode->getType().getCols(); const int rightCols = rightNode->getType().getCols();
const int rightRows = constantNode->getType().getRows(); const int rightRows = rightNode->getType().getRows();
const int resultCols = rightCols; const int resultCols = rightCols;
const int resultRows = leftRows; const int resultRows = leftRows;
tempConstArray = new ConstantUnion[resultCols*resultRows]; tempConstArray = new ConstantUnion[resultCols * resultRows];
for (int row = 0; row < resultRows; row++) for (int row = 0; row < resultRows; row++)
{ {
for (int column = 0; column < resultCols; column++) for (int column = 0; column < resultCols; column++)
...@@ -862,7 +861,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -862,7 +861,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpMatrixTimesVector: case EOpMatrixTimesVector:
{ {
if (node->getBasicType() != EbtFloat) if (rightNode->getBasicType() != EbtFloat)
{ {
infoSink.info.message( infoSink.info.message(
EPrefixInternalError, getLine(), EPrefixInternalError, getLine(),
...@@ -887,7 +886,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -887,7 +886,7 @@ TIntermTyped *TIntermConstantUnion::fold(
} }
} }
returnType = node->getType(); returnType = rightNode->getType();
returnType.setPrimarySize(static_cast<unsigned char>(matrixRows)); returnType.setPrimarySize(static_cast<unsigned char>(matrixRows));
tempNode = new TIntermConstantUnion(tempConstArray, returnType); tempNode = new TIntermConstantUnion(tempConstArray, returnType);
...@@ -906,8 +905,8 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -906,8 +905,8 @@ TIntermTyped *TIntermConstantUnion::fold(
return nullptr; return nullptr;
} }
const int matrixCols = constantNode->getType().getCols(); const int matrixCols = rightNode->getType().getCols();
const int matrixRows = constantNode->getType().getRows(); const int matrixRows = rightNode->getType().getRows();
tempConstArray = new ConstantUnion[matrixCols]; tempConstArray = new ConstantUnion[matrixCols];
...@@ -1035,8 +1034,8 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1035,8 +1034,8 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpEqual: case EOpEqual:
if (getType().getBasicType() == EbtStruct) if (getType().getBasicType() == EbtStruct)
{ {
if (!CompareStructure(node->getType(), if (!CompareStructure(rightNode->getType(),
node->getUnionArrayPointer(), rightNode->getUnionArrayPointer(),
unionArray)) unionArray))
{ {
boolNodeFlag = true; boolNodeFlag = true;
...@@ -1073,8 +1072,8 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1073,8 +1072,8 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpNotEqual: case EOpNotEqual:
if (getType().getBasicType() == EbtStruct) if (getType().getBasicType() == EbtStruct)
{ {
if (CompareStructure(node->getType(), if (CompareStructure(rightNode->getType(),
node->getUnionArrayPointer(), rightNode->getUnionArrayPointer(),
unionArray)) unionArray))
{ {
boolNodeFlag = true; boolNodeFlag = true;
......
...@@ -293,7 +293,7 @@ class TIntermConstantUnion : public TIntermTyped ...@@ -293,7 +293,7 @@ class TIntermConstantUnion : public TIntermTyped
virtual void traverse(TIntermTraverser *); virtual void traverse(TIntermTraverser *);
virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; }
TIntermTyped *fold(TOperator, TIntermTyped *, TInfoSink &); TIntermTyped *fold(TOperator op, TIntermConstantUnion *rightNode, TInfoSink &infoSink);
protected: protected:
ConstantUnion *mUnionArrayPointer; ConstantUnion *mUnionArrayPointer;
......
...@@ -143,7 +143,7 @@ TIntermTyped *TIntermediate::addUnaryMath( ...@@ -143,7 +143,7 @@ TIntermTyped *TIntermediate::addUnaryMath(
if (childTempConstant) if (childTempConstant)
{ {
TIntermTyped *newChild = childTempConstant->fold(op, 0, mInfoSink); TIntermTyped *newChild = childTempConstant->fold(op, nullptr, mInfoSink);
if (newChild) if (newChild)
return newChild; return newChild;
......
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