Title: [248403] trunk/Source/WebCore
Revision
248403
Author
[email protected]
Date
2019-08-07 23:22:58 -0700 (Wed, 07 Aug 2019)

Log Message

[WHLSL] Prune unreachable stdlib functions after the Checker runs
https://bugs.webkit.org/show_bug.cgi?id=200518

Reviewed by Robin Morisset.

We now prune unreachable stdlib functions after the checker runs. We must
do this after the checker runs because that's when we resolve all remaining
function calls. While we can't prune unreachable user code, because we must
still report errors in it, we can prune unreachable standard library code
because we know a priori that it has no errors. This is a 10ms end-to-end
speedup in compute_boids.

* Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
(WebCore::WHLSL::prepareShared):
* Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp: Added.
(WebCore::WHLSL::pruneUnreachableStandardLibraryFunctions):
* Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.h: Added.
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248402 => 248403)


--- trunk/Source/WebCore/ChangeLog	2019-08-08 04:56:41 UTC (rev 248402)
+++ trunk/Source/WebCore/ChangeLog	2019-08-08 06:22:58 UTC (rev 248403)
@@ -1,3 +1,25 @@
+2019-08-07  Saam Barati  <[email protected]>
+
+        [WHLSL] Prune unreachable stdlib functions after the Checker runs
+        https://bugs.webkit.org/show_bug.cgi?id=200518
+
+        Reviewed by Robin Morisset.
+
+        We now prune unreachable stdlib functions after the checker runs. We must
+        do this after the checker runs because that's when we resolve all remaining
+        function calls. While we can't prune unreachable user code, because we must
+        still report errors in it, we can prune unreachable standard library code
+        because we know a priori that it has no errors. This is a 10ms end-to-end
+        speedup in compute_boids.
+
+        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
+        (WebCore::WHLSL::prepareShared):
+        * Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp: Added.
+        (WebCore::WHLSL::pruneUnreachableStandardLibraryFunctions):
+        * Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.h: Added.
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2019-08-07  Kate Cheney  <[email protected]>
 
         Adopt non-deprecated CGColorSpace API

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp (248402 => 248403)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp	2019-08-08 04:56:41 UTC (rev 248402)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp	2019-08-08 06:22:58 UTC (rev 248403)
@@ -42,6 +42,7 @@
 #include "WHLSLPreserveVariableLifetimes.h"
 #include "WHLSLProgram.h"
 #include "WHLSLPropertyResolver.h"
+#include "WHLSLPruneUnreachableStandardLibraryFunctions.h"
 #include "WHLSLRecursionChecker.h"
 #include "WHLSLRecursiveTypeChecker.h"
 #include "WHLSLSemanticMatcher.h"
@@ -183,6 +184,7 @@
     CHECK_PASS(checkDuplicateFunctions, program);
 
     CHECK_PASS(check, program);
+    RUN_PASS(pruneUnreachableStandardLibraryFunctions, program);
 
     RUN_PASS(checkLiteralTypes, program);
     CHECK_PASS(checkTextureReferences, program);

Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp (0 => 248403)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp	2019-08-08 06:22:58 UTC (rev 248403)
@@ -0,0 +1,102 @@
+/*
+ * 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 "WHLSLPruneUnreachableStandardLibraryFunctions.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLAST.h"
+#include "WHLSLProgram.h"
+
+namespace WebCore {
+
+namespace WHLSL {
+
+class ReachableStdlibFunctions final : public Visitor {
+public:
+    void visit(AST::FunctionDefinition& function) override
+    {
+        auto addResult = m_reachableFunctions.add(&function);
+        if (addResult.isNewEntry)
+            Visitor::visit(function);
+    }
+
+    void visit(AST::CallExpression& callExpression) override
+    {
+        Visitor::visit(callExpression);
+        if (is<AST::FunctionDefinition>(callExpression.function()))
+            visit(downcast<AST::FunctionDefinition>(callExpression.function()));
+    }
+
+    void visit(AST::PropertyAccessExpression& _expression_) override
+    {
+        auto visitFunction = [&] (AST::FunctionDeclaration* function) {
+            if (!function)
+                return;
+            if (is<AST::FunctionDefinition>(*function))
+                visit(downcast<AST::FunctionDefinition>(*function));
+        };
+
+        visitFunction(_expression_.getterFunction());
+        visitFunction(_expression_.anderFunction());
+        visitFunction(_expression_.threadAnderFunction());
+        visitFunction(_expression_.setterFunction());
+
+        Visitor::visit(_expression_);
+    }
+
+    HashSet<AST::FunctionDefinition*> takeReachableFunctions() { return WTFMove(m_reachableFunctions); }
+
+private:
+    HashSet<AST::FunctionDefinition*> m_reachableFunctions;
+};
+
+void pruneUnreachableStandardLibraryFunctions(Program& program)
+{
+    ReachableStdlibFunctions reachableStdlibFunctions;
+    Vector<UniqueRef<AST::FunctionDefinition>> functionDefinitions = WTFMove(program.functionDefinitions());
+    for (auto& function : functionDefinitions) {
+        if (function->parsingMode() != ParsingMode::StandardLibrary)
+            reachableStdlibFunctions.visit(function.get());
+        else
+            RELEASE_ASSERT(!function->entryPointType());
+    }
+
+    auto reachableFunctions = reachableStdlibFunctions.takeReachableFunctions();
+    Vector<UniqueRef<AST::FunctionDefinition>> newFunctionDefinitions;
+    for (UniqueRef<AST::FunctionDefinition>& entry : functionDefinitions) {
+        if (reachableFunctions.contains(&entry.get()))
+            newFunctionDefinitions.append(WTFMove(entry));
+    }
+
+    program.functionDefinitions() = WTFMove(newFunctionDefinitions);
+}
+
+} // namespace WHLSL
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Added: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.h (0 => 248403)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.h	2019-08-08 06:22:58 UTC (rev 248403)
@@ -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;
+
+void pruneUnreachableStandardLibraryFunctions(Program&);
+
+}
+
+}
+
+#endif

Modified: trunk/Source/WebCore/Sources.txt (248402 => 248403)


--- trunk/Source/WebCore/Sources.txt	2019-08-08 04:56:41 UTC (rev 248402)
+++ trunk/Source/WebCore/Sources.txt	2019-08-08 06:22:58 UTC (rev 248403)
@@ -312,6 +312,7 @@
 Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
 Modules/webgpu/WHLSL/WHLSLLexer.cpp
 Modules/webgpu/WHLSL/WHLSLParser.cpp
+Modules/webgpu/WHLSL/WHLSLPruneUnreachableStandardLibraryFunctions.cpp
 Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp
 Modules/webgpu/WHLSL/WHLSLChecker.cpp
 Modules/webgpu/WHLSL/WHLSLGatherEntryPointItems.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (248402 => 248403)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-08-08 04:56:41 UTC (rev 248402)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-08-08 06:22:58 UTC (rev 248403)
@@ -8320,6 +8320,8 @@
 		522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLPreserveVariableLifetimes.h; sourceTree = "<group>"; };
 		526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationCocoa.mm; sourceTree = "<group>"; };
 		526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentationCocoa.h; sourceTree = "<group>"; };
+		526B3F0122FB7BDD0076D37D /* WHLSLPruneUnreachableStandardLibraryFunctions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLPruneUnreachableStandardLibraryFunctions.cpp; sourceTree = "<group>"; };
+		526B3F0322FB7BDE0076D37D /* WHLSLPruneUnreachableStandardLibraryFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLPruneUnreachableStandardLibraryFunctions.h; sourceTree = "<group>"; };
 		52914C2A22F93E4E00578150 /* WHLSLParsingMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLParsingMode.h; sourceTree = "<group>"; };
 		52914C2C22F93E5D00578150 /* WHLSLAddressEscapeMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAddressEscapeMode.h; sourceTree = "<group>"; };
 		52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformView.h; sourceTree = "<group>"; };
@@ -25540,6 +25542,8 @@
 				C24A57BB21FEAFEA004C6DD1 /* WHLSLPrepare.h */,
 				522E1A172297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.cpp */,
 				522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */,
+				526B3F0122FB7BDD0076D37D /* WHLSLPruneUnreachableStandardLibraryFunctions.cpp */,
+				526B3F0322FB7BDE0076D37D /* WHLSLPruneUnreachableStandardLibraryFunctions.h */,
 				C21BF73A21CD8D7000227979 /* WHLSLProgram.h */,
 				1CAA82F62242AE0500E84BBB /* WHLSLPropertyResolver.cpp */,
 				1CAA82F72242AE0500E84BBB /* WHLSLPropertyResolver.h */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to