aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2011-07-21 14:47:26 +0200
committerQt by Nokia <qt-info@nokia.com>2011-08-30 13:18:28 +0200
commit039432362d9c0897f4fbe4334c1d9c99aaf98be8 (patch)
tree43226de541b0bd6974493b25781a81079426f205 /src
parentfcc416defbaeabcc77cdbf86b9a5e1942c66585d (diff)
Speedup the V4 code generation.
Skip discarded code and use QVarLengthArray instead of QByteArray to store the bytecode. Change-Id: I4c574e7a817595bc8942ed9a927e79339a2d7b40 Reviewed-on: http://codereview.qt.nokia.com/3760 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/v4/qdeclarativev4compiler.cpp32
-rw-r--r--src/declarative/qml/v4/qdeclarativev4instruction.cpp8
-rw-r--r--src/declarative/qml/v4/qdeclarativev4instruction_p.h13
-rw-r--r--src/declarative/qml/v4/qdeclarativev4irbuilder.cpp29
-rw-r--r--src/declarative/qml/v4/qdeclarativev4irbuilder_p.h4
5 files changed, 55 insertions, 31 deletions
diff --git a/src/declarative/qml/v4/qdeclarativev4compiler.cpp b/src/declarative/qml/v4/qdeclarativev4compiler.cpp
index 4890722667..c77a737dca 100644
--- a/src/declarative/qml/v4/qdeclarativev4compiler.cpp
+++ b/src/declarative/qml/v4/qdeclarativev4compiler.cpp
@@ -85,7 +85,7 @@ void QDeclarativeV4CompilerPrivate::trace(int line, int column)
currentBlockMask = 0x00000001;
- for (int i = 0; i < blocks.size(); ++i) {
+ for (int i = 0; !_discarded && i < blocks.size(); ++i) {
IR::BasicBlock *block = blocks.at(i);
IR::BasicBlock *next = i + 1 < blocks.size() ? blocks.at(i + 1) : 0;
if (IR::Stmt *terminator = block->terminator()) {
@@ -137,8 +137,10 @@ void QDeclarativeV4CompilerPrivate::trace(int line, int column)
blockop.block(currentBlockMask);
gen(blockop);
- foreach (IR::Stmt *s, block->statements)
- s->accept(this);
+ foreach (IR::Stmt *s, block->statements) {
+ if (! _discarded)
+ s->accept(this);
+ }
qSwap(usedSubscriptionIdsChanged, usic);
@@ -148,7 +150,7 @@ void QDeclarativeV4CompilerPrivate::trace(int line, int column)
return;
}
currentBlockMask <<= 1;
- } else {
+ } else if (! _discarded) {
const int adjust = bytecode.remove(blockopIndex);
// Correct patches
for (int ii = patchesCount; ii < patches.count(); ++ii)
@@ -164,13 +166,15 @@ void QDeclarativeV4CompilerPrivate::trace(int line, int column)
#endif
- // back patching
- foreach (const Patch &patch, patches) {
- Instr &instr = bytecode[patch.offset];
- instr.branchop.offset = patch.block->offset - patch.offset - instr.size();
- }
+ if (! _discarded) {
+ // back patching
+ foreach (const Patch &patch, patches) {
+ Instr &instr = bytecode[patch.offset];
+ instr.branchop.offset = patch.block->offset - patch.offset - instr.size();
+ }
- patches.clear();
+ patches.clear();
+ }
}
void QDeclarativeV4CompilerPrivate::trace(QVector<IR::BasicBlock *> *blocks)
@@ -1005,7 +1009,7 @@ int QDeclarativeV4CompilerPrivate::commitCompile()
int rv = committed.count();
committed.offsets << committed.bytecode.count();
committed.dependencies << usedSubscriptionIds;
- committed.bytecode += bytecode.code();
+ committed.bytecode.append(bytecode.constData(), bytecode.size());
committed.data = data;
committed.exceptions = exceptions;
committed.subscriptionIds = subscriptionIds;
@@ -1280,8 +1284,10 @@ QByteArray QDeclarativeV4Compiler::program() const
}
- QByteArray bytecode = bc.code();
- bytecode += d->committed.bytecode;
+ QByteArray bytecode;
+ bytecode.reserve(bc.size() + d->committed.bytecode.size());
+ bytecode.append(bc.constData(), bc.size());
+ bytecode.append(d->committed.bytecode.constData(), d->committed.bytecode.size());
QByteArray data = d->committed.data;
while (data.count() % 4) data.append('\0');
diff --git a/src/declarative/qml/v4/qdeclarativev4instruction.cpp b/src/declarative/qml/v4/qdeclarativev4instruction.cpp
index a520a3584a..93bb206c1a 100644
--- a/src/declarative/qml/v4/qdeclarativev4instruction.cpp
+++ b/src/declarative/qml/v4/qdeclarativev4instruction.cpp
@@ -512,6 +512,8 @@ void Instr::block(quint32 mask)
Bytecode::Bytecode()
{
+ d.reserve(8 * 1024);
+
#ifdef QML_THREADED_INTERPRETER
decodeInstr = QDeclarativeV4Bindings::getDecodeInstrTable();
#endif
@@ -530,12 +532,6 @@ void Bytecode::append(const Instr &instr)
d.append(it, instr.size());
}
-void Bytecode::append(const QVector<Instr> &instrs)
-{
- foreach (const Instr &i, instrs)
- append(i);
-}
-
int Bytecode::remove(int offset)
{
const Instr *instr = (const Instr *) (d.begin() + offset);
diff --git a/src/declarative/qml/v4/qdeclarativev4instruction_p.h b/src/declarative/qml/v4/qdeclarativev4instruction_p.h
index e3ac9027f7..6efe9332d1 100644
--- a/src/declarative/qml/v4/qdeclarativev4instruction_p.h
+++ b/src/declarative/qml/v4/qdeclarativev4instruction_p.h
@@ -56,6 +56,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qvector.h>
+#include <QtCore/qvarlengtharray.h>
QT_BEGIN_HEADER
@@ -414,21 +415,27 @@ class Bytecode
public:
Bytecode();
- QByteArray code() const { return d; }
const char *constData() const { return d.constData(); }
int size() const { return d.size(); }
int count() const { return d.count(); }
void clear() { d.clear(); }
bool isEmpty() const { return d.isEmpty(); }
void append(const Instr &instr);
- void append(const QVector<Instr> &instrs);
+
+ template <typename _It>
+ void append(_It it, _It last)
+ {
+ for (; it != last; ++it)
+ append(*it);
+ }
+
int remove(int index);
const Instr &operator[](int offset) const;
Instr &operator[](int offset);
private:
- QByteArray d;
+ QVarLengthArray<char, 4 * 1024> d;
#ifdef QML_THREADED_INTERPRETER
void **decodeInstr;
#endif
diff --git a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
index 915bf5fa91..18a52bb8cd 100644
--- a/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
+++ b/src/declarative/qml/v4/qdeclarativev4irbuilder.cpp
@@ -136,12 +136,12 @@ QDeclarativeV4IRBuilder::operator()(QDeclarativeJS::IR::Module *module,
return discarded?0:function;
}
-bool QDeclarativeV4IRBuilder::buildName(QStringList &name,
+bool QDeclarativeV4IRBuilder::buildName(QList<QStringRef> &name,
AST::Node *node,
QList<AST::ExpressionNode *> *nodes)
{
if (node->kind == AST::Node::Kind_IdentifierExpression) {
- name << static_cast<AST::IdentifierExpression*>(node)->name.toString();
+ name << static_cast<AST::IdentifierExpression*>(node)->name;
if (nodes) *nodes << static_cast<AST::IdentifierExpression*>(node);
} else if (node->kind == AST::Node::Kind_FieldMemberExpression) {
AST::FieldMemberExpression *expr =
@@ -150,7 +150,7 @@ bool QDeclarativeV4IRBuilder::buildName(QStringList &name,
if (!buildName(name, expr->base, nodes))
return false;
- name << expr->name.toString();
+ name << expr->name;
if (nodes) *nodes << expr;
} else {
return false;
@@ -683,6 +683,11 @@ bool QDeclarativeV4IRBuilder::visit(AST::FieldMemberExpression *ast)
return false;
}
+bool QDeclarativeV4IRBuilder::preVisit(AST::Node *ast)
+{
+ return ! _discard;
+}
+
bool QDeclarativeV4IRBuilder::visit(AST::NewMemberExpression *)
{
return false;
@@ -695,14 +700,22 @@ bool QDeclarativeV4IRBuilder::visit(AST::NewExpression *)
bool QDeclarativeV4IRBuilder::visit(AST::CallExpression *ast)
{
- QStringList names;
+ QList<QStringRef> names;
QList<AST::ExpressionNode *> nameNodes;
+
+ names.reserve(4);
+ nameNodes.reserve(4);
+
if (buildName(names, ast->base, &nameNodes)) {
//ExprResult base = expression(ast->base);
- const QString id = names.join(QLatin1String("."));
- const quint32 line = nameNodes.last()->firstSourceLocation().startLine;
- const quint32 column = nameNodes.last()->firstSourceLocation().startColumn;
- IR::Expr *base = _block->NAME(id, line, column);
+ QString id;
+ for (int i = 0; i < names.size(); ++i) {
+ if (! i)
+ id += QLatin1Char('.');
+ id += names.at(i);
+ }
+ const AST::SourceLocation loc = nameNodes.last()->firstSourceLocation();
+ IR::Expr *base = _block->NAME(id, loc.startLine, loc.startColumn);
IR::ExprList *args = 0, **argsInserter = &args;
for (AST::ArgumentList *it = ast->arguments; it; it = it->next) {
diff --git a/src/declarative/qml/v4/qdeclarativev4irbuilder_p.h b/src/declarative/qml/v4/qdeclarativev4irbuilder_p.h
index 69f9cbabed..47f5b3f6fc 100644
--- a/src/declarative/qml/v4/qdeclarativev4irbuilder_p.h
+++ b/src/declarative/qml/v4/qdeclarativev4irbuilder_p.h
@@ -115,6 +115,8 @@ protected:
void implicitCvt(ExprResult &expr, QDeclarativeJS::IR::Type type);
+ virtual bool preVisit(QDeclarativeJS::AST::Node *ast);
+
// QML
virtual bool visit(QDeclarativeJS::AST::UiProgram *ast);
virtual bool visit(QDeclarativeJS::AST::UiImportList *ast);
@@ -220,7 +222,7 @@ protected:
virtual bool visit(QDeclarativeJS::AST::DebuggerStatement *ast);
private:
- bool buildName(QStringList &name, QDeclarativeJS::AST::Node *node,
+ bool buildName(QList<QStringRef> &name, QDeclarativeJS::AST::Node *node,
QList<QDeclarativeJS::AST::ExpressionNode *> *nodes);
void discard();