Commit 3cbb27a1 by Olli Etuaho Committed by Commit Bot

Simplify loop conditions so that they won't generate statements

Introduce an AST traverser that can move the evaluation of certain types of loop conditions and loop expressions inside the loop. This way subsequent AST transformations don't have to worry about cases where they have to insert new statements to implement a loop condition or expression. This includes the revert of "Unfold short-circuiting operators in loop conditions correctly". The new traverser covers the loop cases that used to be handled in UnfoldShortCircuitToIf. BUG=angleproject:1465 TEST=WebGL conformance tests, dEQP-GLES2.functional.shaders.*select_iteration_count* Change-Id: I88e50e007e924d5884a217117690ac7fa2f96d38 Reviewed-on: https://chromium-review.googlesource.com/362570Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 66fb8206
...@@ -188,6 +188,8 @@ ...@@ -188,6 +188,8 @@
'compiler/translator/SeparateDeclarations.h', 'compiler/translator/SeparateDeclarations.h',
'compiler/translator/SeparateExpressionsReturningArrays.cpp', 'compiler/translator/SeparateExpressionsReturningArrays.cpp',
'compiler/translator/SeparateExpressionsReturningArrays.h', 'compiler/translator/SeparateExpressionsReturningArrays.h',
'compiler/translator/SimplifyLoopConditions.cpp',
'compiler/translator/SimplifyLoopConditions.h',
'compiler/translator/SplitSequenceOperator.cpp', 'compiler/translator/SplitSequenceOperator.cpp',
'compiler/translator/SplitSequenceOperator.h', 'compiler/translator/SplitSequenceOperator.h',
'compiler/translator/StructureHLSL.cpp', 'compiler/translator/StructureHLSL.cpp',
......
...@@ -197,6 +197,7 @@ void TIntermTyped::setTypePreservePrecision(const TType &t) ...@@ -197,6 +197,7 @@ void TIntermTyped::setTypePreservePrecision(const TType &t)
bool TIntermLoop::replaceChildNode( bool TIntermLoop::replaceChildNode(
TIntermNode *original, TIntermNode *replacement) TIntermNode *original, TIntermNode *replacement)
{ {
ASSERT(original != nullptr); // This risks replacing multiple children.
REPLACE_IF_IS(mInit, TIntermNode, original, replacement); REPLACE_IF_IS(mInit, TIntermNode, original, replacement);
REPLACE_IF_IS(mCond, TIntermTyped, original, replacement); REPLACE_IF_IS(mCond, TIntermTyped, original, replacement);
REPLACE_IF_IS(mExpr, TIntermTyped, original, replacement); REPLACE_IF_IS(mExpr, TIntermTyped, original, replacement);
......
...@@ -195,6 +195,10 @@ class TIntermLoop : public TIntermNode ...@@ -195,6 +195,10 @@ class TIntermLoop : public TIntermNode
TIntermTyped *getExpression() { return mExpr; } TIntermTyped *getExpression() { return mExpr; }
TIntermAggregate *getBody() { return mBody; } TIntermAggregate *getBody() { return mBody; }
void setCondition(TIntermTyped *condition) { mCond = condition; }
void setExpression(TIntermTyped *expression) { mExpr = expression; }
void setBody(TIntermAggregate *body) { mBody = body; }
void setUnrollFlag(bool flag) { mUnrollFlag = flag; } void setUnrollFlag(bool flag) { mUnrollFlag = flag; }
bool getUnrollFlag() const { return mUnrollFlag; } bool getUnrollFlag() const { return mUnrollFlag; }
...@@ -912,9 +916,9 @@ class TLValueTrackingTraverser : public TIntermTraverser ...@@ -912,9 +916,9 @@ class TLValueTrackingTraverser : public TIntermTraverser
} }
virtual ~TLValueTrackingTraverser() {} virtual ~TLValueTrackingTraverser() {}
void traverseBinary(TIntermBinary *node) override; void traverseBinary(TIntermBinary *node) final;
void traverseUnary(TIntermUnary *node) override; void traverseUnary(TIntermUnary *node) final;
void traverseAggregate(TIntermAggregate *node) override; void traverseAggregate(TIntermAggregate *node) final;
protected: protected:
bool isLValueRequiredHere() const bool isLValueRequiredHere() const
......
//
// Copyright (c) 2016 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.
//
// SimplifyLoopConditions is an AST traverser that converts loop conditions and loop expressions
// to regular statements inside the loop. This way further transformations that generate statements
// from loop conditions and loop expressions work correctly.
//
#ifndef COMPILER_TRANSLATOR_SIMPLIFYLOOPCONDITIONS_H_
#define COMPILER_TRANSLATOR_SIMPLIFYLOOPCONDITIONS_H_
class TIntermNode;
class TSymbolTable;
void SimplifyLoopConditions(TIntermNode *root,
unsigned int conditionsToSimplify,
unsigned int *temporaryIndex,
const TSymbolTable &symbolTable,
int shaderVersion);
#endif // COMPILER_TRANSLATOR_SIMPLIFYLOOPCONDITIONS_H_
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "compiler/translator/SeparateArrayInitialization.h" #include "compiler/translator/SeparateArrayInitialization.h"
#include "compiler/translator/SeparateDeclarations.h" #include "compiler/translator/SeparateDeclarations.h"
#include "compiler/translator/SeparateExpressionsReturningArrays.h" #include "compiler/translator/SeparateExpressionsReturningArrays.h"
#include "compiler/translator/SimplifyLoopConditions.h"
#include "compiler/translator/SplitSequenceOperator.h" #include "compiler/translator/SplitSequenceOperator.h"
#include "compiler/translator/UnfoldShortCircuitToIf.h" #include "compiler/translator/UnfoldShortCircuitToIf.h"
...@@ -34,9 +35,14 @@ void TranslatorHLSL::translate(TIntermNode *root, int compileOptions) ...@@ -34,9 +35,14 @@ void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
SeparateDeclarations(root); SeparateDeclarations(root);
// TODO (oetuaho): Sequence operators should also be split in case there is dynamic indexing of // Note that SimplifyLoopConditions needs to be run before any other AST transformations that
// a vector or matrix as an l-value inside (RemoveDynamicIndexing transformation step generates // may need to generate new statements from loop conditions or loop expressions.
// statements in this case). SimplifyLoopConditions(root,
IntermNodePatternMatcher::kExpressionReturningArray |
IntermNodePatternMatcher::kUnfoldedShortCircuitExpression |
IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue,
getTemporaryIndex(), getSymbolTable(), getShaderVersion());
SplitSequenceOperator(root, SplitSequenceOperator(root,
IntermNodePatternMatcher::kExpressionReturningArray | IntermNodePatternMatcher::kExpressionReturningArray |
IntermNodePatternMatcher::kUnfoldedShortCircuitExpression | IntermNodePatternMatcher::kUnfoldedShortCircuitExpression |
......
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