From 15f11ab3229c1e9b983cee63c2d3ea1078bf6f42 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Wed, 14 Jun 2017 14:36:38 +0200 Subject: [PATCH] Use cx results in loops with conditions This folds the jumps generated by e.g. && and || expressions directly into the jump to the start/end of the loop. Change-Id: I53f8cb6eb6b995b7418b57ada59c17d3a556935a Reviewed-by: Lars Knoll --- src/qml/compiler/qv4codegen.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 39e852b7b0..dd4c42d171 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2652,8 +2652,7 @@ bool Codegen::visit(DoWhileStatement *ast) statement(ast->statement); cond.link(); - Reference r = expression(ast->expression); - bytecodeGenerator->jumpEq(r.asRValue()).link(body); + condition(ast->expression, &body, &end, false); end.link(); leaveLoop(); @@ -2742,18 +2741,18 @@ bool Codegen::visit(ForStatement *ast) statement(ast->initialiser); Moth::BytecodeGenerator::Label cond = bytecodeGenerator->label(); + Moth::BytecodeGenerator::Label body = bytecodeGenerator->newLabel(); Moth::BytecodeGenerator::Label step = bytecodeGenerator->newLabel(); Moth::BytecodeGenerator::Label end = bytecodeGenerator->newLabel(); enterLoop(ast, &end, &step); - Reference r = expression(ast->condition); - bytecodeGenerator->jumpNe(r.asRValue()).link(end); + condition(ast->condition, &body, &end, true); + body.link(); statement(ast->statement); step.link(); - statement(ast->expression); bytecodeGenerator->jump().link(cond); end.link(); @@ -2881,18 +2880,18 @@ bool Codegen::visit(LocalForStatement *ast) variableDeclarationList(ast->declarations); Moth::BytecodeGenerator::Label cond = bytecodeGenerator->label(); + Moth::BytecodeGenerator::Label body = bytecodeGenerator->newLabel(); Moth::BytecodeGenerator::Label step = bytecodeGenerator->newLabel(); Moth::BytecodeGenerator::Label end = bytecodeGenerator->newLabel(); enterLoop(ast, &end, &step); - Reference r = expression(ast->condition); - bytecodeGenerator->jumpNe(r.asRValue()).link(end); + condition(ast->condition, &body, &end, true); + body.link(); statement(ast->statement); step.link(); - statement(ast->expression); bytecodeGenerator->jump().link(cond); end.link(); @@ -3164,20 +3163,19 @@ bool Codegen::visit(WhileStatement *ast) if (hasError) return true; + Moth::BytecodeGenerator::Label start = bytecodeGenerator->newLabel(); Moth::BytecodeGenerator::Label end = bytecodeGenerator->newLabel(); - Moth::BytecodeGenerator::Label cond = bytecodeGenerator->label(); enterLoop(ast, &end, &cond); - Reference r = expression(ast->expression); - Moth::BytecodeGenerator::Jump jump_end = bytecodeGenerator->jumpNe(r.asRValue()); + condition(ast->expression, &start, &end, true); + start.link(); statement(ast->statement); bytecodeGenerator->jump().link(cond); leaveLoop(); end.link(); - jump_end.link(); return false; }