Hash :
765924f0
Author :
Date :
2018-01-04T12:48:36
Fold ternary and comma ops only after parsing is done In case folding a ternary op or a comma op would change the qualifier of the expression, the folding is deferred to a separate traversal step. After this there are no more cases where the type of a TIntermSymbol node needs to differ from the type of the variable it is referring to. There are still some cases where some parts of TIntermSymbol type are changed while keeping the TVariable type the same though, like when assigning array size to gl_PerVertex nodes or sanitizing qualifiers of struct declarations. BUG=angleproject:2267 TEST=angle_unittests, angle_end2end_tests Change-Id: I1501c8d361f5f765f43ca810d1b7248d9e2c5986 Reviewed-on: https://chromium-review.googlesource.com/850672 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// FoldExpressions.cpp: Fold expressions. This may fold expressions so that the qualifier of the
// folded node differs from the qualifier of the original expression, so it needs to be done after
// parsing and validation of qualifiers is complete. Expressions that are folded:
// 1. Ternary ops with a constant condition.
// 2. Sequence aka comma ops where the left side has no side effects.
// 3. Any expressions containing any of the above.
#include "compiler/translator/FoldExpressions.h"
#include "compiler/translator/Diagnostics.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/IntermTraverse.h"
namespace sh
{
namespace
{
class FoldExpressionsTraverser : public TIntermTraverser
{
public:
FoldExpressionsTraverser(TDiagnostics *diagnostics)
: TIntermTraverser(true, false, false), mDiagnostics(diagnostics), mDidReplace(false)
{
}
bool didReplace() { return mDidReplace; }
void nextIteration() { mDidReplace = false; }
protected:
bool visitTernary(Visit visit, TIntermTernary *node) override
{
TIntermTyped *folded = node->fold(mDiagnostics);
if (folded != node)
{
queueReplacement(folded, OriginalNode::IS_DROPPED);
mDidReplace = true;
return false;
}
return true;
}
bool visitAggregate(Visit visit, TIntermAggregate *node) override
{
TIntermTyped *folded = node->fold(mDiagnostics);
if (folded != node)
{
queueReplacement(folded, OriginalNode::IS_DROPPED);
mDidReplace = true;
return false;
}
return true;
}
bool visitBinary(Visit visit, TIntermBinary *node) override
{
TIntermTyped *folded = node->fold(mDiagnostics);
if (folded != node)
{
queueReplacement(folded, OriginalNode::IS_DROPPED);
mDidReplace = true;
return false;
}
return true;
}
bool visitUnary(Visit visit, TIntermUnary *node) override
{
TIntermTyped *folded = node->fold(mDiagnostics);
if (folded != node)
{
queueReplacement(folded, OriginalNode::IS_DROPPED);
mDidReplace = true;
return false;
}
return true;
}
bool visitSwizzle(Visit visit, TIntermSwizzle *node) override
{
TIntermTyped *folded = node->fold(mDiagnostics);
if (folded != node)
{
queueReplacement(folded, OriginalNode::IS_DROPPED);
mDidReplace = true;
return false;
}
return true;
}
private:
TDiagnostics *mDiagnostics;
bool mDidReplace;
};
} // anonymous namespace
void FoldExpressions(TIntermBlock *root, TDiagnostics *diagnostics)
{
FoldExpressionsTraverser traverser(diagnostics);
do
{
traverser.nextIteration();
root->traverse(&traverser);
traverser.updateTree();
} while (traverser.didReplace());
}
} // namespace sh