Changeset 247127 in webkit
- Timestamp:
- Jul 3, 2019 6:15:38 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r247124 r247127 1 2019-07-03 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 C. 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-03 Robin Morisset <rmorisset@apple.com> 2 35 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h
r247115 r247127 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 70 78 71 FunctionDeclaration& function() … … 91 84 String m_name; 92 85 Vector<UniqueRef<Expression>> m_arguments; 93 Optional<Vector<std::reference_wrapper<FunctionDeclaration>, 1>> m_overloads;94 86 FunctionDeclaration* m_function { nullptr }; 95 87 NamedType* m_castReturnType { nullptr }; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h
r246394 r247127 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
r247062 r247127 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
r247115 r247127 47 47 #include "WHLSLMakeArrayReferenceExpression.h" 48 48 #include "WHLSLMakePointerExpression.h" 49 #include "WHLSLNameContext.h" 49 50 #include "WHLSLPointerType.h" 50 51 #include "WHLSLProgram.h" … … 217 218 } 218 219 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 (AST::FunctionDeclaration* function = resolveFunctionOverload(possibleOverloads, types, castReturnType)) 222 return function; 220 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) 221 { 222 if (possibleOverloads) { 223 if (AST::FunctionDeclaration* function = resolveFunctionOverload(*possibleOverloads, types, castReturnType)) 224 return function; 225 } 223 226 224 227 if (auto newFunction = resolveByInstantiation(name, origin, types, intrinsics)) { … … 1021 1024 if (additionalArgumentType) 1022 1025 getterArgumentTypes.append(*additionalArgumentType); 1023 if ((getterFunction = resolveFunction(m_program, propertyAccessExpression.possibleGetterOverloads(), getterArgumentTypes, propertyAccessExpression.getterFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1026 auto getterName = propertyAccessExpression.getterFunctionName(); 1027 auto* getterFunctions = m_program.nameContext().getFunctions(getterName); 1028 getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.origin(), m_intrinsics); 1029 if (getterFunction) 1024 1030 getterReturnType = &getterFunction->type(); 1025 1031 } … … 1034 1040 if (additionalArgumentType) 1035 1041 anderArgumentTypes.append(*additionalArgumentType); 1036 if ((anderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1042 auto anderName = propertyAccessExpression.anderFunctionName(); 1043 auto* anderFunctions = m_program.nameContext().getFunctions(anderName); 1044 anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics); 1045 if (anderFunction) 1037 1046 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 1038 1047 } … … 1046 1055 if (additionalArgumentType) 1047 1056 threadAnderArgumentTypes.append(*additionalArgumentType); 1048 if ((threadAnderFunction = resolveFunction(m_program, propertyAccessExpression.possibleAnderOverloads(), threadAnderArgumentTypes, propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), m_intrinsics))) 1057 auto anderName = propertyAccessExpression.anderFunctionName(); 1058 auto* anderFunctions = m_program.nameContext().getFunctions(anderName); 1059 threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics); 1060 if (threadAnderFunction) 1049 1061 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 1050 1062 } … … 1090 1102 setterArgumentTypes.append(*additionalArgumentType); 1091 1103 setterArgumentTypes.append(fieldResolvingType); 1092 setterFunction = resolveFunction(m_program, propertyAccessExpression.possibleSetterOverloads(), setterArgumentTypes, propertyAccessExpression.setterFunctionName(), propertyAccessExpression.origin(), m_intrinsics); 1104 auto setterName = propertyAccessExpression.setterFunctionName(); 1105 auto* setterFunctions = m_program.nameContext().getFunctions(setterName); 1106 setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.origin(), m_intrinsics); 1093 1107 if (setterFunction) 1094 1108 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
r247115 r247127 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()) { … … 204 200 void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression) 205 201 { 206 if (m_isResolvingCalls) {207 if (auto* getterFunctions = m_nameContext.getFunctions(propertyAccessExpression.getterFunctionName()))208 propertyAccessExpression.setPossibleGetterOverloads(*getterFunctions);209 if (auto* setterFunctions = m_nameContext.getFunctions(propertyAccessExpression.setterFunctionName()))210 propertyAccessExpression.setPossibleSetterOverloads(*setterFunctions);211 if (auto* anderFunctions = m_nameContext.getFunctions(propertyAccessExpression.anderFunctionName()))212 propertyAccessExpression.setPossibleAnderOverloads(*anderFunctions);213 }214 202 Visitor::visit(propertyAccessExpression); 215 203 } … … 242 230 void NameResolver::visit(AST::CallExpression& callExpression) 243 231 { 244 if (m_isResolvingCalls) {245 if (!callExpression.hasOverloads()) {246 if (auto* functions = m_nameContext.getFunctions(callExpression.name()))247 callExpression.setOverloads(*functions);248 else {249 if (auto* types = m_nameContext.getTypes(callExpression.name())) {250 if (types->size() == 1) {251 if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) {252 callExpression.setCastData((*types)[0].get());253 callExpression.setOverloads(*functions);254 }255 }256 }257 }258 }259 if (!callExpression.hasOverloads()) {260 setError();261 return;262 }263 }264 232 Visitor::visit(callExpression); 265 233 } … … 336 304 } 337 305 338 bool resolveCallsInFunctions(Program& program, NameResolver& nameResolver)339 {340 nameResolver.setIsResolvingCalls(true);341 for (auto& functionDefinition : program.functionDefinitions()) {342 nameResolver.setCurrentFunctionDefinition(&functionDefinition);343 nameResolver.checkErrorAndVisit(functionDefinition);344 if (nameResolver.error())345 return false;346 }347 nameResolver.setCurrentFunctionDefinition(nullptr);348 nameResolver.setIsResolvingCalls(false);349 return true;350 }351 352 306 } // namespace WHLSL 353 307 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
r246631 r247127 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
r247115 r247127 129 129 CHECK_PASS(resolveTypeNamesInFunctions, program, nameResolver); 130 130 CHECK_PASS(synthesizeConstructors, program); 131 CHECK_PASS(resolveCallsInFunctions, program, nameResolver);132 131 CHECK_PASS(checkDuplicateFunctions, program); 133 132
Note: See TracChangeset
for help on using the changeset viewer.