Changeset 246273 in webkit
- Timestamp:
- Jun 10, 2019 12:58:19 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 14 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r246270 r246273 1 2019-06-10 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Auto initialize local variables 4 https://bugs.webkit.org/show_bug.cgi?id=198426 5 6 Reviewed by Myles Maxfield. 7 8 * webgpu/whlsl-zero-initialize-values-2-expected.html: Added. 9 * webgpu/whlsl-zero-initialize-values-2.html: Added. 10 * webgpu/whlsl-zero-initialize-values-expected.html: Added. 11 * webgpu/whlsl-zero-initialize-values.html: Added. 12 1 13 2019-06-10 Timothy Hatcher <timothy@apple.com> 2 14 -
trunk/Source/WebCore/ChangeLog
r246270 r246273 1 2019-06-10 Saam Barati <sbarati@apple.com> 2 3 [WHLSL] Auto initialize local variables 4 https://bugs.webkit.org/show_bug.cgi?id=198426 5 6 Reviewed by Myles Maxfield. 7 8 This patch implements zero-filling for local variables in two parts: 9 1. We add a new pass, autoInitializeVariables, which makes any variable declaration 10 without an initializer call the default constructor for the variable's type. 11 Since we auto generate the default constructor, it's a native function whose 12 implementation we control. 13 14 2. Each native constructor is implemented as a memset(&value, sizeof(value), 0). 15 This memset is an inlined loop in each constructor. The reason this turns 16 everything into zero is that for every primitive type, the "zero" value is 17 represented as all zeroes in memory: float, int, pointers, etc. 18 19 Since our ability to test some of this is limited, I opened a follow-up bug to 20 test this more: 21 https://bugs.webkit.org/show_bug.cgi?id=198413 22 23 Tests: webgpu/whlsl-zero-initialize-values-2.html 24 webgpu/whlsl-zero-initialize-values.html 25 26 * Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h: 27 (WebCore::WHLSL::AST::VariableDeclaration::setInitializer): 28 * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp: 29 (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit): 30 * Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp: 31 (WebCore::WHLSL::Metal::writeNativeFunction): 32 * Modules/webgpu/WHLSL/WHLSLASTDumper.h: 33 * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: Added. 34 (WebCore::WHLSL::AutoInitialize::AutoInitialize): 35 (WebCore::WHLSL::AutoInitialize::visit): 36 (WebCore::WHLSL::autoInitializeVariables): 37 * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h: Added. 38 * Modules/webgpu/WHLSL/WHLSLChecker.cpp: 39 (WebCore::WHLSL::checkOperatorOverload): 40 (WebCore::WHLSL::Checker::visit): 41 * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: 42 (WebCore::WHLSL::inferTypesForCallImpl): 43 (WebCore::WHLSL::inferTypesForCall): 44 * Modules/webgpu/WHLSL/WHLSLInferTypes.h: 45 * Modules/webgpu/WHLSL/WHLSLPrepare.cpp: 46 (WebCore::WHLSL::prepareShared): 47 * Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp: 48 (WebCore::WHLSL::resolveFunctionOverloadImpl): 49 (WebCore::WHLSL::resolveFunctionOverload): 50 * Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.h: 51 * Sources.txt: 52 * WebCore.xcodeproj/project.pbxproj: 53 1 54 2019-06-10 Timothy Hatcher <timothy@apple.com> 2 55 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h
r245945 r246273 71 71 bool isAnonymous() const { return m_name.isNull(); } 72 72 Optional<UniqueRef<Expression>> takeInitializer() { return WTFMove(m_initializer); } 73 void setInitializer(UniqueRef<Expression> expression) 74 { 75 ASSERT(!initializer()); 76 m_initializer = WTFMove(expression); 77 } 73 78 74 79 private: -
trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
r246121 r246273 478 478 checkErrorAndVisit(*variableDeclaration.initializer()); 479 479 m_stringBuilder.append(makeString(m_typeNamer.mangledNameForType(*variableDeclaration.type()), ' ', variableName, " = ", m_stack.takeLast(), ";\n")); 480 } else { 481 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195771 Zero-fill the variable. 480 } else 482 481 m_stringBuilder.append(makeString(m_typeNamer.mangledNameForType(*variableDeclaration.type()), ' ', variableName, ";\n")); 483 }484 482 } 485 483 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp
r246225 r246273 105 105 stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, "() {\n")); 106 106 stringBuilder.append(makeString(" ", metalReturnName, " x;\n")); 107 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195771 Zero-fill 107 stringBuilder.append(" thread char* ptr = static_cast<thread char*>(static_cast<thread void*>(&x));\n"); 108 stringBuilder.append(makeString(" for (size_t i = 0; i < sizeof(", metalReturnName, "); ++i) ptr[i] = 0;\n")); 108 109 stringBuilder.append(" return x;\n"); 109 110 stringBuilder.append("}\n"); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h
r245945 r246273 143 143 MAKE_PRINT_ADAPTOR(StructureDefinitionDumper, AST::StructureDefinition&, dumpASTNode); 144 144 MAKE_PRINT_ADAPTOR(FunctionDefinitionDumper, AST::FunctionDefinition&, dumpASTNode); 145 MAKE_PRINT_ADAPTOR(TypeDumper, AST::UnnamedType&, dumpASTNode); 145 146 146 147 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h
r246272 r246273 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "WHLSLResolvingType.h"31 #include "WHLSLTypeArgument.h"32 #include <functional>33 #include <wtf/Vector.h>34 35 30 namespace WebCore { 36 31 37 32 namespace WHLSL { 38 33 39 namespace AST { 34 class Program; 40 35 41 class FunctionDeclaration; 42 class NamedType; 43 44 } 45 46 AST::FunctionDeclaration* resolveFunctionOverloadImpl(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::NamedType* castReturnType); 47 AST::NamedType* resolveTypeOverloadImpl(Vector<std::reference_wrapper<AST::NamedType>, 1>&, AST::TypeArguments&); 36 void autoInitializeVariables(Program&); 48 37 49 38 } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
r246225 r246273 358 358 for (auto& argumentType : argumentTypes) 359 359 argumentTypeReferences.append(argumentType); 360 auto* overload = resolveFunctionOverload Impl(*getterFuncs, argumentTypeReferences, nullptr);360 auto* overload = resolveFunctionOverload(*getterFuncs, argumentTypeReferences); 361 361 if (!overload) 362 362 return false; … … 980 980 { 981 981 Vector<std::reference_wrapper<ResolvingType>> getterArgumentTypes { baseInfo->resolvingType }; 982 getterFunction = resolveFunctionOverload Impl(dotExpression.possibleGetterOverloads(), getterArgumentTypes, nullptr);982 getterFunction = resolveFunctionOverload(dotExpression.possibleGetterOverloads(), getterArgumentTypes); 983 983 if (getterFunction) 984 984 getterReturnType = &getterFunction->type(); … … 990 990 auto argumentType = makeUniqueRef<AST::PointerType>(Lexer::Token(dotExpression.origin()), *leftAddressSpace, baseUnnamedType->get().clone()); 991 991 Vector<std::reference_wrapper<ResolvingType>> anderArgumentTypes { baseInfo->resolvingType }; 992 anderFunction = resolveFunctionOverload Impl(dotExpression.possibleAnderOverloads(), anderArgumentTypes, nullptr);992 anderFunction = resolveFunctionOverload(dotExpression.possibleAnderOverloads(), anderArgumentTypes); 993 993 if (anderFunction) 994 994 anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer … … 1000 1000 auto argumentType = makeUniqueRef<AST::PointerType>(Lexer::Token(dotExpression.origin()), AST::AddressSpace::Thread, baseUnnamedType->get().clone()); 1001 1001 Vector<std::reference_wrapper<ResolvingType>> threadAnderArgumentTypes { baseInfo->resolvingType }; 1002 threadAnderFunction = resolveFunctionOverload Impl(dotExpression.possibleAnderOverloads(), threadAnderArgumentTypes, nullptr);1002 threadAnderFunction = resolveFunctionOverload(dotExpression.possibleAnderOverloads(), threadAnderArgumentTypes); 1003 1003 if (threadAnderFunction) 1004 1004 threadAnderReturnType = &downcast<AST::PointerType>(threadAnderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer … … 1025 1025 ResolvingType fieldResolvingType(fieldType->clone()); 1026 1026 Vector<std::reference_wrapper<ResolvingType>> setterArgumentTypes { baseInfo->resolvingType, fieldResolvingType }; 1027 setterFunction = resolveFunctionOverload Impl(dotExpression.possibleSetterOverloads(), setterArgumentTypes, nullptr);1027 setterFunction = resolveFunctionOverload(dotExpression.possibleSetterOverloads(), setterArgumentTypes); 1028 1028 if (setterFunction) 1029 1029 setterReturnType = &setterFunction->type(); … … 1398 1398 1399 1399 ASSERT(callExpression.hasOverloads()); 1400 auto* function = resolveFunctionOverload Impl(*callExpression.overloads(), types, callExpression.castReturnType());1400 auto* function = resolveFunctionOverload(*callExpression.overloads(), types, callExpression.castReturnType()); 1401 1401 if (!function) { 1402 1402 if (auto newFunction = resolveByInstantiation(callExpression, types, m_intrinsics)) { -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
r245680 r246273 222 222 } 223 223 224 bool inferTypesForCall(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const AST::NamedType* castReturnType) 224 template <typename TypeKind> 225 ALWAYS_INLINE bool inferTypesForCallImpl(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const TypeKind* castReturnType) 225 226 { 226 227 if (possibleFunction.parameters().size() != argumentTypes.size()) … … 240 241 } 241 242 243 bool inferTypesForCall(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const AST::NamedType* castReturnType) 244 { 245 return inferTypesForCallImpl(possibleFunction, argumentTypes, castReturnType); 246 } 247 248 bool inferTypesForCall(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const AST::UnnamedType* castReturnType) 249 { 250 return inferTypesForCallImpl(possibleFunction, argumentTypes, castReturnType); 251 } 252 242 253 } // namespace WHLSL 243 254 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.h
r246225 r246273 55 55 bool inferTypesForTypeArguments(AST::NamedType& possibleType, AST::TypeArguments&); 56 56 bool inferTypesForCall(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const AST::NamedType* castReturnType); 57 bool inferTypesForCall(AST::FunctionDeclaration& possibleFunction, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, const AST::UnnamedType* castReturnType); 57 58 58 59 } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
r246135 r246273 30 30 31 31 #include "WHLSLASTDumper.h" 32 #include "WHLSLAutoInitializeVariables.h" 32 33 #include "WHLSLCheckDuplicateFunctions.h" 33 34 #include "WHLSLChecker.h" … … 59 60 static constexpr bool dumpASTAfterParsing = false; 60 61 static constexpr bool dumpASTAtEnd = false; 61 static constexpr bool alwaysDumpPassFailures = true;62 static constexpr bool alwaysDumpPassFailures = false; 62 63 static constexpr bool dumpPassFailure = dumpASTBeforeEachPass || dumpASTAfterParsing || dumpASTAtEnd || alwaysDumpPassFailures; 63 64 … … 131 132 132 133 checkLiteralTypes(program); 134 autoInitializeVariables(program); 133 135 resolveProperties(program); 134 136 findHighZombies(program); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp
r245680 r246273 52 52 } 53 53 54 AST::FunctionDeclaration* resolveFunctionOverloadImpl(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::NamedType* castReturnType) 54 template <typename TypeKind> 55 AST::FunctionDeclaration* resolveFunctionOverloadImpl(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, TypeKind* castReturnType) 55 56 { 56 57 Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1> candidates; … … 77 78 } 78 79 80 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes) 81 { 82 return resolveFunctionOverloadImpl(possibleFunctions, argumentTypes, static_cast<AST::NamedType*>(nullptr)); 83 } 84 85 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::NamedType* castReturnType) 86 { 87 return resolveFunctionOverloadImpl(possibleFunctions, argumentTypes, castReturnType); 88 } 89 90 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::UnnamedType* castReturnType) 91 { 92 return resolveFunctionOverloadImpl(possibleFunctions, argumentTypes, castReturnType); 93 } 94 79 95 AST::NamedType* resolveTypeOverloadImpl(Vector<std::reference_wrapper<AST::NamedType>, 1>& possibleTypes, AST::TypeArguments& typeArguments) 80 96 { -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.h
r243091 r246273 44 44 } 45 45 46 AST::FunctionDeclaration* resolveFunctionOverloadImpl(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::NamedType* castReturnType); 46 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes); 47 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::NamedType* castReturnType); 48 AST::FunctionDeclaration* resolveFunctionOverload(Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleFunctions, Vector<std::reference_wrapper<ResolvingType>>& argumentTypes, AST::UnnamedType* castReturnType); 47 49 AST::NamedType* resolveTypeOverloadImpl(Vector<std::reference_wrapper<AST::NamedType>, 1>&, AST::TypeArguments&); 48 50 -
trunk/Source/WebCore/Sources.txt
r246070 r246273 308 308 Modules/webgpu/NavigatorGPU.cpp 309 309 Modules/webgpu/WHLSL/WHLSLASTDumper.cpp 310 Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp 310 311 Modules/webgpu/WHLSL/WHLSLInferTypes.cpp 311 312 Modules/webgpu/WHLSL/WHLSLLexer.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r246270 r246273 8351 8351 52B0D4BF1C57FD660077CE53 /* VideoFullscreenChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenChangeObserver.h; sourceTree = "<group>"; }; 8352 8352 52B0D4C11C57FF910077CE53 /* VideoFullscreenInterfaceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenInterfaceMac.h; sourceTree = "<group>"; }; 8353 52B3434922A0752200E49389 /* WHLSLAutoInitializeVariables.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAutoInitializeVariables.h; sourceTree = "<group>"; }; 8354 52B3434B22A0752300E49389 /* WHLSLAutoInitializeVariables.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLAutoInitializeVariables.cpp; sourceTree = "<group>"; }; 8353 8355 52D5A18D1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenLayerManagerObjC.mm; sourceTree = "<group>"; }; 8354 8356 52D5A18E1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenLayerManagerObjC.h; sourceTree = "<group>"; }; … … 25446 25448 C20F88AA22966B0E00D610FA /* WHLSLASTDumper.cpp */, 25447 25449 C20F88AC22966B0F00D610FA /* WHLSLASTDumper.h */, 25450 52B3434B22A0752300E49389 /* WHLSLAutoInitializeVariables.cpp */, 25451 52B3434922A0752200E49389 /* WHLSLAutoInitializeVariables.h */, 25448 25452 C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */, 25449 25453 C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */,
Note: See TracChangeset
for help on using the changeset viewer.