[WHLSL] Auto initialize local variables
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jun 2019 19:58:19 +0000 (19:58 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jun 2019 19:58:19 +0000 (19:58 +0000)
commitc99b7c2d9dc8be9d805a0df6f9233a3ff34b9cc2
treee2a7ddd91c432babadbd2f7b4a1bfd3b35a69615
parent2eb338848b2e47f413baec83d75094717a877199
[WHLSL] Auto initialize local variables
https://bugs.webkit.org/show_bug.cgi?id=198426

Reviewed by Myles Maxfield.

Source/WebCore:

This patch implements zero-filling for local variables in two parts:
1. We add a new pass, autoInitializeVariables, which makes any variable declaration
without an initializer call the default constructor for the variable's type.
Since we auto generate the default constructor, it's a native function whose
implementation we control.

2. Each native constructor is implemented as a memset(&value, sizeof(value), 0).
This memset is an inlined loop in each constructor. The reason this turns
everything into zero is that for every primitive type, the "zero" value is
represented as all zeroes in memory: float, int, pointers, etc.

Since our ability to test some of this is limited, I opened a follow-up bug to
test this more:
https://bugs.webkit.org/show_bug.cgi?id=198413

Tests: webgpu/whlsl-zero-initialize-values-2.html
       webgpu/whlsl-zero-initialize-values.html

* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h:
(WebCore::WHLSL::AST::VariableDeclaration::setInitializer):
* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
* Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
(WebCore::WHLSL::Metal::writeNativeFunction):
* Modules/webgpu/WHLSL/WHLSLASTDumper.h:
* Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: Added.
(WebCore::WHLSL::AutoInitialize::AutoInitialize):
(WebCore::WHLSL::AutoInitialize::visit):
(WebCore::WHLSL::autoInitializeVariables):
* Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h: Added.
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::checkOperatorOverload):
(WebCore::WHLSL::Checker::visit):
* Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
(WebCore::WHLSL::inferTypesForCallImpl):
(WebCore::WHLSL::inferTypesForCall):
* Modules/webgpu/WHLSL/WHLSLInferTypes.h:
* Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
(WebCore::WHLSL::prepareShared):
* Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp:
(WebCore::WHLSL::resolveFunctionOverloadImpl):
(WebCore::WHLSL::resolveFunctionOverload):
* Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

LayoutTests:

* webgpu/whlsl-zero-initialize-values-2-expected.html: Added.
* webgpu/whlsl-zero-initialize-values-2.html: Added.
* webgpu/whlsl-zero-initialize-values-expected.html: Added.
* webgpu/whlsl-zero-initialize-values.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246273 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl-zero-initialize-values-2-expected.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-zero-initialize-values-2.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-zero-initialize-values-expected.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-zero-initialize-values.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.h
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj