[WHLSL] Remove the auto initialize variables pass
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Aug 2019 20:31:04 +0000 (20:31 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Aug 2019 20:31:04 +0000 (20:31 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248310 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp [deleted file]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h [deleted file]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj

index ab2958a..1e6f782 100644 (file)
@@ -1,3 +1,27 @@
+2019-08-06  Saam Barati  <sbarati@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  <weinig@apple.com>
 
         WHLSL Metal code generation unnecessarily does string copies by passing partial results as Strings
index d20ce0a..761c1a3 100644 (file)
@@ -551,7 +551,7 @@ void FunctionDefinitionWriter::visit(AST::VariableDeclaration& variableDeclarati
         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)
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp
deleted file mode 100644 (file)
index 6f1cba8..0000000
+++ /dev/null
@@ -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)
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h
deleted file mode 100644 (file)
index 2867789..0000000
+++ /dev/null
@@ -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
index 752ac5d..f87f3af 100644 (file)
@@ -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 @@ static Expected<Program, String> prepareShared(PhaseTimes& phaseTimes, String& w
 
     RUN_PASS(checkLiteralTypes, program);
     CHECK_PASS(checkTextureReferences, program);
-    CHECK_PASS(autoInitializeVariables, program);
     RUN_PASS(resolveProperties, program);
     RUN_PASS(findHighZombies, program);
     CHECK_PASS(checkStatementBehavior, program);
index e4eb72c..e54cb96 100644 (file)
@@ -309,7 +309,6 @@ Modules/webgpu/NavigatorGPU.cpp
 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
index bc9ac27..372084c 100644 (file)
                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>"; };
                                1CECB3AD21F2B96400F44542 /* Metal */,
                                C20F88AA22966B0E00D610FA /* WHLSLASTDumper.cpp */,
                                C20F88AC22966B0F00D610FA /* WHLSLASTDumper.h */,
-                               52B3434B22A0752300E49389 /* WHLSLAutoInitializeVariables.cpp */,
-                               52B3434922A0752200E49389 /* WHLSLAutoInitializeVariables.h */,
                                1C6B95DD22C858A400E6F14F /* WHLSLBuildStandardLibraryFunctionMap.py */,
                                C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */,
                                C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */,