zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 1 | // |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/ForLoopUnroll.h" |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 8 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 9 | bool ForLoopUnrollMarker::visitBinary(Visit, TIntermBinary *node) |
| 10 | { |
| 11 | if (mUnrollCondition != kSamplerArrayIndex) |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 12 | return true; |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 13 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 14 | // If a sampler array index is also the loop index, |
| 15 | // 1) if the index type is integer, mark the loop for unrolling; |
| 16 | // 2) if the index type if float, set a flag to later fail compile. |
| 17 | switch (node->getOp()) |
| 18 | { |
| 19 | case EOpIndexIndirect: |
| 20 | if (node->getLeft() != NULL && node->getRight() != NULL && node->getLeft()->getAsSymbolNode()) |
| 21 | { |
| 22 | TIntermSymbol *symbol = node->getLeft()->getAsSymbolNode(); |
| 23 | if (IsSampler(symbol->getBasicType()) && symbol->isArray() && !mLoopStack.empty()) |
| 24 | { |
| 25 | mVisitSamplerArrayIndexNodeInsideLoop = true; |
| 26 | node->getRight()->traverse(this); |
| 27 | mVisitSamplerArrayIndexNodeInsideLoop = false; |
| 28 | // We have already visited all the children. |
| 29 | return false; |
| 30 | } |
| 31 | } |
| 32 | break; |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 33 | default: |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 34 | break; |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 35 | } |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 36 | return true; |
| 37 | } |
| 38 | |
| 39 | bool ForLoopUnrollMarker::visitLoop(Visit, TIntermLoop *node) |
| 40 | { |
| 41 | if (mUnrollCondition == kIntegerIndex) |
| 42 | { |
| 43 | // Check if loop index type is integer. |
| 44 | // This is called after ValidateLimitations pass, so all the calls |
| 45 | // should be valid. See ValidateLimitations::validateForLoopInit(). |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 46 | TIntermSequence *declSeq = node->getInit()->getAsAggregate()->getSequence(); |
| 47 | TIntermSymbol *symbol = (*declSeq)[0]->getAsBinaryNode()->getLeft()->getAsSymbolNode(); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 48 | if (symbol->getBasicType() == EbtInt) |
| 49 | node->setUnrollFlag(true); |
| 50 | } |
| 51 | |
| 52 | TIntermNode *body = node->getBody(); |
| 53 | if (body != NULL) |
| 54 | { |
| 55 | mLoopStack.push(node); |
| 56 | body->traverse(this); |
| 57 | mLoopStack.pop(); |
| 58 | } |
| 59 | // The loop is fully processed - no need to visit children. |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 60 | return false; |
| 61 | } |
| 62 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 63 | void ForLoopUnrollMarker::visitSymbol(TIntermSymbol* symbol) |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 64 | { |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 65 | if (!mVisitSamplerArrayIndexNodeInsideLoop) |
| 66 | return; |
| 67 | TIntermLoop *loop = mLoopStack.findLoop(symbol); |
| 68 | if (loop) |
| 69 | { |
| 70 | switch (symbol->getBasicType()) |
| 71 | { |
| 72 | case EbtFloat: |
| 73 | mSamplerArrayIndexIsFloatLoopIndex = true; |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 74 | break; |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 75 | case EbtInt: |
| 76 | loop->setUnrollFlag(true); |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 77 | break; |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 78 | default: |
| 79 | UNREACHABLE(); |
| 80 | } |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 81 | } |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 82 | } |