Commit b43846ee by Olli Etuaho

Unify aggregate operator folding with other constant folding

Setting the type for folded aggregate nodes should work in a similar way as other constant folding. Common functionality between the different folding functions is refactored into a single function. TEST=dEQP-GLES3.functional.shaders.constant_expressions.* BUG=angleproject:817 Change-Id: Ie0be561f4a30e52e52d570ff0b2bdb426f6e4f7a Reviewed-on: https://chromium-review.googlesource.com/275186Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 35b08e3c
......@@ -302,7 +302,7 @@ class TIntermConstantUnion : public TIntermTyped
TConstantUnion *foldBinary(TOperator op, TIntermConstantUnion *rightNode, TInfoSink &infoSink);
TConstantUnion *foldUnary(TOperator op, TInfoSink &infoSink);
static TIntermTyped *FoldAggregateBuiltIn(TOperator op, TIntermAggregate *aggregate, TInfoSink &infoSink);
static TConstantUnion *FoldAggregateBuiltIn(TIntermAggregate *aggregate, TInfoSink &infoSink);
protected:
TConstantUnion *mUnionArrayPointer;
......@@ -443,6 +443,7 @@ class TIntermAggregate : public TIntermOperator
bool insertChildNodes(TIntermSequence::size_type position, TIntermSequence insertions);
// Conservatively assume function calls and other aggregate operators have side-effects
virtual bool hasSideEffects() const { return true; }
TIntermTyped *fold(TInfoSink &infoSink);
TIntermSequence *getSequence() { return &mSequence; }
......
......@@ -441,9 +441,9 @@ bool TIntermediate::postProcess(TIntermNode *root)
return true;
}
TIntermTyped *TIntermediate::foldAggregateBuiltIn(TOperator op, TIntermAggregate *aggregate)
TIntermTyped *TIntermediate::foldAggregateBuiltIn(TIntermAggregate *aggregate)
{
switch (op)
switch (aggregate->getOp())
{
case EOpAtan:
case EOpPow:
......@@ -466,7 +466,7 @@ TIntermTyped *TIntermediate::foldAggregateBuiltIn(TOperator op, TIntermAggregate
case EOpFaceForward:
case EOpReflect:
case EOpRefract:
return TIntermConstantUnion::FoldAggregateBuiltIn(op, aggregate, mInfoSink);
return aggregate->fold(mInfoSink);
default:
// Constant folding not supported for the built-in.
return nullptr;
......
......@@ -64,7 +64,7 @@ class TIntermediate
static void outputTree(TIntermNode *, TInfoSinkBase &);
TIntermTyped *foldAggregateBuiltIn(TOperator op, TIntermAggregate *aggregate);
TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate);
private:
void operator=(TIntermediate &); // prevent assignments
......
......@@ -3512,19 +3512,20 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
TIntermAggregate *aggregate = intermediate.setAggregateOperator(paramNode, op, loc);
aggregate->setType(fnCandidate->getReturnType());
aggregate->setPrecisionFromChildren();
callNode = aggregate;
// Some built-in functions have out parameters too.
functionCallLValueErrorCheck(fnCandidate, aggregate);
// See if we can constant fold a built-in.
TIntermTyped *foldedNode = intermediate.foldAggregateBuiltIn(op, aggregate);
TIntermTyped *foldedNode = intermediate.foldAggregateBuiltIn(aggregate);
if (foldedNode)
{
foldedNode->setType(callNode->getType());
foldedNode->getTypePointer()->setQualifier(EvqConst);
callNode = foldedNode;
}
else
{
callNode = aggregate;
}
}
}
else
......
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