⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 248303 in webkit


Ignore:
Timestamp:
Aug 6, 2019, 10:37:08 AM (7 years ago)
Author:
sbarati@apple.com
Message:

[WHLSL] Reduce the number of variables that make it into the global struct by skipping stdlib functions and internal uses of MakePointerExpression/MakeArrayReference
https://bugs.webkit.org/show_bug.cgi?id=200463

Reviewed by Myles C. Maxfield.

This patch makes it so that we put fewer variables in the global struct.
This decreases end-to-end running time in compute_boids by 30% (with p = 0.0001).

We achieve this in two ways:

  1. We track if each function is user code or "standard library" code. We also

count native functions as the standard library. We know a priori that the
standard library never escapes any variables. So the preserve variable
lifetimes phase skips analyzing all standard library functions and also
skips passing the global struct to any standard library functions.

  1. We internally emit MakePointerExpression/MakeArrayReferenceExpression nodes in

the compiler in various phases. We sometimes emit these nodes in such a way
that we know that this address-of expression does not cause the variable to
escape. We now mark each address-of expressions as either:

  • Conservatively escaping. We conservatively do this for all user code.
  • Not escaping. This means that this address-of operation definitely does

not escape the variable. If a variable never has an escaping use, we will
omit putting this variable in the struct.

  • Modules/webgpu/WHLSL/AST/WHLSLAddressEscapeMode.h: Added.
  • Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h:

(WebCore::WHLSL::AST::FunctionDeclaration::FunctionDeclaration):
(WebCore::WHLSL::AST::FunctionDeclaration::parsingMode const):

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

(WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression):
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::mightEscape const):

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

(WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression):
(WebCore::WHLSL::AST::MakePointerExpression::mightEscape const):

  • Modules/webgpu/WHLSL/WHLSLChecker.cpp:

(WebCore::WHLSL::resolveWithOperatorAnderIndexer):
(WebCore::WHLSL::resolveWithOperatorLength):
(WebCore::WHLSL::resolveWithReferenceComparator):

  • Modules/webgpu/WHLSL/WHLSLParser.cpp:

(WebCore::WHLSL::Parser::parse):
(WebCore::WHLSL::Parser::parseComputeFunctionDeclaration):
(WebCore::WHLSL::Parser::parseVertexOrFragmentFunctionDeclaration):
(WebCore::WHLSL::Parser::parseRegularFunctionDeclaration):
(WebCore::WHLSL::Parser::parseOperatorFunctionDeclaration):
(WebCore::WHLSL::Parser::parsePossiblePrefix):

  • Modules/webgpu/WHLSL/WHLSLParser.h:
  • Modules/webgpu/WHLSL/WHLSLParsingMode.h: Added.
  • Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

(WebCore::WHLSL::prepareShared):

  • Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
  • Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:

(WebCore::WHLSL::wrapAnderCallArgument):
(WebCore::WHLSL::modify):
(WebCore::WHLSL::PropertyResolver::visit):

  • Modules/webgpu/WHLSL/WHLSLStandardLibraryUtilities.cpp:

(WebCore::WHLSL::includeStandardLibrary):

  • Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:

(WebCore::WHLSL::synthesizeArrayOperatorLength):

  • Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp:

(WebCore::WHLSL::synthesizeConstructors):

  • Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp:

(WebCore::WHLSL::synthesizeEnumerationFunctions):

  • Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:

(WebCore::WHLSL::synthesizeStructureAccessors):

  • WebCore.xcodeproj/project.pbxproj:
Location:
trunk/Source/WebCore
Files:
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248301 r248303  
     12019-08-06  Saam Barati  <sbarati@apple.com>
     2
     3        [WHLSL] Reduce the number of variables that make it into the global struct by skipping stdlib functions and internal uses of MakePointerExpression/MakeArrayReference
     4        https://bugs.webkit.org/show_bug.cgi?id=200463
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        This patch makes it so that we put fewer variables in the global struct.
     9        This decreases end-to-end running time in compute_boids by 30% (with p = 0.0001).
     10       
     11        We achieve this in two ways:
     12        1. We track if each function is user code or "standard library" code. We also
     13        count native functions as the standard library. We know a priori that the
     14        standard library never escapes any variables. So the preserve variable
     15        lifetimes phase skips analyzing all standard library functions and also
     16        skips passing the global struct to any standard library functions.
     17       
     18        2. We internally emit MakePointerExpression/MakeArrayReferenceExpression nodes in
     19        the compiler in various phases. We sometimes emit these nodes in such a way
     20        that we know that this address-of expression does not cause the variable to
     21        escape. We now mark each address-of expressions as either:
     22        - Conservatively escaping. We conservatively do this for all user code.
     23        - Not escaping. This means that this address-of operation definitely does
     24        not escape the variable. If a variable never has an escaping use, we will
     25        omit putting this variable in the struct.
     26
     27        * Modules/webgpu/WHLSL/AST/WHLSLAddressEscapeMode.h: Added.
     28        * Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h:
     29        (WebCore::WHLSL::AST::FunctionDeclaration::FunctionDeclaration):
     30        (WebCore::WHLSL::AST::FunctionDeclaration::parsingMode const):
     31        * Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
     32        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression):
     33        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::mightEscape const):
     34        * Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
     35        (WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression):
     36        (WebCore::WHLSL::AST::MakePointerExpression::mightEscape const):
     37        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
     38        (WebCore::WHLSL::resolveWithOperatorAnderIndexer):
     39        (WebCore::WHLSL::resolveWithOperatorLength):
     40        (WebCore::WHLSL::resolveWithReferenceComparator):
     41        * Modules/webgpu/WHLSL/WHLSLParser.cpp:
     42        (WebCore::WHLSL::Parser::parse):
     43        (WebCore::WHLSL::Parser::parseComputeFunctionDeclaration):
     44        (WebCore::WHLSL::Parser::parseVertexOrFragmentFunctionDeclaration):
     45        (WebCore::WHLSL::Parser::parseRegularFunctionDeclaration):
     46        (WebCore::WHLSL::Parser::parseOperatorFunctionDeclaration):
     47        (WebCore::WHLSL::Parser::parsePossiblePrefix):
     48        * Modules/webgpu/WHLSL/WHLSLParser.h:
     49        * Modules/webgpu/WHLSL/WHLSLParsingMode.h: Added.
     50        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
     51        (WebCore::WHLSL::prepareShared):
     52        * Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
     53        * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
     54        (WebCore::WHLSL::wrapAnderCallArgument):
     55        (WebCore::WHLSL::modify):
     56        (WebCore::WHLSL::PropertyResolver::visit):
     57        * Modules/webgpu/WHLSL/WHLSLStandardLibraryUtilities.cpp:
     58        (WebCore::WHLSL::includeStandardLibrary):
     59        * Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
     60        (WebCore::WHLSL::synthesizeArrayOperatorLength):
     61        * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp:
     62        (WebCore::WHLSL::synthesizeConstructors):
     63        * Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp:
     64        (WebCore::WHLSL::synthesizeEnumerationFunctions):
     65        * Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:
     66        (WebCore::WHLSL::synthesizeStructureAccessors):
     67        * WebCore.xcodeproj/project.pbxproj:
     68
    1692019-08-06  Jer Noble  <jer.noble@apple.com>
    270
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAddressEscapeMode.h

    r248302 r248303  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WHLSLExpression.h"
    31 #include <wtf/FastMalloc.h>
    32 #include <wtf/UniqueRef.h>
    33 
    3430namespace WebCore {
    3531
     
    3834namespace AST {
    3935
    40 class MakePointerExpression : public Expression {
    41     WTF_MAKE_FAST_ALLOCATED;
    42 public:
    43     MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
    44         : Expression(location)
    45         , m_leftValue(WTFMove(leftValue))
    46     {
    47     }
    48 
    49     virtual ~MakePointerExpression() = default;
    50 
    51     MakePointerExpression(const MakePointerExpression&) = delete;
    52     MakePointerExpression(MakePointerExpression&&) = default;
    53 
    54     bool isMakePointerExpression() const override { return true; }
    55 
    56     Expression& leftValue() { return m_leftValue; }
    57 
    58 private:
    59     UniqueRef<Expression> m_leftValue;
     36enum class AddressEscapeMode : uint8_t {
     37    Escapes, // Conservatively, this address-of operation might escape.
     38    DoesNotEscape // This address-of operation definitely does not escape.
    6039};
    6140
    6241} // namespace AST
    6342
    64 }
     43} // namespace WHLSL
    6544
    66 }
     45} // namespace WebCore
    6746
    68 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(MakePointerExpression, isMakePointerExpression())
    69 
    70 #endif
     47#endif // ENABLE(WEBGPU)
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h

    r247878 r248303  
    3131#include "WHLSLEntryPointType.h"
    3232#include "WHLSLFunctionAttribute.h"
     33#include "WHLSLParsingMode.h"
    3334#include "WHLSLSemantic.h"
    3435#include "WHLSLUnnamedType.h"
     
    4748    WTF_MAKE_FAST_ALLOCATED;
    4849public:
    49     FunctionDeclaration(CodeLocation location, AttributeBlock&& attributeBlock, Optional<EntryPointType> entryPointType, Ref<UnnamedType> type, String&& name, VariableDeclarations&& parameters, std::unique_ptr<Semantic>&& semantic, bool isOperator)
     50    FunctionDeclaration(CodeLocation location, AttributeBlock&& attributeBlock, Optional<EntryPointType> entryPointType, Ref<UnnamedType> type, String&& name, VariableDeclarations&& parameters, std::unique_ptr<Semantic>&& semantic, bool isOperator, ParsingMode parsingMode)
    5051        : m_codeLocation(location)
    5152        , m_attributeBlock(WTFMove(attributeBlock))
    5253        , m_entryPointType(entryPointType)
    53         , m_isOperator(WTFMove(isOperator))
     54        , m_isOperator(isOperator)
     55        , m_parsingMode(parsingMode)
    5456        , m_type(WTFMove(type))
    5557        , m_name(WTFMove(name))
     
    8082    const CodeLocation& codeLocation() const { return m_codeLocation; }
    8183
     84    ParsingMode parsingMode() const { return m_parsingMode; }
     85
    8286private:
    8387    CodeLocation m_codeLocation;
     
    8589    Optional<EntryPointType> m_entryPointType;
    8690    bool m_isOperator;
     91    ParsingMode m_parsingMode;
    8792    Ref<UnnamedType> m_type;
    8893    String m_name;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h

    r247834 r248303  
    2828#if ENABLE(WEBGPU)
    2929
     30#include "WHLSLAddressEscapeMode.h"
    3031#include "WHLSLExpression.h"
    3132#include <wtf/FastMalloc.h>
     
    4142    WTF_MAKE_FAST_ALLOCATED;
    4243public:
    43     MakeArrayReferenceExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
     44    MakeArrayReferenceExpression(CodeLocation location, UniqueRef<Expression>&& leftValue, AddressEscapeMode addressEscapeMode)
    4445        : Expression(location)
    4546        , m_leftValue(WTFMove(leftValue))
     47        , m_addressEscapeMode(addressEscapeMode)
    4648    {
    4749    }
     
    5658    Expression& leftValue() { return m_leftValue; }
    5759
     60    bool mightEscape() const { return m_addressEscapeMode == AddressEscapeMode::Escapes; }
     61
    5862private:
    5963    UniqueRef<Expression> m_leftValue;
     64    AddressEscapeMode m_addressEscapeMode;
    6065};
    6166
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h

    r247834 r248303  
    2828#if ENABLE(WEBGPU)
    2929
     30#include "WHLSLAddressEscapeMode.h"
    3031#include "WHLSLExpression.h"
    3132#include <wtf/FastMalloc.h>
     
    4142    WTF_MAKE_FAST_ALLOCATED;
    4243public:
    43     MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
     44    MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue, AddressEscapeMode addressEscapeMode)
    4445        : Expression(location)
    4546        , m_leftValue(WTFMove(leftValue))
     47        , m_addressEscapeMode(addressEscapeMode)
    4648    {
    4749    }
     
    5658    Expression& leftValue() { return m_leftValue; }
    5759
     60    bool mightEscape() const { return m_addressEscapeMode == AddressEscapeMode::Escapes; }
     61
    5862private:
    5963    UniqueRef<Expression> m_leftValue;
     64    AddressEscapeMode m_addressEscapeMode;
    6065};
    6166
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r248022 r248303  
    126126    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), &firstArgument, String(), nullptr, nullptr));
    127127    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), AST::TypeReference::wrap(location, intrinsics.uintType()), String(), nullptr, nullptr));
    128     return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
     128    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    129129}
    130130
     
    135135    AST::VariableDeclarations parameters;
    136136    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), &firstArgument, String(), nullptr, nullptr));
    137     return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
     137    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    138138}
    139139
     
    157157    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), argumentType.copyRef(), String(), nullptr, nullptr));
    158158    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), WTFMove(argumentType), String(), nullptr, nullptr));
    159     return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
     159    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    160160}
    161161
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp

    r247917 r248303  
    6060
    6161// FIXME: https://bugs.webkit.org/show_bug.cgi?id=195682 Return a better error code from this, and report it to JavaScript.
    62 auto Parser::parse(Program& program, StringView stringView, Mode mode) -> Expected<void, Error>
     62auto Parser::parse(Program& program, StringView stringView, ParsingMode mode) -> Expected<void, Error>
    6363{
    6464    m_lexer = Lexer(stringView);
     
    9595        }
    9696        case Token::Type::Native: {
    97             ASSERT(m_mode == Mode::StandardLibrary);
     97            ASSERT(m_mode == ParsingMode::StandardLibrary);
    9898            auto furtherToken = peekFurther();
    9999            if (!furtherToken)
     
    987987
    988988    bool isOperator = false;
    989     return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, WTFMove(*attributeBlock), AST::EntryPointType::Compute, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
     989    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, WTFMove(*attributeBlock), AST::EntryPointType::Compute, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator, m_mode);
    990990}
    991991
     
    10051005
    10061006    bool isOperator = false;
    1007     return AST::FunctionDeclaration({ entryPoint->startOffset(), endOffset }, { }, entryPointType, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
     1007    return AST::FunctionDeclaration({ entryPoint->startOffset(), endOffset }, { }, entryPointType, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator, m_mode);
    10081008}
    10091009
     
    10241024    auto endOffset = m_lexer.peek().startOffset();
    10251025
    1026     return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
     1026    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator, m_mode);
    10271027}
    10281028
     
    10371037
    10381038    bool isOperator = true;
    1039     return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), "operator cast"_str, WTFMove(*parameters), WTFMove(*semantic), isOperator);
     1039    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), "operator cast"_str, WTFMove(*parameters), WTFMove(*semantic), isOperator, m_mode);
    10401040}
    10411041
     
    19381938        }
    19391939        case Token::Type::And:
    1940             return { makeUniqueRef<AST::MakePointerExpression>(location, WTFMove(*next)) };
     1940            return { makeUniqueRef<AST::MakePointerExpression>(location, WTFMove(*next), AST::AddressEscapeMode::Escapes) };
    19411941        case Token::Type::At:
    1942             return { makeUniqueRef<AST::MakeArrayReferenceExpression>(location, WTFMove(*next)) };
     1942            return { makeUniqueRef<AST::MakeArrayReferenceExpression>(location, WTFMove(*next), AST::AddressEscapeMode::Escapes) };
    19431943        default:
    19441944            ASSERT(prefix->type == Token::Type::Star);
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h

    r247878 r248303  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WHLSLArrayReferenceType.h"
    31 #include "WHLSLArrayType.h"
    32 #include "WHLSLAssignmentExpression.h"
    33 #include "WHLSLBaseFunctionAttribute.h"
    34 #include "WHLSLBaseSemantic.h"
    35 #include "WHLSLBlock.h"
    36 #include "WHLSLBooleanLiteral.h"
    37 #include "WHLSLBreak.h"
    38 #include "WHLSLBuiltInSemantic.h"
    39 #include "WHLSLCallExpression.h"
    40 #include "WHLSLCommaExpression.h"
    41 #include "WHLSLConstantExpression.h"
    42 #include "WHLSLContinue.h"
    43 #include "WHLSLDereferenceExpression.h"
    44 #include "WHLSLDoWhileLoop.h"
    45 #include "WHLSLDotExpression.h"
    46 #include "WHLSLEffectfulExpressionStatement.h"
    47 #include "WHLSLEnumerationDefinition.h"
    48 #include "WHLSLEnumerationMember.h"
     30#include "WHLSLAST.h"
    4931#include "WHLSLError.h"
    50 #include "WHLSLExpression.h"
    51 #include "WHLSLFallthrough.h"
    52 #include "WHLSLFloatLiteral.h"
    53 #include "WHLSLForLoop.h"
    54 #include "WHLSLFunctionAttribute.h"
    55 #include "WHLSLFunctionDeclaration.h"
    56 #include "WHLSLFunctionDefinition.h"
    57 #include "WHLSLIfStatement.h"
    58 #include "WHLSLIndexExpression.h"
    59 #include "WHLSLIntegerLiteral.h"
    6032#include "WHLSLLexer.h"
    61 #include "WHLSLLogicalExpression.h"
    62 #include "WHLSLLogicalNotExpression.h"
    63 #include "WHLSLMakeArrayReferenceExpression.h"
    64 #include "WHLSLMakePointerExpression.h"
    65 #include "WHLSLNativeFunctionDeclaration.h"
    66 #include "WHLSLNativeTypeDeclaration.h"
    67 #include "WHLSLNullLiteral.h"
    68 #include "WHLSLNumThreadsFunctionAttribute.h"
    69 #include "WHLSLPointerType.h"
     33#include "WHLSLParsingMode.h"
    7034#include "WHLSLProgram.h"
    71 #include "WHLSLPropertyAccessExpression.h"
    72 #include "WHLSLQualifier.h"
    73 #include "WHLSLReadModifyWriteExpression.h"
    74 #include "WHLSLReferenceType.h"
    75 #include "WHLSLResourceSemantic.h"
    76 #include "WHLSLReturn.h"
    77 #include "WHLSLSemantic.h"
    78 #include "WHLSLSpecializationConstantSemantic.h"
    79 #include "WHLSLStageInOutSemantic.h"
    80 #include "WHLSLStatement.h"
    81 #include "WHLSLStructureDefinition.h"
    82 #include "WHLSLStructureElement.h"
    83 #include "WHLSLSwitchCase.h"
    84 #include "WHLSLSwitchStatement.h"
    85 #include "WHLSLTernaryExpression.h"
    86 #include "WHLSLType.h"
    87 #include "WHLSLTypeArgument.h"
    88 #include "WHLSLTypeDefinition.h"
    89 #include "WHLSLTypeReference.h"
    90 #include "WHLSLUnsignedIntegerLiteral.h"
    91 #include "WHLSLVariableDeclaration.h"
    92 #include "WHLSLVariableDeclarationsStatement.h"
    93 #include "WHLSLVariableReference.h"
    94 #include "WHLSLWhileLoop.h"
    9535#include <wtf/Expected.h>
    9636#include <wtf/Optional.h>
     
    10343class Parser {
    10444public:
    105     enum class Mode {
    106         StandardLibrary,
    107         User
    108     };
    109 
    110     Expected<void, Error> parse(Program&, StringView, Mode);
     45    Expected<void, Error> parse(Program&, StringView, ParsingMode);
    11146
    11247private:
     
    233168
    234169    Lexer m_lexer;
    235     Mode m_mode;
     170    ParsingMode m_mode;
    236171};
    237172
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParsingMode.h

    r248302 r248303  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WHLSLExpression.h"
    31 #include <wtf/FastMalloc.h>
    32 #include <wtf/UniqueRef.h>
    33 
    3430namespace WebCore {
    3531
    3632namespace WHLSL {
    3733
    38 namespace AST {
    39 
    40 class MakePointerExpression : public Expression {
    41     WTF_MAKE_FAST_ALLOCATED;
    42 public:
    43     MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
    44         : Expression(location)
    45         , m_leftValue(WTFMove(leftValue))
    46     {
    47     }
    48 
    49     virtual ~MakePointerExpression() = default;
    50 
    51     MakePointerExpression(const MakePointerExpression&) = delete;
    52     MakePointerExpression(MakePointerExpression&&) = default;
    53 
    54     bool isMakePointerExpression() const override { return true; }
    55 
    56     Expression& leftValue() { return m_leftValue; }
    57 
    58 private:
    59     UniqueRef<Expression> m_leftValue;
     34enum class ParsingMode : uint8_t {
     35    StandardLibrary,
     36    User
    6037};
    6138
    62 } // namespace AST
     39} // namespace WHLSL
    6340
    64 }
     41} // namespace WebCore
    6542
    66 }
    67 
    68 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(MakePointerExpression, isMakePointerExpression())
    69 
    70 #endif
     43#endif // ENABLE(WEBGPU)
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp

    r247834 r248303  
    158158    {
    159159        PhaseTimer phaseTimer("parse", phaseTimes);
    160         auto parseResult = parser.parse(program, whlslSource, Parser::Mode::User);
     160        auto parseResult = parser.parse(program, whlslSource, ParsingMode::User);
    161161        if (!parseResult) {
    162162            if (dumpPassFailure)
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp

    r247878 r248303  
    7878    void visit(AST::MakePointerExpression& makePointerExpression) override
    7979    {
    80         escapeVariableUse(makePointerExpression.leftValue());
     80        if (makePointerExpression.mightEscape())
     81            escapeVariableUse(makePointerExpression.leftValue());
    8182    }
    8283
    8384    void visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpression) override
    8485    {
    85         escapeVariableUse(makeArrayReferenceExpression.leftValue());
     86        if (makeArrayReferenceExpression.mightEscape())
     87            escapeVariableUse(makeArrayReferenceExpression.leftValue());
    8688    }
    8789
     
    134136    void visit(AST::FunctionDefinition& functionDefinition) override
    135137    {
     138        if (functionDefinition.parsingMode() == ParsingMode::StandardLibrary)
     139            return;
     140
    136141        bool isEntryPoint = !!functionDefinition.entryPointType();
    137142        if (isEntryPoint) {
     
    147152            auto structDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.codeLocation(), WTFMove(structVariableDeclarations));
    148153
    149             auto makePointerExpression = std::make_unique<AST::MakePointerExpression>(functionDefinition.codeLocation(), WTFMove(structVariableReference));
     154            auto makePointerExpression = std::make_unique<AST::MakePointerExpression>(functionDefinition.codeLocation(), WTFMove(structVariableReference), AST::AddressEscapeMode::DoesNotEscape);
    150155            makePointerExpression->setType(m_pointerToStructType.copyRef());
    151156            makePointerExpression->setTypeAnnotation(AST::RightValue());
     
    191196        // This works because it's illegal to call an entrypoint. Therefore, we can only
    192197        // call functions where we've already appended this struct as its final parameter.
    193         if (!callExpression.function().isNativeFunctionDeclaration())
     198        if (!callExpression.function().isNativeFunctionDeclaration() && callExpression.function().parsingMode() != ParsingMode::StandardLibrary)
    194199            callExpression.arguments().append(makeStructVariableReference());
    195200    }
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp

    r247878 r248303  
    9999
    100100template <typename ExpressionConstructor, typename TypeConstructor>
    101 static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, Ref<AST::UnnamedType> baseType, bool anderFunction, bool threadAnderFunction)
    102 {
     101static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, Ref<AST::UnnamedType> baseType, AST::FunctionDeclaration* anderFunction, AST::FunctionDeclaration* threadAnderFunction)
     102{
     103    auto functionEscapeMode = [] (AST::FunctionDeclaration& functionDeclaration) {
     104        if (functionDeclaration.isNativeFunctionDeclaration() || functionDeclaration.parsingMode() == ParsingMode::StandardLibrary)
     105            return AST::AddressEscapeMode::DoesNotEscape;
     106        return AST::AddressEscapeMode::Escapes;
     107    };
     108
    103109    auto location = expression->codeLocation();
    104110    if (auto addressSpace = expression->typeAnnotation().leftAddressSpace()) {
    105111        if (!anderFunction)
    106112            return WTF::nullopt;
    107         auto makeArrayReference = makeUniqueRef<ExpressionConstructor>(location, WTFMove(expression));
     113        auto makeArrayReference = makeUniqueRef<ExpressionConstructor>(location, WTFMove(expression), functionEscapeMode(*anderFunction));
    108114        makeArrayReference->setType(TypeConstructor::create(location, *addressSpace, WTFMove(baseType)));
    109115        makeArrayReference->setTypeAnnotation(AST::RightValue());
     
    125131        variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
    126132
    127         auto expression = makeUniqueRef<ExpressionConstructor>(location, WTFMove(variableReference2));
     133        auto expression = makeUniqueRef<ExpressionConstructor>(location, WTFMove(variableReference2), functionEscapeMode(*threadAnderFunction));
    128134        auto resultType = TypeConstructor::create(location, AST::AddressSpace::Thread, WTFMove(baseType));
    129135        expression->setType(resultType.copyRef());
     
    141147}
    142148
    143 static Optional<AnderCallArgumentResult> anderCallArgument(UniqueRef<AST::Expression>& expression, bool anderFunction, bool threadAnderFunction)
     149static Optional<AnderCallArgumentResult> anderCallArgument(UniqueRef<AST::Expression>& expression, AST::FunctionDeclaration* anderFunction, AST::FunctionDeclaration* threadAnderFunction)
    144150{
    145151    if (!anderFunction && !threadAnderFunction)
     
    173179        // *operator&.foo(&v) = newValue
    174180        auto leftValue = leftValueFactory();
    175         auto argument = anderCallArgument(leftValue, true, true);
     181        auto argument = anderCallArgument(leftValue, relevantAnder, relevantAnder);
    176182        ASSERT(argument);
    177183        ASSERT(!argument->variableDeclaration);
     
    234240        // *operator&.foo(&v)
    235241        auto leftValue = leftValueFactory();
    236         auto argument = anderCallArgument(leftValue, true, true);
     242        auto argument = anderCallArgument(leftValue, relevantAnder, relevantAnder);
    237243        ASSERT(argument);
    238244        ASSERT(!argument->variableDeclaration);
     
    363369    // Step 1:
    364370    {
    365         auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(innerLeftExpression.codeLocation(), WTFMove(leftExpression));
     371        auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(innerLeftExpression.codeLocation(), WTFMove(leftExpression), AST::AddressEscapeMode::DoesNotEscape);
    366372        makePointerExpression->setType(AST::PointerType::create(innerLeftExpression.codeLocation(), *innerLeftExpression.typeAnnotation().leftAddressSpace(), innerLeftExpression.resolvedType()));
    367373        makePointerExpression->setTypeAnnotation(AST::RightValue());
     
    560566
    561567        {
    562             auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(leftValueLocation, readModifyWriteExpression.takeLeftValue());
     568            auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(leftValueLocation, readModifyWriteExpression.takeLeftValue(), AST::AddressEscapeMode::DoesNotEscape);
    563569            makePointerExpression->setType(pointerType.copyRef());
    564570            makePointerExpression->setTypeAnnotation(AST::RightValue());
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibraryUtilities.cpp

    r247834 r248303  
    8080    static NeverDestroyed<String> standardLibrary(decompressAndDecodeStandardLibrary());
    8181    if (parseFullStandardLibrary) {
    82         auto parseResult = parser.parse(program, standardLibrary.get(), Parser::Mode::StandardLibrary);
     82        auto parseResult = parser.parse(program, standardLibrary.get(), ParsingMode::StandardLibrary);
    8383        if (!parseResult) {
    8484            dataLogLn("failed to parse the (full) standard library: ", Lexer::errorString(StringView(standardLibrary), parseResult.error()));
     
    9191
    9292    auto stringView = StringView(standardLibrary.get()).substring(0, firstFunctionOffsetInStandardLibrary());
    93     auto parseResult = parser.parse(program, stringView, Parser::Mode::StandardLibrary);
     93    auto parseResult = parser.parse(program, stringView, ParsingMode::StandardLibrary);
    9494    ASSERT_UNUSED(parseResult, parseResult);
    9595
     
    111111                continue;
    112112            auto stringView = StringView(standardLibrary.get()).substring(iterator->value.start, iterator->value.end - iterator->value.start);
    113             auto parseResult = parser.parse(program, stringView, Parser::Mode::StandardLibrary);
     113            auto parseResult = parser.parse(program, stringView, ParsingMode::StandardLibrary);
    114114            if (!parseResult) {
    115115                dataLogLn("failed to parse the (partial) standard library: ", Lexer::errorString(stringView, parseResult.error()));
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp

    r247878 r248303  
    7070        AST::VariableDeclarations parameters;
    7171        parameters.append(WTFMove(variableDeclaration));
    72         AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().uintType()), "operator.length"_str, WTFMove(parameters), nullptr, isOperator));
     72        AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().uintType()), "operator.length"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    7373        if (!program.append(WTFMove(nativeFunctionDeclaration)))
    7474            return makeUnexpected(Error("Cannot synthesize operator.length for array type."));
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp

    r247878 r248303  
    163163            AST::VariableDeclarations parameters;
    164164            parameters.append(WTFMove(variableDeclaration));
    165             AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType, "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
     165            AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType, "operator cast"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    166166            program.append(WTFMove(copyConstructor));
    167167        }
    168168
    169         AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType, "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
     169        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType, "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator, ParsingMode::StandardLibrary));
    170170        if (!program.append(WTFMove(defaultConstructor)))
    171171            return makeUnexpected(Error("Could not synthesize default constructor"));
     
    183183        AST::VariableDeclarations parameters;
    184184        parameters.append(WTFMove(variableDeclaration));
    185         AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
     185        AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    186186        program.append(WTFMove(copyConstructor));
    187187
     
    191191                continue;
    192192        }
    193         AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
     193        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator, ParsingMode::StandardLibrary));
    194194        if (!program.append(WTFMove(defaultConstructor)))
    195195            return makeUnexpected(Error("Could not synthesize default constructor"));
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp

    r247878 r248303  
    4848            parameters.append(WTFMove(variableDeclaration1));
    4949            parameters.append(WTFMove(variableDeclaration2));
    50             AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().boolType()), "operator=="_str, WTFMove(parameters), nullptr, isOperator));
     50            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().boolType()), "operator=="_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    5151            if (!program.append(WTFMove(nativeFunctionDeclaration)))
    5252                return makeUnexpected(Error("Cannot create operator== for enum type."));
     
    5757            AST::VariableDeclarations parameters;
    5858            parameters.append(WTFMove(variableDeclaration));
    59             AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type(), "operator.value"_str, WTFMove(parameters), nullptr, isOperator));
     59            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type(), "operator.value"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    6060            if (!program.append(WTFMove(nativeFunctionDeclaration)))
    6161                return makeUnexpected(Error("Cannot create operator.value for enum type."));
     
    6666            AST::VariableDeclarations parameters;
    6767            parameters.append(WTFMove(variableDeclaration));
    68             AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
     68            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    6969            if (!program.append(WTFMove(nativeFunctionDeclaration)))
    7070                return makeUnexpected(Error("Cannot create copy constructor for enum type."));
     
    7575            AST::VariableDeclarations parameters;
    7676            parameters.append(WTFMove(variableDeclaration));
    77             AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, enumerationDefinition), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
     77            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, enumerationDefinition), "operator cast"_str, WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    7878            if (!program.append(WTFMove(nativeFunctionDeclaration)))
    7979                return makeUnexpected(Error("Cannot create 'operator cast' for enum type."));
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp

    r247878 r248303  
    5252                parameters.append(WTFMove(variableDeclaration));
    5353                auto returnType = AST::PointerType::create(structureElement.codeLocation(), addressSpace, structureElement.type());
    54                 AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(structureElement.codeLocation(), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), makeString("operator&.", structureElement.name()), WTFMove(parameters), nullptr, isOperator));
     54                AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(structureElement.codeLocation(), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), makeString("operator&.", structureElement.name()), WTFMove(parameters), nullptr, isOperator, ParsingMode::StandardLibrary));
    5555                return nativeFunctionDeclaration;
    5656            };
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r248282 r248303  
    83208320                526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationCocoa.mm; sourceTree = "<group>"; };
    83218321                526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentationCocoa.h; sourceTree = "<group>"; };
     8322                52914C2A22F93E4E00578150 /* WHLSLParsingMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLParsingMode.h; sourceTree = "<group>"; };
     8323                52914C2C22F93E5D00578150 /* WHLSLAddressEscapeMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAddressEscapeMode.h; sourceTree = "<group>"; };
    83228324                52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformView.h; sourceTree = "<group>"; };
    83238325                52B0D4BF1C57FD660077CE53 /* VideoFullscreenChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenChangeObserver.h; sourceTree = "<group>"; };
     
    1705617058                        children = (
    1705717059                                1C840B9021EC30F900D0500D /* WHLSLAddressSpace.h */,
     17060                                52914C2C22F93E5D00578150 /* WHLSLAddressEscapeMode.h */,
    1705817061                                C21BF72521CD89E200227979 /* WHLSLArrayReferenceType.h */,
    1705917062                                C21BF70921CD89CA00227979 /* WHLSLArrayType.h */,
     
    2552725530                                C21BF73721CD8A0200227979 /* WHLSLParser.cpp */,
    2552825531                                C21BF73821CD8A0300227979 /* WHLSLParser.h */,
     25532                                52914C2A22F93E4E00578150 /* WHLSLParsingMode.h */,
    2552925533                                C24A57AF21FAD53F004C6DD1 /* WHLSLPipelineDescriptor.h */,
    2553025534                                C24A57BA21FEAFEA004C6DD1 /* WHLSLPrepare.cpp */,
Note: See TracChangeset for help on using the changeset viewer.