• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2011 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 
7 #ifndef COMPILER_FORLOOPUNROLL_H_
8 #define COMPILER_FORLOOPUNROLL_H_
9 
10 #include "compiler/intermediate.h"
11 
12 struct TLoopIndexInfo {
13     int id;
14     int initValue;
15     int stopValue;
16     int incrementValue;
17     TOperator op;
18     int currentValue;
19 };
20 
21 class ForLoopUnroll {
22 public:
ForLoopUnroll()23     ForLoopUnroll() { }
24 
25     void FillLoopIndexInfo(TIntermLoop* node, TLoopIndexInfo& info);
26 
27     // Update the info.currentValue for the next loop iteration.
28     void Step();
29 
30     // Return false if loop condition is no longer satisfied.
31     bool SatisfiesLoopCondition();
32 
33     // Check if the symbol is the index of a loop that's unrolled.
34     bool NeedsToReplaceSymbolWithValue(TIntermSymbol* symbol);
35 
36     // Return the current value of a given loop index symbol.
37     int GetLoopIndexValue(TIntermSymbol* symbol);
38 
39     void Push(TLoopIndexInfo& info);
40     void Pop();
41 
42     static void MarkForLoopsWithIntegerIndicesForUnrolling(TIntermNode* root);
43 
44 private:
45     int getLoopIncrement(TIntermLoop* node);
46 
47     int evaluateIntConstant(TIntermConstantUnion* node);
48 
49     TVector<TLoopIndexInfo> mLoopIndexStack;
50 };
51 
52 #endif
53