Skip to content

Commit

Permalink
[WGSL] Convert statement nodes to be arena allocated
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=256600
rdar://109163279

Reviewed by Dan Glastonbury.

Continue incrementally converting nodes to be arena allocated

* Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h:
* Source/WebGPU/WGSL/AST/ASTBreakStatement.h:
* Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h:
(WGSL::AST::CompoundAssignmentStatement::leftExpression):
(WGSL::AST::CompoundAssignmentStatement::rightExpression):
(WGSL::AST::CompoundAssignmentStatement::operation const):
* Source/WebGPU/WGSL/AST/ASTCompoundStatement.h:
* Source/WebGPU/WGSL/AST/ASTContinueStatement.h:
* Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h:
* Source/WebGPU/WGSL/AST/ASTDiscardStatement.h:
* Source/WebGPU/WGSL/AST/ASTForStatement.h:
* Source/WebGPU/WGSL/AST/ASTFunction.h:
* Source/WebGPU/WGSL/AST/ASTIfStatement.h:
* Source/WebGPU/WGSL/AST/ASTLoopStatement.h:
* Source/WebGPU/WGSL/AST/ASTPhonyStatement.h:
* Source/WebGPU/WGSL/AST/ASTReturnStatement.h:
* Source/WebGPU/WGSL/AST/ASTStatement.h:
* Source/WebGPU/WGSL/AST/ASTStaticAssertStatement.h:
* Source/WebGPU/WGSL/AST/ASTSwitchStatement.h:
* Source/WebGPU/WGSL/AST/ASTVariable.h:
* Source/WebGPU/WGSL/AST/ASTVariableStatement.h:
* Source/WebGPU/WGSL/AST/ASTWhileStatement.h:
* Source/WebGPU/WGSL/EntryPointRewriter.cpp:
(WGSL::EntryPointRewriter::materialize):
(WGSL::EntryPointRewriter::visit):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parseStatement):
(WGSL::Parser<Lexer>::parseCompoundStatement):
(WGSL::Parser<Lexer>::parseIfStatement):
(WGSL::Parser<Lexer>::parseIfStatementWithAttributes):
(WGSL::Parser<Lexer>::parseForStatement):
(WGSL::Parser<Lexer>::parseReturnStatement):
* Source/WebGPU/WGSL/ParserPrivate.h:

Canonical link: https://commits.webkit.org/263956@main
  • Loading branch information
tadeuzagallo committed May 11, 2023
1 parent 51a237c commit e911b9b
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 137 deletions.
12 changes: 6 additions & 6 deletions Source/WebGPU/WGSL/AST/ASTAssignmentStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
namespace WGSL::AST {

class AssignmentStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(AssignmentStatement);
public:
NodeKind kind() const override;
Expression& lhs() { return m_lhs.get(); }
Expression& rhs() { return m_rhs.get(); }

private:
AssignmentStatement(SourceSpan span, Expression::Ref&& lhs, Expression::Ref&& rhs)
: Statement(span)
, m_lhs(WTFMove(lhs))
, m_rhs(WTFMove(rhs))
{ }

NodeKind kind() const override;
Expression& lhs() { return m_lhs.get(); }
Expression& rhs() { return m_rhs.get(); }

private:
Expression::Ref m_lhs;
Expression::Ref m_rhs;
};
Expand Down
7 changes: 4 additions & 3 deletions Source/WebGPU/WGSL/AST/ASTBreakStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
namespace WGSL::AST {

class BreakStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(BreakStatement);
public:
NodeKind kind() const override;

private:
BreakStatement(SourceSpan span)
: Statement(span)
{ }

NodeKind kind() const override;
};

} // namespace WGSL::AST
Expand Down
14 changes: 7 additions & 7 deletions Source/WebGPU/WGSL/AST/ASTCompoundAssignmentStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
namespace WGSL::AST {

class CompoundAssignmentStatement : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(CompoundAssignmentStatement);
public:
NodeKind kind() const override;
Expression& leftExpression() { return m_leftExpression; }
Expression& rightExpression() { return m_rightExpression; }
BinaryOperation operation() const { return m_operation; }

private:
CompoundAssignmentStatement(SourceSpan span, Expression::Ref&& lhs, Expression::Ref&& rhs, BinaryOperation operation)
: Statement(span)
, m_leftExpression(WTFMove(lhs))
, m_rightExpression(WTFMove(rhs))
, m_operation(operation)
{ }

NodeKind kind() const override;
Expression& leftExpression() { return m_leftExpression; }
Expression& rightExpression() { return m_rightExpression; }
BinaryOperation operation() const { return m_operation; }

private:
Expression::Ref m_leftExpression;
Expression::Ref m_rightExpression;
BinaryOperation m_operation;
Expand Down
13 changes: 6 additions & 7 deletions Source/WebGPU/WGSL/AST/ASTCompoundStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@
namespace WGSL::AST {

class CompoundStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(CompoundStatement);
public:
using Ref = std::reference_wrapper<CompoundStatement>;

using Ref = UniqueRef<CompoundStatement>;
NodeKind kind() const override;
Statement::List& statements() { return m_statements; }
const Statement::List& statements() const { return m_statements; }

private:
CompoundStatement(SourceSpan span, Statement::List&& statements)
: Statement(span)
, m_statements(WTFMove(statements))
{ }

NodeKind kind() const override;
Statement::List& statements() { return m_statements; }
const Statement::List& statements() const { return m_statements; }

private:
Statement::List m_statements;
};

Expand Down
7 changes: 4 additions & 3 deletions Source/WebGPU/WGSL/AST/ASTContinueStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
namespace WGSL::AST {

class ContinueStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(ContinueStatement);
public:
NodeKind kind() const override;

private:
ContinueStatement(SourceSpan span)
: Statement(span)
{ }

NodeKind kind() const override;
};

} // namespace WGSL::AST
Expand Down
11 changes: 5 additions & 6 deletions Source/WebGPU/WGSL/AST/ASTDecrementIncrementStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
namespace WGSL::AST {

class DecrementIncrementStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(DecrementIncrementStatement);
public:

enum class Operation : uint8_t {
Decrement,
Increment,
};

NodeKind kind() const override;
Expression& expression() { return m_expression; }

private:
DecrementIncrementStatement(SourceSpan span, Expression::Ref&& expression)
: Statement(span)
, m_expression(WTFMove(expression))
{ }

NodeKind kind() const override;
Expression& expression() { return m_expression; }

private:
Expression::Ref m_expression;
};

Expand Down
9 changes: 4 additions & 5 deletions Source/WebGPU/WGSL/AST/ASTDiscardStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@

#pragma once

#pragma once

#include "ASTStatement.h"

namespace WGSL::AST {

class DiscardStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(DiscardStatement);
public:
NodeKind kind() const override;

private:
DiscardStatement(SourceSpan span)
: Statement(span)
{ }

NodeKind kind() const override;
};

} // namespace WGSL::AST
Expand Down
24 changes: 12 additions & 12 deletions Source/WebGPU/WGSL/AST/ASTForStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
namespace WGSL::AST {

class ForStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(ForStatement);
public:
ForStatement(SourceSpan span, Statement::Ptr&& initializer, Expression::Ptr test, Statement::Ptr&& update, CompoundStatement&& body)
: Statement(span)
, m_initializer(WTFMove(initializer))
, m_test(test)
, m_update(WTFMove(update))
, m_body(WTFMove(body))
{ }

NodeKind kind() const override;
Statement* maybeInitializer() { return m_initializer.get(); }
Statement* maybeInitializer() { return m_initializer; }
Expression* maybeTest() { return m_test; }
Statement* maybeUpdate() { return m_update.get(); }
Statement* maybeUpdate() { return m_update; }
CompoundStatement& body() { return m_body; }

private:
ForStatement(SourceSpan span, Statement::Ptr initializer, Expression::Ptr test, Statement::Ptr update, CompoundStatement::Ref&& body)
: Statement(span)
, m_initializer(initializer)
, m_test(test)
, m_update(update)
, m_body(WTFMove(body))
{ }

Statement::Ptr m_initializer;
Expression::Ptr m_test;
Statement::Ptr m_update;
CompoundStatement m_body;
CompoundStatement::Ref m_body;
};

} // namespace WGSL::AST
Expand Down
8 changes: 4 additions & 4 deletions Source/WebGPU/WGSL/AST/ASTFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ class Function final : public Declaration {
Attribute::List& attributes() { return m_attributes; }
Attribute::List& returnAttributes() { return m_returnAttributes; }
TypeName* maybeReturnType() { return m_returnType; }
CompoundStatement& body() { return m_body; }
CompoundStatement& body() { return m_body.get(); }
const Identifier& name() const { return m_name; }
const Parameter::List& parameters() const { return m_parameters; }
const Attribute::List& attributes() const { return m_attributes; }
const Attribute::List& returnAttributes() const { return m_returnAttributes; }
const TypeName* maybeReturnType() const { return m_returnType; }
const CompoundStatement& body() const { return m_body; }
const CompoundStatement& body() const { return m_body.get(); }

private:
Function(SourceSpan span, Identifier&& name, Parameter::List&& parameters, TypeName::Ptr returnType, CompoundStatement&& body, Attribute::List&& attributes, Attribute::List&& returnAttributes)
Function(SourceSpan span, Identifier&& name, Parameter::List&& parameters, TypeName::Ptr returnType, CompoundStatement::Ref&& body, Attribute::List&& attributes, Attribute::List&& returnAttributes)
: Declaration(span)
, m_name(WTFMove(name))
, m_parameters(WTFMove(parameters))
Expand All @@ -71,7 +71,7 @@ class Function final : public Declaration {
Attribute::List m_attributes;
Attribute::List m_returnAttributes;
TypeName::Ptr m_returnType;
CompoundStatement m_body;
CompoundStatement::Ref m_body;
};

} // namespace WGSL::AST
Expand Down
22 changes: 11 additions & 11 deletions Source/WebGPU/WGSL/AST/ASTIfStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
namespace WGSL::AST {

class IfStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(IfStatement);
public:
IfStatement(SourceSpan span, Expression::Ref&& test, CompoundStatement&& trueBody, Statement::Ptr&& falseBody, Attribute::List&& attributes)
NodeKind kind() const override;
Expression& test() { return m_test.get(); }
CompoundStatement& trueBody() { return m_trueBody.get(); }
Statement* maybeFalseBody() { return m_falseBody; }
Attribute::List& attributes() { return m_attributes; }

private:
IfStatement(SourceSpan span, Expression::Ref&& test, CompoundStatement::Ref&& trueBody, Statement::Ptr falseBody, Attribute::List&& attributes)
: Statement(span)
, m_test(WTFMove(test))
, m_trueBody(WTFMove(trueBody))
, m_falseBody(WTFMove(falseBody))
, m_falseBody(falseBody)
, m_attributes(WTFMove(attributes))
{ }

NodeKind kind() const override;
Expression& test() { return m_test.get(); }
CompoundStatement& trueBody() { return m_trueBody; }
Statement* maybeFalseBody() { return m_falseBody.get(); }
Attribute::List& attributes() { return m_attributes; }

private:
Expression::Ref m_test;
CompoundStatement m_trueBody;
CompoundStatement::Ref m_trueBody;
Statement::Ptr m_falseBody;
Attribute::List m_attributes;
};
Expand Down
12 changes: 6 additions & 6 deletions Source/WebGPU/WGSL/AST/ASTLoopStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
namespace WGSL::AST {

class LoopStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(LoopStatement);
public:
NodeKind kind() const override;
CompoundStatement& body() { return m_body.get(); }
CompoundStatement& continuingBody() { return m_continuingBody.get(); }

private:
LoopStatement(SourceSpan span, CompoundStatement::Ref&& body, CompoundStatement::Ref&& continuingBody)
: Statement(span)
, m_body(WTFMove(body))
, m_continuingBody(WTFMove(continuingBody))
{ }

NodeKind kind() const override;
CompoundStatement& body() { return m_body.get(); }
CompoundStatement& continuingBody() { return m_continuingBody.get(); }

private:
CompoundStatement::Ref m_body;
CompoundStatement::Ref m_continuingBody;
};
Expand Down
10 changes: 5 additions & 5 deletions Source/WebGPU/WGSL/AST/ASTPhonyStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
namespace WGSL::AST {

class PhonyAssignmentStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(PhonyAssignmentStatement);
public:
NodeKind kind() const override;
Expression& rhs() { return m_rhs.get(); }

private:
PhonyAssignmentStatement(SourceSpan span, Expression::Ref&& rhs)
: Statement(span)
, m_rhs(WTFMove(rhs))
{ }

NodeKind kind() const override;
Expression& rhs() { return m_rhs.get(); }

private:
Expression::Ref m_rhs;
};

Expand Down
10 changes: 5 additions & 5 deletions Source/WebGPU/WGSL/AST/ASTReturnStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
namespace WGSL::AST {

class ReturnStatement final : public Statement {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(ReturnStatement);
public:
NodeKind kind() const override;
Expression* maybeExpression() { return m_expression; }

private:
ReturnStatement(SourceSpan span, Expression::Ptr expression)
: Statement(span)
, m_expression(expression)
{ }

NodeKind kind() const override;
Expression* maybeExpression() { return m_expression; }

private:
Expression::Ptr m_expression;
};

Expand Down
13 changes: 7 additions & 6 deletions Source/WebGPU/WGSL/AST/ASTStatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@

#pragma once

#include "ASTBuilder.h"
#include "ASTNode.h"

#include <wtf/UniqueRefVector.h>
#include <wtf/ReferenceWrapperVector.h>

namespace WGSL::AST {

class Statement : public Node {
WTF_MAKE_FAST_ALLOCATED;
WGSL_AST_BUILDER_NODE(Statement);
public:
using Ref = UniqueRef<Statement>;
using Ptr = std::unique_ptr<Statement>;
using List = UniqueRefVector<Statement>;
using Ref = std::reference_wrapper<Statement>;
using Ptr = Statement*;
using List = ReferenceWrapperVector<Statement>;

protected:
Statement(SourceSpan span)
: Node(span)
{ }
Expand Down
Loading

0 comments on commit e911b9b

Please sign in to comment.