Changeset 247170 in webkit


Ignore:
Timestamp:
Jul 5, 2019 1:09:39 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 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:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247165 r247170  
     12019-07-05  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 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-05  Youenn Fablet  <youenn@apple.com>
    235
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h

    r247164 r247170  
    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     }
    77 
    7870    FunctionDeclaration* function() { return m_function; }
    7971
     
    8779    String m_name;
    8880    Vector<UniqueRef<Expression>> m_arguments;
    89     Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>> m_overloads;
    9081    FunctionDeclaration* m_function { nullptr };
    9182    NamedType* m_castReturnType { nullptr };
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h

    r247144 r247170  
    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

    r247144 r247170  
    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

    r247164 r247170  
    4747#include "WHLSLMakeArrayReferenceExpression.h"
    4848#include "WHLSLMakePointerExpression.h"
     49#include "WHLSLNameContext.h"
    4950#include "WHLSLPointerType.h"
    5051#include "WHLSLProgram.h"
     
    216217}
    217218
    218 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)
    219 {
    220     if (AST::FunctionDeclaration* function = resolveFunctionOverload(possibleOverloads, types, castReturnType))
    221         return function;
     219static 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 (possibleOverloads) {
     222        if (AST::FunctionDeclaration* function = resolveFunctionOverload(*possibleOverloads, types, castReturnType))
     223            return function;
     224    }
    222225
    223226    if (auto newFunction = resolveByInstantiation(name, origin, types, intrinsics)) {
     
    10201023        if (additionalArgumentType)
    10211024            getterArgumentTypes.append(*additionalArgumentType);
    1022         if ((getterFunction = resolveFunction(m_program, propertyAccessExpression.possibleGetterOverloads(), getterArgumentTypes, propertyAccessExpression.getterFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1025        auto getterName = propertyAccessExpression.getterFunctionName();
     1026        auto* getterFunctions = m_program.nameContext().getFunctions(getterName);
     1027        getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.origin(), m_intrinsics);
     1028        if (getterFunction)
    10231029            getterReturnType = &getterFunction->type();
    10241030    }
     
    10331039            if (additionalArgumentType)
    10341040                anderArgumentTypes.append(*additionalArgumentType);
    1035             if ((anderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1041            auto anderName = propertyAccessExpression.anderFunctionName();
     1042            auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
     1043            anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
     1044            if (anderFunction)
    10361045                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
    10371046        }
     
    10451054        if (additionalArgumentType)
    10461055            threadAnderArgumentTypes.append(*additionalArgumentType);
    1047         if ((threadAnderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), threadAnderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics)))
     1056        auto anderName = propertyAccessExpression.anderFunctionName();
     1057        auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
     1058        threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
     1059        if (threadAnderFunction)
    10481060            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
    10491061    }
     
    10891101            setterArgumentTypes.append(*additionalArgumentType);
    10901102        setterArgumentTypes.append(fieldResolvingType);
    1091         setterFunction = resolveFunction(m_program, propertyAccessExpression.possibleSetterOverloads(), setterArgumentTypes, propertyAccessExpression.setterFunctionName(), propertyAccessExpression.origin(), m_intrinsics);
     1103        auto setterName = propertyAccessExpression.setterFunctionName();
     1104        auto* setterFunctions = m_program.nameContext().getFunctions(setterName);
     1105        setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.origin(), m_intrinsics);
    10921106        if (setterFunction)
    10931107            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

    r247164 r247170  
    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()) {
     
    200196void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression)
    201197{
    202     if (m_isResolvingCalls) {
    203         if (auto* getterFunctions = m_nameContext.getFunctions(propertyAccessExpression.getterFunctionName()))
    204             propertyAccessExpression.setPossibleGetterOverloads(*getterFunctions);
    205         if (auto* setterFunctions = m_nameContext.getFunctions(propertyAccessExpression.setterFunctionName()))
    206             propertyAccessExpression.setPossibleSetterOverloads(*setterFunctions);
    207         if (auto* anderFunctions = m_nameContext.getFunctions(propertyAccessExpression.anderFunctionName()))
    208             propertyAccessExpression.setPossibleAnderOverloads(*anderFunctions);
    209     }
    210198    Visitor::visit(propertyAccessExpression);
    211199}
     
    238226void NameResolver::visit(AST::CallExpression& callExpression)
    239227{
    240     if (m_isResolvingCalls) {
    241         if (!callExpression.hasOverloads()) {
    242             if (auto* functions = m_nameContext.getFunctions(callExpression.name()))
    243                 callExpression.setOverloads(*functions);
    244             else {
    245                 if (auto* types = m_nameContext.getTypes(callExpression.name())) {
    246                     if (types->size() == 1) {
    247                         if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) {
    248                             callExpression.setCastData((*types)[0].get());
    249                             callExpression.setOverloads(*functions);
    250                         }
    251                     }
    252                 }
    253             }
    254         }
    255         if (!callExpression.hasOverloads()) {
    256             setError();
    257             return;
    258         }
    259     }
    260228    Visitor::visit(callExpression);
    261229}
     
    332300}
    333301
    334 bool resolveCallsInFunctions(Program& program, NameResolver& nameResolver)
    335 {
    336     nameResolver.setIsResolvingCalls(true);
    337     for (auto& functionDefinition : program.functionDefinitions()) {
    338         nameResolver.setCurrentFunctionDefinition(&functionDefinition);
    339         nameResolver.checkErrorAndVisit(functionDefinition);
    340         if (nameResolver.error())
    341             return false;
    342     }
    343     nameResolver.setCurrentFunctionDefinition(nullptr);
    344     nameResolver.setIsResolvingCalls(false);
    345     return true;
    346 }
    347 
    348302} // namespace WHLSL
    349303
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h

    r247144 r247170  
    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

    r247164 r247170  
    134134    CHECK_PASS(resolveTypeNamesInFunctions, program, nameResolver);
    135135    CHECK_PASS(synthesizeConstructors, program);
    136     CHECK_PASS(resolveCallsInFunctions, program, nameResolver);
    137136    CHECK_PASS(checkDuplicateFunctions, program);
    138137
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp

    r247110 r247170  
    760760    Vector<UniqueRef<AST::Expression>> arguments;
    761761    arguments.append(propertyAccessExpression.takeBase());
    762     if (is<AST::IndexExpression>(propertyAccessExpression))
    763         arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex());
    764     auto* callExpression = AST::replaceWith<AST::CallExpression>(propertyAccessExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments));
     762    AST::CallExpression* callExpression;
     763    if (is<AST::IndexExpression>(propertyAccessExpression)) {
     764        auto& indexExpression = downcast<AST::IndexExpression>(propertyAccessExpression);
     765        arguments.append(indexExpression.takeIndex());
     766        callExpression = AST::replaceWith<AST::CallExpression>(indexExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments));
     767    } else {
     768        ASSERT(is<AST::DotExpression>(propertyAccessExpression));
     769        auto& dotExpression = downcast<AST::DotExpression>(propertyAccessExpression);
     770        callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments));
     771    }
    765772    callExpression->setFunction(getterFunction);
    766773    callExpression->setType(getterFunction.type().clone());
Note: See TracChangeset for help on using the changeset viewer.