Hash :
e839078e
Author :
Date :
2017-04-06T14:34:43
compiler: Prune literal statements when outputting ESSL The ESSL output doesn't have a default precision for floats, this causes float literal statements to not have any precision defined, which is an error. We fix this by removing literal statements as they are dead code anyway. BUG=angleproject:1967 Change-Id: I498f4f8495f854240ee8a2182415bf982c5166a4 Reviewed-on: https://chromium-review.googlesource.com/470268 Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Commit-Queue: 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
//
// Copyright (c) 2017 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.
//
// PrunePureLiteralStatements.cpp: Removes statements that are literals and nothing else.
#include "compiler/translator/PrunePureLiteralStatements.h"
#include "compiler/translator/IntermNode.h"
namespace sh
{
namespace
{
class PrunePureLiteralStatementsTraverser : public TIntermTraverser
{
public:
PrunePureLiteralStatementsTraverser() : TIntermTraverser(true, false, false) {}
bool visitBlock(Visit visit, TIntermBlock *node) override
{
TIntermSequence *statements = node->getSequence();
if (statements == nullptr)
{
return false;
}
// Empty case statements at the end of a switch are invalid: if the last statements
// of a block was a pure literal, also delete all the case statements directly preceding it.
bool deleteCaseStatements = false;
for (int i = static_cast<int>(statements->size()); i-- > 0;)
{
TIntermNode *statement = (*statements)[i];
if (statement->getAsConstantUnion() != nullptr)
{
TIntermSequence emptyReplacement;
mMultiReplacements.push_back(
NodeReplaceWithMultipleEntry(node, statement, emptyReplacement));
if (i == static_cast<int>(statements->size()) - 1)
{
deleteCaseStatements = true;
}
continue;
}
if (deleteCaseStatements)
{
if (statement->getAsCaseNode() != nullptr)
{
TIntermSequence emptyReplacement;
mMultiReplacements.push_back(
NodeReplaceWithMultipleEntry(node, statement, emptyReplacement));
}
else
{
deleteCaseStatements = false;
}
}
}
return true;
}
bool visitLoop(Visit visit, TIntermLoop *loop) override
{
TIntermTyped *expr = loop->getExpression();
if (expr != nullptr && expr->getAsConstantUnion() != nullptr)
{
loop->setExpression(nullptr);
}
return true;
}
};
} // namespace
void PrunePureLiteralStatements(TIntermNode *root)
{
PrunePureLiteralStatementsTraverser prune;
root->traverse(&prune);
prune.updateTree();
}
} // namespace sh