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(""); ...@@ -21,8 +21,10 @@ constexpr const ImmutableString kEmptyName("");
} // anonymous namespace } // anonymous namespace
TFunctionLookup::TFunctionLookup(const ImmutableString &name, const TType *constructorType) TFunctionLookup::TFunctionLookup(const ImmutableString &name,
: mName(name), mConstructorType(constructorType), mThisNode(nullptr) 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 ...@@ -30,14 +32,15 @@ TFunctionLookup::TFunctionLookup(const ImmutableString &name, const TType *const
TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type) TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type)
{ {
ASSERT(type != nullptr); ASSERT(type != nullptr);
return new TFunctionLookup(kEmptyName, type); return new TFunctionLookup(kEmptyName, type, nullptr);
} }
// static // static
TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name) TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name,
const TSymbol *symbol)
{ {
ASSERT(name != ""); ASSERT(name != "");
return new TFunctionLookup(name, nullptr); return new TFunctionLookup(name, nullptr, symbol);
} }
const ImmutableString &TFunctionLookup::name() const const ImmutableString &TFunctionLookup::name() const
...@@ -93,4 +96,9 @@ TIntermSequence &TFunctionLookup::arguments() ...@@ -93,4 +96,9 @@ TIntermSequence &TFunctionLookup::arguments()
return mArguments; return mArguments;
} }
const TSymbol *TFunctionLookup::symbol() const
{
return mSymbol;
}
} // namespace sh } // namespace sh
...@@ -22,7 +22,7 @@ class TFunctionLookup : angle::NonCopyable ...@@ -22,7 +22,7 @@ class TFunctionLookup : angle::NonCopyable
POOL_ALLOCATOR_NEW_DELETE(); POOL_ALLOCATOR_NEW_DELETE();
static TFunctionLookup *CreateConstructor(const TType *type); 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; const ImmutableString &name() const;
ImmutableString getMangledName() const; ImmutableString getMangledName() const;
...@@ -38,13 +38,20 @@ class TFunctionLookup : angle::NonCopyable ...@@ -38,13 +38,20 @@ class TFunctionLookup : angle::NonCopyable
void addArgument(TIntermTyped *argument); void addArgument(TIntermTyped *argument);
TIntermSequence &arguments(); 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: private:
TFunctionLookup(const ImmutableString &name, const TType *constructorType); TFunctionLookup(const ImmutableString &name,
const TType *constructorType,
const TSymbol *symbol);
const ImmutableString mName; const ImmutableString mName;
const TType *const mConstructorType; const TType *const mConstructorType;
TIntermTyped *mThisNode; TIntermTyped *mThisNode;
TIntermSequence mArguments; TIntermSequence mArguments;
const TSymbol *mSymbol;
}; };
} // namespace sh } // namespace sh
......
...@@ -3432,9 +3432,10 @@ TFunction *TParseContext::parseFunctionHeader(const TPublicType &type, ...@@ -3432,9 +3432,10 @@ TFunction *TParseContext::parseFunctionHeader(const TPublicType &type,
return new TFunction(&symbolTable, name, new TType(type), SymbolType::UserDefined, false); 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) TFunctionLookup *TParseContext::addConstructorFunc(const TPublicType &publicType)
...@@ -5798,11 +5799,10 @@ TIntermTyped *TParseContext::addMethod(TFunctionLookup *fnCall, const TSourceLoc ...@@ -5798,11 +5799,10 @@ TIntermTyped *TParseContext::addMethod(TFunctionLookup *fnCall, const TSourceLoc
TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunctionLookup *fnCall, TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunctionLookup *fnCall,
const TSourceLoc &loc) const TSourceLoc &loc)
{ {
// First find by unmangled name to check whether the function name has been // First check whether the function has been hidden by a variable name or struct typename by
// hidden by a variable name or struct typename. // using the symbol looked up in the lexical phase. If the function is not hidden, look for one
// If a function is found, check for one with a matching argument list. // with a matching argument list.
const TSymbol *symbol = symbolTable.find(fnCall->name(), mShaderVersion); if (fnCall->symbol() != nullptr && !fnCall->symbol()->isFunction())
if (symbol != nullptr && !symbol->isFunction())
{ {
error(loc, "function name expected", fnCall->name()); error(loc, "function name expected", fnCall->name());
} }
...@@ -5810,7 +5810,7 @@ TIntermTyped *TParseContext::addNonConstructorFunctionCall(TFunctionLookup *fnCa ...@@ -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 // There are no inner functions, so it's enough to look for user-defined functions in the
// global scope. // global scope.
symbol = symbolTable.findGlobal(fnCall->getMangledName()); const TSymbol *symbol = symbolTable.findGlobal(fnCall->getMangledName());
if (symbol != nullptr) if (symbol != nullptr)
{ {
// A user-defined function - could be an overloaded built-in as well. // A user-defined function - could be an overloaded built-in as well.
......
...@@ -296,7 +296,7 @@ class TParseContext : angle::NonCopyable ...@@ -296,7 +296,7 @@ class TParseContext : angle::NonCopyable
const ImmutableString &name, const ImmutableString &name,
const TSourceLoc &location); const TSourceLoc &location);
TFunctionLookup *addNonConstructorFunc(const ImmutableString &name); TFunctionLookup *addNonConstructorFunc(const ImmutableString &name, const TSymbol *symbol);
TFunctionLookup *addConstructorFunc(const TPublicType &publicType); TFunctionLookup *addConstructorFunc(const TPublicType &publicType);
TParameter parseParameterDeclarator(const TPublicType &publicType, TParameter parseParameterDeclarator(const TPublicType &publicType,
......
...@@ -384,10 +384,10 @@ function_identifier ...@@ -384,10 +384,10 @@ function_identifier
$$ = context->addConstructorFunc($1); $$ = context->addConstructorFunc($1);
} }
| IDENTIFIER { | IDENTIFIER {
$$ = context->addNonConstructorFunc(ImmutableString($1.string)); $$ = context->addNonConstructorFunc(ImmutableString($1.string), $1.symbol);
} }
| FIELD_SELECTION { | FIELD_SELECTION {
$$ = context->addNonConstructorFunc(ImmutableString($1.string)); $$ = context->addNonConstructorFunc(ImmutableString($1.string), $1.symbol);
} }
; ;
......
...@@ -2725,7 +2725,7 @@ yyreduce: ...@@ -2725,7 +2725,7 @@ yyreduce:
case 30: 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; break;
...@@ -2733,7 +2733,7 @@ yyreduce: ...@@ -2733,7 +2733,7 @@ yyreduce:
case 31: 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; 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