From 3f2efbd1b904cdc9358ed328235502e338b020bf Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 23 Nov 2018 12:34:48 +0100 Subject: V4: Generate labels for backward jumps When analyzing the bytecode from top-to-bottom in a single pass, we don't know when a jump back to previously seen code occurs. For example, in the baseline JIT we would already have generated code for some bytecode when we see a jump back (like at the end of a loop body), and we can't go back and insert a label to jump to. As JavaScript has no goto's, the only backward jumps are at the end of loops, so there are very few cases where we need to actually generate labels. This was previously handled by analyzing the bytecode twice: once to collect all jump targets, and then second pass over the bytecode to do the actual JITting (which would use the jump targets to insert labels). We can now do that with one single pass. So the trade-off is to store 4 bytes more per function plus 4 bytes for each loop, instead of having to analyze all functions only to find where all jumps are each time that function is JITted. Change-Id: I3abfcb69f65851a397dbd4a9762ea5e9e57495f6 Reviewed-by: Ulf Hermann --- src/qml/compiler/qv4compiler.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/qml/compiler/qv4compiler.cpp') diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 8735cc074b..0833f552e6 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -445,6 +445,12 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte currentOffset += function->nDependingScopeProperties * sizeof(quint32) * 2; } + if (!irFunction->labelInfo.empty()) { + function->nLabelInfos = quint32(irFunction->labelInfo.size()); + Q_ASSERT(function->labelInfosOffset() == currentOffset); + currentOffset += function->nLabelInfos * sizeof(quint32); + } + function->location.line = irFunction->line; function->location.column = irFunction->column; @@ -483,6 +489,11 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte *writtenDeps++ = property.value(); // notify index } + quint32_le *labels = (quint32_le *)(f + function->labelInfosOffset()); + for (unsigned u : irFunction->labelInfo) { + *labels++ = u; + } + // write byte code memcpy(f + function->codeOffset, irFunction->code.constData(), irFunction->code.size()); } @@ -682,7 +693,7 @@ QV4::CompiledData::Unit QV4::Compiler::JSUnitGenerator::generateHeader(QV4::Comp const int qmlIdDepsCount = f->idObjectDependencies.count(); const int qmlPropertyDepsCount = f->scopeObjectPropertyDependencies.count() + f->contextObjectPropertyDependencies.count(); quint32 size = QV4::CompiledData::Function::calculateSize(f->arguments.size(), f->locals.size(), f->lineNumberMapping.size(), f->nestedContexts.size(), - qmlIdDepsCount, qmlPropertyDepsCount, f->code.size()); + qmlIdDepsCount, qmlPropertyDepsCount, int(f->labelInfo.size()), f->code.size()); functionSize += size - f->code.size(); nextOffset += size; } -- cgit v1.2.3