1 //
2 // Copyright (c) 2002-2014 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_TRANSLATOR_LOOPINFO_H_
8 #define COMPILER_TRANSLATOR_LOOPINFO_H_
9 
10 #include "compiler/translator/IntermNode.h"
11 
12 namespace sh
13 {
14 
15 class TLoopIndexInfo
16 {
17   public:
18     TLoopIndexInfo();
19 
20     // If type is EbtInt, fill all fields of the structure with info
21     // extracted from a loop node.
22     // If type is not EbtInt, only fill id and type.
23     void fillInfo(TIntermLoop *node);
24 
getId()25     int getId() const { return mId; }
setId(int id)26     void setId(int id) { mId = id; }
getType()27     TBasicType getType() const { return mType; }
setType(TBasicType type)28     void setType(TBasicType type) { mType = type; }
getCurrentValue()29     int getCurrentValue() const { return mCurrentValue; }
30 
step()31     void step() { mCurrentValue += mIncrementValue; }
32 
33     // Check if the current value satisfies the loop condition.
34     bool satisfiesLoopCondition() const;
35 
36   private:
37     int mId;
38     TBasicType mType;  // Either EbtInt or EbtFloat
39 
40     // Below fields are only valid if the index's type is int.
41     int mInitValue;
42     int mStopValue;
43     int mIncrementValue;
44     TOperator mOp;
45     int mCurrentValue;
46 };
47 
48 struct TLoopInfo
49 {
50     TLoopIndexInfo index;
51     TIntermLoop *loop;
52 
53     TLoopInfo();
54     TLoopInfo(TIntermLoop *node);
55 };
56 
57 class TLoopStack : public TVector<TLoopInfo>
58 {
59   public:
60     // Search loop stack for a loop whose index matches the input symbol.
61     TIntermLoop *findLoop(TIntermSymbol *symbol);
62 
63     // Find the loop index info in the loop stack by the input symbol.
64     TLoopIndexInfo *getIndexInfo(TIntermSymbol *symbol);
65 
66     // Update the currentValue for the next loop iteration.
67     void step();
68 
69     // Return false if loop condition is no longer satisfied.
70     bool satisfiesLoopCondition();
71 
72     // Check if the symbol is the index of a loop that's unrolled.
73     bool needsToReplaceSymbolWithValue(TIntermSymbol *symbol);
74 
75     // Return the current value of a given loop index symbol.
76     int getLoopIndexValue(TIntermSymbol *symbol);
77 
78     void push(TIntermLoop *info);
79     void pop();
80 };
81 
82 }  // namespace sh
83 
84 #endif // COMPILER_TRANSLATOR_LOOPINFO_H_
85 
86