Changeset 247170 in webkit
- Timestamp:
- Jul 5, 2019, 1:09:39 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r247165 r247170 1 2019-07-05 Robin Morisset <rmorisset@apple.com> 2 3 [WHLSL] Remove the phase resolveCallsInFunctions 4 https://bugs.webkit.org/show_bug.cgi?id=199474 5 6 Reviewed by Myles Maxfield. 7 8 This pass only stores into each property access and call expression vectors of all the functions it might be calling, for use by the Checker afterwards. 9 But the checker is perfectly able to compute a pointer to these vectors by itself. 10 So by removing this pass, we gain the following: 11 - One less pass over the AST 12 - No need to copy these vectors (which can be large for heavily overloaded functions, of which there are quite a few in the stdlib) 13 - No need to have these vectors in the expressions, saving 24 bytes per CallExpression and 72 bytes per PropertyAccessExpression 14 - No need to allocate and then destroy these vectors. 15 16 No new tests as there is no intended functional change. 17 18 * Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h: 19 (WebCore::WHLSL::AST::CallExpression::castReturnType): 20 * Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h: 21 * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: 22 (WebCore::WHLSL::AutoInitialize::visit): 23 * Modules/webgpu/WHLSL/WHLSLChecker.cpp: 24 (WebCore::WHLSL::resolveFunction): 25 (WebCore::WHLSL::Checker::finishVisiting): 26 (WebCore::WHLSL::Checker::visit): 27 * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: 28 (WebCore::WHLSL::NameResolver::NameResolver): 29 (WebCore::WHLSL::NameResolver::visit): 30 * Modules/webgpu/WHLSL/WHLSLNameResolver.h: 31 * Modules/webgpu/WHLSL/WHLSLPrepare.cpp: 32 (WebCore::WHLSL::prepareShared): 33 1 34 2019-07-05 Youenn Fablet <youenn@apple.com> 2 35 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h
r247164 r247170 68 68 bool isCast() { return m_castReturnType; } 69 69 NamedType* castReturnType() { return m_castReturnType; } 70 bool hasOverloads() const { return static_cast<bool>(m_overloads); }71 Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>>& overloads() { return m_overloads; }72 void setOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)73 {74 assert(!hasOverloads());75 m_overloads = overloads;76 }77 78 70 FunctionDeclaration* function() { return m_function; } 79 71 … … 87 79 String m_name; 88 80 Vector<UniqueRef<Expression>> m_arguments; 89 Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>> m_overloads;90 81 FunctionDeclaration* m_function { nullptr }; 91 82 NamedType* m_castReturnType { nullptr }; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h
r247144 r247170 58 58 virtual String anderFunctionName() const = 0; 59 59 60 Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleGetterOverloads() { return m_possibleGetterOverloads; }61 Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleSetterOverloads() { return m_possibleSetterOverloads; }62 Vector<std::reference_wrapper<FunctionDeclaration>, 1>& possibleAnderOverloads() { return m_possibleAnderOverloads; }63 60 FunctionDeclaration* getterFunction() { return m_getterFunction; } 64 61 FunctionDeclaration* anderFunction() { return m_anderFunction; } 65 62 FunctionDeclaration* threadAnderFunction() { return m_threadAnderFunction; } 66 63 FunctionDeclaration* setterFunction() { return m_setterFunction; } 67 68 void setPossibleGetterOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)69 {70 m_possibleGetterOverloads = overloads;71 }72 void setPossibleAnderOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)73 {74 m_possibleAnderOverloads = overloads;75 }76 void setPossibleSetterOverloads(const Vector<std::reference_wrapper<FunctionDeclaration>, 1>& overloads)77 {78 m_possibleSetterOverloads = overloads;79 }80 64 81 65 void setGetterFunction(FunctionDeclaration* getterFunction) … … 105 89 private: 106 90 UniqueRef<Expression> m_base; 107 Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleGetterOverloads;108 Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleSetterOverloads;109 Vector<std::reference_wrapper<FunctionDeclaration>, 1> m_possibleAnderOverloads;110 91 FunctionDeclaration* m_getterFunction { nullptr }; 111 92 FunctionDeclaration* m_anderFunction { nullptr }; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp
r247144 r247170 73 73 callExpression->setType(type->clone()); 74 74 callExpression->setTypeAnnotation(AST::RightValue()); 75 callExpression->setOverloads(m_castFunctions);76 75 Vector<std::reference_wrapper<ResolvingType>> argumentTypes; 77 auto* function = resolveFunctionOverload( *callExpression->overloads(), argumentTypes, type);76 auto* function = resolveFunctionOverload(m_castFunctions, argumentTypes, type); 78 77 if (!function) { 79 78 setError(); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
r247164 r247170 47 47 #include "WHLSLMakeArrayReferenceExpression.h" 48 48 #include "WHLSLMakePointerExpression.h" 49 #include "WHLSLNameContext.h" 49 50 #include "WHLSLPointerType.h" 50 51 #include "WHLSLProgram.h" … … 216 217 } 217 218 218 static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>& possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, Lexer::Token origin, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr) 219 { 220 if (AST::FunctionDeclaration* function = resolveFunctionOverload(possibleOverloads, types, castReturnType)) 221 return function; 219 static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, Lexer::Token origin, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr) 220 { 221 if (possibleOverloads) { 222 if (AST::FunctionDeclaration* function = resolveFunctionOverload(*possibleOverloads, types, castReturnType)) 223 return function; 224 } 222 225 223 226 if (auto newFunction = resolveByInstantiation(name, origin, types, intrinsics)) { … … 1020 1023 if (additionalArgumentType) 1021 1024 getterArgumentTypes.append(*additionalArgumentType); 1022 if ((getterFunction = resolveFunction(m_program, propertyAccessExpression.possibleGetterOverloads(), getterArgumentTypes, propertyAccessExpression.getterFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1025 auto getterName = propertyAccessExpression.getterFunctionName(); 1026 auto* getterFunctions = m_program.nameContext().getFunctions(getterName); 1027 getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.origin(), m_intrinsics); 1028 if (getterFunction) 1023 1029 getterReturnType = &getterFunction->type(); 1024 1030 } … … 1033 1039 if (additionalArgumentType) 1034 1040 anderArgumentTypes.append(*additionalArgumentType); 1035 if ((anderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1041 auto anderName = propertyAccessExpression.anderFunctionName(); 1042 auto* anderFunctions = m_program.nameContext().getFunctions(anderName); 1043 anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics); 1044 if (anderFunction) 1036 1045 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 1037 1046 } … … 1045 1054 if (additionalArgumentType) 1046 1055 threadAnderArgumentTypes.append(*additionalArgumentType); 1047 if ((threadAnderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), threadAnderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1056 auto anderName = propertyAccessExpression.anderFunctionName(); 1057 auto* anderFunctions = m_program.nameContext().getFunctions(anderName); 1058 threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics); 1059 if (threadAnderFunction) 1048 1060 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 1049 1061 } … … 1089 1101 setterArgumentTypes.append(*additionalArgumentType); 1090 1102 setterArgumentTypes.append(fieldResolvingType); 1091 setterFunction = resolveFunction(m_program, propertyAccessExpression.possibleSetterOverloads(), setterArgumentTypes, propertyAccessExpression.setterFunctionName(), propertyAccessExpression.origin(), m_intrinsics); 1103 auto setterName = propertyAccessExpression.setterFunctionName(); 1104 auto* setterFunctions = m_program.nameContext().getFunctions(setterName); 1105 setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.origin(), m_intrinsics); 1092 1106 if (setterFunction) 1093 1107 setterReturnType = &setterFunction->type(); … … 1470 1484 // We don't want to recurse to the same node twice. 1471 1485 1472 ASSERT(callExpression.hasOverloads()); 1473 auto* function = resolveFunction(m_program, *callExpression.overloads(), types, callExpression.name(), callExpression.origin(), m_intrinsics, callExpression.castReturnType()); 1486 NameContext& nameContext = m_program.nameContext(); 1487 auto* functions = nameContext.getFunctions(callExpression.name()); 1488 if (!functions) { 1489 if (auto* types = nameContext.getTypes(callExpression.name())) { 1490 if (types->size() == 1) { 1491 if ((functions = nameContext.getFunctions("operator cast"_str))) 1492 callExpression.setCastData((*types)[0].get()); 1493 } 1494 } 1495 } 1496 if (!functions) { 1497 setError(); 1498 return; 1499 } 1500 1501 auto* function = resolveFunction(m_program, functions, types, callExpression.name(), callExpression.origin(), m_intrinsics, callExpression.castReturnType()); 1474 1502 if (!function) { 1475 1503 setError(); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
r247164 r247170 62 62 , m_parentNameResolver(&parentResolver) 63 63 { 64 m_isResolvingCalls = parentResolver.m_isResolvingCalls;65 64 setCurrentFunctionDefinition(parentResolver.m_currentFunction); 66 65 } … … 74 73 void NameResolver::visit(AST::TypeReference& typeReference) 75 74 { 76 if (m_isResolvingCalls)77 return;78 79 75 ScopedSetAdder<AST::TypeReference*> adder(m_typeReferences, &typeReference); 80 76 if (!adder.isNewEntry()) { … … 200 196 void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression) 201 197 { 202 if (m_isResolvingCalls) {203 if (auto* getterFunctions = m_nameContext.getFunctions(propertyAccessExpression.getterFunctionName()))204 propertyAccessExpression.setPossibleGetterOverloads(*getterFunctions);205 if (auto* setterFunctions = m_nameContext.getFunctions(propertyAccessExpression.setterFunctionName()))206 propertyAccessExpression.setPossibleSetterOverloads(*setterFunctions);207 if (auto* anderFunctions = m_nameContext.getFunctions(propertyAccessExpression.anderFunctionName()))208 propertyAccessExpression.setPossibleAnderOverloads(*anderFunctions);209 }210 198 Visitor::visit(propertyAccessExpression); 211 199 } … … 238 226 void NameResolver::visit(AST::CallExpression& callExpression) 239 227 { 240 if (m_isResolvingCalls) {241 if (!callExpression.hasOverloads()) {242 if (auto* functions = m_nameContext.getFunctions(callExpression.name()))243 callExpression.setOverloads(*functions);244 else {245 if (auto* types = m_nameContext.getTypes(callExpression.name())) {246 if (types->size() == 1) {247 if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) {248 callExpression.setCastData((*types)[0].get());249 callExpression.setOverloads(*functions);250 }251 }252 }253 }254 }255 if (!callExpression.hasOverloads()) {256 setError();257 return;258 }259 }260 228 Visitor::visit(callExpression); 261 229 } … … 332 300 } 333 301 334 bool resolveCallsInFunctions(Program& program, NameResolver& nameResolver)335 {336 nameResolver.setIsResolvingCalls(true);337 for (auto& functionDefinition : program.functionDefinitions()) {338 nameResolver.setCurrentFunctionDefinition(&functionDefinition);339 nameResolver.checkErrorAndVisit(functionDefinition);340 if (nameResolver.error())341 return false;342 }343 nameResolver.setCurrentFunctionDefinition(nullptr);344 nameResolver.setIsResolvingCalls(false);345 return true;346 }347 348 302 } // namespace WHLSL 349 303 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
r247144 r247170 52 52 } 53 53 54 void setIsResolvingCalls(bool isResolvingCalls) { m_isResolvingCalls = isResolvingCalls; }55 56 54 private: 57 55 void visit(AST::NativeFunctionDeclaration&) override; … … 74 72 AST::FunctionDefinition* m_currentFunction { nullptr }; 75 73 NameResolver* m_parentNameResolver { nullptr }; 76 bool m_isResolvingCalls { false };77 74 }; 78 75 79 76 bool resolveNamesInTypes(Program&, NameResolver&); 80 77 bool resolveTypeNamesInFunctions(Program&, NameResolver&); 81 bool resolveCallsInFunctions(Program&, NameResolver&);82 78 83 79 } // namespace WHLSL -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp
r247164 r247170 134 134 CHECK_PASS(resolveTypeNamesInFunctions, program, nameResolver); 135 135 CHECK_PASS(synthesizeConstructors, program); 136 CHECK_PASS(resolveCallsInFunctions, program, nameResolver);137 136 CHECK_PASS(checkDuplicateFunctions, program); 138 137 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
r247110 r247170 760 760 Vector<UniqueRef<AST::Expression>> arguments; 761 761 arguments.append(propertyAccessExpression.takeBase()); 762 if (is<AST::IndexExpression>(propertyAccessExpression)) 763 arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex()); 764 auto* callExpression = AST::replaceWith<AST::CallExpression>(propertyAccessExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); 762 AST::CallExpression* callExpression; 763 if (is<AST::IndexExpression>(propertyAccessExpression)) { 764 auto& indexExpression = downcast<AST::IndexExpression>(propertyAccessExpression); 765 arguments.append(indexExpression.takeIndex()); 766 callExpression = AST::replaceWith<AST::CallExpression>(indexExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); 767 } else { 768 ASSERT(is<AST::DotExpression>(propertyAccessExpression)); 769 auto& dotExpression = downcast<AST::DotExpression>(propertyAccessExpression); 770 callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); 771 } 765 772 callExpression->setFunction(getterFunction); 766 773 callExpression->setType(getterFunction.type().clone());
Note:
See TracChangeset
for help on using the changeset viewer.