Changeset 247127 in webkit


Ignore:
Timestamp:
Jul 3, 2019 6:15:38 PM (5 years ago)
Author:
rmorisset@apple.com
Message:

[WHLSL] Remove the phase resolveCallsInFunctions
https://bugs.webkit.org/show_bug.cgi?id=199474

Reviewed by Myles C. Maxfield.

This pass only stores into each property access and call expression vectors of all the functions it might be calling, for use by the Checker afterwards.
But the checker is perfectly able to compute a pointer to these vectors by itself.
So by removing this pass, we gain the following:

  • One less pass over the AST
  • No need to copy these vectors (which can be large for heavily overloaded functions, of which there are quite a few in the stdlib)
  • No need to have these vectors in the expressions, saving 24 bytes per CallExpression and 72 bytes per PropertyAccessExpression
  • No need to allocate and then destroy these vectors.

No new tests as there is no intended functional change.

  • Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:

(WebCore::WHLSL::AST::CallExpression::castReturnType):

  • Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
  • Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp:

(WebCore::WHLSL::AutoInitialize::visit):

  • Modules/webgpu/WHLSL/WHLSLChecker.cpp:

(WebCore::WHLSL::resolveFunction):
(WebCore::WHLSL::Checker::finishVisiting):
(WebCore::WHLSL::Checker::visit):

  • Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:

(WebCore::WHLSL::NameResolver::NameResolver):
(WebCore::WHLSL::NameResolver::visit):

  • Modules/webgpu/WHLSL/WHLSLNameResolver.h:
  • Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

(WebCore::WHLSL::prepareShared):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247124 r247127  
     12019-07-03  Robin Morisset  <rmorisset@apple.com>
     2
     3        [WHLSL] Remove the phase resolveCallsInFunctions
     4        https://bugs.webkit.org/show_bug.cgi?id=199474
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        This pass only stores into each property access and call expression vectors of all the functions it might be calling, for use by the Checker afterwards.
     9        But the checker is perfectly able to compute a pointer to these vectors by itself.
     10        So by removing this pass, we gain the following:
     11        - One less pass over the AST
     12        - No need to copy these vectors (which can be large for heavily overloaded functions, of which there are quite a few in the stdlib)
     13        - No need to have these vectors in the expressions, saving 24 bytes per CallExpression and 72 bytes per PropertyAccessExpression
     14        - No need to allocate and then destroy these vectors.
     15
     16        No new tests as there is no intended functional change.
     17
     18        * Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
     19        (WebCore::WHLSL::AST::CallExpression::castReturnType):
     20        * Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
     21        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp:
     22        (WebCore::WHLSL::AutoInitialize::visit):
     23        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
     24        (WebCore::WHLSL::resolveFunction):
     25        (WebCore::WHLSL::Checker::finishVisiting):
     26        (WebCore::WHLSL::Checker::visit):
     27        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
     28        (WebCore::WHLSL::NameResolver::NameResolver):
     29        (WebCore::WHLSL::NameResolver::visit):
     30        * Modules/webgpu/WHLSL/WHLSLNameResolver.h:
     31        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
     32        (WebCore::WHLSL::prepareShared):
     33
    1342019-07-03  Robin Morisset  <rmorisset@apple.com>
    235
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h

    r247115 r247127  
    6868    bool isCast() { return m_castReturnType; }
    6969    NamedType* castReturnType() { return m_castReturnType; }
    70     bool hasOverloads() const { return static_cast<bool>(m_overloads); }
    71     Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>>& overloads() { return m_overloads; }
    72     void setOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)
    73     {
    74         ASSERT(!hasOverloads());
    75         m_overloads = overloads;
    76     }
    7770
    7871    FunctionDeclaration& function()
     
    9184    String m_name;
    9285    Vector<UniqueRef<Expression>> m_arguments;
    93     Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>> m_overloads;
    9486    FunctionDeclaration* m_function { nullptr };
    9587    NamedType* m_castReturnType { nullptr };
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h

    r246394 r247127  
    5858    virtual String anderFunctionName() const = 0;
    5959
    60     Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleGetterOverloads() { return m_possibleGetterOverloads; }
    61     Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleSetterOverloads() { return m_possibleSetterOverloads; }
    62     Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleAnderOverloads() { return m_possibleAnderOverloads; }
    6360    FunctionDeclaration* getterFunction() { return m_getterFunction; }
    6461    FunctionDeclaration* anderFunction() { return m_anderFunction; }
    6562    FunctionDeclaration* threadAnderFunction() { return m_threadAnderFunction; }
    6663    FunctionDeclaration* setterFunction() { return m_setterFunction; }
    67 
    68     void setPossibleGetterOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)
    69     {
    70         m_possibleGetterOverloads = overloads;
    71     }
    72     void setPossibleAnderOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)
    73     {
    74         m_possibleAnderOverloads = overloads;
    75     }
    76     void setPossibleSetterOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)
    77     {
    78         m_possibleSetterOverloads = overloads;
    79     }
    8064
    8165    void setGetterFunction(FunctionDeclaration* getterFunction)
     
    10589private:
    10690    UniqueRef<Expression> m_base;
    107     Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleGetterOverloads;
    108     Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleSetterOverloads;
    109     Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleAnderOverloads;
    11091    FunctionDeclaration* m_getterFunction { nullptr };
    11192    FunctionDeclaration* m_anderFunction { nullptr };
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp

    r247062 r247127  
    7373        callExpression->setType(type->clone());
    7474        callExpression->setTypeAnnotation(AST::RightValue());
    75         callExpression->setOverloads(m_castFunctions);
    7675        Vector<std::reference_wrapper<ResolvingType>> argumentTypes;
    77         auto* function = resolveFunctionOverload(*callExpression->overloads(), argumentTypes, type);
     76        auto* function = resolveFunctionOverload(m_castFunctions, argumentTypes, type);
    7877        if (!function) {
    7978            setError();
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r247115 r247127  
    4747#include "WHLSLMakeArrayReferenceExpression.h"
    4848#include "WHLSLMakePointerExpression.h"
     49#include "WHLSLNameContext.h"
    4950#include "WHLSLPointerType.h"
    5051#include "WHLSLProgram.h"
     
    217218}
    218219
    219 static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, Lexer::Token origin, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr)
    220 {
    221     if (AST::FunctionDeclaration* function = resolveFunctionOverload(possibleOverloads, types, castReturnType))
    222         return function;
     220static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, Lexer::Token origin, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr)
     221{
     222    if (possibleOverloads) {
     223        if (AST::FunctionDeclaration* function = resolveFunctionOverload(*possibleOverloads, types, castReturnType))
     224            return function;
     225    }
    223226
    224227    if (auto newFunction = resolveByInstantiation(name, origin, types, intrinsics)) {
     
    10211024        if (additionalArgumentType)
    10221025            getterArgumentTypes.append(*additionalArgumentType);
    1023         if ((getterFunction = resolveFunction(m_program, propertyAccessExpression.possibleGetterOverloads(), getterArgumentTypes, propertyAccessExpression.getterFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1026        auto getterName = propertyAccessExpression.getterFunctionName();
     1027        auto* getterFunctions = m_program.nameContext().getFunctions(getterName);
     1028        getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.origin(), m_intrinsics);
     1029        if (getterFunction)
    10241030            getterReturnType = &getterFunction->type();
    10251031    }
     
    10341040            if (additionalArgumentType)
    10351041                anderArgumentTypes.append(*additionalArgumentType);
    1036             if ((anderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1042            auto anderName = propertyAccessExpression.anderFunctionName();
     1043            auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
     1044            anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
     1045            if (anderFunction)
    10371046                anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer
    10381047        }
     
    10461055        if (additionalArgumentType)
    10471056            threadAnderArgumentTypes.append(*additionalArgumentType);
    1048         if ((threadAnderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), threadAnderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1057        auto anderName = propertyAccessExpression.anderFunctionName();
     1058        auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
     1059        threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
     1060        if (threadAnderFunction)
    10491061            threadAnderReturnType = &downcast<AST::PointerType>(threadAnderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer
    10501062    }
     
    10901102            setterArgumentTypes.append(*additionalArgumentType);
    10911103        setterArgumentTypes.append(fieldResolvingType);
    1092         setterFunction = resolveFunction(m_program, propertyAccessExpression.possibleSetterOverloads(), setterArgumentTypes, propertyAccessExpression.setterFunctionName(), propertyAccessExpression.origin(), m_intrinsics);
     1104        auto setterName = propertyAccessExpression.setterFunctionName();
     1105        auto* setterFunctions = m_program.nameContext().getFunctions(setterName);
     1106        setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.origin(), m_intrinsics);
    10931107        if (setterFunction)
    10941108            setterReturnType = &setterFunction->type();
     
    14701484    // We don't want to recurse to the same node twice.
    14711485
    1472     ASSERT(callExpression.hasOverloads());
    1473     auto* function = resolveFunction(m_program, *callExpression.overloads(), types, callExpression.name(), callExpression.origin(), m_intrinsics, callExpression.castReturnType());
     1486    NameContext& nameContext = m_program.nameContext();
     1487    auto* functions = nameContext.getFunctions(callExpression.name());
     1488    if (!functions) {
     1489        if (auto* types = nameContext.getTypes(callExpression.name())) {
     1490            if (types->size() == 1) {
     1491                if ((functions = nameContext.getFunctions("operator cast"_str)))
     1492                    callExpression.setCastData((*types)[0].get());
     1493            }
     1494        }
     1495    }
     1496    if (!functions) {
     1497        setError();
     1498        return;
     1499    }
     1500
     1501    auto* function = resolveFunction(m_program, functions, types, callExpression.name(), callExpression.origin(), m_intrinsics, callExpression.castReturnType());
    14741502    if (!function) {
    14751503        setError();
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp

    r247115 r247127  
    6262    , m_parentNameResolver(&parentResolver)
    6363{
    64     m_isResolvingCalls = parentResolver.m_isResolvingCalls;
    6564    setCurrentFunctionDefinition(parentResolver.m_currentFunction);
    6665}
     
    7473void NameResolver::visit(AST::TypeReference& typeReference)
    7574{
    76     if (m_isResolvingCalls)
    77         return;
    78 
    7975    ScopedSetAdder<AST::TypeReference*> adder(m_typeReferences, &typeReference);
    8076    if (!adder.isNewEntry()) {
     
    204200void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression)
    205201{
    206     if (m_isResolvingCalls) {
    207         if (auto* getterFunctions = m_nameContext.getFunctions(propertyAccessExpression.getterFunctionName()))
    208             propertyAccessExpression.setPossibleGetterOverloads(*getterFunctions);
    209         if (auto* setterFunctions = m_nameContext.getFunctions(propertyAccessExpression.setterFunctionName()))
    210             propertyAccessExpression.setPossibleSetterOverloads(*setterFunctions);
    211         if (auto* anderFunctions = m_nameContext.getFunctions(propertyAccessExpression.anderFunctionName()))
    212             propertyAccessExpression.setPossibleAnderOverloads(*anderFunctions);
    213     }
    214202    Visitor::visit(propertyAccessExpression);
    215203}
     
    242230void NameResolver::visit(AST::CallExpression& callExpression)
    243231{
    244     if (m_isResolvingCalls) {
    245         if (!callExpression.hasOverloads()) {
    246             if (auto* functions = m_nameContext.getFunctions(callExpression.name()))
    247                 callExpression.setOverloads(*functions);
    248             else {
    249                 if (auto* types = m_nameContext.getTypes(callExpression.name())) {
    250                     if (types->size() == 1) {
    251                         if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) {
    252                             callExpression.setCastData((*types)[0].get());
    253                             callExpression.setOverloads(*functions);
    254                         }
    255                     }
    256                 }
    257             }
    258         }
    259         if (!callExpression.hasOverloads()) {
    260             setError();
    261             return;
    262         }
    263     }
    264232    Visitor::visit(callExpression);
    265233}
     
    336304}
    337305
    338 bool resolveCallsInFunctions(Program& program, NameResolver& nameResolver)
    339 {
    340     nameResolver.setIsResolvingCalls(true);
    341     for (auto& functionDefinition : program.functionDefinitions()) {
    342         nameResolver.setCurrentFunctionDefinition(&functionDefinition);
    343         nameResolver.checkErrorAndVisit(functionDefinition);
    344         if (nameResolver.error())
    345             return false;
    346     }
    347     nameResolver.setCurrentFunctionDefinition(nullptr);
    348     nameResolver.setIsResolvingCalls(false);
    349     return true;
    350 }
    351 
    352306} // namespace WHLSL
    353307
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h

    r246631 r247127  
    5252    }
    5353
    54     void setIsResolvingCalls(bool isResolvingCalls) { m_isResolvingCalls = isResolvingCalls; }
    55 
    5654private:
    5755    void visit(AST::NativeFunctionDeclaration&) override;
     
    7472    AST::FunctionDefinition* m_currentFunction { nullptr };
    7573    NameResolver* m_parentNameResolver { nullptr };
    76     bool m_isResolvingCalls { false };
    7774};
    7875
    7976bool resolveNamesInTypes(Program&, NameResolver&);
    8077bool resolveTypeNamesInFunctions(Program&, NameResolver&);
    81 bool resolveCallsInFunctions(Program&, NameResolver&);
    8278
    8379} // namespace WHLSL
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp

    r247115 r247127  
    129129    CHECK_PASS(resolveTypeNamesInFunctions, program, nameResolver);
    130130    CHECK_PASS(synthesizeConstructors, program);
    131     CHECK_PASS(resolveCallsInFunctions, program, nameResolver);
    132131    CHECK_PASS(checkDuplicateFunctions, program);
    133132
Note: See TracChangeset for help on using the changeset viewer.