daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +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 | |
| 7 | // |
| 8 | // Definition of the in-memory high-level intermediate representation |
| 9 | // of shaders. This is a tree that parser creates. |
| 10 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 11 | // Nodes in the tree are defined as a hierarchy of classes derived from |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | // TIntermNode. Each is a node in a tree. There is no preset branching factor; |
| 13 | // each node can have it's own type of list of children. |
| 14 | // |
| 15 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 16 | #ifndef COMPILER_TRANSLATOR_INTERMEDIATE_H_ |
| 17 | #define COMPILER_TRANSLATOR_INTERMEDIATE_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 19 | #include "GLSLANG/ShaderLang.h" |
| 20 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 21 | #include <algorithm> |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 22 | #include <queue> |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 23 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 24 | #include "compiler/translator/Common.h" |
| 25 | #include "compiler/translator/Types.h" |
| 26 | #include "compiler/translator/ConstantUnion.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 27 | |
| 28 | // |
| 29 | // Operators used by the high-level (parse tree) representation. |
| 30 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 31 | enum TOperator |
| 32 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 33 | EOpNull, // if in a node, should only mean a node is still being built |
| 34 | EOpSequence, // denotes a list of statements, or parameters, etc. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 35 | EOpFunctionCall, |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 36 | EOpFunction, // For function definition |
| 37 | EOpParameters, // an aggregate listing the parameters to a function |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 38 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 39 | EOpDeclaration, |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 40 | EOpPrototype, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 42 | // |
| 43 | // Unary operators |
| 44 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 45 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 46 | EOpNegative, |
| 47 | EOpLogicalNot, |
| 48 | EOpVectorLogicalNot, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 50 | EOpPostIncrement, |
| 51 | EOpPostDecrement, |
| 52 | EOpPreIncrement, |
| 53 | EOpPreDecrement, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 54 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 55 | // |
| 56 | // binary operations |
| 57 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 58 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 59 | EOpAdd, |
| 60 | EOpSub, |
| 61 | EOpMul, |
| 62 | EOpDiv, |
| 63 | EOpEqual, |
| 64 | EOpNotEqual, |
| 65 | EOpVectorEqual, |
| 66 | EOpVectorNotEqual, |
| 67 | EOpLessThan, |
| 68 | EOpGreaterThan, |
| 69 | EOpLessThanEqual, |
| 70 | EOpGreaterThanEqual, |
| 71 | EOpComma, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 72 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 73 | EOpVectorTimesScalar, |
| 74 | EOpVectorTimesMatrix, |
| 75 | EOpMatrixTimesVector, |
| 76 | EOpMatrixTimesScalar, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 77 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 78 | EOpLogicalOr, |
| 79 | EOpLogicalXor, |
| 80 | EOpLogicalAnd, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 81 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 82 | EOpIndexDirect, |
| 83 | EOpIndexIndirect, |
| 84 | EOpIndexDirectStruct, |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 85 | EOpIndexDirectInterfaceBlock, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 87 | EOpVectorSwizzle, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 88 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 89 | // |
| 90 | // Built-in functions potentially mapped to operators |
| 91 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 92 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 93 | EOpRadians, |
| 94 | EOpDegrees, |
| 95 | EOpSin, |
| 96 | EOpCos, |
| 97 | EOpTan, |
| 98 | EOpAsin, |
| 99 | EOpAcos, |
| 100 | EOpAtan, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 101 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 102 | EOpPow, |
| 103 | EOpExp, |
| 104 | EOpLog, |
| 105 | EOpExp2, |
| 106 | EOpLog2, |
| 107 | EOpSqrt, |
| 108 | EOpInverseSqrt, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 109 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 110 | EOpAbs, |
| 111 | EOpSign, |
| 112 | EOpFloor, |
| 113 | EOpCeil, |
| 114 | EOpFract, |
| 115 | EOpMod, |
| 116 | EOpMin, |
| 117 | EOpMax, |
| 118 | EOpClamp, |
| 119 | EOpMix, |
| 120 | EOpStep, |
| 121 | EOpSmoothStep, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 123 | EOpLength, |
| 124 | EOpDistance, |
| 125 | EOpDot, |
| 126 | EOpCross, |
| 127 | EOpNormalize, |
| 128 | EOpFaceForward, |
| 129 | EOpReflect, |
| 130 | EOpRefract, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 131 | |
alokp@chromium.org | 0609889 | 2010-08-26 19:36:42 +0000 | [diff] [blame] | 132 | EOpDFdx, // Fragment only, OES_standard_derivatives extension |
| 133 | EOpDFdy, // Fragment only, OES_standard_derivatives extension |
| 134 | EOpFwidth, // Fragment only, OES_standard_derivatives extension |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 135 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 136 | EOpMatrixTimesMatrix, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 138 | EOpAny, |
| 139 | EOpAll, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 140 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 141 | // |
| 142 | // Branch |
| 143 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 144 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 145 | EOpKill, // Fragment only |
| 146 | EOpReturn, |
| 147 | EOpBreak, |
| 148 | EOpContinue, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 149 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 150 | // |
| 151 | // Constructors |
| 152 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 153 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 154 | EOpConstructInt, |
Nicolas Capens | ab60b93 | 2013-06-05 10:31:21 -0400 | [diff] [blame] | 155 | EOpConstructUInt, |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 156 | EOpConstructBool, |
| 157 | EOpConstructFloat, |
| 158 | EOpConstructVec2, |
| 159 | EOpConstructVec3, |
| 160 | EOpConstructVec4, |
| 161 | EOpConstructBVec2, |
| 162 | EOpConstructBVec3, |
| 163 | EOpConstructBVec4, |
| 164 | EOpConstructIVec2, |
| 165 | EOpConstructIVec3, |
| 166 | EOpConstructIVec4, |
shannonwoods@chromium.org | 8c788e8 | 2013-05-30 00:20:21 +0000 | [diff] [blame] | 167 | EOpConstructUVec2, |
| 168 | EOpConstructUVec3, |
| 169 | EOpConstructUVec4, |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 170 | EOpConstructMat2, |
| 171 | EOpConstructMat3, |
| 172 | EOpConstructMat4, |
| 173 | EOpConstructStruct, |
| 174 | |
| 175 | // |
| 176 | // moves |
| 177 | // |
| 178 | |
| 179 | EOpAssign, |
| 180 | EOpInitialize, |
| 181 | EOpAddAssign, |
| 182 | EOpSubAssign, |
| 183 | EOpMulAssign, |
| 184 | EOpVectorTimesMatrixAssign, |
| 185 | EOpVectorTimesScalarAssign, |
| 186 | EOpMatrixTimesScalarAssign, |
| 187 | EOpMatrixTimesMatrixAssign, |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 188 | EOpDivAssign |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | class TIntermTraverser; |
| 192 | class TIntermAggregate; |
| 193 | class TIntermBinary; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 194 | class TIntermUnary; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 195 | class TIntermConstantUnion; |
| 196 | class TIntermSelection; |
| 197 | class TIntermTyped; |
| 198 | class TIntermSymbol; |
alokp@chromium.org | d88b773 | 2010-05-26 15:13:14 +0000 | [diff] [blame] | 199 | class TIntermLoop; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 200 | class TInfoSink; |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 201 | class TIntermRaw; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 202 | |
| 203 | // |
| 204 | // Base class for the tree nodes |
| 205 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 206 | class TIntermNode |
| 207 | { |
| 208 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 209 | POOL_ALLOCATOR_NEW_DELETE(); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 210 | TIntermNode() |
| 211 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 212 | // TODO: Move this to TSourceLoc constructor |
| 213 | // after getting rid of TPublicType. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 214 | mLine.first_file = mLine.last_file = 0; |
| 215 | mLine.first_line = mLine.last_line = 0; |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 216 | } |
| 217 | virtual ~TIntermNode() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 218 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 219 | const TSourceLoc &getLine() const { return mLine; } |
| 220 | void setLine(const TSourceLoc &l) { mLine = l; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 221 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 222 | virtual void traverse(TIntermTraverser *) = 0; |
| 223 | virtual TIntermTyped *getAsTyped() { return 0; } |
| 224 | virtual TIntermConstantUnion *getAsConstantUnion() { return 0; } |
| 225 | virtual TIntermAggregate *getAsAggregate() { return 0; } |
| 226 | virtual TIntermBinary *getAsBinaryNode() { return 0; } |
| 227 | virtual TIntermUnary *getAsUnaryNode() { return 0; } |
| 228 | virtual TIntermSelection *getAsSelectionNode() { return 0; } |
| 229 | virtual TIntermSymbol *getAsSymbolNode() { return 0; } |
| 230 | virtual TIntermLoop *getAsLoopNode() { return 0; } |
| 231 | virtual TIntermRaw *getAsRawNode() { return 0; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 232 | |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 233 | // Replace a child node. Return true if |original| is a child |
| 234 | // node and it is replaced; otherwise, return false. |
| 235 | virtual bool replaceChildNode( |
| 236 | TIntermNode *original, TIntermNode *replacement) = 0; |
| 237 | |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 238 | // For traversing a tree in no particular order, but using |
| 239 | // heap memory. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 240 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const = 0; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 241 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 242 | protected: |
| 243 | TSourceLoc mLine; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | // |
| 247 | // This is just to help yacc. |
| 248 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 249 | struct TIntermNodePair |
| 250 | { |
| 251 | TIntermNode *node1; |
| 252 | TIntermNode *node2; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 255 | // |
| 256 | // Intermediate class for nodes that have a type. |
| 257 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 258 | class TIntermTyped : public TIntermNode |
| 259 | { |
| 260 | public: |
| 261 | TIntermTyped(const TType &t) : mType(t) { } |
| 262 | virtual TIntermTyped *getAsTyped() { return this; } |
alokp@chromium.org | dd037b2 | 2010-03-30 18:47:20 +0000 | [diff] [blame] | 263 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 264 | virtual bool hasSideEffects() const = 0; |
| 265 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 266 | void setType(const TType &t) { mType = t; } |
| 267 | const TType &getType() const { return mType; } |
| 268 | TType *getTypePointer() { return &mType; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 269 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 270 | TBasicType getBasicType() const { return mType.getBasicType(); } |
| 271 | TQualifier getQualifier() const { return mType.getQualifier(); } |
| 272 | TPrecision getPrecision() const { return mType.getPrecision(); } |
| 273 | int getCols() const { return mType.getCols(); } |
| 274 | int getRows() const { return mType.getRows(); } |
| 275 | int getNominalSize() const { return mType.getNominalSize(); } |
| 276 | int getSecondarySize() const { return mType.getSecondarySize(); } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 277 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 278 | bool isInterfaceBlock() const { return mType.isInterfaceBlock(); } |
| 279 | bool isMatrix() const { return mType.isMatrix(); } |
| 280 | bool isArray() const { return mType.isArray(); } |
| 281 | bool isVector() const { return mType.isVector(); } |
| 282 | bool isScalar() const { return mType.isScalar(); } |
| 283 | bool isScalarInt() const { return mType.isScalarInt(); } |
| 284 | const char *getBasicString() const { return mType.getBasicString(); } |
| 285 | const char *getQualifierString() const { return mType.getQualifierString(); } |
| 286 | TString getCompleteString() const { return mType.getCompleteString(); } |
daniel@transgaming.com | 3ca980a | 2012-12-20 21:11:52 +0000 | [diff] [blame] | 287 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 288 | int getArraySize() const { return mType.getArraySize(); } |
| 289 | |
| 290 | protected: |
| 291 | TType mType; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | // |
| 295 | // Handle for, do-while, and while loops. |
| 296 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 297 | enum TLoopType |
| 298 | { |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 299 | ELoopFor, |
| 300 | ELoopWhile, |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 301 | ELoopDoWhile |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 304 | class TIntermLoop : public TIntermNode |
| 305 | { |
| 306 | public: |
| 307 | TIntermLoop(TLoopType type, |
| 308 | TIntermNode *init, TIntermTyped *cond, TIntermTyped *expr, |
| 309 | TIntermNode *body) |
| 310 | : mType(type), |
| 311 | mInit(init), |
| 312 | mCond(cond), |
| 313 | mExpr(expr), |
| 314 | mBody(body), |
| 315 | mUnrollFlag(false) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 316 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 317 | virtual TIntermLoop *getAsLoopNode() { return this; } |
| 318 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 319 | virtual bool replaceChildNode( |
| 320 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 321 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 322 | TLoopType getType() const { return mType; } |
| 323 | TIntermNode *getInit() { return mInit; } |
| 324 | TIntermTyped *getCondition() { return mCond; } |
| 325 | TIntermTyped *getExpression() { return mExpr; } |
| 326 | TIntermNode *getBody() { return mBody; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 327 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 328 | void setUnrollFlag(bool flag) { mUnrollFlag = flag; } |
| 329 | bool getUnrollFlag() const { return mUnrollFlag; } |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 330 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 331 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 332 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 333 | protected: |
| 334 | TLoopType mType; |
| 335 | TIntermNode *mInit; // for-loop initialization |
| 336 | TIntermTyped *mCond; // loop exit condition |
| 337 | TIntermTyped *mExpr; // for-loop expression |
| 338 | TIntermNode *mBody; // loop body |
zmo@google.com | 0b8d4eb | 2011-04-04 19:17:11 +0000 | [diff] [blame] | 339 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 340 | bool mUnrollFlag; // Whether the loop should be unrolled or not. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | // |
| 344 | // Handle break, continue, return, and kill. |
| 345 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 346 | class TIntermBranch : public TIntermNode |
| 347 | { |
| 348 | public: |
| 349 | TIntermBranch(TOperator op, TIntermTyped *e) |
| 350 | : mFlowOp(op), |
| 351 | mExpression(e) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 352 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 353 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 354 | virtual bool replaceChildNode( |
| 355 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 356 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 357 | TOperator getFlowOp() { return mFlowOp; } |
| 358 | TIntermTyped* getExpression() { return mExpression; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 359 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 360 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 361 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 362 | protected: |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 363 | TOperator mFlowOp; |
| 364 | TIntermTyped *mExpression; // non-zero except for "return exp;" statements |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | // |
| 368 | // Nodes that correspond to symbols or constants in the source code. |
| 369 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 370 | class TIntermSymbol : public TIntermTyped |
| 371 | { |
| 372 | public: |
| 373 | // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. |
| 374 | // If sym comes from per process globalpoolallocator, then it causes increased memory usage |
| 375 | // per compile it is essential to use "symbol = sym" to assign to symbol |
| 376 | TIntermSymbol(int id, const TString &symbol, const TType &type) |
| 377 | : TIntermTyped(type), |
| 378 | mId(id) |
| 379 | { |
| 380 | mSymbol = symbol; |
| 381 | } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 382 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 383 | virtual bool hasSideEffects() const { return false; } |
| 384 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 385 | int getId() const { return mId; } |
| 386 | const TString &getSymbol() const { return mSymbol; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 387 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 388 | void setId(int newId) { mId = newId; } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 389 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 390 | virtual void traverse(TIntermTraverser *); |
| 391 | virtual TIntermSymbol *getAsSymbolNode() { return this; } |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 392 | virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 393 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 394 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const {} |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 395 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 396 | protected: |
| 397 | int mId; |
| 398 | TString mSymbol; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 399 | }; |
| 400 | |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 401 | // A Raw node stores raw code, that the translator will insert verbatim |
| 402 | // into the output stream. Useful for transformation operations that make |
| 403 | // complex code that might not fit naturally into the GLSL model. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 404 | class TIntermRaw : public TIntermTyped |
| 405 | { |
| 406 | public: |
| 407 | TIntermRaw(const TType &type, const TString &rawText) |
| 408 | : TIntermTyped(type), |
| 409 | mRawText(rawText) { } |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 410 | |
| 411 | virtual bool hasSideEffects() const { return false; } |
| 412 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 413 | TString getRawText() const { return mRawText; } |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 414 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 415 | virtual void traverse(TIntermTraverser *); |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 416 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 417 | virtual TIntermRaw *getAsRawNode() { return this; } |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 418 | virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 419 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const {} |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 420 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 421 | protected: |
| 422 | TString mRawText; |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 423 | }; |
| 424 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 425 | class TIntermConstantUnion : public TIntermTyped |
| 426 | { |
| 427 | public: |
| 428 | TIntermConstantUnion(ConstantUnion *unionPointer, const TType &type) |
| 429 | : TIntermTyped(type), |
| 430 | mUnionArrayPointer(unionPointer) { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 431 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 432 | virtual bool hasSideEffects() const { return false; } |
| 433 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 434 | ConstantUnion *getUnionArrayPointer() const { return mUnionArrayPointer; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 435 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 436 | int getIConst(size_t index) const |
| 437 | { |
| 438 | return mUnionArrayPointer ? mUnionArrayPointer[index].getIConst() : 0; |
| 439 | } |
| 440 | unsigned int getUConst(size_t index) const |
| 441 | { |
| 442 | return mUnionArrayPointer ? mUnionArrayPointer[index].getUConst() : 0; |
| 443 | } |
| 444 | float getFConst(size_t index) const |
| 445 | { |
| 446 | return mUnionArrayPointer ? mUnionArrayPointer[index].getFConst() : 0.0f; |
| 447 | } |
| 448 | bool getBConst(size_t index) const |
| 449 | { |
| 450 | return mUnionArrayPointer ? mUnionArrayPointer[index].getBConst() : false; |
| 451 | } |
| 452 | |
| 453 | virtual TIntermConstantUnion *getAsConstantUnion() { return this; } |
| 454 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 455 | virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 456 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 457 | TIntermTyped *fold(TOperator, TIntermTyped *, TInfoSink &); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 458 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 459 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const {} |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 460 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 461 | protected: |
| 462 | ConstantUnion *mUnionArrayPointer; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | // |
| 466 | // Intermediate class for node types that hold operators. |
| 467 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 468 | class TIntermOperator : public TIntermTyped |
| 469 | { |
| 470 | public: |
| 471 | TOperator getOp() const { return mOp; } |
| 472 | void setOp(TOperator op) { mOp = op; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 473 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 474 | bool isAssignment() const; |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 475 | bool isConstructor() const; |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 476 | |
Jamie Madill | f4b79ba | 2013-11-26 10:38:18 -0500 | [diff] [blame] | 477 | virtual bool hasSideEffects() const { return isAssignment(); } |
| 478 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 479 | protected: |
| 480 | TIntermOperator(TOperator op) |
| 481 | : TIntermTyped(TType(EbtFloat, EbpUndefined)), |
| 482 | mOp(op) {} |
| 483 | TIntermOperator(TOperator op, const TType &type) |
| 484 | : TIntermTyped(type), |
| 485 | mOp(op) {} |
| 486 | |
| 487 | TOperator mOp; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | // |
| 491 | // Nodes for all the basic binary math operators. |
| 492 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 493 | class TIntermBinary : public TIntermOperator |
| 494 | { |
| 495 | public: |
| 496 | TIntermBinary(TOperator op) |
| 497 | : TIntermOperator(op), |
| 498 | mAddIndexClamp(false) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 499 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 500 | virtual TIntermBinary *getAsBinaryNode() { return this; } |
| 501 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 502 | virtual bool replaceChildNode( |
| 503 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 504 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 505 | virtual bool hasSideEffects() const |
| 506 | { |
| 507 | return isAssignment() || mLeft->hasSideEffects() || mRight->hasSideEffects(); |
| 508 | } |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 509 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 510 | void setLeft(TIntermTyped *node) { mLeft = node; } |
| 511 | void setRight(TIntermTyped *node) { mRight = node; } |
| 512 | TIntermTyped *getLeft() const { return mLeft; } |
| 513 | TIntermTyped *getRight() const { return mRight; } |
| 514 | bool promote(TInfoSink &); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 515 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 516 | void setAddIndexClamp() { mAddIndexClamp = true; } |
| 517 | bool getAddIndexClamp() { return mAddIndexClamp; } |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 518 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 519 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 520 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 521 | protected: |
| 522 | TIntermTyped* mLeft; |
| 523 | TIntermTyped* mRight; |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 524 | |
| 525 | // If set to true, wrap any EOpIndexIndirect with a clamp to bounds. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 526 | bool mAddIndexClamp; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 527 | }; |
| 528 | |
| 529 | // |
| 530 | // Nodes for unary math operators. |
| 531 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 532 | class TIntermUnary : public TIntermOperator |
| 533 | { |
| 534 | public: |
| 535 | TIntermUnary(TOperator op, const TType &type) |
| 536 | : TIntermOperator(op, type), |
| 537 | mOperand(NULL), |
| 538 | mUseEmulatedFunction(false) {} |
| 539 | TIntermUnary(TOperator op) |
| 540 | : TIntermOperator(op), |
| 541 | mOperand(NULL), |
| 542 | mUseEmulatedFunction(false) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 543 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 544 | virtual void traverse(TIntermTraverser *); |
| 545 | virtual TIntermUnary *getAsUnaryNode() { return this; } |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 546 | virtual bool replaceChildNode( |
| 547 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 548 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 549 | virtual bool hasSideEffects() const |
| 550 | { |
| 551 | return isAssignment() || mOperand->hasSideEffects(); |
| 552 | } |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 553 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 554 | void setOperand(TIntermTyped *operand) { mOperand = operand; } |
| 555 | TIntermTyped *getOperand() { return mOperand; } |
| 556 | bool promote(TInfoSink &); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 557 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 558 | void setUseEmulatedFunction() { mUseEmulatedFunction = true; } |
| 559 | bool getUseEmulatedFunction() { return mUseEmulatedFunction; } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 560 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 561 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 562 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 563 | protected: |
| 564 | TIntermTyped *mOperand; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 565 | |
| 566 | // If set to true, replace the built-in function call with an emulated one |
| 567 | // to work around driver bugs. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 568 | bool mUseEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 571 | typedef TVector<TIntermNode *> TIntermSequence; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 572 | typedef TVector<int> TQualifierList; |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 573 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 574 | // |
| 575 | // Nodes that operate on an arbitrary sized set of children. |
| 576 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 577 | class TIntermAggregate : public TIntermOperator |
| 578 | { |
| 579 | public: |
| 580 | TIntermAggregate() |
| 581 | : TIntermOperator(EOpNull), |
| 582 | mUserDefined(false), |
| 583 | mUseEmulatedFunction(false) { } |
| 584 | TIntermAggregate(TOperator op) |
| 585 | : TIntermOperator(op), |
| 586 | mUseEmulatedFunction(false) { } |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 587 | ~TIntermAggregate() { } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 588 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 589 | virtual TIntermAggregate *getAsAggregate() { return this; } |
| 590 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 591 | virtual bool replaceChildNode( |
| 592 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 593 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 594 | // Conservatively assume function calls and other aggregate operators have side-effects |
| 595 | virtual bool hasSideEffects() const { return true; } |
| 596 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 597 | TIntermSequence *getSequence() { return &mSequence; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 598 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 599 | void setName(const TString &name) { mName = name; } |
| 600 | const TString &getName() const { return mName; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 601 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 602 | void setUserDefined() { mUserDefined = true; } |
| 603 | bool isUserDefined() const { return mUserDefined; } |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 604 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 605 | void setOptimize(bool optimize) { mOptimize = optimize; } |
| 606 | bool getOptimize() const { return mOptimize; } |
| 607 | void setDebug(bool debug) { mDebug = debug; } |
| 608 | bool getDebug() const { return mDebug; } |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 609 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 610 | void setUseEmulatedFunction() { mUseEmulatedFunction = true; } |
| 611 | bool getUseEmulatedFunction() { return mUseEmulatedFunction; } |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 612 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 613 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 614 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 615 | protected: |
| 616 | TIntermAggregate(const TIntermAggregate &); // disallow copy constructor |
| 617 | TIntermAggregate &operator=(const TIntermAggregate &); // disallow assignment operator |
| 618 | TIntermSequence mSequence; |
| 619 | TString mName; |
| 620 | bool mUserDefined; // used for user defined function names |
alokp@chromium.org | b19403a | 2010-09-08 17:56:26 +0000 | [diff] [blame] | 621 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 622 | bool mOptimize; |
| 623 | bool mDebug; |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 624 | |
| 625 | // If set to true, replace the built-in function call with an emulated one |
| 626 | // to work around driver bugs. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 627 | bool mUseEmulatedFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | // |
| 631 | // For if tests. Simplified since there is no switch statement. |
| 632 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 633 | class TIntermSelection : public TIntermTyped |
| 634 | { |
| 635 | public: |
| 636 | TIntermSelection(TIntermTyped *cond, TIntermNode *trueB, TIntermNode *falseB) |
| 637 | : TIntermTyped(TType(EbtVoid, EbpUndefined)), |
| 638 | mCondition(cond), |
| 639 | mTrueBlock(trueB), |
| 640 | mFalseBlock(falseB) {} |
| 641 | TIntermSelection(TIntermTyped *cond, TIntermNode *trueB, TIntermNode *falseB, |
| 642 | const TType &type) |
| 643 | : TIntermTyped(type), |
| 644 | mCondition(cond), |
| 645 | mTrueBlock(trueB), |
| 646 | mFalseBlock(falseB) {} |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 647 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 648 | virtual void traverse(TIntermTraverser *); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 649 | virtual bool replaceChildNode( |
| 650 | TIntermNode *original, TIntermNode *replacement); |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 651 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 652 | // Conservatively assume selections have side-effects |
| 653 | virtual bool hasSideEffects() const { return true; } |
| 654 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 655 | bool usesTernaryOperator() const { return getBasicType() != EbtVoid; } |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 656 | TIntermNode *getCondition() const { return mCondition; } |
| 657 | TIntermNode *getTrueBlock() const { return mTrueBlock; } |
| 658 | TIntermNode *getFalseBlock() const { return mFalseBlock; } |
| 659 | TIntermSelection *getAsSelectionNode() { return this; } |
alokp@chromium.org | 58e5429 | 2010-08-24 21:40:03 +0000 | [diff] [blame] | 660 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 661 | virtual void enqueueChildren(std::queue<TIntermNode *> *nodeQueue) const; |
Jamie Madill | dd0d342 | 2014-03-26 14:01:56 -0400 | [diff] [blame] | 662 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 663 | protected: |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 664 | TIntermTyped *mCondition; |
| 665 | TIntermNode *mTrueBlock; |
| 666 | TIntermNode *mFalseBlock; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 667 | }; |
| 668 | |
| 669 | enum Visit |
| 670 | { |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 671 | PreVisit, |
| 672 | InVisit, |
| 673 | PostVisit |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 674 | }; |
| 675 | |
| 676 | // |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 677 | // For traversing the tree. User should derive from this, |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 678 | // put their traversal specific data in it, and then pass |
| 679 | // it to a Traverse method. |
| 680 | // |
| 681 | // When using this, just fill in the methods for nodes you want visited. |
| 682 | // Return false from a pre-visit to skip visiting that node's subtree. |
| 683 | // |
| 684 | class TIntermTraverser |
| 685 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 686 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 687 | POOL_ALLOCATOR_NEW_DELETE(); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 688 | // TODO(zmo): remove default values. |
| 689 | TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, |
| 690 | bool rightToLeft = false) |
| 691 | : preVisit(preVisit), |
| 692 | inVisit(inVisit), |
| 693 | postVisit(postVisit), |
| 694 | rightToLeft(rightToLeft), |
| 695 | mDepth(0), |
| 696 | mMaxDepth(0) {} |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 697 | virtual ~TIntermTraverser() {} |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 698 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 699 | virtual void visitSymbol(TIntermSymbol *) {} |
| 700 | virtual void visitRaw(TIntermRaw *) {} |
| 701 | virtual void visitConstantUnion(TIntermConstantUnion *) {} |
| 702 | virtual bool visitBinary(Visit, TIntermBinary *) { return true; } |
| 703 | virtual bool visitUnary(Visit, TIntermUnary *) { return true; } |
| 704 | virtual bool visitSelection(Visit, TIntermSelection *) { return true; } |
| 705 | virtual bool visitAggregate(Visit, TIntermAggregate *) { return true; } |
| 706 | virtual bool visitLoop(Visit, TIntermLoop *) { return true; } |
| 707 | virtual bool visitBranch(Visit, TIntermBranch *) { return true; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 708 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 709 | int getMaxDepth() const { return mMaxDepth; } |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 710 | |
| 711 | void incrementDepth(TIntermNode *current) |
| 712 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 713 | mDepth++; |
| 714 | mMaxDepth = std::max(mMaxDepth, mDepth); |
| 715 | mPath.push_back(current); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void decrementDepth() |
| 719 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 720 | mDepth--; |
| 721 | mPath.pop_back(); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | TIntermNode *getParentNode() |
| 725 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 726 | return mPath.size() == 0 ? NULL : mPath.back(); |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 727 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 728 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 729 | // Return the original name if hash function pointer is NULL; |
| 730 | // otherwise return the hashed name. |
| 731 | static TString hash(const TString& name, ShHashFunction64 hashFunction); |
| 732 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 733 | const bool preVisit; |
| 734 | const bool inVisit; |
| 735 | const bool postVisit; |
| 736 | const bool rightToLeft; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 737 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 738 | protected: |
| 739 | int mDepth; |
| 740 | int mMaxDepth; |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 741 | |
| 742 | // All the nodes from root to the current node's parent during traversing. |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 743 | TVector<TIntermNode *> mPath; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 744 | }; |
| 745 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 746 | // |
| 747 | // For traversing the tree, and computing max depth. |
| 748 | // Takes a maximum depth limit to prevent stack overflow. |
| 749 | // |
| 750 | class TMaxDepthTraverser : public TIntermTraverser |
| 751 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 752 | public: |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 753 | POOL_ALLOCATOR_NEW_DELETE(); |
| 754 | TMaxDepthTraverser(int depthLimit) |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 755 | : TIntermTraverser(true, true, false, false), |
| 756 | mDepthLimit(depthLimit) { } |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 757 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 758 | virtual bool visitBinary(Visit, TIntermBinary *) { return depthCheck(); } |
| 759 | virtual bool visitUnary(Visit, TIntermUnary *) { return depthCheck(); } |
| 760 | virtual bool visitSelection(Visit, TIntermSelection *) { return depthCheck(); } |
| 761 | virtual bool visitAggregate(Visit, TIntermAggregate *) { return depthCheck(); } |
| 762 | virtual bool visitLoop(Visit, TIntermLoop *) { return depthCheck(); } |
| 763 | virtual bool visitBranch(Visit, TIntermBranch *) { return depthCheck(); } |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 764 | |
| 765 | protected: |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 766 | bool depthCheck() const { return mMaxDepth < mDepthLimit; } |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 767 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 768 | int mDepthLimit; |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 769 | }; |
| 770 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame^] | 771 | #endif // COMPILER_TRANSLATOR_INTERMEDIATE_H_ |