Assign symbol ids in RemoveDynamicIndexing
Assign consistent symbol ids to out base, index and value nodes that
get created in RemoveDynamicIndexing. Some utility functions in
RemoveDynamicIndexing have also now become unnecessary now that there
are better generic helpers and node constructors.
BUG=angleproject:1490
TEST=angle_unittests, angle_end2end_tests
Change-Id: I98891e448b85d51518dbf3156ec93f9661def57e
Reviewed-on: https://chromium-review.googlesource.com/580954
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/RemoveDynamicIndexing.cpp b/src/compiler/translator/RemoveDynamicIndexing.cpp
index b0c0fde..c1085de 100644
--- a/src/compiler/translator/RemoveDynamicIndexing.cpp
+++ b/src/compiler/translator/RemoveDynamicIndexing.cpp
@@ -57,25 +57,26 @@
return nameSink.str();
}
-TIntermSymbol *CreateBaseSymbol(const TType &type, TQualifier qualifier)
+TIntermSymbol *CreateBaseSymbol(const TType &type, TQualifier qualifier, TSymbolTable *symbolTable)
{
- TIntermSymbol *symbol = new TIntermSymbol(0, "base", type);
+ TIntermSymbol *symbol = new TIntermSymbol(symbolTable->nextUniqueId(), "base", type);
symbol->setInternal(true);
symbol->getTypePointer()->setQualifier(qualifier);
return symbol;
}
-TIntermSymbol *CreateIndexSymbol()
+TIntermSymbol *CreateIndexSymbol(TSymbolTable *symbolTable)
{
- TIntermSymbol *symbol = new TIntermSymbol(0, "index", TType(EbtInt, EbpHigh));
+ TIntermSymbol *symbol =
+ new TIntermSymbol(symbolTable->nextUniqueId(), "index", TType(EbtInt, EbpHigh));
symbol->setInternal(true);
symbol->getTypePointer()->setQualifier(EvqIn);
return symbol;
}
-TIntermSymbol *CreateValueSymbol(const TType &type)
+TIntermSymbol *CreateValueSymbol(const TType &type, TSymbolTable *symbolTable)
{
- TIntermSymbol *symbol = new TIntermSymbol(0, "value", type);
+ TIntermSymbol *symbol = new TIntermSymbol(symbolTable->nextUniqueId(), "value", type);
symbol->setInternal(true);
symbol->getTypePointer()->setQualifier(EvqIn);
return symbol;
@@ -88,22 +89,6 @@
return new TIntermConstantUnion(constant, TType(EbtInt, EbpHigh));
}
-TIntermBinary *CreateIndexDirectBaseSymbolNode(const TType &indexedType,
- const TType &fieldType,
- const int index,
- TQualifier baseQualifier)
-{
- TIntermSymbol *baseSymbol = CreateBaseSymbol(indexedType, baseQualifier);
- TIntermBinary *indexNode =
- new TIntermBinary(EOpIndexDirect, baseSymbol, CreateIndexNode(index));
- return indexNode;
-}
-
-TIntermBinary *CreateAssignValueSymbolNode(TIntermTyped *targetNode, const TType &assignedValueType)
-{
- return new TIntermBinary(EOpAssign, targetNode, CreateValueSymbol(assignedValueType));
-}
-
TIntermTyped *EnsureSignedInt(TIntermTyped *node)
{
if (node->getBasicType() == EbtInt)
@@ -173,7 +158,8 @@
// Note that else is not used in above functions to avoid the RewriteElseBlocks transformation.
TIntermFunctionDefinition *GetIndexFunctionDefinition(TType type,
bool write,
- const TSymbolUniqueId &functionId)
+ const TSymbolUniqueId &functionId,
+ TSymbolTable *symbolTable)
{
ASSERT(!type.isArray());
// Conservatively use highp here, even if the indexed type is not highp. That way the code can't
@@ -206,13 +192,14 @@
TQualifier baseQualifier = EvqInOut;
if (!write)
baseQualifier = EvqIn;
- TIntermSymbol *baseParam = CreateBaseSymbol(type, baseQualifier);
+ TIntermSymbol *baseParam = CreateBaseSymbol(type, baseQualifier, symbolTable);
prototypeNode->getSequence()->push_back(baseParam);
- TIntermSymbol *indexParam = CreateIndexSymbol();
+ TIntermSymbol *indexParam = CreateIndexSymbol(symbolTable);
prototypeNode->getSequence()->push_back(indexParam);
+ TIntermSymbol *valueParam = nullptr;
if (write)
{
- TIntermSymbol *valueParam = CreateValueSymbol(fieldType);
+ valueParam = CreateValueSymbol(fieldType, symbolTable);
prototypeNode->getSequence()->push_back(valueParam);
}
@@ -223,10 +210,11 @@
statementList->getSequence()->push_back(caseNode);
TIntermBinary *indexNode =
- CreateIndexDirectBaseSymbolNode(type, fieldType, i, baseQualifier);
+ new TIntermBinary(EOpIndexDirect, baseParam->deepCopy(), CreateIndexNode(i));
if (write)
{
- TIntermBinary *assignNode = CreateAssignValueSymbolNode(indexNode, fieldType);
+ TIntermBinary *assignNode =
+ new TIntermBinary(EOpAssign, indexNode, valueParam->deepCopy());
statementList->getSequence()->push_back(assignNode);
TIntermBranch *returnNode = new TIntermBranch(EOpReturn, nullptr);
statementList->getSequence()->push_back(returnNode);
@@ -244,13 +232,13 @@
TIntermBranch *breakNode = new TIntermBranch(EOpBreak, nullptr);
statementList->getSequence()->push_back(breakNode);
- TIntermSwitch *switchNode = new TIntermSwitch(CreateIndexSymbol(), statementList);
+ TIntermSwitch *switchNode = new TIntermSwitch(indexParam->deepCopy(), statementList);
TIntermBlock *bodyNode = new TIntermBlock();
bodyNode->getSequence()->push_back(switchNode);
TIntermBinary *cond =
- new TIntermBinary(EOpLessThan, CreateIndexSymbol(), CreateIntConstantNode(0));
+ new TIntermBinary(EOpLessThan, indexParam->deepCopy(), CreateIntConstantNode(0));
cond->setType(TType(EbtBool, EbpUndefined));
// Two blocks: one accesses (either reads or writes) the first element and returns,
@@ -258,17 +246,19 @@
TIntermBlock *useFirstBlock = new TIntermBlock();
TIntermBlock *useLastBlock = new TIntermBlock();
TIntermBinary *indexFirstNode =
- CreateIndexDirectBaseSymbolNode(type, fieldType, 0, baseQualifier);
+ new TIntermBinary(EOpIndexDirect, baseParam->deepCopy(), CreateIndexNode(0));
TIntermBinary *indexLastNode =
- CreateIndexDirectBaseSymbolNode(type, fieldType, numCases - 1, baseQualifier);
+ new TIntermBinary(EOpIndexDirect, baseParam->deepCopy(), CreateIndexNode(numCases - 1));
if (write)
{
- TIntermBinary *assignFirstNode = CreateAssignValueSymbolNode(indexFirstNode, fieldType);
+ TIntermBinary *assignFirstNode =
+ new TIntermBinary(EOpAssign, indexFirstNode, valueParam->deepCopy());
useFirstBlock->getSequence()->push_back(assignFirstNode);
TIntermBranch *returnNode = new TIntermBranch(EOpReturn, nullptr);
useFirstBlock->getSequence()->push_back(returnNode);
- TIntermBinary *assignLastNode = CreateAssignValueSymbolNode(indexLastNode, fieldType);
+ TIntermBinary *assignLastNode =
+ new TIntermBinary(EOpAssign, indexLastNode, valueParam->deepCopy());
useLastBlock->getSequence()->push_back(assignLastNode);
}
else
@@ -332,11 +322,13 @@
TIntermSequence insertions;
for (auto &type : mIndexedVecAndMatrixTypes)
{
- insertions.push_back(GetIndexFunctionDefinition(type.first, false, *type.second));
+ insertions.push_back(
+ GetIndexFunctionDefinition(type.first, false, *type.second, mSymbolTable));
}
for (auto &type : mWrittenVecAndMatrixTypes)
{
- insertions.push_back(GetIndexFunctionDefinition(type.first, true, *type.second));
+ insertions.push_back(
+ GetIndexFunctionDefinition(type.first, true, *type.second, mSymbolTable));
}
mInsertions.push_back(NodeInsertMultipleEntry(rootBlock, 0, insertions, TIntermSequence()));
}