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