Title: [248310] trunk/Source/WebCore
Revision
248310
Author
sbar...@apple.com
Date
2019-08-06 13:31:04 -0700 (Tue, 06 Aug 2019)

Log Message

[WHLSL] Remove the auto initialize variables pass
https://bugs.webkit.org/show_bug.cgi?id=200472

Reviewed by Robin Morisset.

>From a separation of concerns perspective, it's a bit nicer to make variables
without initializers call their default constructors as a transformation over the AST.
This removes the need for the lowering to need to worry about such things. However,
changing metal lowering to deal with this is trivial. It means we need to change one
line of code in Metal code generation, and we get to remove a ~50 LOC AST pass.
Also, in this case, it saves us from the compile time hit of having to run the
auto initialize variables phase, which takes ~1.2ms on compute_boids.

* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
* Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: Removed.
* Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h: Removed.
* Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
(WebCore::WHLSL::prepareShared):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248309 => 248310)


--- trunk/Source/WebCore/ChangeLog	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/ChangeLog	2019-08-06 20:31:04 UTC (rev 248310)
@@ -1,3 +1,27 @@
+2019-08-06  Saam Barati  <sbar...@apple.com>
+
+        [WHLSL] Remove the auto initialize variables pass
+        https://bugs.webkit.org/show_bug.cgi?id=200472
+
+        Reviewed by Robin Morisset.
+
+        From a separation of concerns perspective, it's a bit nicer to make variables
+        without initializers call their default constructors as a transformation over the AST.
+        This removes the need for the lowering to need to worry about such things. However,
+        changing metal lowering to deal with this is trivial. It means we need to change one
+        line of code in Metal code generation, and we get to remove a ~50 LOC AST pass.
+        Also, in this case, it saves us from the compile time hit of having to run the
+        auto initialize variables phase, which takes ~1.2ms on compute_boids.
+
+        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
+        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: Removed.
+        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h: Removed.
+        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
+        (WebCore::WHLSL::prepareShared):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2019-08-06  Sam Weinig  <wei...@apple.com>
 
         WHLSL Metal code generation unnecessarily does string copies by passing partial results as Strings

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp (248309 => 248310)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp	2019-08-06 20:31:04 UTC (rev 248310)
@@ -551,7 +551,7 @@
         checkErrorAndVisit(*variableDeclaration.initializer());
         m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(*variableDeclaration.type()), ' ', variableName, " = ", takeLastValue(), ";\n");
     } else
-        m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(*variableDeclaration.type()), ' ', variableName, ";\n");
+        m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(*variableDeclaration.type()), ' ', variableName, " = { };\n");
 }
 
 void FunctionDefinitionWriter::visit(AST::AssignmentExpression& assignmentExpression)

Deleted: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp (248309 => 248310)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp	2019-08-06 20:31:04 UTC (rev 248310)
@@ -1,102 +0,0 @@
-/*
- * 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 "WHLSLAutoInitializeVariables.h"
-
-#if ENABLE(WEBGPU)
-
-#include "WHLSLAST.h"
-#include "WHLSLASTDumper.h"
-#include "WHLSLNameContext.h"
-#include "WHLSLProgram.h"
-#include "WHLSLResolveOverloadImpl.h"
-#include "WHLSLResolvingType.h"
-#include "WHLSLVisitor.h"
-#include <wtf/StringPrintStream.h>
-
-namespace WebCore {
-
-namespace WHLSL {
-
-class AutoInitialize : public Visitor {
-    using Base = Visitor;
-public:
-    AutoInitialize(NameContext& nameContext)
-        : m_nameContext(nameContext)
-        , m_castFunctions(*m_nameContext.getFunctions("operator cast"_str))
-    { }
-
-private:
-    void visit(AST::FunctionDeclaration&)
-    {
-        // Skip argument declarations.
-    }
-
-    void visit(AST::VariableDeclaration& variableDeclaration)
-    {
-        if (variableDeclaration.initializer())
-            return;
-
-        AST::UnnamedType* type = variableDeclaration.type();
-        RELEASE_ASSERT(type);
-
-#ifndef NDEBUG
-        StringPrintStream printStream;
-        printStream.print(TypeDumper(*type));
-        String functionName = printStream.toString();
-#else
-        String functionName = "<zero-init>"_s;
-#endif
-        auto callExpression = std::make_unique<AST::CallExpression>(variableDeclaration.codeLocation(), WTFMove(functionName), Vector<UniqueRef<AST::_expression_>>());
-        callExpression->setType(*type);
-        callExpression->setTypeAnnotation(AST::RightValue());
-        Vector<std::reference_wrapper<ResolvingType>> argumentTypes;
-        auto* function = resolveFunctionOverload(m_castFunctions, argumentTypes, type);
-        if (!function) {
-            setError(Error("Cannot find the default constructor for variable.", variableDeclaration.codeLocation()));
-            return;
-        }
-        callExpression->setFunction(*function);
-
-        variableDeclaration.setInitializer(WTFMove(callExpression));
-    }
-
-    NameContext& m_nameContext;
-    Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& m_castFunctions;
-};
-
-Expected<void, Error> autoInitializeVariables(Program& program)
-{
-    AutoInitialize autoInitialize(program.nameContext());
-    autoInitialize.Visitor::visit(program);
-    return autoInitialize.result();
-}
-
-} // namespace WHLSL
-
-} // namespace WebCore
-
-#endif // ENABLE(WEBGPU)

Deleted: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h (248309 => 248310)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h	2019-08-06 20:31:04 UTC (rev 248310)
@@ -1,45 +0,0 @@
-/*
- * 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)
-
-#include "WHLSLError.h"
-#include <wtf/Expected.h>
-
-namespace WebCore {
-
-namespace WHLSL {
-
-class Program;
-
-Expected<void, Error> autoInitializeVariables(Program&);
-
-}
-
-}
-
-#endif

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


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp	2019-08-06 20:31:04 UTC (rev 248310)
@@ -29,7 +29,6 @@
 #if ENABLE(WEBGPU)
 
 #include "WHLSLASTDumper.h"
-#include "WHLSLAutoInitializeVariables.h"
 #include "WHLSLCheckDuplicateFunctions.h"
 #include "WHLSLCheckTextureReferences.h"
 #include "WHLSLChecker.h"
@@ -187,7 +186,6 @@
 
     RUN_PASS(checkLiteralTypes, program);
     CHECK_PASS(checkTextureReferences, program);
-    CHECK_PASS(autoInitializeVariables, program);
     RUN_PASS(resolveProperties, program);
     RUN_PASS(findHighZombies, program);
     CHECK_PASS(checkStatementBehavior, program);

Modified: trunk/Source/WebCore/Sources.txt (248309 => 248310)


--- trunk/Source/WebCore/Sources.txt	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/Sources.txt	2019-08-06 20:31:04 UTC (rev 248310)
@@ -309,7 +309,6 @@
 Modules/webgpu/WHLSL/WHLSLComputeDimensions.cpp
 Modules/webgpu/WHLSL/WHLSLStandardLibraryUtilities.cpp
 Modules/webgpu/WHLSL/WHLSLASTDumper.cpp
-Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp
 Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
 Modules/webgpu/WHLSL/WHLSLLexer.cpp
 Modules/webgpu/WHLSL/WHLSLParser.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (248309 => 248310)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-08-06 20:18:43 UTC (rev 248309)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-08-06 20:31:04 UTC (rev 248310)
@@ -8324,8 +8324,6 @@
 		52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformView.h; sourceTree = "<group>"; };
 		52B0D4BF1C57FD660077CE53 /* VideoFullscreenChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenChangeObserver.h; sourceTree = "<group>"; };
 		52B0D4C11C57FF910077CE53 /* VideoFullscreenInterfaceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenInterfaceMac.h; sourceTree = "<group>"; };
-		52B3434922A0752200E49389 /* WHLSLAutoInitializeVariables.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAutoInitializeVariables.h; sourceTree = "<group>"; };
-		52B3434B22A0752300E49389 /* WHLSLAutoInitializeVariables.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLAutoInitializeVariables.cpp; sourceTree = "<group>"; };
 		52D5A18D1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenLayerManagerObjC.mm; sourceTree = "<group>"; };
 		52D5A18E1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenLayerManagerObjC.h; sourceTree = "<group>"; };
 		52D5A1A41C57488900DE34A3 /* VideoFullscreenModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenModel.h; sourceTree = "<group>"; };
@@ -25496,8 +25494,6 @@
 				1CECB3AD21F2B96400F44542 /* Metal */,
 				C20F88AA22966B0E00D610FA /* WHLSLASTDumper.cpp */,
 				C20F88AC22966B0F00D610FA /* WHLSLASTDumper.h */,
-				52B3434B22A0752300E49389 /* WHLSLAutoInitializeVariables.cpp */,
-				52B3434922A0752200E49389 /* WHLSLAutoInitializeVariables.h */,
 				1C6B95DD22C858A400E6F14F /* WHLSLBuildStandardLibraryFunctionMap.py */,
 				C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */,
 				C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to