Changeset 245945 in webkit
- Timestamp:
- May 30, 2019, 9:31:54 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 19 edited
- 3 copied
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime-2-expected.html (added)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime-2.html (added)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime-3-expected.html (added)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime-3.html (added)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime-expected.html (added)
-
LayoutTests/webgpu/whlsl-ensure-proper-variable-lifetime.html (added)
-
LayoutTests/webgpu/whlsl-return-local-variable-expected.html (added)
-
LayoutTests/webgpu/whlsl-return-local-variable.html (added)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/PrintStream.h (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAST.h (modified) (2 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.h (modified) (4 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h (modified) (1 diff)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h (copied) (copied from trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLValue.h ) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h (modified) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatementList.h (copied) (copied from trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLValue.h ) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLValue.h (modified) (2 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h (modified) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h (modified) (1 diff)
-
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h (modified) (5 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp (modified) (4 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp (added)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h (copied) (copied from trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLValue.h ) (1 diff)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp (modified) (4 diffs)
-
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.h (modified) (4 diffs)
-
Source/WebCore/Sources.txt (modified) (1 diff)
-
Source/WebCore/WebCore.xcodeproj/project.pbxproj (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r245944 r245945 1 2019-05-30 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Enforce variable lifetimes 4 https://bugs.webkit.org/show_bug.cgi?id=195794 5 <rdar://problem/50746293> 6 7 Reviewed by Myles C. Maxfield. 8 9 * webgpu/whlsl-ensure-proper-variable-lifetime-2-expected.html: Added. 10 * webgpu/whlsl-ensure-proper-variable-lifetime-2.html: Added. 11 * webgpu/whlsl-ensure-proper-variable-lifetime-3-expected.html: Added. 12 * webgpu/whlsl-ensure-proper-variable-lifetime-3.html: Added. 13 * webgpu/whlsl-ensure-proper-variable-lifetime-expected.html: Added. 14 * webgpu/whlsl-ensure-proper-variable-lifetime.html: Added. 15 * webgpu/whlsl-return-local-variable-expected.html: Added. 16 * webgpu/whlsl-return-local-variable.html: Added. 17 1 18 2019-05-30 Ryan Haddad <ryanhaddad@apple.com> 2 19 -
trunk/Source/WTF/ChangeLog
r245898 r245945 1 2019-05-30 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Enforce variable lifetimes 4 https://bugs.webkit.org/show_bug.cgi?id=195794 5 <rdar://problem/50746293> 6 7 Reviewed by Myles C. Maxfield. 8 9 * wtf/PrintStream.h: 10 1 11 2019-05-30 Keith Rollin <krollin@apple.com> 2 12 -
trunk/Source/WTF/wtf/PrintStream.h
r239427 r245945 133 133 class Name { \ 134 134 public: \ 135 Name( const Type& value)\135 Name(Type value) \ 136 136 : m_value(value) \ 137 137 { \ -
trunk/Source/WebCore/ChangeLog
r245944 r245945 1 2019-05-30 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Enforce variable lifetimes 4 https://bugs.webkit.org/show_bug.cgi?id=195794 5 <rdar://problem/50746293> 6 7 Reviewed by Myles C. Maxfield. 8 9 In WHLSL, each variable has global lifetime. So returning a pointer to a 10 local variable is a legitimate and well specified thing to do. Each local 11 variable has a unique place in memory. So, for example: 12 13 ``` 14 thread int* ptr() { int local; return &local; } 15 thread int* ptrPtr() { return ptr(); } 16 ``` 17 18 In the above program, ptr() must always return the same value 19 as ptrPtr(). So, the following would print "42": 20 ``` 21 thread int* p = ptrPtr(); 22 *ptr() = 42; 23 print(*p); 24 ``` 25 26 To implement these semantics, this patch introduces a new pass which does the 27 following transformations: 28 - It notes every variable whose address is taken in the program. 29 - Each such variable gets defined as a field in a struct. 30 - Each function which is an entry point defines this struct. 31 - Each non entry point takes a pointer to this struct as its final parameter. 32 - Each call to a non-native function is rewritten to pass a pointer to the 33 struct as the last call argument. 34 - Each variable reference to "x", where "x" ends up in the struct, is 35 modified to instead be "struct->x". We store to "struct->x" after declaring 36 "x". If "x" is a function parameter, we store to "struct->x" as the first 37 thing we do in the function body. 38 39 Tests: webgpu/whlsl-ensure-proper-variable-lifetime-2.html 40 webgpu/whlsl-ensure-proper-variable-lifetime-3.html 41 webgpu/whlsl-ensure-proper-variable-lifetime.html 42 webgpu/whlsl-return-local-variable.html 43 44 * Modules/webgpu/WHLSL/AST/WHLSLAST.h: 45 * Modules/webgpu/WHLSL/AST/WHLSLExpression.h: 46 (WebCore::WHLSL::AST::Expression::Expression): 47 (WebCore::WHLSL::AST::Expression::isGlobalVariableReference const): 48 (WebCore::WHLSL::AST::Expression::origin const): Deleted. 49 * Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h: 50 (WebCore::WHLSL::AST::FunctionDeclaration::origin): 51 * Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h: Added. 52 (WebCore::WHLSL::AST::GlobalVariableReference::GlobalVariableReference): 53 (WebCore::WHLSL::AST::GlobalVariableReference::structField): 54 (WebCore::WHLSL::AST::GlobalVariableReference::base): 55 * Modules/webgpu/WHLSL/AST/WHLSLStatement.h: 56 (WebCore::WHLSL::AST::Statement::Statement): 57 (WebCore::WHLSL::AST::Statement::isStatementList const): 58 (WebCore::WHLSL::AST::Statement::isWhileLoop const): 59 * Modules/webgpu/WHLSL/AST/WHLSLStatementList.h: Added. 60 (WebCore::WHLSL::AST::StatementList::StatementList): 61 (WebCore::WHLSL::AST::StatementList::statements): 62 * Modules/webgpu/WHLSL/AST/WHLSLValue.h: 63 (WebCore::WHLSL::AST::Value::Value): 64 (WebCore::WHLSL::AST::Value::origin const): 65 * Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h: 66 (WebCore::WHLSL::AST::VariableDeclaration::VariableDeclaration): 67 (WebCore::WHLSL::AST::VariableDeclaration::takeInitializer): 68 (WebCore::WHLSL::AST::VariableDeclaration::origin const): Deleted. 69 * Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h: 70 (WebCore::WHLSL::AST::VariableReference::wrap): 71 * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp: 72 (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit): 73 * Modules/webgpu/WHLSL/WHLSLASTDumper.cpp: 74 (WebCore::WHLSL::ASTDumper::visit): 75 * Modules/webgpu/WHLSL/WHLSLASTDumper.h: 76 (WebCore::WHLSL::dumpASTNode): 77 (WebCore::WHLSL::dumpAST): 78 (WebCore::WHLSL::toString): Deleted. 79 * Modules/webgpu/WHLSL/WHLSLPrepare.cpp: 80 (WebCore::WHLSL::prepareShared): 81 * Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp: Added. 82 (WebCore::WHLSL::EscapedVariableCollector::takeEscapedVariables): 83 (WebCore::WHLSL::anonymousToken): 84 (WebCore::WHLSL::PreserveLifetimes::PreserveLifetimes): 85 (WebCore::WHLSL::PreserveLifetimes::makeStructVariableReference): 86 (WebCore::WHLSL::preserveVariableLifetimes): 87 * Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h: Added. 88 * Modules/webgpu/WHLSL/WHLSLVisitor.cpp: 89 (WebCore::WHLSL::Visitor::visit): 90 * Modules/webgpu/WHLSL/WHLSLVisitor.h: 91 * Sources.txt: 92 * WebCore.xcodeproj/project.pbxproj: 93 1 94 2019-05-30 Ryan Haddad <ryanhaddad@apple.com> 2 95 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAST.h
r245613 r245945 58 58 #include "WHLSLFunctionDeclaration.h" 59 59 #include "WHLSLFunctionDefinition.h" 60 #include "WHLSLGlobalVariableReference.h" 60 61 #include "WHLSLIfStatement.h" 61 62 #include "WHLSLIndexExpression.h" … … 85 86 #include "WHLSLStageInOutSemantic.h" 86 87 #include "WHLSLStatement.h" 88 #include "WHLSLStatementList.h" 87 89 #include "WHLSLStructureDefinition.h" 88 90 #include "WHLSLStructureElement.h" -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.h
r245680 r245945 42 42 43 43 class Expression : public Value { 44 using Base = Value; 44 45 public: 45 46 Expression(Lexer::Token&& origin) 46 : m_origin(WTFMove(origin))47 : Base(WTFMove(origin)) 47 48 { 48 49 } … … 55 56 Expression& operator=(const Expression&) = delete; 56 57 Expression& operator=(Expression&&) = default; 57 58 const Lexer::Token& origin() const { return m_origin; }59 58 60 59 UnnamedType* maybeResolvedType() { return m_type ? &*m_type : nullptr; } … … 92 91 virtual bool isDereferenceExpression() const { return false; } 93 92 virtual bool isDotExpression() const { return false; } 93 virtual bool isGlobalVariableReference() const { return false; } 94 94 virtual bool isFloatLiteral() const { return false; } 95 95 virtual bool isIndexExpression() const { return false; } … … 108 108 109 109 private: 110 Lexer::Token m_origin;111 110 Optional<UniqueRef<UnnamedType>> m_type; 112 111 Optional<TypeAnnotation> m_typeAnnotation; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h
r240230 r245945 77 77 Optional<Semantic>& semantic() { return m_semantic; } 78 78 bool isOperator() const { return m_isOperator; } 79 Lexer::Token origin() { return m_origin; } 79 80 80 81 private: -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h
r245944 r245945 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "WHLSLNode.h" 30 #include "WHLSLLexer.h" 31 #include "WHLSLStructureElement.h" 32 #include <wtf/UniqueRef.h> 31 33 32 34 namespace WebCore { … … 36 38 namespace AST { 37 39 38 class Value : public Node{40 class GlobalVariableReference : public Expression { 39 41 public: 40 Value() 42 GlobalVariableReference(Lexer::Token&& origin, UniqueRef<Expression>&& base, StructureElement* structField) 43 : Expression(WTFMove(origin)) 44 , m_base(WTFMove(base)) 45 , m_structField(*structField) 41 46 { 47 ASSERT(structField); 42 48 } 43 49 44 virtual ~Value() = default; 50 virtual ~GlobalVariableReference() = default; 51 bool isGlobalVariableReference() const override { return true; } 52 StructureElement& structField() { return m_structField; } 45 53 46 explicit Value(const Value&) = default; 47 Value(Value&&) = default; 48 49 Value& operator=(const Value&) = default; 50 Value& operator=(Value&&) = default; 54 Expression& base() { return m_base.get(); } 51 55 52 56 private: 57 UniqueRef<Expression> m_base; 58 StructureElement& m_structField; 53 59 }; 54 60 … … 59 65 } 60 66 67 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(GlobalVariableReference, isGlobalVariableReference()) 68 61 69 #endif -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h
r239844 r245945 39 39 40 40 class Statement : public Value { 41 using Base = Value; 41 42 public: 42 43 Statement(Lexer::Token&& origin) 43 : m_origin(WTFMove(origin))44 : Base(WTFMove(origin)) 44 45 { 45 46 } … … 59 60 virtual bool isIfStatement() const { return false; } 60 61 virtual bool isReturn() const { return false; } 62 virtual bool isStatementList() const { return false; } 61 63 virtual bool isSwitchCase() const { return false; } 62 64 virtual bool isSwitchStatement() const { return false; } … … 64 66 virtual bool isVariableDeclarationsStatement() const { return false; } 65 67 virtual bool isWhileLoop() const { return false; } 66 67 private:68 Lexer::Token m_origin;69 68 }; 70 69 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatementList.h
r245944 r245945 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "WHLSLNode.h" 30 #include "WHLSLLexer.h" 31 #include "WHLSLStatement.h" 32 #include <wtf/Vector.h> 31 33 32 34 namespace WebCore { … … 36 38 namespace AST { 37 39 38 class Value : public Node { 40 class StatementList : public Statement { 41 using Base = Statement; 39 42 public: 40 Value() 41 { 42 } 43 StatementList(Lexer::Token&& origin, Statements&& statements) 44 : Base(WTFMove(origin)) 45 , m_statements(WTFMove(statements)) 46 { } 43 47 44 virtual ~ Value() = default;48 virtual ~StatementList() = default; 45 49 46 explicit Value(const Value&) = default; 47 Value(Value&&) = default; 50 Statements& statements() { return m_statements; } 48 51 49 Value& operator=(const Value&) = default; 50 Value& operator=(Value&&) = default; 52 bool isStatementList() const override { return true; } 51 53 52 54 private: 55 Statements m_statements; 53 56 }; 54 57 … … 59 62 } 60 63 64 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(StatementList, isStatementList()) 65 61 66 #endif -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLValue.h
r239844 r245945 38 38 class Value : public Node { 39 39 public: 40 Value() 40 Value(Lexer::Token&& origin) 41 : m_origin(WTFMove(origin)) 41 42 { 42 43 } … … 50 51 Value& operator=(Value&&) = default; 51 52 52 private: 53 Lexer::Token origin() const { return m_origin; } 54 55 protected: 56 Lexer::Token m_origin; 53 57 }; 54 58 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h
r245680 r245945 46 46 47 47 class VariableDeclaration : public Value { 48 using Base = Value; 48 49 public: 49 50 VariableDeclaration(Lexer::Token&& origin, Qualifiers&& qualifiers, Optional<UniqueRef<UnnamedType>>&& type, String&& name, Optional<Semantic>&& semantic, Optional<UniqueRef<Expression>>&& initializer) 50 : m_origin(WTFMove(origin))51 : Base(WTFMove(origin)) 51 52 , m_qualifiers(WTFMove(qualifiers)) 52 53 , m_type(WTFMove(type)) … … 62 63 VariableDeclaration(VariableDeclaration&&) = default; 63 64 64 const Lexer::Token& origin() const { return m_origin; }65 65 String& name() { return m_name; } 66 66 … … 70 70 Expression* initializer() { return m_initializer ? &*m_initializer : nullptr; } 71 71 bool isAnonymous() const { return m_name.isNull(); } 72 Optional<UniqueRef<Expression>> takeInitializer() { return WTFMove(m_initializer); } 72 73 73 74 private: 74 Lexer::Token m_origin;75 75 Qualifiers m_qualifiers; 76 76 Optional<UniqueRef<UnnamedType>> m_type; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h
r243091 r245945 56 56 VariableReference result(Lexer::Token(variableDeclaration.origin())); 57 57 result.m_variable = &variableDeclaration; 58 result.m_name = variableDeclaration.name(); 58 59 return result; 59 60 } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
r245680 r245945 30 30 31 31 #include "NotImplemented.h" 32 #include "WHLSLArrayReferenceType.h" 33 #include "WHLSLArrayType.h" 34 #include "WHLSLAssignmentExpression.h" 35 #include "WHLSLBooleanLiteral.h" 36 #include "WHLSLBuiltInSemantic.h" 37 #include "WHLSLCallExpression.h" 38 #include "WHLSLCommaExpression.h" 39 #include "WHLSLDereferenceExpression.h" 40 #include "WHLSLDoWhileLoop.h" 41 #include "WHLSLEffectfulExpressionStatement.h" 42 #include "WHLSLEntryPointScaffolding.h" 43 #include "WHLSLEntryPointType.h" 44 #include "WHLSLFloatLiteral.h" 45 #include "WHLSLForLoop.h" 46 #include "WHLSLFunctionDeclaration.h" 47 #include "WHLSLFunctionDefinition.h" 48 #include "WHLSLIfStatement.h" 49 #include "WHLSLIntegerLiteral.h" 50 #include "WHLSLLogicalExpression.h" 51 #include "WHLSLLogicalNotExpression.h" 52 #include "WHLSLMakeArrayReferenceExpression.h" 53 #include "WHLSLMakePointerExpression.h" 54 #include "WHLSLNativeFunctionDeclaration.h" 32 #include "WHLSLAST.h" 55 33 #include "WHLSLNativeFunctionWriter.h" 56 #include "WHLSLNativeTypeDeclaration.h"57 #include "WHLSLPointerType.h"58 34 #include "WHLSLProgram.h" 59 #include "WHLSLReturn.h"60 #include "WHLSLSwitchCase.h"61 #include "WHLSLSwitchStatement.h"62 #include "WHLSLTernaryExpression.h"63 35 #include "WHLSLTypeNamer.h" 64 #include "WHLSLUnsignedIntegerLiteral.h"65 #include "WHLSLVariableDeclaration.h"66 #include "WHLSLVariableDeclarationsStatement.h"67 #include "WHLSLVariableReference.h"68 36 #include "WHLSLVisitor.h" 69 #include "WHLSLWhileLoop.h"70 37 #include <wtf/HashMap.h> 71 38 #include <wtf/text/StringBuilder.h> … … 157 124 void visit(AST::Expression&) override; 158 125 void visit(AST::DotExpression&) override; 126 void visit(AST::GlobalVariableReference&) override; 159 127 void visit(AST::IndexExpression&) override; 160 128 void visit(AST::PropertyAccessExpression&) override; … … 447 415 } 448 416 417 void FunctionDefinitionWriter::visit(AST::GlobalVariableReference& globalVariableReference) 418 { 419 auto variableName = generateNextVariableName(); 420 auto mangledTypeName = m_typeNamer.mangledNameForType(globalVariableReference.resolvedType()); 421 checkErrorAndVisit(globalVariableReference.base()); 422 m_stringBuilder.append(makeString("thread ", mangledTypeName, "& ", variableName, " = ", m_stack.takeLast(), "->", m_typeNamer.mangledNameForStructureElement(globalVariableReference.structField()), ";\n")); 423 m_stack.append(variableName); 424 } 425 449 426 void FunctionDefinitionWriter::visit(AST::IndexExpression&) 450 427 { -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp
r245745 r245945 373 373 } 374 374 375 void ASTDumper::visit(AST::StatementList& statementList) 376 { 377 bool once = false; 378 for (auto& statement : statementList.statements()) { 379 if (once) 380 m_out.print(";\n", m_indent); 381 once = true; 382 visit(statement); 383 } 384 } 385 375 386 void ASTDumper::visit(AST::Break&) 376 387 { … … 442 453 } 443 454 455 void ASTDumper::visit(AST::GlobalVariableReference& globalVariableReference) 456 { 457 visit(globalVariableReference.base()); 458 m_out.print("=>", globalVariableReference.structField().name()); 459 } 460 444 461 void ASTDumper::visit(AST::IndexExpression& indexExpression) 445 462 { … … 530 547 m_out.print(" "); 531 548 } 532 m_out.print(variableDeclaration.name()); 549 550 if (variableDeclaration.name().isEmpty()) 551 m_out.print("$", RawPointer(&variableDeclaration)); 552 else 553 m_out.print(variableDeclaration.name()); 554 533 555 if (variableDeclaration.semantic()) 534 556 visit(*variableDeclaration.semantic()); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h
r245613 r245945 45 45 String toString() { return m_out.toString(); } 46 46 47 private:48 47 void visit(AST::UnnamedType&) override; 49 48 void visit(AST::NamedType&) override; … … 83 82 void visit(AST::NumThreadsFunctionAttribute&) override; 84 83 void visit(AST::Block&) override; 84 void visit(AST::StatementList&) override; 85 85 void visit(AST::Statement&) override; 86 86 void visit(AST::Break&) override; … … 89 89 void visit(AST::Expression&) override; 90 90 void visit(AST::DotExpression&) override; 91 void visit(AST::GlobalVariableReference&) override; 91 92 void visit(AST::IndexExpression&) override; 92 93 void visit(AST::PropertyAccessExpression&) override; … … 114 115 void visit(AST::VariableReference&) override; 115 116 117 private: 116 118 struct Indent { 117 119 Indent(ASTDumper& dumper) … … 129 131 }; 130 132 131 static ALWAYS_INLINE String toString(Program& program) 133 template <typename T> 134 ALWAYS_INLINE void dumpASTNode(PrintStream& out, T& value) 132 135 { 133 136 ASTDumper dumper; 134 dumper.visit( program);135 return dumper.toString();137 dumper.visit(value); 138 out.print(dumper.toString()); 136 139 } 140 MAKE_PRINT_ADAPTOR(ExpressionDumper, AST::Expression&, dumpASTNode); 141 MAKE_PRINT_ADAPTOR(StatementDumper, AST::Statement&, dumpASTNode); 142 MAKE_PRINT_ADAPTOR(ProgramDumper, Program&, dumpASTNode); 143 MAKE_PRINT_ADAPTOR(StructureDefinitionDumper, AST::StructureDefinition&, dumpASTNode); 144 MAKE_PRINT_ADAPTOR(FunctionDefinitionDumper, AST::FunctionDefinition&, dumpASTNode); 145 137 146 138 147 static ALWAYS_INLINE void dumpAST(Program& program) 139 148 { 140 dataLogLn( toString(program));149 dataLogLn(ProgramDumper(program)); 141 150 } 142 151 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
r245680 r245945 38 38 #include "WHLSLNameResolver.h" 39 39 #include "WHLSLParser.h" 40 #include "WHLSLPreserveVariableLifetimes.h" 40 41 #include "WHLSLProgram.h" 41 42 #include "WHLSLPropertyResolver.h" … … 57 58 static constexpr bool dumpASTBeforeEachPass = false; 58 59 static constexpr bool dumpASTAfterParsing = false; 59 static constexpr bool dumpASTAtEnd = false; 60 static constexpr bool dumpASTAtEnd = true; 61 static constexpr bool alwaysDumpPassFailures = false; 62 static constexpr bool dumpPassFailure = dumpASTBeforeEachPass || dumpASTAfterParsing || dumpASTAtEnd || alwaysDumpPassFailures; 60 63 61 64 static bool dumpASTIfNeeded(bool shouldDump, Program& program, const char* message) … … 88 91 do { \ 89 92 dumpASTBetweenEachPassIfNeeded(program, "AST before " # pass); \ 90 if (!pass(__VA_ARGS__)) \ 93 if (!pass(__VA_ARGS__)) { \ 94 if (dumpPassFailure) \ 95 dataLogLn("failed pass: " # pass); \ 91 96 return WTF::nullopt; \ 97 } \ 92 98 } while (0) 93 99 … … 124 130 RUN_PASS(checkRecursion, program); 125 131 RUN_PASS(checkFunctionStages, program); 132 preserveVariableLifetimes(program); 126 133 127 134 dumpASTAtEndIfNeeded(program); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.h
r245944 r245945 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "WHLSLNode.h"31 32 30 namespace WebCore { 33 31 34 32 namespace WHLSL { 35 33 36 namespace AST { 34 class Program; 37 35 38 class Value : public Node { 39 public: 40 Value() 41 { 42 } 43 44 virtual ~Value() = default; 45 46 explicit Value(const Value&) = default; 47 Value(Value&&) = default; 48 49 Value& operator=(const Value&) = default; 50 Value& operator=(Value&&) = default; 51 52 private: 53 }; 54 55 } // namespace AST 36 void preserveVariableLifetimes(Program&); 56 37 57 38 } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp
r245745 r245945 301 301 } 302 302 303 void Visitor::visit(AST::StatementList& statementList) 304 { 305 for (auto& statement : statementList.statements()) 306 checkErrorAndVisit(statement); 307 } 308 303 309 void Visitor::visit(AST::Statement& statement) 304 310 { … … 321 327 else if (is<AST::Return>(statement)) 322 328 checkErrorAndVisit(downcast<AST::Return>(statement)); 329 else if (is<AST::StatementList>(statement)) 330 checkErrorAndVisit(downcast<AST::StatementList>(statement)); 323 331 else if (is<AST::SwitchCase>(statement)) 324 332 checkErrorAndVisit(downcast<AST::SwitchCase>(statement)); … … 377 385 else if (is<AST::DotExpression>(expression)) 378 386 checkErrorAndVisit(downcast<AST::DotExpression>(expression)); 387 else if (is<AST::GlobalVariableReference>(expression)) 388 checkErrorAndVisit(downcast<AST::GlobalVariableReference>(expression)); 379 389 else if (is<AST::IndexExpression>(expression)) 380 390 checkErrorAndVisit(downcast<AST::IndexExpression>(expression)); … … 398 408 } 399 409 410 void Visitor::visit(AST::GlobalVariableReference& globalVariableReference) 411 { 412 checkErrorAndVisit(globalVariableReference.base()); 413 } 414 400 415 void Visitor::visit(AST::IndexExpression& indexExpression) 401 416 { -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.h
r245680 r245945 67 67 class NumThreadsFunctionAttribute; 68 68 class Block; 69 class StatementList; 69 70 class Statement; 70 71 class Break; … … 73 74 class Expression; 74 75 class DotExpression; 76 class GlobalVariableReference; 75 77 class IndexExpression; 76 78 class PropertyAccessExpression; … … 146 148 virtual void visit(AST::NumThreadsFunctionAttribute&); 147 149 virtual void visit(AST::Block&); 150 virtual void visit(AST::StatementList&); 148 151 virtual void visit(AST::Statement&); 149 152 virtual void visit(AST::Break&); … … 152 155 virtual void visit(AST::Expression&); 153 156 virtual void visit(AST::DotExpression&); 157 virtual void visit(AST::GlobalVariableReference&); 154 158 virtual void visit(AST::IndexExpression&); 155 159 virtual void visit(AST::PropertyAccessExpression&); -
trunk/Source/WebCore/Sources.txt
r245905 r245945 323 323 Modules/webgpu/WHLSL/WHLSLNameContext.cpp 324 324 Modules/webgpu/WHLSL/WHLSLNameResolver.cpp 325 Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp 325 326 Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp 326 327 Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r245905 r245945 8337 8337 52131E5A1C4F15610033F802 /* VideoFullscreenInterfaceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenInterfaceMac.mm; sourceTree = "<group>"; }; 8338 8338 5215862C229377B7005925EF /* WHLSLAST.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAST.h; sourceTree = "<group>"; }; 8339 522DA3D3229E1D390042D151 /* WHLSLGlobalVariableReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLGlobalVariableReference.h; sourceTree = "<group>"; }; 8340 522E1A172297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLPreserveVariableLifetimes.cpp; sourceTree = "<group>"; }; 8341 522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLPreserveVariableLifetimes.h; sourceTree = "<group>"; }; 8339 8342 526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationCocoa.mm; sourceTree = "<group>"; }; 8340 8343 526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentationCocoa.h; sourceTree = "<group>"; }; … … 17069 17072 C21BF6FD21CD89C000227979 /* WHLSLFunctionDeclaration.h */, 17070 17073 C21BF6F421CD89B300227979 /* WHLSLFunctionDefinition.h */, 17074 522DA3D3229E1D390042D151 /* WHLSLGlobalVariableReference.h */, 17071 17075 C21BF6FF21CD89C200227979 /* WHLSLIfStatement.h */, 17072 17076 C21BF6F721CD89B900227979 /* WHLSLIndexExpression.h */, … … 25456 25460 C24A57BA21FEAFEA004C6DD1 /* WHLSLPrepare.cpp */, 25457 25461 C24A57BB21FEAFEA004C6DD1 /* WHLSLPrepare.h */, 25462 522E1A172297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.cpp */, 25463 522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */, 25458 25464 C21BF73A21CD8D7000227979 /* WHLSLProgram.h */, 25459 25465 1CAA82F62242AE0500E84BBB /* WHLSLPropertyResolver.cpp */,
Note:
See TracChangeset
for help on using the changeset viewer.