Title: [248384] trunk/Source/WebCore
Revision
248384
Author
rmoris...@apple.com
Date
2019-08-07 12:58:15 -0700 (Wed, 07 Aug 2019)

Log Message

[WHLSL] Simplify and eliminate redundant work in WHLSLFunctionWriter.cpp
https://bugs.webkit.org/show_bug.cgi?id=200460

Reviewed by Myles Maxfield.

2 trivial simplifications:
- Replace FunctionDeclarationWriter by a standalone function, there was no reason to make it a subclass of Visitor
- Avoid an exponential blow-up in the computation of reachable functions.

I have way too much noise on my system (swings back and forth between 7 and 12ms for this phase) to measure a performance win,
but since this patch simplifies things without adding complexity I think it is worth it.

No new test as there is no functional change intended.

* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::declareFunction):
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::FunctionDefinitionWriter):
(WebCore::WHLSL::Metal::RenderFunctionDefinitionWriter::RenderFunctionDefinitionWriter):
(WebCore::WHLSL::Metal::ComputeFunctionDefinitionWriter::ComputeFunctionDefinitionWriter):
(WebCore::WHLSL::Metal::sharedMetalFunctions):
(WebCore::WHLSL::Metal::metalFunctions):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248383 => 248384)


--- trunk/Source/WebCore/ChangeLog	2019-08-07 19:50:04 UTC (rev 248383)
+++ trunk/Source/WebCore/ChangeLog	2019-08-07 19:58:15 UTC (rev 248384)
@@ -1,3 +1,27 @@
+2019-08-07  Robin Morisset  <rmoris...@apple.com>
+
+        [WHLSL] Simplify and eliminate redundant work in WHLSLFunctionWriter.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=200460
+
+        Reviewed by Myles Maxfield.
+
+        2 trivial simplifications:
+        - Replace FunctionDeclarationWriter by a standalone function, there was no reason to make it a subclass of Visitor
+        - Avoid an exponential blow-up in the computation of reachable functions.
+
+        I have way too much noise on my system (swings back and forth between 7 and 12ms for this phase) to measure a performance win,
+        but since this patch simplifies things without adding complexity I think it is worth it.
+
+        No new test as there is no functional change intended.
+
+        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::declareFunction):
+        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::FunctionDefinitionWriter):
+        (WebCore::WHLSL::Metal::RenderFunctionDefinitionWriter::RenderFunctionDefinitionWriter):
+        (WebCore::WHLSL::Metal::ComputeFunctionDefinitionWriter::ComputeFunctionDefinitionWriter):
+        (WebCore::WHLSL::Metal::sharedMetalFunctions):
+        (WebCore::WHLSL::Metal::metalFunctions):
+
 2019-08-07  Saam Barati  <sbar...@apple.com>
 
         [WHLSL] checkRecursion, checkTextureReferences, and EscapedVariableCollector should skip stdlib functions

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


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp	2019-08-07 19:50:04 UTC (rev 248383)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp	2019-08-07 19:58:15 UTC (rev 248384)
@@ -47,39 +47,20 @@
 
 namespace Metal {
 
-class FunctionDeclarationWriter final : public Visitor {
-public:
-    FunctionDeclarationWriter(StringBuilder& stringBuilder, TypeNamer& typeNamer, HashMap<AST::FunctionDeclaration*, MangledFunctionName>& functionMapping)
-        : m_typeNamer(typeNamer)
-        , m_functionMapping(functionMapping)
-        , m_stringBuilder(stringBuilder)
-    {
-    }
-
-    virtual ~FunctionDeclarationWriter() = default;
-
-    void visit(AST::FunctionDeclaration&) override;
-
-private:
-    TypeNamer& m_typeNamer;
-    HashMap<AST::FunctionDeclaration*, MangledFunctionName>& m_functionMapping;
-    StringBuilder& m_stringBuilder;
-};
-
-void FunctionDeclarationWriter::visit(AST::FunctionDeclaration& functionDeclaration)
+static void declareFunction(StringBuilder& stringBuilder, AST::FunctionDeclaration& functionDeclaration, TypeNamer& typeNamer, HashMap<AST::FunctionDeclaration*, MangledFunctionName>& functionMapping)
 {
     if (functionDeclaration.entryPointType())
         return;
 
-    auto iterator = m_functionMapping.find(&functionDeclaration);
-    ASSERT(iterator != m_functionMapping.end());
-    m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(functionDeclaration.type()), ' ', iterator->value, '(');
+    auto iterator = functionMapping.find(&functionDeclaration);
+    ASSERT(iterator != functionMapping.end());
+    stringBuilder.flexibleAppend(typeNamer.mangledNameForType(functionDeclaration.type()), ' ', iterator->value, '(');
     for (size_t i = 0; i < functionDeclaration.parameters().size(); ++i) {
         if (i)
-            m_stringBuilder.append(", ");
-        m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(*functionDeclaration.parameters()[i]->type()));
+            stringBuilder.append(", ");
+        stringBuilder.flexibleAppend(typeNamer.mangledNameForType(*functionDeclaration.parameters()[i]->type()));
     }
-    m_stringBuilder.append(");\n");
+    stringBuilder.append(");\n");
 }
 
 class FunctionDefinitionWriter : public Visitor {
@@ -827,10 +808,9 @@
 
 static void emitSharedMetalFunctions(StringBuilder& stringBuilder, Program& program, TypeNamer& typeNamer, const HashSet<AST::FunctionDeclaration*>& reachableFunctions, HashMap<AST::FunctionDeclaration*, MangledFunctionName>& functionMapping)
 {
-    FunctionDeclarationWriter functionDeclarationWriter(stringBuilder, typeNamer, functionMapping);
     for (auto& functionDefinition : program.functionDefinitions()) {
         if (!functionDefinition->entryPointType() && reachableFunctions.contains(&functionDefinition))
-            functionDeclarationWriter.visit(functionDefinition);
+            declareFunction(stringBuilder, functionDefinition, typeNamer, functionMapping);
     }
 
     stringBuilder.append('\n');
@@ -840,8 +820,9 @@
 public:
     void visit(AST::FunctionDeclaration& functionDeclaration) override
     {
-        Visitor::visit(functionDeclaration);
-        m_reachableFunctions.add(&functionDeclaration);
+        auto result = m_reachableFunctions.add(&functionDeclaration);
+        if (result.isNewEntry)
+            Visitor::visit(functionDeclaration);
     }
 
     void visit(AST::CallExpression& callExpression) override
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to