Commit f2209f74 by Olli Etuaho Committed by Commit Bot

Clean up function name mangling code

Fix a few incorrect comments about mangled names, and refactor generating mangled names from function call nodes. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I3ee68c4c0982f1a9c28d8e87aafa19f19559bbf8 Reviewed-on: https://chromium-review.googlesource.com/465826Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent dd43e6cd
...@@ -26,7 +26,7 @@ namespace sh ...@@ -26,7 +26,7 @@ namespace sh
// can be reused by multiple analyses. // can be reused by multiple analyses.
// //
// It stores a vector of function records, with one record per function. // It stores a vector of function records, with one record per function.
// Records are accessed by index but a mangled function name can be converted // Records are accessed by index but a function symbol id can be converted
// to the index of the corresponding record. The records mostly contain the // to the index of the corresponding record. The records mostly contain the
// AST node of the function and the indices of the function's callees. // AST node of the function and the indices of the function's callees.
// //
......
...@@ -690,9 +690,9 @@ void InsertBuiltInFunctions(sh::GLenum type, ...@@ -690,9 +690,9 @@ void InsertBuiltInFunctions(sh::GLenum type,
symbolTable.insert(COMMON_BUILTINS, depthRangeParameters); symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
depthRange->setQualifier(EvqUniform); depthRange->setQualifier(EvqUniform);
// Ensure we evaluate the mangled name for depth range, so we allocate to the current scope. // Do lazy initialization for depth range, so we allocate to the current scope.
depthRangeParameters->getType().getMangledName(); depthRangeParameters->getType().realize();
depthRange->getType().getMangledName(); depthRange->getType().realize();
symbolTable.insert(COMMON_BUILTINS, depthRange); symbolTable.insert(COMMON_BUILTINS, depthRange);
// //
......
...@@ -450,6 +450,21 @@ void TIntermAggregate::setBuiltInFunctionPrecision() ...@@ -450,6 +450,21 @@ void TIntermAggregate::setBuiltInFunctionPrecision()
mType.setPrecision(precision); mType.setPrecision(precision);
} }
TString TIntermAggregate::getSymbolTableMangledName() const
{
ASSERT(!isConstructor());
switch (mOp)
{
case EOpCallInternalRawFunction:
case EOpCallBuiltInFunction:
case EOpCallFunctionInAST:
return TFunction::GetMangledNameFromCall(mFunctionInfo.getName(), mArguments);
default:
TString opString = GetOperatorString(mOp);
return TFunction::GetMangledNameFromCall(opString, mArguments);
}
}
void TIntermBlock::appendStatement(TIntermNode *statement) void TIntermBlock::appendStatement(TIntermNode *statement)
{ {
// Declaration nodes with no children can appear if all the declarators just added constants to // Declaration nodes with no children can appear if all the declarators just added constants to
......
...@@ -544,7 +544,6 @@ class TFunctionSymbolInfo ...@@ -544,7 +544,6 @@ class TFunctionSymbolInfo
void setFromFunction(const TFunction &function); void setFromFunction(const TFunction &function);
// The name stored here should always be mangled.
void setNameObj(const TName &name) { mName = name; } void setNameObj(const TName &name) { mName = name; }
const TName &getNameObj() const { return mName; } const TName &getNameObj() const { return mName; }
...@@ -629,6 +628,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -629,6 +628,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
TIntermSequence *getSequence() override { return &mArguments; } TIntermSequence *getSequence() override { return &mArguments; }
const TIntermSequence *getSequence() const override { return &mArguments; } const TIntermSequence *getSequence() const override { return &mArguments; }
TString getSymbolTableMangledName() const;
void setUseEmulatedFunction() { mUseEmulatedFunction = true; } void setUseEmulatedFunction() { mUseEmulatedFunction = true; }
bool getUseEmulatedFunction() { return mUseEmulatedFunction; } bool getUseEmulatedFunction() { return mUseEmulatedFunction; }
......
...@@ -690,7 +690,8 @@ void TLValueTrackingTraverser::traverseAggregate(TIntermAggregate *node) ...@@ -690,7 +690,8 @@ void TLValueTrackingTraverser::traverseAggregate(TIntermAggregate *node)
TFunction *builtInFunc = nullptr; TFunction *builtInFunc = nullptr;
if (!node->isFunctionCall() && !node->isConstructor()) if (!node->isFunctionCall() && !node->isConstructor())
{ {
builtInFunc = mSymbolTable.findBuiltInOp(node, mShaderVersion); builtInFunc = static_cast<TFunction *>(
mSymbolTable.findBuiltIn(node->getSymbolTableMangledName(), mShaderVersion));
} }
size_t paramIndex = 0; size_t paramIndex = 0;
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
namespace sh namespace sh
{ {
namespace
{
static const char kFunctionMangledNameSeparator = '(';
} // anonymous namespace
int TSymbolTable::uniqueIdCounter = 0; int TSymbolTable::uniqueIdCounter = 0;
TSymbolUniqueId::TSymbolUniqueId() : mId(TSymbolTable::nextUniqueId()) TSymbolUniqueId::TSymbolUniqueId() : mId(TSymbolTable::nextUniqueId())
...@@ -70,20 +77,22 @@ void TFunction::swapParameters(const TFunction &parametersSource) ...@@ -70,20 +77,22 @@ void TFunction::swapParameters(const TFunction &parametersSource)
const TString *TFunction::buildMangledName() const const TString *TFunction::buildMangledName() const
{ {
std::string newName = mangleName(getName()).c_str(); std::string newName = getName().c_str();
newName += kFunctionMangledNameSeparator;
for (const auto &p : parameters) for (const auto &p : parameters)
{ {
newName += p.type->getMangledName().c_str(); newName += p.type->getMangledName().c_str();
} }
return NewPoolTString(newName.c_str()); return NewPoolTString(newName.c_str());
} }
const TString &TFunction::GetMangledNameFromCall(const TString &unmangledFunctionName, const TString &TFunction::GetMangledNameFromCall(const TString &functionName,
TIntermSequence &arguments) const TIntermSequence &arguments)
{ {
std::string newName = mangleName(unmangledFunctionName).c_str(); std::string newName = functionName.c_str();
newName += kFunctionMangledNameSeparator;
for (TIntermNode *argument : arguments) for (TIntermNode *argument : arguments)
{ {
newName += argument->getAsTyped()->getType().getMangledName().c_str(); newName += argument->getAsTyped()->getType().getMangledName().c_str();
...@@ -179,20 +188,6 @@ TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion) const ...@@ -179,20 +188,6 @@ TSymbol *TSymbolTable::findBuiltIn(const TString &name, int shaderVersion) const
return 0; return 0;
} }
TFunction *TSymbolTable::findBuiltInOp(TIntermAggregate *callNode, int shaderVersion) const
{
ASSERT(!callNode->isConstructor());
ASSERT(!callNode->isFunctionCall());
TString opString = GetOperatorString(callNode->getOp());
TSymbol *sym = findBuiltIn(
TFunction::GetMangledNameFromCall(opString, *callNode->getSequence()), shaderVersion);
ASSERT(sym != nullptr && sym->isFunction());
TFunction *builtInFunc = static_cast<TFunction *>(sym);
ASSERT(builtInFunc->getParamCount() == callNode->getSequence()->size());
return builtInFunc;
}
TSymbolTable::~TSymbolTable() TSymbolTable::~TSymbolTable()
{ {
while (table.size() > 0) while (table.size() > 0)
......
...@@ -174,8 +174,6 @@ class TFunction : public TSymbol ...@@ -174,8 +174,6 @@ class TFunction : public TSymbol
~TFunction() override; ~TFunction() override;
bool isFunction() const override { return true; } bool isFunction() const override { return true; }
static TString mangleName(const TString &name) { return name + '('; }
void addParameter(const TConstParameter &p) void addParameter(const TConstParameter &p)
{ {
parameters.push_back(p); parameters.push_back(p);
...@@ -193,8 +191,8 @@ class TFunction : public TSymbol ...@@ -193,8 +191,8 @@ class TFunction : public TSymbol
return *mangledName; return *mangledName;
} }
static const TString &GetMangledNameFromCall(const TString &unmangledFunctionName, static const TString &GetMangledNameFromCall(const TString &functionName,
TIntermSequence &arguments); const TIntermSequence &arguments);
const TType &getReturnType() const { return *returnType; } const TType &getReturnType() const { return *returnType; }
...@@ -440,10 +438,6 @@ class TSymbolTable : angle::NonCopyable ...@@ -440,10 +438,6 @@ class TSymbolTable : angle::NonCopyable
TSymbol *findBuiltIn(const TString &name, int shaderVersion) const; TSymbol *findBuiltIn(const TString &name, int shaderVersion) const;
// Helper front-end for regular findBuiltIn that constructs the mangled function name from
// callNode.
TFunction *findBuiltInOp(TIntermAggregate *callNode, int shaderVersion) const;
TSymbolTableLevel *getOuterLevel() TSymbolTableLevel *getOuterLevel()
{ {
assert(currentLevel() >= 1); assert(currentLevel() >= 1);
......
...@@ -375,7 +375,8 @@ bool ValidateMultiviewTraverser::visitAggregate(Visit visit, TIntermAggregate *n ...@@ -375,7 +375,8 @@ bool ValidateMultiviewTraverser::visitAggregate(Visit visit, TIntermAggregate *n
} }
else if (!node->isConstructor()) else if (!node->isConstructor())
{ {
TFunction *builtInFunc = mSymbolTable.findBuiltInOp(node, mShaderVersion); TFunction *builtInFunc = static_cast<TFunction *>(
mSymbolTable.findBuiltIn(node->getSymbolTableMangledName(), mShaderVersion));
for (size_t paramIndex = 0u; paramIndex < builtInFunc->getParamCount(); ++paramIndex) for (size_t paramIndex = 0u; paramIndex < builtInFunc->getParamCount(); ++paramIndex)
{ {
TQualifier qualifier = builtInFunc->getParam(paramIndex).type->getQualifier(); TQualifier qualifier = builtInFunc->getParam(paramIndex).type->getQualifier();
......
...@@ -29,9 +29,7 @@ class FunctionCallFinder : public TIntermTraverser ...@@ -29,9 +29,7 @@ class FunctionCallFinder : public TIntermTraverser
bool visitAggregate(Visit visit, TIntermAggregate *node) override bool visitAggregate(Visit visit, TIntermAggregate *node) override
{ {
if (node->isFunctionCall() && if (node->isFunctionCall() && node->getSymbolTableMangledName() == mFunctionMangledName)
TFunction::GetMangledNameFromCall(node->getFunctionSymbolInfo()->getName(),
*node->getSequence()) == mFunctionMangledName)
{ {
mNodeFound = node; mNodeFound = node;
return false; return false;
......
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