Diff
Modified: trunk/Source/WebCore/ChangeLog (240017 => 240018)
--- trunk/Source/WebCore/ChangeLog 2019-01-16 00:08:52 UTC (rev 240017)
+++ trunk/Source/WebCore/ChangeLog 2019-01-16 00:27:00 UTC (rev 240018)
@@ -1,3 +1,21 @@
+2019-01-15 Myles C. Maxfield <[email protected]>
+
+ [WHLSL] Implement the loop checker
+ https://bugs.webkit.org/show_bug.cgi?id=193434
+
+ Reviewed by Saam Barati.
+
+ This is a translation of https://github.com/gpuweb/WHLSL/blob/master/Source/LoopChecker.mjs into C++.
+
+ No new tests because it isn't hooked up yet. Not enough of the compiler exists to have any meaningful sort
+ of test. When enough of the compiler is present, I'll port the reference implementation's test suite.
+
+ * Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp: Added.
+ (WebCore::WHLSL::findHighZombies):
+ * Modules/webgpu/WHLSL/WHLSLLoopChecker.h: Added.
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+
2019-01-15 Chris Dumez <[email protected]>
Unreviewed, rolling out r239993, r239995, r239997, and
Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp (0 => 240018)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp 2019-01-16 00:27:00 UTC (rev 240018)
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WHLSLLoopChecker.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLBreak.h"
+#include "WHLSLContinue.h"
+#include "WHLSLDoWhileLoop.h"
+#include "WHLSLFallthrough.h"
+#include "WHLSLForLoop.h"
+#include "WHLSLSwitchStatement.h"
+#include "WHLSLVisitor.h"
+#include "WHLSLWhileLoop.h"
+#include <wtf/SetForScope.h>
+
+namespace WebCore {
+
+namespace WHLSL {
+
+// This makes sure that every occurance of "continue," "break," and "fallthrough" appear within the relevant control flow structure.
+class LoopChecker : public Visitor {
+public:
+ LoopChecker() = default;
+
+ virtual ~LoopChecker() = default;
+
+private:
+ void visit(AST::FunctionDefinition& functionDefinition) override
+ {
+ ASSERT(!m_loopDepth);
+ ASSERT(!m_switchDepth);
+ Visitor::visit(functionDefinition);
+ }
+
+ void visit(AST::WhileLoop& whileLoop) override
+ {
+ checkErrorAndVisit(whileLoop.conditional());
+
+ SetForScope<unsigned> change(m_loopDepth, m_loopDepth + 1);
+ checkErrorAndVisit(whileLoop.body());
+ ASSERT(m_loopDepth);
+ }
+
+ void visit(AST::DoWhileLoop& doWhileLoop) override
+ {
+ {
+ SetForScope<unsigned> change(m_loopDepth, m_loopDepth + 1);
+ checkErrorAndVisit(doWhileLoop.body());
+ ASSERT(m_loopDepth);
+ }
+
+ checkErrorAndVisit(doWhileLoop.conditional());
+ }
+
+ void visit(AST::ForLoop& forLoop) override
+ {
+ WTF::visit(WTF::makeVisitor([&](AST::VariableDeclarationsStatement& variableDeclarationsStatement) {
+ checkErrorAndVisit(variableDeclarationsStatement);
+ }, [&](UniqueRef<AST::_expression_>& _expression_) {
+ checkErrorAndVisit(_expression_);
+ }), forLoop.initialization());
+ if (forLoop.condition())
+ checkErrorAndVisit(*forLoop.condition());
+ if (forLoop.increment())
+ checkErrorAndVisit(*forLoop.increment());
+
+ SetForScope<unsigned> change(m_loopDepth, m_loopDepth + 1);
+ checkErrorAndVisit(forLoop.body());
+ ASSERT(m_loopDepth);
+ }
+
+ void visit(AST::SwitchStatement& switchStatement) override
+ {
+ checkErrorAndVisit(switchStatement.value());
+
+ SetForScope<unsigned> change(m_switchDepth, m_switchDepth + 1);
+ for (auto& switchCase : switchStatement.switchCases())
+ checkErrorAndVisit(switchCase);
+ ASSERT(m_switchDepth);
+ }
+
+ void visit(AST::Break& breakStatement) override
+ {
+ if (!m_loopDepth && !m_switchDepth) {
+ setError();
+ return;
+ }
+ Visitor::visit(breakStatement);
+ }
+
+ void visit(AST::Continue& continueStatement) override
+ {
+ if (!m_loopDepth) {
+ setError();
+ return;
+ }
+ Visitor::visit(continueStatement);
+ }
+
+ void visit(AST::Fallthrough& fallthroughStatement) override
+ {
+ if (!m_switchDepth) {
+ setError();
+ return;
+ }
+ Visitor::visit(fallthroughStatement);
+ }
+
+ unsigned m_loopDepth { 0 };
+ unsigned m_switchDepth { 0 };
+};
+
+bool findHighZombies(Program& program)
+{
+ LoopChecker loopChecker;
+ loopChecker.Visitor::visit(program);
+ return !loopChecker.error();
+}
+
+}
+
+}
+
+#endif
Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.h (0 => 240018)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.h (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLoopChecker.h 2019-01-16 00:27:00 UTC (rev 240018)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+namespace WHLSL {
+
+class Program;
+
+bool findHighZombies(Program&);
+
+}
+
+}
+
+#endif
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp (240017 => 240018)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp 2019-01-16 00:08:52 UTC (rev 240017)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp 2019-01-16 00:27:00 UTC (rev 240018)
@@ -28,6 +28,9 @@
#if ENABLE(WEBGPU)
+#include "WHLSLStructureDefinition.h"
+#include "WHLSLTypeDefinition.h"
+#include "WHLSLTypeReference.h"
#include "WHLSLVisitor.h"
#include <wtf/HashSet.h>
Modified: trunk/Source/WebCore/Sources.txt (240017 => 240018)
--- trunk/Source/WebCore/Sources.txt 2019-01-16 00:08:52 UTC (rev 240017)
+++ trunk/Source/WebCore/Sources.txt 2019-01-16 00:27:00 UTC (rev 240018)
@@ -322,6 +322,7 @@
Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
Modules/webgpu/WHLSL/WHLSLVisitor.cpp
+Modules/webgpu/WHLSL/WHLSLLoopChecker.cpp
Modules/webgpu/WHLSL/AST/WHLSLTypeArgument.cpp
Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp
Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (240017 => 240018)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-16 00:08:52 UTC (rev 240017)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-01-16 00:27:00 UTC (rev 240018)
@@ -6427,6 +6427,8 @@
1C840B9A21EC400900D0500D /* WHLSLGatherEntryPointItems.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLGatherEntryPointItems.h; sourceTree = "<group>"; };
1C840B9B21EC400900D0500D /* WHLSLChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLChecker.cpp; sourceTree = "<group>"; };
1C904DF90BA9D2C80081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
+ 1C9AE5CF21EDA27E0069D5F2 /* WHLSLLoopChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLoopChecker.cpp; sourceTree = "<group>"; };
+ 1C9AE5D021EDA27E0069D5F2 /* WHLSLLoopChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLoopChecker.h; sourceTree = "<group>"; };
1CA19E030DC255950065A994 /* EventLoopMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EventLoopMac.mm; sourceTree = "<group>"; };
1CA19E150DC255CA0065A994 /* EventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventLoop.h; sourceTree = "<group>"; };
1CAF347E0A6C405200ABE06E /* WebScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObject.h; sourceTree = "<group>"; };
@@ -25460,6 +25462,8 @@
C234A9B621E92CC0003C984D /* WHLSLIntrinsics.h */,
C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */,
C210E91221B4BD1000B7F83D /* WHLSLLexer.h */,
+ 1C9AE5CF21EDA27E0069D5F2 /* WHLSLLoopChecker.cpp */,
+ 1C9AE5D021EDA27E0069D5F2 /* WHLSLLoopChecker.h */,
C234A98D21E88884003C984D /* WHLSLNameContext.cpp */,
C234A98E21E88885003C984D /* WHLSLNameContext.h */,
C234A98A21E8883E003C984D /* WHLSLNameResolver.cpp */,