From 327af26d8d5421983a10693bb9039de31a5788be Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 9 Jan 2015 14:17:31 +0100 Subject: [PATCH] V4 IR: move the MemberResolver out of IR::Temp. Temps are copied around a lot. This patch reduces the size by storing a single pointer to the resolver. Change-Id: I074b8b729fce310542cf4697ef42107085b304b3 Reviewed-by: Simon Hausmann Reviewed-by: Robin Burchell --- src/qml/compiler/qqmlirbuilder.cpp | 29 +++++++++++++++++++---------- src/qml/compiler/qv4jsir_p.h | 14 ++++++++------ src/qml/compiler/qv4ssa.cpp | 27 +++++++++++++++------------ 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 357ce37..45edbb6 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1573,8 +1573,6 @@ QQmlPropertyData *JSCodeGen::lookupQmlCompliantProperty(QQmlPropertyCache *cache return pd; } -static void initMetaObjectResolver(QV4::IR::MemberExpressionResolver *resolver, QQmlPropertyCache *metaObject); - enum MetaObjectResolverFlags { AllPropertiesAreFinal = 0x1, LookupsIncludeEnums = 0x2, @@ -1630,6 +1628,8 @@ static QV4::IR::Type resolveQmlType(QQmlEnginePrivate *qmlEngine, QV4::IR::Membe static void initQmlTypeResolver(QV4::IR::MemberExpressionResolver *resolver, QQmlType *qmlType) { + Q_ASSERT(resolver); + resolver->resolveMember = &resolveQmlType; resolver->data = qmlType; resolver->extraData = 0; @@ -1751,6 +1751,8 @@ static QV4::IR::Type resolveMetaObjectProperty(QQmlEnginePrivate *qmlEngine, QV4 static void initMetaObjectResolver(QV4::IR::MemberExpressionResolver *resolver, QQmlPropertyCache *metaObject) { + Q_ASSERT(resolver); + resolver->resolveMember = &resolveMetaObjectProperty; resolver->data = metaObject; resolver->flags = 0; @@ -1767,11 +1769,13 @@ void JSCodeGen::beginFunctionBodyHook() #ifndef V4_BOOTSTRAP QV4::IR::Temp *temp = _block->TEMP(_contextObjectTemp); - initMetaObjectResolver(&temp->memberResolver, _contextObject); + temp->memberResolver = _function->New(); + initMetaObjectResolver(temp->memberResolver, _contextObject); move(temp, _block->NAME(QV4::IR::Name::builtin_qml_context_object, 0, 0)); temp = _block->TEMP(_scopeObjectTemp); - initMetaObjectResolver(&temp->memberResolver, _scopeObject); + temp->memberResolver = _function->New(); + initMetaObjectResolver(temp->memberResolver, _scopeObject); move(temp, _block->NAME(QV4::IR::Name::builtin_qml_scope_object, 0, 0)); move(_block->TEMP(_importedScriptsTemp), _block->NAME(QV4::IR::Name::builtin_qml_imported_scripts_object, 0, 0)); @@ -1806,8 +1810,9 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int _block->MOVE(result, s); result = _block->TEMP(result->index); if (mapping.type) { - initMetaObjectResolver(&result->memberResolver, mapping.type); - result->memberResolver.flags |= AllPropertiesAreFinal; + result->memberResolver = _function->New(); + initMetaObjectResolver(result->memberResolver, mapping.type); + result->memberResolver->flags |= AllPropertiesAreFinal; } result->isReadOnly = true; // don't allow use as lvalue return result; @@ -1827,14 +1832,16 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int _block->MOVE(result, typeName); result = _block->TEMP(result->index); - initQmlTypeResolver(&result->memberResolver, r.type); + result->memberResolver = _function->New(); + initQmlTypeResolver(result->memberResolver, r.type); return result; } else { Q_ASSERT(r.importNamespace); QV4::IR::Name *namespaceName = _block->NAME(name, line, col); namespaceName->freeOfSideEffects = true; QV4::IR::Temp *result = _block->TEMP(_block->newTemp()); - initImportNamespaceResolver(&result->memberResolver, imports, r.importNamespace); + result->memberResolver = _function->New(); + initImportNamespaceResolver(result->memberResolver, imports, r.importNamespace); _block->MOVE(result, namespaceName); return _block->TEMP(result->index); @@ -1849,7 +1856,8 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int return 0; if (pd) { QV4::IR::Temp *base = _block->TEMP(_scopeObjectTemp); - initMetaObjectResolver(&base->memberResolver, _scopeObject); + base->memberResolver = _function->New(); + initMetaObjectResolver(base->memberResolver, _scopeObject); return _block->MEMBER(base, _function->newString(name), pd, QV4::IR::Member::MemberOfQmlScopeObject); } } @@ -1861,7 +1869,8 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int return 0; if (pd) { QV4::IR::Temp *base = _block->TEMP(_contextObjectTemp); - initMetaObjectResolver(&base->memberResolver, _contextObject); + base->memberResolver = _function->New(); + initMetaObjectResolver(base->memberResolver, _contextObject); return _block->MEMBER(base, _function->newString(name), pd, QV4::IR::Member::MemberOfQmlContextObject); } } diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h index 41de238..c6a192e 100644 --- a/src/qml/compiler/qv4jsir_p.h +++ b/src/qml/compiler/qv4jsir_p.h @@ -368,23 +368,25 @@ struct Q_AUTOTEST_EXPORT Temp: Expr { StackSlot }; + // Used when temp is used as base in member expression + MemberExpressionResolver *memberResolver; + unsigned index : 28; - unsigned kind : 3; unsigned isReadOnly : 1; - // Used when temp is used as base in member expression - MemberExpressionResolver memberResolver; + unsigned kind : 3; Temp() - : index((1 << 28) - 1) - , kind(Invalid) + : memberResolver(0) + , index((1 << 28) - 1) , isReadOnly(0) + , kind(Invalid) {} void init(unsigned kind, unsigned index) { - this->kind = kind; this->index = index; this->isReadOnly = false; + this->kind = kind; } bool isInvalid() const { return kind == Invalid; } diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index 718a226..d89ea07 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -2079,12 +2079,15 @@ protected: struct DiscoveredType { int type; - MemberExpressionResolver memberResolver; + MemberExpressionResolver *memberResolver; - DiscoveredType() : type(UnknownType) {} - DiscoveredType(Type t) : type(t) { Q_ASSERT(type != QObjectType); } - explicit DiscoveredType(int t) : type(t) { Q_ASSERT(type != QObjectType); } - explicit DiscoveredType(MemberExpressionResolver memberResolver) : type(QObjectType), memberResolver(memberResolver) {} + DiscoveredType() : type(UnknownType), memberResolver(0) {} + DiscoveredType(Type t) : type(t), memberResolver(0) { Q_ASSERT(type != QObjectType); } + explicit DiscoveredType(int t) : type(t), memberResolver(0) { Q_ASSERT(type != QObjectType); } + explicit DiscoveredType(MemberExpressionResolver *memberResolver) + : type(QObjectType) + , memberResolver(memberResolver) + { Q_ASSERT(memberResolver); } bool test(Type t) const { return type & t; } bool isNumber() const { return (type & NumberType) && !(type & ~NumberType); } @@ -2189,7 +2192,7 @@ class TypeInference: public StmtVisitor, public ExprVisitor this->type = type; fullyTyped = type.type != UnknownType; } - explicit TypingResult(MemberExpressionResolver memberResolver) + explicit TypingResult(MemberExpressionResolver *memberResolver) : type(memberResolver) , fullyTyped(true) {} @@ -2323,7 +2326,7 @@ protected: virtual void visitRegExp(IR::RegExp *) { _ty = TypingResult(VarType); } virtual void visitName(Name *) { _ty = TypingResult(VarType); } virtual void visitTemp(Temp *e) { - if (e->memberResolver.isValid()) + if (e->memberResolver && e->memberResolver->isValid()) _ty = TypingResult(e->memberResolver); else _ty = TypingResult(_tempTypes[e->index]); @@ -2434,9 +2437,9 @@ protected: virtual void visitMember(Member *e) { _ty = run(e->base); - if (_ty.fullyTyped && _ty.type.memberResolver.isValid()) { - MemberExpressionResolver &resolver = _ty.type.memberResolver; - _ty.type.type = resolver.resolveMember(qmlEngine, &resolver, e); + if (_ty.fullyTyped && _ty.type.memberResolver && _ty.type.memberResolver->isValid()) { + MemberExpressionResolver *resolver = _ty.type.memberResolver; + _ty.type.type = resolver->resolveMember(qmlEngine, resolver, e); } else _ty.type = VarType; } @@ -2470,8 +2473,8 @@ protected: } _ty.type.type |= ty.type.type; _ty.fullyTyped &= ty.fullyTyped; - if (_ty.type.test(QObjectType)) - _ty.type.memberResolver.clear(); // ### TODO: find common ancestor meta-object + if (_ty.type.test(QObjectType) && _ty.type.memberResolver) + _ty.type.memberResolver->clear(); // ### TODO: find common ancestor meta-object } switch (_ty.type.type) { -- 2.7.4