[WHLSL] Inline typedef'd types during Metal code generation to simplify generated...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2019 18:11:12 +0000 (18:11 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2019 18:11:12 +0000 (18:11 +0000)
commit66ea2a1a7b73b1dbf714fe0895360471d40e9ed8
treeeaba91409206b7dc7e73123f1ee8c0e08d04fcca
parent469d1ad9e32e3be7be62fac37e6cce7af45c897b
[WHLSL] Inline typedef'd types during Metal code generation to simplify generated code while also making it easier to read
https://bugs.webkit.org/show_bug.cgi?id=201185

Reviewed by Saam Barati.

The current Metal code generation generates many unnecessary typedefs during TypeNamer::emitMetalTypeDefinitions
such as 'typedef float2 type19;' that can be removed by just using resolved type whereever the typedef would have
been used. The only types that actually need to be predefined are the types that declare a new struct or enum, which
means we can stop emitting for AST::TypeReference, AST::Pointer, AST::Array, and AST::TypeDefinition. Instead, the
relevent mangledNameForType constructs the computed name on the fly.

This is a 25% speedup in the metal code generation phase.

* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
Switch to using auto rather than Mangled*Name when it is obvious and the actual return type
may need to become more complicated (e.g. MangledOrNativeTypeName).

* Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.h:
* Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp:
(WebCore::WHLSL::Metal::TypeNamer::visit):
There is no need to generate typenames for AST::TypeDefinitions if they are never used.

(WebCore::WHLSL::Metal::TypeNamer::generateUniquedTypeName):
The only UnnamedType that needs a generated typename now is AST::ArrayReferenceType, which emits a struct interface.

(WebCore::WHLSL::Metal::TypeNamer::emitUnnamedTypeDefinition):
Stop generating type definitions for AST::TypeReference, AST::Pointer, AST::Array.

(WebCore::WHLSL::Metal::TypeNamer::emitNamedTypeDefinition):
Stop generating type definitions for AST::TypeDefinition.

(WebCore::WHLSL::Metal::TypeNamer::emitMetalTypeDefinitions):
Update for rename from m_unnamedTypeMapping to m_arrayReferenceTypeMapping.

(WebCore::WHLSL::Metal::TypeNamer::mangledNameForType):
Look into the types and generate a concrete type name when necessary. Lazily cache the constructed
names for AST::ArrayType and AST::Pointer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249209 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.h