Commit 697bf65c by Olli Etuaho Committed by Commit Bot

Avoid redundant symbol lookup when parsing functions

The lexical phase looks up symbols when it encounters an identifier. Instead of duplicating this work when parsing non-constructor functions, we now store the symbol looked up in the lexical phase in TFunctionLookup. This improves scores of the real world shader compiler perf test by 1-2%. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Idc99776571313d8b654910f9daaf9bf34a048228 Reviewed-on: https://chromium-review.googlesource.com/923725 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 9fdaa497
......@@ -21,8 +21,10 @@ constexpr const ImmutableString kEmptyName("");
} // anonymous namespace
TFunctionLookup::TFunctionLookup(const ImmutableString &name, const TType *constructorType)
: mName(name), mConstructorType(constructorType), mThisNode(nullptr)
TFunctionLookup::TFunctionLookup(const ImmutableString &name,
const TType *constructorType,
const TSymbol *symbol)
: mName(name), mConstructorType(constructorType), mThisNode(nullptr), mSymbol(symbol)
{
}
......@@ -30,14 +32,15 @@ TFunctionLookup::TFunctionLookup(const ImmutableString &name, const TType *const
TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type)
{
ASSERT(type != nullptr);
return new TFunctionLookup(kEmptyName, type);
return new TFunctionLookup(kEmptyName, type, nullptr);
}
// static
TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name)
TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name,
const TSymbol *symbol)
{
ASSERT(name != "");
return new TFunctionLookup(name, nullptr);
return new TFunctionLookup(name, nullptr, symbol);
}
const ImmutableString &TFunctionLookup::name() const
......@@ -93,4 +96,9 @@ TIntermSequence &TFunctionLookup::arguments()
return mArguments;
}
const TSymbol *TFunctionLookup::symbol() const
{
return mSymbol;
}
} // namespace sh
......@@ -22,7 +22,7 @@ class TFunctionLookup : angle::NonCopyable
POOL_ALLOCATOR_NEW_DELETE();
static TFunctionLookup *CreateConstructor(const TType *type);
static TFunctionLookup *CreateFunctionCall(const ImmutableString &name);
static TFunctionLookup *CreateFunctionCall(const ImmutableString &name, const TSymbol *symbol);
const ImmutableString &name() const;
ImmutableString getMangledName() const;
......@@ -38,13 +38,20 @@ class TFunctionLookup : angle::NonCopyable
void addArgument(TIntermTyped *argument);
TIntermSequence &arguments();
// Symbol looked up in the lexical phase using only the name of the function.
// This does not necessarily correspond to the correct overloaded function.
const TSymbol *symbol() const;
private:
TFunctionLookup(const ImmutableString &name, const TType *constructorType);
TFunctionLookup(const ImmutableString &name,
const TType *constructorType,
const TSymbol *symbol);
const ImmutableString mName;
const TType *const mConstructorType;
TIntermTyped *mThisNode;
TIntermSequence mArguments;
const TSymbol *mSymbol;
};
} // namespace sh
......
......@@ -3432,9 +3432,10 @@ TFunction *TParseContext::parseFunctionHeader(const TPublicType &type,
return new TFunction(&symbolTable, name, new TType(type), SymbolType::UserDefined, false);
}
TFunctionLookup *TParseContext::addNonConstructorFunc(const ImmutableString &name)
TFunctionLookup *TParseContext::addNonConstructorFunc(const ImmutableString &name,
const TSymbol *symbol)
{
return TFunctionLookup::CreateFunctionCall(name);
return TFunctionLookup::CreateFunctionCall(name, symbol);
}
TFunctionLookup *TParseContext::addConstructorFunc(const TPublicType &publicType)
......@@ -5798,11 +5799,10 @@ TIntermTyped *TParseContext::addMethod(TFunctionLookup *fnCall, const TSourceLoc
TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunctionLookup *fnCall,
const TSourceLoc &loc)
{
// First find by unmangled name to check whether the function name has been
// hidden by a variable name or struct typename.
// If a function is found, check for one with a matching argument list.
const TSymbol *symbol = symbolTable.find(fnCall->name(), mShaderVersion);
if (symbol != nullptr && !symbol->isFunction())
// First check whether the function has been hidden by a variable name or struct typename by
// using the symbol looked up in the lexical phase. If the function is not hidden, look for one
// with a matching argument list.
if (fnCall->symbol() != nullptr && !fnCall->symbol()->isFunction())
{
error(loc, "function name expected", fnCall->name());
}
......@@ -5810,7 +5810,7 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunctionLookup *fnCa
{
// There are no inner functions, so it's enough to look for user-defined functions in the
// global scope.
symbol = symbolTable.findGlobal(fnCall->getMangledName());
const TSymbol *symbol = symbolTable.findGlobal(fnCall->getMangledName());
if (symbol != nullptr)
{
// A user-defined function - could be an overloaded built-in as well.
......
......@@ -296,7 +296,7 @@ class TParseContext : angle::NonCopyable
const ImmutableString &name,
const TSourceLoc &location);
TFunctionLookup *addNonConstructorFunc(const ImmutableString &name);
TFunctionLookup *addNonConstructorFunc(const ImmutableString &name, const TSymbol *symbol);
TFunctionLookup *addConstructorFunc(const TPublicType &publicType);
TParameter parseParameterDeclarator(const TPublicType &publicType,
......
......@@ -384,10 +384,10 @@ function_identifier
$$ = context->addConstructorFunc($1);
}
| IDENTIFIER {
$$ = context->addNonConstructorFunc(ImmutableString($1.string));
$$ = context->addNonConstructorFunc(ImmutableString($1.string), $1.symbol);
}
| FIELD_SELECTION {
$$ = context->addNonConstructorFunc(ImmutableString($1.string));
$$ = context->addNonConstructorFunc(ImmutableString($1.string), $1.symbol);
}
;
......
......@@ -2725,7 +2725,7 @@ yyreduce:
case 30:
{
(yyval.interm.functionLookup) = context->addNonConstructorFunc(ImmutableString((yyvsp[0].lex).string));
(yyval.interm.functionLookup) = context->addNonConstructorFunc(ImmutableString((yyvsp[0].lex).string), (yyvsp[0].lex).symbol);
}
break;
......@@ -2733,7 +2733,7 @@ yyreduce:
case 31:
{
(yyval.interm.functionLookup) = context->addNonConstructorFunc(ImmutableString((yyvsp[0].lex).string));
(yyval.interm.functionLookup) = context->addNonConstructorFunc(ImmutableString((yyvsp[0].lex).string), (yyvsp[0].lex).symbol);
}
break;
......
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