From patchwork Tue Oct 2 18:32:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 188608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C108A2C008D for ; Wed, 3 Oct 2012 04:34:03 +1000 (EST) Received: from localhost ([::1]:35742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7I9-0006Jg-NG for incoming@patchwork.ozlabs.org; Tue, 02 Oct 2012 14:34:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7Hd-0004xE-3a for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJ7HU-0007eE-57 for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:33:28 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:55783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ7HT-0007bu-Tf for qemu-devel@nongnu.org; Tue, 02 Oct 2012 14:33:20 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so5568448pad.4 for ; Tue, 02 Oct 2012 11:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=pzyn7vlQG82rJYpK3hrdpjwJuGvxflk/Km2vKHhqTis=; b=xGn9p2OjXLXcyocgo09OO1h2vmfUI+NnIeomfNgLNDethOomkfDlwvMNYBFLUAfmNW KH7/rU1ho6+rX3OU4hD04yOI7bz1rxA2J//XYqZKYlZPOlTVCRX+sDRifJmM24rqx6uE BD6MrIhra80L9jM4Hcnjq4Dqi+axtYOiOKjt8AQJKpvvbNGjOJYPrWbZwAUkwDGJzamc 01ScV4qnxrdZjsQke1J8Q8pAtM2vV4bdaXBjJbMrTu6iwJsYsg8ZaPRiCk+CM4n7C6mp g0+h4y9qES5B+cheVsjh3XG217WCTE4vxzqAAHPevlsLz2zPkLG1myeCFlS4rUY4NMl3 1WIQ== Received: by 10.66.78.195 with SMTP id d3mr46153587pax.17.1349202798331; Tue, 02 Oct 2012 11:33:18 -0700 (PDT) Received: from pebble.twiddle.home (me00536d0.tmodns.net. [208.54.5.224]) by mx.google.com with ESMTPS id nu8sm1259765pbc.45.2012.10.02.11.33.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Oct 2012 11:33:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 2 Oct 2012 11:32:24 -0700 Message-Id: <1349202750-16815-5-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1349202750-16815-1-git-send-email-rth@twiddle.net> References: <1349202750-16815-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: Aurelien Jarno Subject: [Qemu-devel] [PATCH 04/10] tcg: Use common code when failing to optimize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This saves a whole lot of repetitive code sequences. Signed-off-by: Richard Henderson Reviewed-by: Aurelien Jarno --- tcg/optimize.c | 91 +++++++++++++++++++++------------------------------------- 1 file changed, 32 insertions(+), 59 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index a713513..592d166 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -639,6 +639,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, gen_args += 2; args += 2; break; + CASE_OP_32_64(not): CASE_OP_32_64(neg): CASE_OP_32_64(ext8s): @@ -651,14 +652,12 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, gen_opc_buf[op_index] = op_to_movi(op); tmp = do_constant_folding(op, temps[args[1]].val, 0); tcg_opt_gen_movi(gen_args, args[0], tmp); - } else { - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; + gen_args += 2; + args += 2; + break; } - gen_args += 2; - args += 2; - break; + goto do_default; + CASE_OP_32_64(add): CASE_OP_32_64(sub): CASE_OP_32_64(mul): @@ -682,15 +681,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, temps[args[2]].val); tcg_opt_gen_movi(gen_args, args[0], tmp); gen_args += 2; - } else { - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; - gen_args[2] = args[2]; - gen_args += 3; + args += 3; + break; } - args += 3; - break; + goto do_default; + CASE_OP_32_64(deposit): if (temps[args[1]].state == TCG_TEMP_CONST && temps[args[2]].state == TCG_TEMP_CONST) { @@ -700,33 +695,22 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, | ((temps[args[2]].val & tmp) << args[3]); tcg_opt_gen_movi(gen_args, args[0], tmp); gen_args += 2; - } else { - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; - gen_args[2] = args[2]; - gen_args[3] = args[3]; - gen_args[4] = args[4]; - gen_args += 5; + args += 5; + break; } - args += 5; - break; + goto do_default; + CASE_OP_32_64(setcond): tmp = do_constant_folding_cond(op, args[1], args[2], args[3]); if (tmp != 2) { gen_opc_buf[op_index] = op_to_movi(op); tcg_opt_gen_movi(gen_args, args[0], tmp); gen_args += 2; - } else { - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; - gen_args[2] = args[2]; - gen_args[3] = args[3]; - gen_args += 4; + args += 4; + break; } - args += 4; - break; + goto do_default; + CASE_OP_32_64(brcond): tmp = do_constant_folding_cond(op, args[0], args[1], args[2]); if (tmp != 2) { @@ -738,17 +722,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, } else { gen_opc_buf[op_index] = INDEX_op_nop; } - } else { - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; - gen_args[2] = args[2]; - gen_args[3] = args[3]; - gen_args += 4; + args += 4; + break; } - args += 4; - break; + goto do_default; + CASE_OP_32_64(movcond): tmp = do_constant_folding_cond(op, args[1], args[2], args[5]); if (tmp != 2) { @@ -763,18 +741,11 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, tcg_opt_gen_mov(s, gen_args, args[0], args[4-tmp]); gen_args += 2; } - } else { - reset_temp(args[0]); - gen_args[0] = args[0]; - gen_args[1] = args[1]; - gen_args[2] = args[2]; - gen_args[3] = args[3]; - gen_args[4] = args[4]; - gen_args[5] = args[5]; - gen_args += 6; + args += 6; + break; } - args += 6; - break; + goto do_default; + case INDEX_op_call: nb_call_args = (args[0] >> 16) + (args[0] & 0xffff); if (!(args[nb_call_args + 1] & (TCG_CALL_CONST | TCG_CALL_PURE))) { @@ -793,11 +764,13 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, i--; } break; + default: - /* Default case: we do know nothing about operation so no - propagation is done. We trash everything if the operation - is the end of a basic block, otherwise we only trash the - output args. */ + do_default: + /* Default case: we know nothing about operation (or were unable + to compute the operation result) so no propagation is done. + We trash everything if the operation is the end of a basic + block, otherwise we only trash the output args. */ if (def->flags & TCG_OPF_BB_END) { memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); } else {