michael@0: // michael@0: // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef ForLoopUnroll_h michael@0: #define ForLoopUnroll_h michael@0: michael@0: #include "compiler/intermediate.h" michael@0: michael@0: struct TLoopIndexInfo { michael@0: int id; michael@0: int initValue; michael@0: int stopValue; michael@0: int incrementValue; michael@0: TOperator op; michael@0: int currentValue; michael@0: }; michael@0: michael@0: class ForLoopUnroll { michael@0: public: michael@0: ForLoopUnroll() { } michael@0: michael@0: void FillLoopIndexInfo(TIntermLoop* node, TLoopIndexInfo& info); michael@0: michael@0: // Update the info.currentValue for the next loop iteration. michael@0: void Step(); michael@0: michael@0: // Return false if loop condition is no longer satisfied. michael@0: bool SatisfiesLoopCondition(); michael@0: michael@0: // Check if the symbol is the index of a loop that's unrolled. michael@0: bool NeedsToReplaceSymbolWithValue(TIntermSymbol* symbol); michael@0: michael@0: // Return the current value of a given loop index symbol. michael@0: int GetLoopIndexValue(TIntermSymbol* symbol); michael@0: michael@0: void Push(TLoopIndexInfo& info); michael@0: void Pop(); michael@0: michael@0: static void MarkForLoopsWithIntegerIndicesForUnrolling(TIntermNode* root); michael@0: michael@0: private: michael@0: int getLoopIncrement(TIntermLoop* node); michael@0: michael@0: int evaluateIntConstant(TIntermConstantUnion* node); michael@0: michael@0: TVector mLoopIndexStack; michael@0: }; michael@0: michael@0: #endif