Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // SimplifyLoopConditions is an AST traverser that converts loop conditions and loop expressions |
| 7 | // to regular statements inside the loop. This way further transformations that generate statements |
| 8 | // from loop conditions and loop expressions work correctly. |
| 9 | // |
| 10 | |
| 11 | #include "compiler/translator/SimplifyLoopConditions.h" |
| 12 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 13 | #include "compiler/translator/IntermNodePatternMatcher.h" |
Olli Etuaho | 3ec7568 | 2017-07-05 17:02:55 +0300 | [diff] [blame] | 14 | #include "compiler/translator/IntermNode_util.h" |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 15 | #include "compiler/translator/IntermTraverse.h" |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame^] | 16 | #include "compiler/translator/StaticType.h" |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 17 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 18 | namespace sh |
| 19 | { |
| 20 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 21 | namespace |
| 22 | { |
| 23 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 24 | class SimplifyLoopConditionsTraverser : public TLValueTrackingTraverser |
| 25 | { |
| 26 | public: |
| 27 | SimplifyLoopConditionsTraverser(unsigned int conditionsToSimplifyMask, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 28 | TSymbolTable *symbolTable, |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 29 | int shaderVersion); |
| 30 | |
| 31 | void traverseLoop(TIntermLoop *node) override; |
| 32 | |
Olli Etuaho | bb5a7e2 | 2017-08-30 13:03:12 +0300 | [diff] [blame] | 33 | bool visitUnary(Visit visit, TIntermUnary *node) override; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 34 | bool visitBinary(Visit visit, TIntermBinary *node) override; |
| 35 | bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 36 | bool visitTernary(Visit visit, TIntermTernary *node) override; |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 37 | bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 38 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 39 | bool foundLoopToChange() const { return mFoundLoopToChange; } |
| 40 | |
| 41 | protected: |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 42 | // Marked to true once an operation that needs to be hoisted out of a loop expression has been |
| 43 | // found. |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 44 | bool mFoundLoopToChange; |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 45 | bool mInsideLoopInitConditionOrExpression; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 46 | IntermNodePatternMatcher mConditionsToSimplify; |
| 47 | }; |
| 48 | |
| 49 | SimplifyLoopConditionsTraverser::SimplifyLoopConditionsTraverser( |
| 50 | unsigned int conditionsToSimplifyMask, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 51 | TSymbolTable *symbolTable, |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 52 | int shaderVersion) |
| 53 | : TLValueTrackingTraverser(true, false, false, symbolTable, shaderVersion), |
| 54 | mFoundLoopToChange(false), |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 55 | mInsideLoopInitConditionOrExpression(false), |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 56 | mConditionsToSimplify(conditionsToSimplifyMask) |
| 57 | { |
| 58 | } |
| 59 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 60 | // If we're inside a loop initialization, condition, or expression, we check for expressions that |
| 61 | // should be moved out of the loop condition or expression. If one is found, the loop is |
| 62 | // transformed. |
| 63 | // If we're not inside loop initialization, condition, or expression, we only need to traverse nodes |
| 64 | // that may contain loops. |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 65 | |
Olli Etuaho | bb5a7e2 | 2017-08-30 13:03:12 +0300 | [diff] [blame] | 66 | bool SimplifyLoopConditionsTraverser::visitUnary(Visit visit, TIntermUnary *node) |
| 67 | { |
| 68 | if (!mInsideLoopInitConditionOrExpression) |
| 69 | return false; |
| 70 | |
| 71 | if (mFoundLoopToChange) |
| 72 | return false; // Already decided to change this loop. |
| 73 | |
| 74 | mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 75 | return !mFoundLoopToChange; |
| 76 | } |
| 77 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 78 | bool SimplifyLoopConditionsTraverser::visitBinary(Visit visit, TIntermBinary *node) |
| 79 | { |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 80 | if (!mInsideLoopInitConditionOrExpression) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 81 | return false; |
| 82 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 83 | if (mFoundLoopToChange) |
| 84 | return false; // Already decided to change this loop. |
| 85 | |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 86 | mFoundLoopToChange = mConditionsToSimplify.match(node, getParentNode(), isLValueRequiredHere()); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 87 | return !mFoundLoopToChange; |
| 88 | } |
| 89 | |
| 90 | bool SimplifyLoopConditionsTraverser::visitAggregate(Visit visit, TIntermAggregate *node) |
| 91 | { |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 92 | if (!mInsideLoopInitConditionOrExpression) |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 93 | return false; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 94 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 95 | if (mFoundLoopToChange) |
| 96 | return false; // Already decided to change this loop. |
| 97 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 98 | mFoundLoopToChange = mConditionsToSimplify.match(node, getParentNode()); |
| 99 | return !mFoundLoopToChange; |
| 100 | } |
| 101 | |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 102 | bool SimplifyLoopConditionsTraverser::visitTernary(Visit visit, TIntermTernary *node) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 103 | { |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 104 | if (!mInsideLoopInitConditionOrExpression) |
| 105 | return false; |
| 106 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 107 | if (mFoundLoopToChange) |
| 108 | return false; // Already decided to change this loop. |
| 109 | |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 110 | mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 111 | return !mFoundLoopToChange; |
| 112 | } |
| 113 | |
| 114 | bool SimplifyLoopConditionsTraverser::visitDeclaration(Visit visit, TIntermDeclaration *node) |
| 115 | { |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 116 | if (!mInsideLoopInitConditionOrExpression) |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 117 | return false; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 118 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 119 | if (mFoundLoopToChange) |
| 120 | return false; // Already decided to change this loop. |
| 121 | |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 122 | mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 123 | return !mFoundLoopToChange; |
| 124 | } |
| 125 | |
| 126 | void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 127 | { |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 128 | // Mark that we're inside a loop condition or expression, and determine if the loop needs to be |
| 129 | // transformed. |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 130 | |
Olli Etuaho | 1d9dcc2 | 2017-01-19 11:25:32 +0000 | [diff] [blame] | 131 | ScopedNodeInTraversalPath addToPath(this, node); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 132 | |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 133 | mInsideLoopInitConditionOrExpression = true; |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 134 | mFoundLoopToChange = false; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 135 | |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 136 | if (!mFoundLoopToChange && node->getInit()) |
| 137 | { |
| 138 | node->getInit()->traverse(this); |
| 139 | } |
| 140 | |
| 141 | if (!mFoundLoopToChange && node->getCondition()) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 142 | { |
| 143 | node->getCondition()->traverse(this); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (!mFoundLoopToChange && node->getExpression()) |
| 147 | { |
| 148 | node->getExpression()->traverse(this); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 149 | } |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 150 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 151 | mInsideLoopInitConditionOrExpression = false; |
| 152 | |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 153 | if (mFoundLoopToChange) |
| 154 | { |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame^] | 155 | const TType *boolType = StaticType::Get<EbtBool, EbpUndefined, EvqTemporary, 1, 1>(); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 156 | TVariable *conditionVariable = CreateTempVariable(mSymbolTable, boolType); |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 157 | |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 158 | // Replace the loop condition with a boolean variable that's updated on each iteration. |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 159 | TLoopType loopType = node->getType(); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 160 | if (loopType == ELoopWhile) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 161 | { |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 162 | // Transform: |
| 163 | // while (expr) { body; } |
| 164 | // into |
| 165 | // bool s0 = expr; |
| 166 | // while (s0) { { body; } s0 = expr; } |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 167 | TIntermDeclaration *tempInitDeclaration = |
| 168 | CreateTempInitDeclarationNode(conditionVariable, node->getCondition()->deepCopy()); |
| 169 | insertStatementInParentBlock(tempInitDeclaration); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 170 | |
| 171 | TIntermBlock *newBody = new TIntermBlock(); |
| 172 | if (node->getBody()) |
| 173 | { |
| 174 | newBody->getSequence()->push_back(node->getBody()); |
| 175 | } |
| 176 | newBody->getSequence()->push_back( |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 177 | CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 178 | |
| 179 | // Can't use queueReplacement to replace old body, since it may have been nullptr. |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 180 | // It's safe to do the replacements in place here - the new body will still be |
| 181 | // traversed, but that won't create any problems. |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 182 | node->setBody(newBody); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 183 | node->setCondition(CreateTempSymbolNode(conditionVariable)); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 184 | } |
| 185 | else if (loopType == ELoopDoWhile) |
| 186 | { |
| 187 | // Transform: |
| 188 | // do { |
| 189 | // body; |
| 190 | // } while (expr); |
| 191 | // into |
| 192 | // bool s0 = true; |
| 193 | // do { |
| 194 | // { body; } |
| 195 | // s0 = expr; |
| 196 | // } while (s0); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 197 | TIntermDeclaration *tempInitDeclaration = |
| 198 | CreateTempInitDeclarationNode(conditionVariable, CreateBoolNode(true)); |
| 199 | insertStatementInParentBlock(tempInitDeclaration); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 200 | |
| 201 | TIntermBlock *newBody = new TIntermBlock(); |
| 202 | if (node->getBody()) |
| 203 | { |
| 204 | newBody->getSequence()->push_back(node->getBody()); |
| 205 | } |
| 206 | newBody->getSequence()->push_back( |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 207 | CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 208 | |
| 209 | // Can't use queueReplacement to replace old body, since it may have been nullptr. |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 210 | // It's safe to do the replacements in place here - the new body will still be |
| 211 | // traversed, but that won't create any problems. |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 212 | node->setBody(newBody); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 213 | node->setCondition(CreateTempSymbolNode(conditionVariable)); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 214 | } |
| 215 | else if (loopType == ELoopFor) |
| 216 | { |
| 217 | // Move the loop condition inside the loop. |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 218 | // Transform: |
| 219 | // for (init; expr; exprB) { body; } |
| 220 | // into |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 221 | // { |
| 222 | // init; |
| 223 | // bool s0 = expr; |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 224 | // while (s0) { |
| 225 | // { body; } |
| 226 | // exprB; |
| 227 | // s0 = expr; |
| 228 | // } |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 229 | // } |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 230 | TIntermBlock *loopScope = new TIntermBlock(); |
| 231 | TIntermSequence *loopScopeSequence = loopScope->getSequence(); |
| 232 | |
| 233 | // Insert "init;" |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 234 | if (node->getInit()) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 235 | { |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 236 | loopScopeSequence->push_back(node->getInit()); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 237 | } |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 238 | |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 239 | // Insert "bool s0 = expr;" if applicable, "bool s0 = true;" otherwise |
| 240 | TIntermTyped *conditionInitializer = nullptr; |
| 241 | if (node->getCondition()) |
| 242 | { |
| 243 | conditionInitializer = node->getCondition()->deepCopy(); |
| 244 | } |
| 245 | else |
| 246 | { |
Olli Etuaho | 3ec7568 | 2017-07-05 17:02:55 +0300 | [diff] [blame] | 247 | conditionInitializer = CreateBoolNode(true); |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 248 | } |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 249 | loopScopeSequence->push_back( |
| 250 | CreateTempInitDeclarationNode(conditionVariable, conditionInitializer)); |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 251 | |
| 252 | // Insert "{ body; }" in the while loop |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 253 | TIntermBlock *whileLoopBody = new TIntermBlock(); |
| 254 | if (node->getBody()) |
| 255 | { |
| 256 | whileLoopBody->getSequence()->push_back(node->getBody()); |
| 257 | } |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 258 | // Insert "exprB;" in the while loop |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 259 | if (node->getExpression()) |
| 260 | { |
| 261 | whileLoopBody->getSequence()->push_back(node->getExpression()); |
| 262 | } |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 263 | // Insert "s0 = expr;" in the while loop |
| 264 | if (node->getCondition()) |
| 265 | { |
| 266 | whileLoopBody->getSequence()->push_back( |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 267 | CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
Corentin Wallez | 36fd100 | 2016-12-08 11:30:44 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // Create "while(s0) { whileLoopBody }" |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 271 | TIntermLoop *whileLoop = |
| 272 | new TIntermLoop(ELoopWhile, nullptr, CreateTempSymbolNode(conditionVariable), |
| 273 | nullptr, whileLoopBody); |
Corentin Wallez | 1212bca | 2016-11-23 13:44:05 -0500 | [diff] [blame] | 274 | loopScope->getSequence()->push_back(whileLoop); |
Olli Etuaho | ea39a22 | 2017-07-06 12:47:59 +0300 | [diff] [blame] | 275 | queueReplacement(loopScope, OriginalNode::IS_DROPPED); |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 276 | |
| 277 | // After this the old body node will be traversed and loops inside it may be |
| 278 | // transformed. This is fine, since the old body node will still be in the AST after the |
| 279 | // transformation that's queued here, and transforming loops inside it doesn't need to |
| 280 | // know the exact post-transform path to it. |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 284 | mFoundLoopToChange = false; |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 285 | |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 286 | // We traverse the body of the loop even if the loop is transformed. |
| 287 | if (node->getBody()) |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 288 | node->getBody()->traverse(this); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | } // namespace |
| 292 | |
| 293 | void SimplifyLoopConditions(TIntermNode *root, |
| 294 | unsigned int conditionsToSimplifyMask, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 295 | TSymbolTable *symbolTable, |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 296 | int shaderVersion) |
| 297 | { |
| 298 | SimplifyLoopConditionsTraverser traverser(conditionsToSimplifyMask, symbolTable, shaderVersion); |
Olli Etuaho | 9676d1a | 2017-05-16 11:29:24 +0300 | [diff] [blame] | 299 | root->traverse(&traverser); |
| 300 | traverser.updateTree(); |
Olli Etuaho | 3cbb27a | 2016-07-14 11:55:48 +0300 | [diff] [blame] | 301 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 302 | |
| 303 | } // namespace sh |