Commit bd674557 by Olli Etuaho Committed by Commit Bot

Separate function info from TIntermAggregate

This change will make it easier to split types of TIntermAggregate nodes representing functions and function calls into different node classes. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I730aa7858fe31fda86218fc685980c6ad486f5e0 Reviewed-on: https://chromium-review.googlesource.com/394706Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent bd3f8780
...@@ -103,7 +103,7 @@ class PullGradient : public TIntermTraverser ...@@ -103,7 +103,7 @@ class PullGradient : public TIntermTraverser
{ {
if (node->isUserDefined()) if (node->isUserDefined())
{ {
size_t calleeIndex = mDag.findIndex(node); size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex); ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
UNUSED_ASSERTION_VARIABLE(mIndex); UNUSED_ASSERTION_VARIABLE(mIndex);
...@@ -113,7 +113,8 @@ class PullGradient : public TIntermTraverser ...@@ -113,7 +113,8 @@ class PullGradient : public TIntermTraverser
} }
else else
{ {
TString name = TFunction::unmangleName(node->getName()); TString name =
TFunction::unmangleName(node->getFunctionSymbolInfo()->getName());
if (name == "texture2D" || if (name == "texture2D" ||
name == "texture2DProj" || name == "texture2DProj" ||
...@@ -275,7 +276,7 @@ class PullComputeDiscontinuousAndGradientLoops : public TIntermTraverser ...@@ -275,7 +276,7 @@ class PullComputeDiscontinuousAndGradientLoops : public TIntermTraverser
{ {
if (node->isUserDefined()) if (node->isUserDefined())
{ {
size_t calleeIndex = mDag.findIndex(node); size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex); ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
UNUSED_ASSERTION_VARIABLE(mIndex); UNUSED_ASSERTION_VARIABLE(mIndex);
...@@ -356,7 +357,7 @@ class PushDiscontinuousLoops : public TIntermTraverser ...@@ -356,7 +357,7 @@ class PushDiscontinuousLoops : public TIntermTraverser
case EOpFunctionCall: case EOpFunctionCall:
if (visit == PreVisit && node->isUserDefined() && mNestedDiscont > 0) if (visit == PreVisit && node->isUserDefined() && mNestedDiscont > 0)
{ {
size_t calleeIndex = mDag.findIndex(node); size_t calleeIndex = mDag.findIndex(node->getFunctionSymbolInfo());
ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex); ASSERT(calleeIndex != CallDAG::InvalidIndex && calleeIndex < mIndex);
UNUSED_ASSERTION_VARIABLE(mIndex); UNUSED_ASSERTION_VARIABLE(mIndex);
......
...@@ -41,8 +41,7 @@ TIntermAggregate *CreateReplacementCall(TIntermAggregate *originalCall, TIntermT ...@@ -41,8 +41,7 @@ TIntermAggregate *CreateReplacementCall(TIntermAggregate *originalCall, TIntermT
TIntermAggregate *replacementCall = new TIntermAggregate(EOpFunctionCall); TIntermAggregate *replacementCall = new TIntermAggregate(EOpFunctionCall);
replacementCall->setType(TType(EbtVoid)); replacementCall->setType(TType(EbtVoid));
replacementCall->setUserDefined(); replacementCall->setUserDefined();
replacementCall->setNameObj(originalCall->getNameObj()); *replacementCall->getFunctionSymbolInfo() = *originalCall->getFunctionSymbolInfo();
replacementCall->setFunctionId(originalCall->getFunctionId());
replacementCall->setLine(originalCall->getLine()); replacementCall->setLine(originalCall->getLine());
TIntermSequence *replacementParameters = replacementCall->getSequence(); TIntermSequence *replacementParameters = replacementCall->getSequence();
TIntermSequence *originalParameters = originalCall->getSequence(); TIntermSequence *originalParameters = originalCall->getSequence();
...@@ -118,8 +117,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitAggregate(Visit visit, TInter ...@@ -118,8 +117,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitAggregate(Visit visit, TInter
CopyAggregateChildren(node, replacement); CopyAggregateChildren(node, replacement);
replacement->getSequence()->push_back(CreateReturnValueOutSymbol(node->getType())); replacement->getSequence()->push_back(CreateReturnValueOutSymbol(node->getType()));
replacement->setUserDefined(); replacement->setUserDefined();
replacement->setNameObj(node->getNameObj()); *replacement->getFunctionSymbolInfo() = *node->getFunctionSymbolInfo();
replacement->setFunctionId(node->getFunctionId());
replacement->setLine(node->getLine()); replacement->setLine(node->getLine());
replacement->setType(TType(EbtVoid)); replacement->setType(TType(EbtVoid));
......
...@@ -76,7 +76,8 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -76,7 +76,8 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
record.callees.push_back(static_cast<int>(callee->index)); record.callees.push_back(static_cast<int>(callee->index));
} }
(*idToIndex)[data.node->getFunctionId()] = static_cast<int>(data.index); (*idToIndex)[data.node->getFunctionSymbolInfo()->getId()] =
static_cast<int>(data.index);
} }
} }
...@@ -109,8 +110,8 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -109,8 +110,8 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
if (visit == PreVisit) if (visit == PreVisit)
{ {
// Function declaration, create an empty record. // Function declaration, create an empty record.
auto& record = mFunctions[node->getName()]; auto &record = mFunctions[node->getFunctionSymbolInfo()->getName()];
record.name = node->getName(); record.name = node->getFunctionSymbolInfo()->getName();
} }
break; break;
case EOpFunction: case EOpFunction:
...@@ -118,11 +119,11 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -118,11 +119,11 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
// Function definition, create the record if need be and remember the node. // Function definition, create the record if need be and remember the node.
if (visit == PreVisit) if (visit == PreVisit)
{ {
auto it = mFunctions.find(node->getName()); auto it = mFunctions.find(node->getFunctionSymbolInfo()->getName());
if (it == mFunctions.end()) if (it == mFunctions.end())
{ {
mCurrentFunction = &mFunctions[node->getName()]; mCurrentFunction = &mFunctions[node->getFunctionSymbolInfo()->getName()];
} }
else else
{ {
...@@ -130,8 +131,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -130,8 +131,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
} }
mCurrentFunction->node = node; mCurrentFunction->node = node;
mCurrentFunction->name = node->getName(); mCurrentFunction->name = node->getFunctionSymbolInfo()->getName();
} }
else if (visit == PostVisit) else if (visit == PostVisit)
{ {
...@@ -147,7 +147,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser ...@@ -147,7 +147,7 @@ class CallDAG::CallDAGCreator : public TIntermTraverser
// Do not handle calls to builtin functions // Do not handle calls to builtin functions
if (node->isUserDefined()) if (node->isUserDefined())
{ {
auto it = mFunctions.find(node->getName()); auto it = mFunctions.find(node->getFunctionSymbolInfo()->getName());
ASSERT(it != mFunctions.end()); ASSERT(it != mFunctions.end());
// We might be in a top-level function call to set a global variable // We might be in a top-level function call to set a global variable
...@@ -283,13 +283,9 @@ CallDAG::~CallDAG() ...@@ -283,13 +283,9 @@ CallDAG::~CallDAG()
const size_t CallDAG::InvalidIndex = std::numeric_limits<size_t>::max(); const size_t CallDAG::InvalidIndex = std::numeric_limits<size_t>::max();
size_t CallDAG::findIndex(const TIntermAggregate *function) const size_t CallDAG::findIndex(const TFunctionSymbolInfo *functionInfo) const
{ {
TOperator op = function->getOp(); auto it = mFunctionIdToIndex.find(functionInfo->getId());
ASSERT(op == EOpPrototype || op == EOpFunction || op == EOpFunctionCall);
UNUSED_ASSERTION_VARIABLE(op);
auto it = mFunctionIdToIndex.find(function->getFunctionId());
if (it == mFunctionIdToIndex.end()) if (it == mFunctionIdToIndex.end())
{ {
...@@ -309,7 +305,7 @@ const CallDAG::Record &CallDAG::getRecordFromIndex(size_t index) const ...@@ -309,7 +305,7 @@ const CallDAG::Record &CallDAG::getRecordFromIndex(size_t index) const
const CallDAG::Record &CallDAG::getRecord(const TIntermAggregate *function) const const CallDAG::Record &CallDAG::getRecord(const TIntermAggregate *function) const
{ {
size_t index = findIndex(function); size_t index = findIndex(function->getFunctionSymbolInfo());
ASSERT(index != InvalidIndex && index < mRecords.size()); ASSERT(index != InvalidIndex && index < mRecords.size());
return mRecords[index]; return mRecords[index];
} }
......
...@@ -57,7 +57,7 @@ class CallDAG : angle::NonCopyable ...@@ -57,7 +57,7 @@ class CallDAG : angle::NonCopyable
InitResult init(TIntermNode *root, TInfoSinkBase *info); InitResult init(TIntermNode *root, TInfoSinkBase *info);
// Returns InvalidIndex if the function wasn't found // Returns InvalidIndex if the function wasn't found
size_t findIndex(const TIntermAggregate *function) const; size_t findIndex(const TFunctionSymbolInfo *functionInfo) const;
const Record &getRecordFromIndex(size_t index) const; const Record &getRecordFromIndex(size_t index) const;
const Record &getRecord(const TIntermAggregate *function) const; const Record &getRecord(const TIntermAggregate *function) const;
......
...@@ -769,7 +769,7 @@ class TCompiler::UnusedPredicate ...@@ -769,7 +769,7 @@ class TCompiler::UnusedPredicate
return false; return false;
} }
size_t callDagIndex = mCallDag->findIndex(asAggregate); size_t callDagIndex = mCallDag->findIndex(asAggregate->getFunctionSymbolInfo());
if (callDagIndex == CallDAG::InvalidIndex) if (callDagIndex == CallDAG::InvalidIndex)
{ {
// This happens only for unimplemented prototypes which are thus unused // This happens only for unimplemented prototypes which are thus unused
......
...@@ -18,23 +18,23 @@ ...@@ -18,23 +18,23 @@
namespace namespace
{ {
void SetInternalFunctionName(TIntermAggregate *functionNode, const char *name) void SetInternalFunctionName(TFunctionSymbolInfo *functionInfo, const char *name)
{ {
TString nameStr(name); TString nameStr(name);
nameStr = TFunction::mangleName(nameStr); nameStr = TFunction::mangleName(nameStr);
TName nameObj(nameStr); TName nameObj(nameStr);
nameObj.setInternal(true); nameObj.setInternal(true);
functionNode->setNameObj(nameObj); functionInfo->setNameObj(nameObj);
} }
TIntermAggregate *CreateFunctionPrototypeNode(const char *name, const int functionId) TIntermAggregate *CreateFunctionPrototypeNode(const char *name, const int functionId)
{ {
TIntermAggregate *functionNode = new TIntermAggregate(EOpPrototype); TIntermAggregate *functionNode = new TIntermAggregate(EOpPrototype);
SetInternalFunctionName(functionNode, name); SetInternalFunctionName(functionNode->getFunctionSymbolInfo(), name);
TType returnType(EbtVoid); TType returnType(EbtVoid);
functionNode->setType(returnType); functionNode->setType(returnType);
functionNode->setFunctionId(functionId); functionNode->getFunctionSymbolInfo()->setId(functionId);
return functionNode; return functionNode;
} }
...@@ -47,10 +47,10 @@ TIntermAggregate *CreateFunctionDefinitionNode(const char *name, ...@@ -47,10 +47,10 @@ TIntermAggregate *CreateFunctionDefinitionNode(const char *name,
functionNode->getSequence()->push_back(paramsNode); functionNode->getSequence()->push_back(paramsNode);
functionNode->getSequence()->push_back(functionBody); functionNode->getSequence()->push_back(functionBody);
SetInternalFunctionName(functionNode, name); SetInternalFunctionName(functionNode->getFunctionSymbolInfo(), name);
TType returnType(EbtVoid); TType returnType(EbtVoid);
functionNode->setType(returnType); functionNode->setType(returnType);
functionNode->setFunctionId(functionId); functionNode->getFunctionSymbolInfo()->setId(functionId);
return functionNode; return functionNode;
} }
...@@ -59,10 +59,10 @@ TIntermAggregate *CreateFunctionCallNode(const char *name, const int functionId) ...@@ -59,10 +59,10 @@ TIntermAggregate *CreateFunctionCallNode(const char *name, const int functionId)
TIntermAggregate *functionNode = new TIntermAggregate(EOpFunctionCall); TIntermAggregate *functionNode = new TIntermAggregate(EOpFunctionCall);
functionNode->setUserDefined(); functionNode->setUserDefined();
SetInternalFunctionName(functionNode, name); SetInternalFunctionName(functionNode->getFunctionSymbolInfo(), name);
TType returnType(EbtVoid); TType returnType(EbtVoid);
functionNode->setType(returnType); functionNode->setType(returnType);
functionNode->setFunctionId(functionId); functionNode->getFunctionSymbolInfo()->setId(functionId);
return functionNode; return functionNode;
} }
...@@ -165,7 +165,7 @@ void DeferGlobalInitializersTraverser::insertInitFunction(TIntermBlock *root) ...@@ -165,7 +165,7 @@ void DeferGlobalInitializersTraverser::insertInitFunction(TIntermBlock *root)
{ {
TIntermAggregate *nodeAgg = node->getAsAggregate(); TIntermAggregate *nodeAgg = node->getAsAggregate();
if (nodeAgg != nullptr && nodeAgg->getOp() == EOpFunction && if (nodeAgg != nullptr && nodeAgg->getOp() == EOpFunction &&
TFunction::unmangleName(nodeAgg->getName()) == "main") nodeAgg->getFunctionSymbolInfo()->isMain())
{ {
TIntermAggregate *functionCallNode = TIntermAggregate *functionCallNode =
CreateFunctionCallNode(functionName, initFunctionId); CreateFunctionCallNode(functionName, initFunctionId);
......
...@@ -81,7 +81,7 @@ bool GLFragColorBroadcastTraverser::visitAggregate(Visit visit, TIntermAggregate ...@@ -81,7 +81,7 @@ bool GLFragColorBroadcastTraverser::visitAggregate(Visit visit, TIntermAggregate
case EOpFunction: case EOpFunction:
// Function definition. // Function definition.
ASSERT(visit == PreVisit); ASSERT(visit == PreVisit);
if (node->getName() == "main(") if (node->getFunctionSymbolInfo()->isMain())
{ {
TIntermSequence *sequence = node->getSequence(); TIntermSequence *sequence = node->getSequence();
ASSERT(sequence->size() == 2); ASSERT(sequence->size() == 2);
......
...@@ -430,7 +430,7 @@ TIntermAggregate *createInternalFunctionCallNode(TString name, TIntermNode *chil ...@@ -430,7 +430,7 @@ TIntermAggregate *createInternalFunctionCallNode(TString name, TIntermNode *chil
callNode->setOp(EOpFunctionCall); callNode->setOp(EOpFunctionCall);
TName nameObj(TFunction::mangleName(name)); TName nameObj(TFunction::mangleName(name));
nameObj.setInternal(true); nameObj.setInternal(true);
callNode->setNameObj(nameObj); callNode->getFunctionSymbolInfo()->setNameObj(nameObj);
callNode->getSequence()->push_back(child); callNode->getSequence()->push_back(child);
return callNode; return callNode;
} }
......
...@@ -49,7 +49,7 @@ bool VariableInitializer::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -49,7 +49,7 @@ bool VariableInitializer::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
// Function definition. // Function definition.
ASSERT(visit == PreVisit); ASSERT(visit == PreVisit);
if (node->getName() == "main(") if (node->getFunctionSymbolInfo()->isMain())
{ {
TIntermSequence *sequence = node->getSequence(); TIntermSequence *sequence = node->getSequence();
ASSERT(sequence->size() == 2); ASSERT(sequence->size() == 2);
......
...@@ -305,7 +305,7 @@ void TIntermAggregate::setBuiltInFunctionPrecision() ...@@ -305,7 +305,7 @@ void TIntermAggregate::setBuiltInFunctionPrecision()
} }
// ESSL 3.0 spec section 8: textureSize always gets highp precision. // ESSL 3.0 spec section 8: textureSize always gets highp precision.
// All other functions that take a sampler are assumed to be texture functions. // All other functions that take a sampler are assumed to be texture functions.
if (mName.getString().find("textureSize") == 0) if (mFunctionInfo.getName().find("textureSize") == 0)
mType.setPrecision(EbpHigh); mType.setPrecision(EbpHigh);
else else
mType.setPrecision(precision); mType.setPrecision(precision);
...@@ -455,13 +455,18 @@ TIntermConstantUnion::TIntermConstantUnion(const TIntermConstantUnion &node) : T ...@@ -455,13 +455,18 @@ TIntermConstantUnion::TIntermConstantUnion(const TIntermConstantUnion &node) : T
mUnionArrayPointer = node.mUnionArrayPointer; mUnionArrayPointer = node.mUnionArrayPointer;
} }
void TFunctionSymbolInfo::setFromFunction(const TFunction &function)
{
setName(function.getMangledName());
setId(function.getUniqueId());
}
TIntermAggregate::TIntermAggregate(const TIntermAggregate &node) TIntermAggregate::TIntermAggregate(const TIntermAggregate &node)
: TIntermOperator(node), : TIntermOperator(node),
mName(node.mName),
mUserDefined(node.mUserDefined), mUserDefined(node.mUserDefined),
mFunctionId(node.mFunctionId),
mUseEmulatedFunction(node.mUseEmulatedFunction), mUseEmulatedFunction(node.mUseEmulatedFunction),
mGotPrecisionFromChildren(node.mGotPrecisionFromChildren) mGotPrecisionFromChildren(node.mGotPrecisionFromChildren),
mFunctionInfo(node.mFunctionInfo)
{ {
for (TIntermNode *child : node.mSequence) for (TIntermNode *child : node.mSequence)
{ {
......
...@@ -49,6 +49,7 @@ class TIntermRaw; ...@@ -49,6 +49,7 @@ class TIntermRaw;
class TIntermBranch; class TIntermBranch;
class TSymbolTable; class TSymbolTable;
class TFunction;
// Encapsulate an identifier string and track whether it is coming from the original shader code // Encapsulate an identifier string and track whether it is coming from the original shader code
// (not internal) or from ANGLE (internal). Usually internal names shouldn't be decorated or hashed. // (not internal) or from ANGLE (internal). Usually internal names shouldn't be decorated or hashed.
...@@ -524,6 +525,31 @@ class TIntermUnary : public TIntermOperator ...@@ -524,6 +525,31 @@ class TIntermUnary : public TIntermOperator
TIntermUnary(const TIntermUnary &node); // note: not deleted, just private! TIntermUnary(const TIntermUnary &node); // note: not deleted, just private!
}; };
class TFunctionSymbolInfo
{
public:
POOL_ALLOCATOR_NEW_DELETE();
TFunctionSymbolInfo() : mId(0) {}
TFunctionSymbolInfo(const TFunctionSymbolInfo &) = default;
TFunctionSymbolInfo &operator=(const TFunctionSymbolInfo &) = default;
void setFromFunction(const TFunction &function);
void setNameObj(const TName &name) { mName = name; }
const TName &getNameObj() const { return mName; }
const TString &getName() const { return mName.getString(); }
void setName(const TString &name) { mName.setString(name); }
bool isMain() const { return mName.getString() == "main("; }
void setId(int functionId) { mId = functionId; }
int getId() const { return mId; }
private:
TName mName;
int mId;
};
typedef TVector<TIntermNode *> TIntermSequence; typedef TVector<TIntermNode *> TIntermSequence;
typedef TVector<int> TQualifierList; typedef TVector<int> TQualifierList;
...@@ -554,7 +580,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -554,7 +580,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
TIntermAggregate() TIntermAggregate()
: TIntermOperator(EOpNull), : TIntermOperator(EOpNull),
mUserDefined(false), mUserDefined(false),
mFunctionId(0),
mUseEmulatedFunction(false), mUseEmulatedFunction(false),
mGotPrecisionFromChildren(false) mGotPrecisionFromChildren(false)
{ {
...@@ -562,7 +587,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -562,7 +587,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
TIntermAggregate(TOperator op) TIntermAggregate(TOperator op)
: TIntermOperator(op), : TIntermOperator(op),
mUserDefined(false), mUserDefined(false),
mFunctionId(0),
mUseEmulatedFunction(false), mUseEmulatedFunction(false),
mGotPrecisionFromChildren(false) mGotPrecisionFromChildren(false)
{ {
...@@ -585,18 +609,9 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -585,18 +609,9 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
TIntermSequence *getSequence() override { return &mSequence; } TIntermSequence *getSequence() override { return &mSequence; }
const TIntermSequence *getSequence() const override { return &mSequence; } const TIntermSequence *getSequence() const override { return &mSequence; }
void setNameObj(const TName &name) { mName = name; }
const TName &getNameObj() const { return mName; }
void setName(const TString &name) { mName.setString(name); }
const TString &getName() const { return mName.getString(); }
void setUserDefined() { mUserDefined = true; } void setUserDefined() { mUserDefined = true; }
bool isUserDefined() const { return mUserDefined; } bool isUserDefined() const { return mUserDefined; }
void setFunctionId(int functionId) { mFunctionId = functionId; }
int getFunctionId() const { return mFunctionId; }
void setUseEmulatedFunction() { mUseEmulatedFunction = true; } void setUseEmulatedFunction() { mUseEmulatedFunction = true; }
bool getUseEmulatedFunction() { return mUseEmulatedFunction; } bool getUseEmulatedFunction() { return mUseEmulatedFunction; }
...@@ -607,11 +622,12 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -607,11 +622,12 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
// Returns true if changing parameter precision may affect the return value. // Returns true if changing parameter precision may affect the return value.
bool gotPrecisionFromChildren() const { return mGotPrecisionFromChildren; } bool gotPrecisionFromChildren() const { return mGotPrecisionFromChildren; }
TFunctionSymbolInfo *getFunctionSymbolInfo() { return &mFunctionInfo; }
const TFunctionSymbolInfo *getFunctionSymbolInfo() const { return &mFunctionInfo; }
protected: protected:
TIntermSequence mSequence; TIntermSequence mSequence;
TName mName;
bool mUserDefined; // used for user defined function names bool mUserDefined; // used for user defined function names
int mFunctionId;
// If set to true, replace the built-in function call with an emulated one // If set to true, replace the built-in function call with an emulated one
// to work around driver bugs. // to work around driver bugs.
...@@ -619,6 +635,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -619,6 +635,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
bool mGotPrecisionFromChildren; bool mGotPrecisionFromChildren;
TFunctionSymbolInfo mFunctionInfo;
private: private:
TIntermAggregate(const TIntermAggregate &node); // note: not deleted, just private! TIntermAggregate(const TIntermAggregate &node); // note: not deleted, just private!
}; };
......
...@@ -199,13 +199,14 @@ void TLValueTrackingTraverser::addToFunctionMap(const TName &name, TIntermSequen ...@@ -199,13 +199,14 @@ void TLValueTrackingTraverser::addToFunctionMap(const TName &name, TIntermSequen
bool TLValueTrackingTraverser::isInFunctionMap(const TIntermAggregate *callNode) const bool TLValueTrackingTraverser::isInFunctionMap(const TIntermAggregate *callNode) const
{ {
ASSERT(callNode->getOp() == EOpFunctionCall); ASSERT(callNode->getOp() == EOpFunctionCall);
return (mFunctionMap.find(callNode->getNameObj()) != mFunctionMap.end()); return (mFunctionMap.find(callNode->getFunctionSymbolInfo()->getNameObj()) !=
mFunctionMap.end());
} }
TIntermSequence *TLValueTrackingTraverser::getFunctionParameters(const TIntermAggregate *callNode) TIntermSequence *TLValueTrackingTraverser::getFunctionParameters(const TIntermAggregate *callNode)
{ {
ASSERT(isInFunctionMap(callNode)); ASSERT(isInFunctionMap(callNode));
return mFunctionMap[callNode->getNameObj()]; return mFunctionMap[callNode->getFunctionSymbolInfo()->getNameObj()];
} }
void TLValueTrackingTraverser::setInFunctionCallOutParameter(bool inOutParameter) void TLValueTrackingTraverser::setInFunctionCallOutParameter(bool inOutParameter)
...@@ -507,11 +508,11 @@ void TLValueTrackingTraverser::traverseAggregate(TIntermAggregate *node) ...@@ -507,11 +508,11 @@ void TLValueTrackingTraverser::traverseAggregate(TIntermAggregate *node)
TIntermAggregate *params = sequence->front()->getAsAggregate(); TIntermAggregate *params = sequence->front()->getAsAggregate();
ASSERT(params != nullptr); ASSERT(params != nullptr);
ASSERT(params->getOp() == EOpParameters); ASSERT(params->getOp() == EOpParameters);
addToFunctionMap(node->getNameObj(), params->getSequence()); addToFunctionMap(node->getFunctionSymbolInfo()->getNameObj(), params->getSequence());
break; break;
} }
case EOpPrototype: case EOpPrototype:
addToFunctionMap(node->getNameObj(), sequence); addToFunctionMap(node->getFunctionSymbolInfo()->getNameObj(), sequence);
break; break;
default: default:
break; break;
......
...@@ -803,7 +803,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -803,7 +803,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
out << arrayBrackets(type); out << arrayBrackets(type);
} }
out << " " << hashFunctionNameIfNeeded(node->getNameObj()); out << " " << hashFunctionNameIfNeeded(node->getFunctionSymbolInfo()->getNameObj());
out << "("; out << "(";
writeFunctionParameters(*(node->getSequence())); writeFunctionParameters(*(node->getSequence()));
...@@ -821,7 +821,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -821,7 +821,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
out << arrayBrackets(type); out << arrayBrackets(type);
} }
out << " " << hashFunctionNameIfNeeded(node->getNameObj()); out << " " << hashFunctionNameIfNeeded(node->getFunctionSymbolInfo()->getNameObj());
incrementDepth(node); incrementDepth(node);
// Function definition node contains two child nodes representing the function parameters // Function definition node contains two child nodes representing the function parameters
...@@ -847,7 +847,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -847,7 +847,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpFunctionCall: case EOpFunctionCall:
// Function call. // Function call.
if (visit == PreVisit) if (visit == PreVisit)
out << hashFunctionNameIfNeeded(node->getNameObj()) << "("; out << hashFunctionNameIfNeeded(node->getFunctionSymbolInfo()->getNameObj()) << "(";
else if (visit == InVisit) else if (visit == InVisit)
out << ", "; out << ", ";
else else
......
...@@ -1533,7 +1533,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1533,7 +1533,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpPrototype: case EOpPrototype:
if (visit == PreVisit) if (visit == PreVisit)
{ {
size_t index = mCallDag.findIndex(node); size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
// Skip the prototype if it is not implemented (and thus not used) // Skip the prototype if it is not implemented (and thus not used)
if (index == CallDAG::InvalidIndex) if (index == CallDAG::InvalidIndex)
{ {
...@@ -1542,7 +1542,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1542,7 +1542,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermSequence *arguments = node->getSequence(); TIntermSequence *arguments = node->getSequence();
TString name = DecorateFunctionIfNeeded(node->getNameObj()); TString name =
DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj());
out << TypeString(node->getType()) << " " << name out << TypeString(node->getType()) << " " << name
<< DisambiguateFunctionName(arguments) << (mOutputLod0Function ? "Lod0(" : "("); << DisambiguateFunctionName(arguments) << (mOutputLod0Function ? "Lod0(" : "(");
...@@ -1583,9 +1584,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1583,9 +1584,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpFunction: case EOpFunction:
{ {
ASSERT(mCurrentFunctionMetadata == nullptr); ASSERT(mCurrentFunctionMetadata == nullptr);
TString name = TFunction::unmangleName(node->getNameObj().getString());
size_t index = mCallDag.findIndex(node); size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
ASSERT(index != CallDAG::InvalidIndex); ASSERT(index != CallDAG::InvalidIndex);
mCurrentFunctionMetadata = &mASTMetadataList[index]; mCurrentFunctionMetadata = &mASTMetadataList[index];
...@@ -1594,13 +1594,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1594,13 +1594,13 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermSequence *sequence = node->getSequence(); TIntermSequence *sequence = node->getSequence();
TIntermSequence *arguments = (*sequence)[0]->getAsAggregate()->getSequence(); TIntermSequence *arguments = (*sequence)[0]->getAsAggregate()->getSequence();
if (name == "main") if (node->getFunctionSymbolInfo()->isMain())
{ {
out << "gl_main("; out << "gl_main(";
} }
else else
{ {
out << DecorateFunctionIfNeeded(node->getNameObj()) out << DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj())
<< DisambiguateFunctionName(arguments) << (mOutputLod0Function ? "Lod0(" : "("); << DisambiguateFunctionName(arguments) << (mOutputLod0Function ? "Lod0(" : "(");
} }
...@@ -1637,7 +1637,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1637,7 +1637,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
bool needsLod0 = mASTMetadataList[index].mNeedsLod0; bool needsLod0 = mASTMetadataList[index].mNeedsLod0;
if (needsLod0 && !mOutputLod0Function && mShaderType == GL_FRAGMENT_SHADER) if (needsLod0 && !mOutputLod0Function && mShaderType == GL_FRAGMENT_SHADER)
{ {
ASSERT(name != "main"); ASSERT(!node->getFunctionSymbolInfo()->isMain());
mOutputLod0Function = true; mOutputLod0Function = true;
node->traverse(this); node->traverse(this);
mOutputLod0Function = false; mOutputLod0Function = false;
...@@ -1656,23 +1656,23 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1656,23 +1656,23 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
size_t index = mCallDag.findIndex(node); size_t index = mCallDag.findIndex(node->getFunctionSymbolInfo());
ASSERT(index != CallDAG::InvalidIndex); ASSERT(index != CallDAG::InvalidIndex);
lod0 &= mASTMetadataList[index].mNeedsLod0; lod0 &= mASTMetadataList[index].mNeedsLod0;
out << DecorateFunctionIfNeeded(node->getNameObj()); out << DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj());
out << DisambiguateFunctionName(node->getSequence()); out << DisambiguateFunctionName(node->getSequence());
out << (lod0 ? "Lod0(" : "("); out << (lod0 ? "Lod0(" : "(");
} }
else if (node->getNameObj().isInternal()) else if (node->getFunctionSymbolInfo()->getNameObj().isInternal())
{ {
// This path is used for internal functions that don't have their definitions in the // This path is used for internal functions that don't have their definitions in the
// AST, such as precision emulation functions. // AST, such as precision emulation functions.
out << DecorateFunctionIfNeeded(node->getNameObj()) << "("; out << DecorateFunctionIfNeeded(node->getFunctionSymbolInfo()->getNameObj()) << "(";
} }
else else
{ {
TString name = TFunction::unmangleName(node->getNameObj().getString()); TString name = TFunction::unmangleName(node->getFunctionSymbolInfo()->getName());
TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType(); TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType();
int coords = (*arguments)[1]->getAsTyped()->getNominalSize(); int coords = (*arguments)[1]->getAsTyped()->getNominalSize();
TString textureFunctionName = mTextureFunctionHLSL->useTextureFunction( TString textureFunctionName = mTextureFunctionHLSL->useTextureFunction(
......
...@@ -2026,8 +2026,7 @@ TIntermAggregate *TParseContext::addFunctionPrototypeDeclaration(const TFunction ...@@ -2026,8 +2026,7 @@ TIntermAggregate *TParseContext::addFunctionPrototypeDeclaration(const TFunction
// TODO(oetuaho@nvidia.com): Instead of converting the function information here, the node could // TODO(oetuaho@nvidia.com): Instead of converting the function information here, the node could
// point to the data that already exists in the symbol table. // point to the data that already exists in the symbol table.
prototype->setType(function->getReturnType()); prototype->setType(function->getReturnType());
prototype->setName(function->getMangledName()); prototype->getFunctionSymbolInfo()->setFromFunction(*function);
prototype->setFunctionId(function->getUniqueId());
for (size_t i = 0; i < function->getParamCount(); i++) for (size_t i = 0; i < function->getParamCount(); i++)
{ {
...@@ -2084,9 +2083,8 @@ TIntermAggregate *TParseContext::addFunctionDefinition(const TFunction &function ...@@ -2084,9 +2083,8 @@ TIntermAggregate *TParseContext::addFunctionDefinition(const TFunction &function
} }
functionNode->getSequence()->push_back(functionBody); functionNode->getSequence()->push_back(functionBody);
functionNode->setName(function.getMangledName().c_str()); functionNode->getFunctionSymbolInfo()->setFromFunction(function);
functionNode->setType(function.getReturnType()); functionNode->setType(function.getReturnType());
functionNode->setFunctionId(function.getUniqueId());
symbolTable.pop(); symbolTable.pop();
return functionNode; return functionNode;
...@@ -3688,7 +3686,7 @@ TIntermBranch *TParseContext::addBranch(TOperator op, ...@@ -3688,7 +3686,7 @@ TIntermBranch *TParseContext::addBranch(TOperator op,
void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall) void TParseContext::checkTextureOffsetConst(TIntermAggregate *functionCall)
{ {
ASSERT(!functionCall->isUserDefined()); ASSERT(!functionCall->isUserDefined());
const TString &name = functionCall->getName(); const TString &name = functionCall->getFunctionSymbolInfo()->getName();
TIntermNode *offset = nullptr; TIntermNode *offset = nullptr;
TIntermSequence *arguments = functionCall->getSequence(); TIntermSequence *arguments = functionCall->getSequence();
if (name.compare(0, 16, "texelFetchOffset") == 0 || if (name.compare(0, 16, "texelFetchOffset") == 0 ||
...@@ -3877,10 +3875,9 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, ...@@ -3877,10 +3875,9 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall,
// if builtIn == true, it's definitely a builtIn function with EOpNull // if builtIn == true, it's definitely a builtIn function with EOpNull
if (!builtIn) if (!builtIn)
aggregate->setUserDefined(); aggregate->setUserDefined();
aggregate->setName(fnCandidate->getMangledName()); aggregate->getFunctionSymbolInfo()->setFromFunction(*fnCandidate);
aggregate->setFunctionId(fnCandidate->getUniqueId());
// This needs to happen after the name is set // This needs to happen after the function info including name is set
if (builtIn) if (builtIn)
{ {
aggregate->setBuiltInFunctionPrecision(); aggregate->setBuiltInFunctionPrecision();
......
...@@ -181,7 +181,7 @@ TIntermAggregate *GetIndexFunctionDefinition(TType type, bool write) ...@@ -181,7 +181,7 @@ TIntermAggregate *GetIndexFunctionDefinition(TType type, bool write)
// principle this code could be used with multiple backends. // principle this code could be used with multiple backends.
type.setPrecision(EbpHigh); type.setPrecision(EbpHigh);
TIntermAggregate *indexingFunction = new TIntermAggregate(EOpFunction); TIntermAggregate *indexingFunction = new TIntermAggregate(EOpFunction);
indexingFunction->setNameObj(GetIndexFunctionName(type, write)); indexingFunction->getFunctionSymbolInfo()->setNameObj(GetIndexFunctionName(type, write));
TType fieldType = GetFieldType(type); TType fieldType = GetFieldType(type);
int numCases = 0; int numCases = 0;
...@@ -350,7 +350,8 @@ TIntermAggregate *CreateIndexFunctionCall(TIntermBinary *node, ...@@ -350,7 +350,8 @@ TIntermAggregate *CreateIndexFunctionCall(TIntermBinary *node,
TIntermAggregate *indexingCall = new TIntermAggregate(EOpFunctionCall); TIntermAggregate *indexingCall = new TIntermAggregate(EOpFunctionCall);
indexingCall->setLine(node->getLine()); indexingCall->setLine(node->getLine());
indexingCall->setUserDefined(); indexingCall->setUserDefined();
indexingCall->setNameObj(GetIndexFunctionName(indexedNode->getType(), false)); indexingCall->getFunctionSymbolInfo()->setNameObj(
GetIndexFunctionName(indexedNode->getType(), false));
indexingCall->getSequence()->push_back(indexedNode); indexingCall->getSequence()->push_back(indexedNode);
indexingCall->getSequence()->push_back(index); indexingCall->getSequence()->push_back(index);
...@@ -368,7 +369,8 @@ TIntermAggregate *CreateIndexedWriteFunctionCall(TIntermBinary *node, ...@@ -368,7 +369,8 @@ TIntermAggregate *CreateIndexedWriteFunctionCall(TIntermBinary *node,
ASSERT(leftCopy != nullptr && leftCopy->getAsTyped() != nullptr); ASSERT(leftCopy != nullptr && leftCopy->getAsTyped() != nullptr);
TIntermAggregate *indexedWriteCall = TIntermAggregate *indexedWriteCall =
CreateIndexFunctionCall(node, leftCopy->getAsTyped(), index); CreateIndexFunctionCall(node, leftCopy->getAsTyped(), index);
indexedWriteCall->setNameObj(GetIndexFunctionName(node->getLeft()->getType(), true)); indexedWriteCall->getFunctionSymbolInfo()->setNameObj(
GetIndexFunctionName(node->getLeft()->getType(), true));
indexedWriteCall->setType(TType(EbtVoid)); indexedWriteCall->setType(TType(EbtVoid));
indexedWriteCall->getSequence()->push_back(writtenValue); indexedWriteCall->getSequence()->push_back(writtenValue);
return indexedWriteCall; return indexedWriteCall;
......
...@@ -75,7 +75,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -75,7 +75,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
return true; return true;
} }
if (node->getName().compare(0, 16, "texelFetchOffset") != 0) if (node->getFunctionSymbolInfo()->getName().compare(0, 16, "texelFetchOffset") != 0)
{ {
return true; return true;
} }
...@@ -85,11 +85,12 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -85,11 +85,12 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
ASSERT(sequence->size() == 4u); ASSERT(sequence->size() == 4u);
// Decide if there is a 2DArray sampler. // Decide if there is a 2DArray sampler.
bool is2DArray = node->getName().find("s2a1") != TString::npos; bool is2DArray = node->getFunctionSymbolInfo()->getName().find("s2a1") != TString::npos;
// Create new argument list from node->getName(). // Create new argument list from node->getName().
// e.g. Get "(is2a1;vi3;i1;" from "texelFetchOffset(is2a1;vi3;i1;vi2;" // e.g. Get "(is2a1;vi3;i1;" from "texelFetchOffset(is2a1;vi3;i1;vi2;"
TString newArgs = node->getName().substr(16, node->getName().length() - 20); TString newArgs = node->getFunctionSymbolInfo()->getName().substr(
16, node->getFunctionSymbolInfo()->getName().length() - 20);
TString newName = "texelFetch" + newArgs; TString newName = "texelFetch" + newArgs;
TSymbol *texelFetchSymbol = symbolTable->findBuiltIn(newName, shaderVersion); TSymbol *texelFetchSymbol = symbolTable->findBuiltIn(newName, shaderVersion);
ASSERT(texelFetchSymbol); ASSERT(texelFetchSymbol);
...@@ -98,8 +99,8 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -98,8 +99,8 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
// Create new node that represents the call of function texelFetch. // Create new node that represents the call of function texelFetch.
// Its argument list will be: texelFetch(sampler, Position+offset, lod). // Its argument list will be: texelFetch(sampler, Position+offset, lod).
TIntermAggregate *texelFetchNode = new TIntermAggregate(EOpFunctionCall); TIntermAggregate *texelFetchNode = new TIntermAggregate(EOpFunctionCall);
texelFetchNode->setName(newName); texelFetchNode->getFunctionSymbolInfo()->setName(newName);
texelFetchNode->setFunctionId(uniqueId); texelFetchNode->getFunctionSymbolInfo()->setId(uniqueId);
texelFetchNode->setType(node->getType()); texelFetchNode->setType(node->getType());
texelFetchNode->setLine(node->getLine()); texelFetchNode->setLine(node->getLine());
......
...@@ -59,12 +59,11 @@ TIntermAggregate *CopyAggregateNode(TIntermAggregate *node) ...@@ -59,12 +59,11 @@ TIntermAggregate *CopyAggregateNode(TIntermAggregate *node)
TIntermSequence *copySeq = copyNode->getSequence(); TIntermSequence *copySeq = copyNode->getSequence();
copySeq->insert(copySeq->begin(), node->getSequence()->begin(), node->getSequence()->end()); copySeq->insert(copySeq->begin(), node->getSequence()->begin(), node->getSequence()->end());
copyNode->setType(node->getType()); copyNode->setType(node->getType());
copyNode->setFunctionId(node->getFunctionId()); *copyNode->getFunctionSymbolInfo() = *node->getFunctionSymbolInfo();
if (node->isUserDefined()) if (node->isUserDefined())
{ {
copyNode->setUserDefined(); copyNode->setUserDefined();
} }
copyNode->setNameObj(node->getNameObj());
return copyNode; return copyNode;
} }
......
...@@ -423,7 +423,8 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node) ...@@ -423,7 +423,8 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate *node)
bool valid = true; bool valid = true;
TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable; TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable;
TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->getShaderVersion()); TSymbol *symbol = symbolTable.find(node->getFunctionSymbolInfo()->getName(),
GetGlobalParseContext()->getShaderVersion());
ASSERT(symbol && symbol->isFunction()); ASSERT(symbol && symbol->isFunction());
TFunction *function = static_cast<TFunction *>(symbol); TFunction *function = static_cast<TFunction *>(symbol);
for (ParamIndex::const_iterator i = pIndex.begin(); for (ParamIndex::const_iterator i = pIndex.begin();
......
...@@ -12,8 +12,9 @@ namespace ...@@ -12,8 +12,9 @@ namespace
void OutputFunction(TInfoSinkBase &out, const char *str, TIntermAggregate *node) void OutputFunction(TInfoSinkBase &out, const char *str, TIntermAggregate *node)
{ {
const char *internal = node->getNameObj().isInternal() ? " (internal function)" : ""; const char *internal =
out << str << internal << ": " << node->getNameObj().getString(); node->getFunctionSymbolInfo()->getNameObj().isInternal() ? " (internal function)" : "";
out << str << internal << ": " << node->getFunctionSymbolInfo()->getNameObj().getString();
} }
// //
......
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