Commit 4dd06d5d by Olli Etuaho Committed by Commit Bot

Set proper symbol ids on temporary symbol nodes

Temporary symbols used to all have symbol id 0. Now they get assigned unique symbol ids. This makes it possible to keep track of them according to the symbol id instead of their name, paving way to more robust AST handling in the future. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I292e2e483cc39173524fd30a30b48c4c808442e5 Reviewed-on: https://chromium-review.googlesource.com/559335Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 69df242c
...@@ -60,7 +60,7 @@ TIntermAggregate *CreateReplacementCall(TIntermAggregate *originalCall, ...@@ -60,7 +60,7 @@ TIntermAggregate *CreateReplacementCall(TIntermAggregate *originalCall,
class ArrayReturnValueToOutParameterTraverser : private TIntermTraverser class ArrayReturnValueToOutParameterTraverser : private TIntermTraverser
{ {
public: public:
static void apply(TIntermNode *root, unsigned int *temporaryIndex); static void apply(TIntermNode *root, TSymbolUniqueId *temporaryId);
private: private:
ArrayReturnValueToOutParameterTraverser(); ArrayReturnValueToOutParameterTraverser();
...@@ -74,10 +74,10 @@ class ArrayReturnValueToOutParameterTraverser : private TIntermTraverser ...@@ -74,10 +74,10 @@ class ArrayReturnValueToOutParameterTraverser : private TIntermTraverser
bool mInFunctionWithArrayReturnValue; bool mInFunctionWithArrayReturnValue;
}; };
void ArrayReturnValueToOutParameterTraverser::apply(TIntermNode *root, unsigned int *temporaryIndex) void ArrayReturnValueToOutParameterTraverser::apply(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
ArrayReturnValueToOutParameterTraverser arrayReturnValueToOutParam; ArrayReturnValueToOutParameterTraverser arrayReturnValueToOutParam;
arrayReturnValueToOutParam.useTemporaryIndex(temporaryIndex); arrayReturnValueToOutParam.useTemporaryId(temporaryId);
root->traverse(&arrayReturnValueToOutParam); root->traverse(&arrayReturnValueToOutParam);
arrayReturnValueToOutParam.updateTree(); arrayReturnValueToOutParam.updateTree();
} }
...@@ -139,7 +139,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitAggregate(Visit visit, TInter ...@@ -139,7 +139,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitAggregate(Visit visit, TInter
TIntermBlock *parentBlock = getParentNode()->getAsBlock(); TIntermBlock *parentBlock = getParentNode()->getAsBlock();
if (parentBlock) if (parentBlock)
{ {
nextTemporaryIndex(); nextTemporaryId();
TIntermSequence replacements; TIntermSequence replacements;
replacements.push_back(createTempDeclaration(node->getType())); replacements.push_back(createTempDeclaration(node->getType()));
TIntermSymbol *returnSymbol = createTempSymbol(node->getType()); TIntermSymbol *returnSymbol = createTempSymbol(node->getType());
...@@ -194,9 +194,9 @@ bool ArrayReturnValueToOutParameterTraverser::visitBinary(Visit visit, TIntermBi ...@@ -194,9 +194,9 @@ bool ArrayReturnValueToOutParameterTraverser::visitBinary(Visit visit, TIntermBi
} // namespace } // namespace
void ArrayReturnValueToOutParameter(TIntermNode *root, unsigned int *temporaryIndex) void ArrayReturnValueToOutParameter(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
ArrayReturnValueToOutParameterTraverser::apply(root, temporaryIndex); ArrayReturnValueToOutParameterTraverser::apply(root, temporaryId);
} }
} // namespace sh } // namespace sh
...@@ -12,9 +12,12 @@ ...@@ -12,9 +12,12 @@
namespace sh namespace sh
{ {
class TIntermNode; class TIntermNode;
class TSymbolUniqueId;
void ArrayReturnValueToOutParameter(TIntermNode *root, TSymbolUniqueId *temporaryId);
void ArrayReturnValueToOutParameter(TIntermNode *root, unsigned int *temporaryIndex);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_ARRAYRETURNVALUETOOUTPARAMETER_H_ #endif // COMPILER_TRANSLATOR_ARRAYRETURNVALUETOOUTPARAMETER_H_
...@@ -240,7 +240,7 @@ TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) ...@@ -240,7 +240,7 @@ TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
mDiagnostics(infoSink.info), mDiagnostics(infoSink.info),
mSourcePath(nullptr), mSourcePath(nullptr),
mComputeShaderLocalSizeDeclared(false), mComputeShaderLocalSizeDeclared(false),
mTemporaryIndex(0) mTemporaryId()
{ {
mComputeShaderLocalSize.fill(1); mComputeShaderLocalSize.fill(1);
} }
...@@ -434,7 +434,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -434,7 +434,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
// This pass might emit short circuits so keep it before the short circuit unfolding // This pass might emit short circuits so keep it before the short circuit unfolding
if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)) if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS))
RewriteDoWhile(root, getTemporaryIndex()); RewriteDoWhile(root, getTemporaryId());
if (success && (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION)) if (success && (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION))
sh::AddAndTrueToLoopCondition(root); sh::AddAndTrueToLoopCondition(root);
...@@ -501,7 +501,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -501,7 +501,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)) if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
{ {
ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh, ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh,
&mTemporaryIndex); getTemporaryId());
} }
if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES)) if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
...@@ -537,7 +537,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -537,7 +537,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
IntermNodePatternMatcher::kMultiDeclaration | IntermNodePatternMatcher::kMultiDeclaration |
IntermNodePatternMatcher::kArrayDeclaration | IntermNodePatternMatcher::kArrayDeclaration |
IntermNodePatternMatcher::kNamelessStructDeclaration, IntermNodePatternMatcher::kNamelessStructDeclaration,
getTemporaryIndex(), getSymbolTable(), getShaderVersion()); getTemporaryId(), getSymbolTable(), getShaderVersion());
} }
// We only really need to separate array declarations and nameless struct declarations, // We only really need to separate array declarations and nameless struct declarations,
// but it's simpler to just use the regular SeparateDeclarations. // but it's simpler to just use the regular SeparateDeclarations.
...@@ -742,7 +742,7 @@ void TCompiler::clearResults() ...@@ -742,7 +742,7 @@ void TCompiler::clearResults()
nameMap.clear(); nameMap.clear();
mSourcePath = nullptr; mSourcePath = nullptr;
mTemporaryIndex = 0; mTemporaryId = TSymbolUniqueId();
} }
bool TCompiler::initCallDag(TIntermNode *root) bool TCompiler::initCallDag(TIntermNode *root)
......
...@@ -157,7 +157,7 @@ class TCompiler : public TShHandleBase ...@@ -157,7 +157,7 @@ class TCompiler : public TShHandleBase
const char *getSourcePath() const; const char *getSourcePath() const;
const TPragma &getPragma() const { return mPragma; } const TPragma &getPragma() const { return mPragma; }
void writePragma(ShCompileOptions compileOptions); void writePragma(ShCompileOptions compileOptions);
unsigned int *getTemporaryIndex() { return &mTemporaryIndex; } TSymbolUniqueId *getTemporaryId() { return &mTemporaryId; }
// Relies on collectVariables having been called. // Relies on collectVariables having been called.
bool isVaryingDefined(const char *varyingName); bool isVaryingDefined(const char *varyingName);
...@@ -248,7 +248,7 @@ class TCompiler : public TShHandleBase ...@@ -248,7 +248,7 @@ class TCompiler : public TShHandleBase
TPragma mPragma; TPragma mPragma;
unsigned int mTemporaryIndex; TSymbolUniqueId mTemporaryId;
}; };
// //
......
...@@ -22,7 +22,7 @@ namespace ...@@ -22,7 +22,7 @@ namespace
class Traverser : public TIntermTraverser class Traverser : public TIntermTraverser
{ {
public: public:
static void Apply(TIntermNode *root, unsigned int *tempIndex); static void Apply(TIntermNode *root, TSymbolUniqueId *temporaryId);
private: private:
Traverser(); Traverser();
...@@ -33,10 +33,10 @@ class Traverser : public TIntermTraverser ...@@ -33,10 +33,10 @@ class Traverser : public TIntermTraverser
}; };
// static // static
void Traverser::Apply(TIntermNode *root, unsigned int *tempIndex) void Traverser::Apply(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
Traverser traverser; Traverser traverser;
traverser.useTemporaryIndex(tempIndex); traverser.useTemporaryId(temporaryId);
do do
{ {
traverser.nextIteration(); traverser.nextIteration();
...@@ -55,7 +55,7 @@ Traverser::Traverser() : TIntermTraverser(true, false, false) ...@@ -55,7 +55,7 @@ Traverser::Traverser() : TIntermTraverser(true, false, false)
void Traverser::nextIteration() void Traverser::nextIteration()
{ {
mFound = false; mFound = false;
nextTemporaryIndex(); nextTemporaryId();
} }
bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
...@@ -111,7 +111,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -111,7 +111,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
} }
// Potential problem case detected, apply workaround. // Potential problem case detected, apply workaround.
nextTemporaryIndex(); nextTemporaryId();
TIntermTyped *lhs = sequence->at(0)->getAsTyped(); TIntermTyped *lhs = sequence->at(0)->getAsTyped();
ASSERT(lhs); ASSERT(lhs);
...@@ -146,9 +146,9 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -146,9 +146,9 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
} // anonymous namespace } // anonymous namespace
void ExpandIntegerPowExpressions(TIntermNode *root, unsigned int *tempIndex) void ExpandIntegerPowExpressions(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
Traverser::Apply(root, tempIndex); Traverser::Apply(root, temporaryId);
} }
} // namespace sh } // namespace sh
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
#ifndef COMPILER_TRANSLATOR_EXPANDINTEGERPOWEXPRESSIONS_H_ #ifndef COMPILER_TRANSLATOR_EXPANDINTEGERPOWEXPRESSIONS_H_
#define COMPILER_TRANSLATOR_EXPANDINTEGERPOWEXPRESSIONS_H_ #define COMPILER_TRANSLATOR_EXPANDINTEGERPOWEXPRESSIONS_H_
class TIntermNode;
namespace sh namespace sh
{ {
void ExpandIntegerPowExpressions(TIntermNode *root, unsigned int *tempIndex); class TIntermNode;
class TSymbolUniqueId;
void ExpandIntegerPowExpressions(TIntermNode *root, TSymbolUniqueId *temporaryId);
} // namespace sh } // namespace sh
......
...@@ -997,7 +997,7 @@ class TIntermTraverser : angle::NonCopyable ...@@ -997,7 +997,7 @@ class TIntermTraverser : angle::NonCopyable
void updateTree(); void updateTree();
// Start creating temporary symbols from the given temporary symbol index + 1. // Start creating temporary symbols from the given temporary symbol index + 1.
void useTemporaryIndex(unsigned int *temporaryIndex); void useTemporaryId(TSymbolUniqueId *temporaryId);
static TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode( static TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(
const TType &returnType, const TType &returnType,
...@@ -1123,7 +1123,7 @@ class TIntermTraverser : angle::NonCopyable ...@@ -1123,7 +1123,7 @@ class TIntermTraverser : angle::NonCopyable
// Create a node that assigns rightNode to the current temporary symbol. // Create a node that assigns rightNode to the current temporary symbol.
TIntermBinary *createTempAssignment(TIntermTyped *rightNode); TIntermBinary *createTempAssignment(TIntermTyped *rightNode);
// Increment temporary symbol index. // Increment temporary symbol index.
void nextTemporaryIndex(); void nextTemporaryId();
enum class OriginalNode enum class OriginalNode
{ {
...@@ -1200,7 +1200,7 @@ class TIntermTraverser : angle::NonCopyable ...@@ -1200,7 +1200,7 @@ class TIntermTraverser : angle::NonCopyable
// All the code blocks from the root to the current node's parent during traversal. // All the code blocks from the root to the current node's parent during traversal.
std::vector<ParentBlock> mParentBlockStack; std::vector<ParentBlock> mParentBlockStack;
unsigned int *mTemporaryIndex; TSymbolUniqueId *mTemporaryId;
}; };
// Traverser parent class that tracks where a node is a destination of a write operation and so is // Traverser parent class that tracks where a node is a destination of a write operation and so is
......
...@@ -108,7 +108,7 @@ TIntermTraverser::TIntermTraverser(bool preVisit, bool inVisit, bool postVisit) ...@@ -108,7 +108,7 @@ TIntermTraverser::TIntermTraverser(bool preVisit, bool inVisit, bool postVisit)
mDepth(-1), mDepth(-1),
mMaxDepth(0), mMaxDepth(0),
mInGlobalScope(true), mInGlobalScope(true),
mTemporaryIndex(nullptr) mTemporaryId(nullptr)
{ {
} }
...@@ -167,11 +167,11 @@ TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type, TQualifier ...@@ -167,11 +167,11 @@ TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type, TQualifier
// Each traversal uses at most one temporary variable, so the index stays the same within a // Each traversal uses at most one temporary variable, so the index stays the same within a
// single traversal. // single traversal.
TInfoSinkBase symbolNameOut; TInfoSinkBase symbolNameOut;
ASSERT(mTemporaryIndex != nullptr); ASSERT(mTemporaryId != nullptr);
symbolNameOut << "s" << (*mTemporaryIndex); symbolNameOut << "s" << (mTemporaryId->get());
TString symbolName = symbolNameOut.c_str(); TString symbolName = symbolNameOut.c_str();
TIntermSymbol *node = new TIntermSymbol(0, symbolName, type); TIntermSymbol *node = new TIntermSymbol(mTemporaryId->get(), symbolName, type);
node->setInternal(true); node->setInternal(true);
ASSERT(qualifier == EvqTemporary || qualifier == EvqConst || qualifier == EvqGlobal); ASSERT(qualifier == EvqTemporary || qualifier == EvqConst || qualifier == EvqGlobal);
...@@ -217,15 +217,15 @@ TIntermBinary *TIntermTraverser::createTempAssignment(TIntermTyped *rightNode) ...@@ -217,15 +217,15 @@ TIntermBinary *TIntermTraverser::createTempAssignment(TIntermTyped *rightNode)
return assignment; return assignment;
} }
void TIntermTraverser::useTemporaryIndex(unsigned int *temporaryIndex) void TIntermTraverser::useTemporaryId(TSymbolUniqueId *temporaryId)
{ {
mTemporaryIndex = temporaryIndex; mTemporaryId = temporaryId;
} }
void TIntermTraverser::nextTemporaryIndex() void TIntermTraverser::nextTemporaryId()
{ {
ASSERT(mTemporaryIndex != nullptr); ASSERT(mTemporaryId != nullptr);
++(*mTemporaryIndex); *mTemporaryId = TSymbolUniqueId();
} }
void TLValueTrackingTraverser::addToFunctionMap(const TSymbolUniqueId &id, void TLValueTrackingTraverser::addToFunctionMap(const TSymbolUniqueId &id,
......
...@@ -145,17 +145,17 @@ void RecordConstantPrecisionTraverser::visitConstantUnion(TIntermConstantUnion * ...@@ -145,17 +145,17 @@ void RecordConstantPrecisionTraverser::visitConstantUnion(TIntermConstantUnion *
void RecordConstantPrecisionTraverser::nextIteration() void RecordConstantPrecisionTraverser::nextIteration()
{ {
nextTemporaryIndex(); nextTemporaryId();
mFoundHigherPrecisionConstant = false; mFoundHigherPrecisionConstant = false;
} }
} // namespace } // namespace
void RecordConstantPrecision(TIntermNode *root, unsigned int *temporaryIndex) void RecordConstantPrecision(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
RecordConstantPrecisionTraverser traverser; RecordConstantPrecisionTraverser traverser;
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
// Iterate as necessary, and reset the traverser between iterations. // Iterate as necessary, and reset the traverser between iterations.
do do
{ {
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
namespace sh namespace sh
{ {
class TIntermNode; class TIntermNode;
class TSymbolUniqueId;
void RecordConstantPrecision(TIntermNode *root, unsigned int *temporaryIndex); void RecordConstantPrecision(TIntermNode *root, TSymbolUniqueId *temporaryId);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_RECORDCONSTANTPRECISION_H_ #endif // COMPILER_TRANSLATOR_RECORDCONSTANTPRECISION_H_
...@@ -478,15 +478,15 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod ...@@ -478,15 +478,15 @@ bool RemoveDynamicIndexingTraverser::visitBinary(Visit visit, TIntermBinary *nod
initIndex->setLine(node->getLine()); initIndex->setLine(node->getLine());
insertionsBefore.push_back(initIndex); insertionsBefore.push_back(initIndex);
// Create a node for referring to the index after the nextTemporaryIndex() call // Create a node for referring to the index after the nextTemporaryId() call
// below. // below.
TIntermSymbol *tempIndex = createTempSymbol(indexInitializer->getType()); TIntermSymbol *tempIndex = createTempSymbol(indexInitializer->getType());
TIntermAggregate *indexingCall = TIntermAggregate *indexingCall =
CreateIndexFunctionCall(node, tempIndex, indexingFunctionId); CreateIndexFunctionCall(node, tempIndex, indexingFunctionId);
nextTemporaryIndex(); // From now on, creating temporary symbols that refer to the nextTemporaryId(); // From now on, creating temporary symbols that refer to the
// field value. // field value.
insertionsBefore.push_back(createTempInitDeclaration(indexingCall)); insertionsBefore.push_back(createTempInitDeclaration(indexingCall));
TIntermAggregate *indexedWriteCall = CreateIndexedWriteFunctionCall( TIntermAggregate *indexedWriteCall = CreateIndexedWriteFunctionCall(
...@@ -517,19 +517,19 @@ void RemoveDynamicIndexingTraverser::nextIteration() ...@@ -517,19 +517,19 @@ void RemoveDynamicIndexingTraverser::nextIteration()
{ {
mUsedTreeInsertion = false; mUsedTreeInsertion = false;
mRemoveIndexSideEffectsInSubtree = false; mRemoveIndexSideEffectsInSubtree = false;
nextTemporaryIndex(); nextTemporaryId();
} }
} // namespace } // namespace
void RemoveDynamicIndexing(TIntermNode *root, void RemoveDynamicIndexing(TIntermNode *root,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion) int shaderVersion)
{ {
RemoveDynamicIndexingTraverser traverser(symbolTable, shaderVersion); RemoveDynamicIndexingTraverser traverser(symbolTable, shaderVersion);
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
do do
{ {
traverser.nextIteration(); traverser.nextIteration();
......
...@@ -15,9 +15,10 @@ namespace sh ...@@ -15,9 +15,10 @@ namespace sh
class TIntermNode; class TIntermNode;
class TSymbolTable; class TSymbolTable;
class TSymbolUniqueId;
void RemoveDynamicIndexing(TIntermNode *root, void RemoveDynamicIndexing(TIntermNode *root,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion); int shaderVersion);
......
...@@ -138,7 +138,7 @@ class DoWhileRewriter : public TIntermTraverser ...@@ -138,7 +138,7 @@ class DoWhileRewriter : public TIntermTraverser
node->replaceChildNodeWithMultiple(loop, replacement); node->replaceChildNodeWithMultiple(loop, replacement);
nextTemporaryIndex(); nextTemporaryId();
} }
return true; return true;
} }
...@@ -146,12 +146,12 @@ class DoWhileRewriter : public TIntermTraverser ...@@ -146,12 +146,12 @@ class DoWhileRewriter : public TIntermTraverser
} // anonymous namespace } // anonymous namespace
void RewriteDoWhile(TIntermNode *root, unsigned int *temporaryIndex) void RewriteDoWhile(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
ASSERT(temporaryIndex != 0); ASSERT(temporaryId != 0);
DoWhileRewriter rewriter; DoWhileRewriter rewriter;
rewriter.useTemporaryIndex(temporaryIndex); rewriter.useTemporaryId(temporaryId);
root->traverse(&rewriter); root->traverse(&rewriter);
} }
......
...@@ -12,8 +12,12 @@ ...@@ -12,8 +12,12 @@
namespace sh namespace sh
{ {
class TIntermNode; class TIntermNode;
void RewriteDoWhile(TIntermNode *root, unsigned int *temporaryIndex); class TSymbolUniqueId;
void RewriteDoWhile(TIntermNode *root, TSymbolUniqueId *temporaryId);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_REWRITEDOWHILE_H_ #endif // COMPILER_TRANSLATOR_REWRITEDOWHILE_H_
...@@ -67,7 +67,7 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse) ...@@ -67,7 +67,7 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
{ {
ASSERT(ifElse != nullptr); ASSERT(ifElse != nullptr);
nextTemporaryIndex(); nextTemporaryId();
TIntermDeclaration *storeCondition = createTempInitDeclaration(ifElse->getCondition()); TIntermDeclaration *storeCondition = createTempInitDeclaration(ifElse->getCondition());
...@@ -110,10 +110,10 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse) ...@@ -110,10 +110,10 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
} // anonymous namespace } // anonymous namespace
void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex) void RewriteElseBlocks(TIntermNode *node, TSymbolUniqueId *temporaryId)
{ {
ElseBlockRewriter rewriter; ElseBlockRewriter rewriter;
rewriter.useTemporaryIndex(temporaryIndex); rewriter.useTemporaryId(temporaryId);
node->traverse(&rewriter); node->traverse(&rewriter);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace sh namespace sh
{ {
void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex); void RewriteElseBlocks(TIntermNode *node, TSymbolUniqueId *temporaryId);
} }
#endif // COMPILER_TRANSLATOR_REWRITEELSEBLOCKS_H_ #endif // COMPILER_TRANSLATOR_REWRITEELSEBLOCKS_H_
...@@ -63,12 +63,12 @@ class ScalarizeArgsTraverser : public TIntermTraverser ...@@ -63,12 +63,12 @@ class ScalarizeArgsTraverser : public TIntermTraverser
public: public:
ScalarizeArgsTraverser(sh::GLenum shaderType, ScalarizeArgsTraverser(sh::GLenum shaderType,
bool fragmentPrecisionHigh, bool fragmentPrecisionHigh,
unsigned int *temporaryIndex) TSymbolUniqueId *temporaryId)
: TIntermTraverser(true, false, false), : TIntermTraverser(true, false, false),
mShaderType(shaderType), mShaderType(shaderType),
mFragmentPrecisionHigh(fragmentPrecisionHigh) mFragmentPrecisionHigh(fragmentPrecisionHigh)
{ {
useTemporaryIndex(temporaryIndex); useTemporaryId(temporaryId);
} }
protected: protected:
...@@ -204,7 +204,7 @@ void ScalarizeArgsTraverser::scalarizeArgs(TIntermAggregate *aggregate, ...@@ -204,7 +204,7 @@ void ScalarizeArgsTraverser::scalarizeArgs(TIntermAggregate *aggregate,
void ScalarizeArgsTraverser::createTempVariable(TIntermTyped *original) void ScalarizeArgsTraverser::createTempVariable(TIntermTyped *original)
{ {
ASSERT(original); ASSERT(original);
nextTemporaryIndex(); nextTemporaryId();
TIntermDeclaration *decl = createTempInitDeclaration(original); TIntermDeclaration *decl = createTempInitDeclaration(original);
TType type = original->getType(); TType type = original->getType();
...@@ -230,9 +230,9 @@ void ScalarizeArgsTraverser::createTempVariable(TIntermTyped *original) ...@@ -230,9 +230,9 @@ void ScalarizeArgsTraverser::createTempVariable(TIntermTyped *original)
void ScalarizeVecAndMatConstructorArgs(TIntermBlock *root, void ScalarizeVecAndMatConstructorArgs(TIntermBlock *root,
sh::GLenum shaderType, sh::GLenum shaderType,
bool fragmentPrecisionHigh, bool fragmentPrecisionHigh,
unsigned int *temporaryIndex) TSymbolUniqueId *temporaryId)
{ {
ScalarizeArgsTraverser scalarizer(shaderType, fragmentPrecisionHigh, temporaryIndex); ScalarizeArgsTraverser scalarizer(shaderType, fragmentPrecisionHigh, temporaryId);
root->traverse(&scalarizer); root->traverse(&scalarizer);
} }
......
...@@ -16,11 +16,12 @@ ...@@ -16,11 +16,12 @@
namespace sh namespace sh
{ {
class TIntermBlock; class TIntermBlock;
class TSymbolUniqueId;
void ScalarizeVecAndMatConstructorArgs(TIntermBlock *root, void ScalarizeVecAndMatConstructorArgs(TIntermBlock *root,
sh::GLenum shaderType, sh::GLenum shaderType,
bool fragmentPrecisionHigh, bool fragmentPrecisionHigh,
unsigned int *temporaryIndex); TSymbolUniqueId *temporaryId);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_SCALARIZEVECANDMATCONSTRUCTORARGS_H_ #endif // COMPILER_TRANSLATOR_SCALARIZEVECANDMATCONSTRUCTORARGS_H_
...@@ -105,16 +105,16 @@ bool SeparateExpressionsTraverser::visitAggregate(Visit visit, TIntermAggregate ...@@ -105,16 +105,16 @@ bool SeparateExpressionsTraverser::visitAggregate(Visit visit, TIntermAggregate
void SeparateExpressionsTraverser::nextIteration() void SeparateExpressionsTraverser::nextIteration()
{ {
mFoundArrayExpression = false; mFoundArrayExpression = false;
nextTemporaryIndex(); nextTemporaryId();
} }
} // namespace } // namespace
void SeparateExpressionsReturningArrays(TIntermNode *root, unsigned int *temporaryIndex) void SeparateExpressionsReturningArrays(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
SeparateExpressionsTraverser traverser; SeparateExpressionsTraverser traverser;
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
// Separate one expression at a time, and reset the traverser between iterations. // Separate one expression at a time, and reset the traverser between iterations.
do do
{ {
......
...@@ -15,8 +15,9 @@ ...@@ -15,8 +15,9 @@
namespace sh namespace sh
{ {
class TIntermNode; class TIntermNode;
class TSymbolUniqueId;
void SeparateExpressionsReturningArrays(TIntermNode *root, unsigned int *temporaryIndex); void SeparateExpressionsReturningArrays(TIntermNode *root, TSymbolUniqueId *temporaryId);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_SEPARATEEXPRESSIONSRETURNINGARRAYS_H_ #endif // COMPILER_TRANSLATOR_SEPARATEEXPRESSIONSRETURNINGARRAYS_H_
...@@ -146,7 +146,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) ...@@ -146,7 +146,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node)
if (mFoundLoopToChange) if (mFoundLoopToChange)
{ {
nextTemporaryIndex(); nextTemporaryId();
// Replace the loop condition with a boolean variable that's updated on each iteration. // Replace the loop condition with a boolean variable that's updated on each iteration.
TLoopType loopType = node->getType(); TLoopType loopType = node->getType();
...@@ -284,13 +284,13 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) ...@@ -284,13 +284,13 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node)
void SimplifyLoopConditions(TIntermNode *root, void SimplifyLoopConditions(TIntermNode *root,
unsigned int conditionsToSimplifyMask, unsigned int conditionsToSimplifyMask,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion) int shaderVersion)
{ {
SimplifyLoopConditionsTraverser traverser(conditionsToSimplifyMask, symbolTable, shaderVersion); SimplifyLoopConditionsTraverser traverser(conditionsToSimplifyMask, symbolTable, shaderVersion);
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
root->traverse(&traverser); root->traverse(&traverser);
traverser.updateTree(); traverser.updateTree();
} }
......
...@@ -15,10 +15,11 @@ namespace sh ...@@ -15,10 +15,11 @@ namespace sh
{ {
class TIntermNode; class TIntermNode;
class TSymbolTable; class TSymbolTable;
class TSymbolUniqueId;
void SimplifyLoopConditions(TIntermNode *root, void SimplifyLoopConditions(TIntermNode *root,
unsigned int conditionsToSimplify, unsigned int conditionsToSimplify,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion); int shaderVersion);
} // namespace sh } // namespace sh
......
...@@ -57,7 +57,7 @@ void SplitSequenceOperatorTraverser::nextIteration() ...@@ -57,7 +57,7 @@ void SplitSequenceOperatorTraverser::nextIteration()
{ {
mFoundExpressionToSplit = false; mFoundExpressionToSplit = false;
mInsideSequenceOperator = 0; mInsideSequenceOperator = 0;
nextTemporaryIndex(); nextTemporaryId();
} }
bool SplitSequenceOperatorTraverser::visitAggregate(Visit visit, TIntermAggregate *node) bool SplitSequenceOperatorTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
...@@ -138,13 +138,13 @@ bool SplitSequenceOperatorTraverser::visitTernary(Visit visit, TIntermTernary *n ...@@ -138,13 +138,13 @@ bool SplitSequenceOperatorTraverser::visitTernary(Visit visit, TIntermTernary *n
void SplitSequenceOperator(TIntermNode *root, void SplitSequenceOperator(TIntermNode *root,
int patternsToSplitMask, int patternsToSplitMask,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion) int shaderVersion)
{ {
SplitSequenceOperatorTraverser traverser(patternsToSplitMask, symbolTable, shaderVersion); SplitSequenceOperatorTraverser traverser(patternsToSplitMask, symbolTable, shaderVersion);
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
// Separate one expression at a time, and reset the traverser between iterations. // Separate one expression at a time, and reset the traverser between iterations.
do do
{ {
......
...@@ -17,10 +17,11 @@ namespace sh ...@@ -17,10 +17,11 @@ namespace sh
class TIntermNode; class TIntermNode;
class TSymbolTable; class TSymbolTable;
class TSymbolUniqueId;
void SplitSequenceOperator(TIntermNode *root, void SplitSequenceOperator(TIntermNode *root,
int patternsToSplitMask, int patternsToSplitMask,
unsigned int *temporaryIndex, TSymbolUniqueId *temporaryId,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
int shaderVersion); int shaderVersion);
......
...@@ -62,7 +62,7 @@ void TranslatorESSL::translate(TIntermBlock *root, ShCompileOptions compileOptio ...@@ -62,7 +62,7 @@ void TranslatorESSL::translate(TIntermBlock *root, ShCompileOptions compileOptio
emulatePrecision.writeEmulationHelpers(sink, shaderVer, SH_ESSL_OUTPUT); emulatePrecision.writeEmulationHelpers(sink, shaderVer, SH_ESSL_OUTPUT);
} }
RecordConstantPrecision(root, getTemporaryIndex()); RecordConstantPrecision(root, getTemporaryId());
// Write emulated built-in functions if needed. // Write emulated built-in functions if needed.
if (!getBuiltInFunctionEmulator().isOutputEmpty()) if (!getBuiltInFunctionEmulator().isOutputEmpty())
......
...@@ -46,7 +46,7 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio ...@@ -46,7 +46,7 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio
IntermNodePatternMatcher::kUnfoldedShortCircuitExpression | IntermNodePatternMatcher::kUnfoldedShortCircuitExpression |
IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue | IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue |
IntermNodePatternMatcher::kMultiDeclaration, IntermNodePatternMatcher::kMultiDeclaration,
getTemporaryIndex(), getSymbolTable(), getShaderVersion()); getTemporaryId(), getSymbolTable(), getShaderVersion());
// Note that separate declarations need to be run before other AST transformations that // Note that separate declarations need to be run before other AST transformations that
// generate new statements from expressions. // generate new statements from expressions.
...@@ -56,31 +56,31 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio ...@@ -56,31 +56,31 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio
IntermNodePatternMatcher::kExpressionReturningArray | IntermNodePatternMatcher::kExpressionReturningArray |
IntermNodePatternMatcher::kUnfoldedShortCircuitExpression | IntermNodePatternMatcher::kUnfoldedShortCircuitExpression |
IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue, IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue,
getTemporaryIndex(), getSymbolTable(), getShaderVersion()); getTemporaryId(), getSymbolTable(), getShaderVersion());
// Note that SeparateDeclarations needs to be run before UnfoldShortCircuitToIf. // Note that SeparateDeclarations needs to be run before UnfoldShortCircuitToIf.
UnfoldShortCircuitToIf(root, getTemporaryIndex()); UnfoldShortCircuitToIf(root, getTemporaryId());
SeparateExpressionsReturningArrays(root, getTemporaryIndex()); SeparateExpressionsReturningArrays(root, getTemporaryId());
// Note that SeparateDeclarations needs to be run before SeparateArrayInitialization. // Note that SeparateDeclarations needs to be run before SeparateArrayInitialization.
SeparateArrayInitialization(root); SeparateArrayInitialization(root);
// HLSL doesn't support arrays as return values, we'll need to make functions that have an array // HLSL doesn't support arrays as return values, we'll need to make functions that have an array
// as a return value to use an out parameter to transfer the array data instead. // as a return value to use an out parameter to transfer the array data instead.
ArrayReturnValueToOutParameter(root, getTemporaryIndex()); ArrayReturnValueToOutParameter(root, getTemporaryId());
if (!shouldRunLoopAndIndexingValidation(compileOptions)) if (!shouldRunLoopAndIndexingValidation(compileOptions))
{ {
// HLSL doesn't support dynamic indexing of vectors and matrices. // HLSL doesn't support dynamic indexing of vectors and matrices.
RemoveDynamicIndexing(root, getTemporaryIndex(), getSymbolTable(), getShaderVersion()); RemoveDynamicIndexing(root, getTemporaryId(), getSymbolTable(), getShaderVersion());
} }
// Work around D3D9 bug that would manifest in vertex shaders with selection blocks which // Work around D3D9 bug that would manifest in vertex shaders with selection blocks which
// use a vertex attribute as a condition, and some related computation in the else block. // use a vertex attribute as a condition, and some related computation in the else block.
if (getOutputType() == SH_HLSL_3_0_OUTPUT && getShaderType() == GL_VERTEX_SHADER) if (getOutputType() == SH_HLSL_3_0_OUTPUT && getShaderType() == GL_VERTEX_SHADER)
{ {
sh::RewriteElseBlocks(root, getTemporaryIndex()); sh::RewriteElseBlocks(root, getTemporaryId());
} }
// Work around an HLSL compiler frontend aliasing optimization bug. // Work around an HLSL compiler frontend aliasing optimization bug.
...@@ -103,7 +103,7 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio ...@@ -103,7 +103,7 @@ void TranslatorHLSL::translate(TIntermBlock *root, ShCompileOptions compileOptio
if ((compileOptions & SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS) != 0) if ((compileOptions & SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS) != 0)
{ {
sh::ExpandIntegerPowExpressions(root, getTemporaryIndex()); sh::ExpandIntegerPowExpressions(root, getTemporaryId());
} }
if ((compileOptions & SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH) != 0) if ((compileOptions & SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH) != 0)
......
...@@ -165,16 +165,16 @@ bool UnfoldShortCircuitTraverser::visitTernary(Visit visit, TIntermTernary *node ...@@ -165,16 +165,16 @@ bool UnfoldShortCircuitTraverser::visitTernary(Visit visit, TIntermTernary *node
void UnfoldShortCircuitTraverser::nextIteration() void UnfoldShortCircuitTraverser::nextIteration()
{ {
mFoundShortCircuit = false; mFoundShortCircuit = false;
nextTemporaryIndex(); nextTemporaryId();
} }
} // namespace } // namespace
void UnfoldShortCircuitToIf(TIntermNode *root, unsigned int *temporaryIndex) void UnfoldShortCircuitToIf(TIntermNode *root, TSymbolUniqueId *temporaryId)
{ {
UnfoldShortCircuitTraverser traverser; UnfoldShortCircuitTraverser traverser;
ASSERT(temporaryIndex != nullptr); ASSERT(temporaryId != nullptr);
traverser.useTemporaryIndex(temporaryIndex); traverser.useTemporaryId(temporaryId);
// Unfold one operator at a time, and reset the traverser between iterations. // Unfold one operator at a time, and reset the traverser between iterations.
do do
{ {
......
...@@ -14,9 +14,12 @@ ...@@ -14,9 +14,12 @@
namespace sh namespace sh
{ {
class TIntermNode; class TIntermNode;
class TSymbolUniqueId;
void UnfoldShortCircuitToIf(TIntermNode *root, TSymbolUniqueId *temporaryId);
void UnfoldShortCircuitToIf(TIntermNode *root, unsigned int *temporaryIndex);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_UNFOLDSHORTCIRCUIT_H_ #endif // COMPILER_TRANSLATOR_UNFOLDSHORTCIRCUIT_H_
...@@ -88,7 +88,9 @@ void TOutputTraverser::visitSymbol(TIntermSymbol *node) ...@@ -88,7 +88,9 @@ void TOutputTraverser::visitSymbol(TIntermSymbol *node)
OutputTreeText(sink, node, mDepth); OutputTreeText(sink, node, mDepth);
sink << "'" << node->getSymbol() << "' "; sink << "'" << node->getSymbol() << "' ";
sink << "(" << node->getCompleteString() << ")\n"; sink << "(symbol id " << node->getId() << ") ";
sink << "(" << node->getCompleteString() << ")";
sink << "\n";
} }
bool TOutputTraverser::visitSwizzle(Visit visit, TIntermSwizzle *node) bool TOutputTraverser::visitSwizzle(Visit visit, TIntermSwizzle *node)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment