From nobody Mon Feb 9 19:10:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545772937886240.22782476801046; Tue, 25 Dec 2018 13:22:17 -0800 (PST) Received: from localhost ([127.0.0.1]:43262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbu9Y-0003so-Dd for importer@patchew.org; Tue, 25 Dec 2018 16:22:16 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtoJ-0000WC-RL for qemu-devel@nongnu.org; Tue, 25 Dec 2018 16:00:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbtoH-0002Gi-T4 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 16:00:19 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:33767) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbtoF-0002DK-Sz for qemu-devel@nongnu.org; Tue, 25 Dec 2018 16:00:17 -0500 Received: by mail-pl1-x633.google.com with SMTP id z23so6818468plo.0 for ; Tue, 25 Dec 2018 13:00:14 -0800 (PST) Received: from cloudburst.home (c211-28-135-144.sunsh3.vic.optusnet.com.au. [211.28.135.144]) by smtp.gmail.com with ESMTPSA id t21sm48501628pgg.24.2018.12.25.13.00.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Dec 2018 13:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ibeCwK+lB/vRcdT+EuLDFRREAhB9Zzm2qXgGDB0YY1Q=; b=R7crSbNyYfWC0SJ5uhPv62HU4KT9CasoKZ8078rFlAORAPYkcMm274uImn+EJFq2aG bRZKKdM034lq4UaHJTzj+IFxve0mjpe8fF27X7nn18+aaeou00LWLfeiINtlVSnZ1BZG 2jIw67laHuejgVFVpJn6PrtvhqO/KD3zXUsU0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ibeCwK+lB/vRcdT+EuLDFRREAhB9Zzm2qXgGDB0YY1Q=; b=n2d7jDvo0/+6eGjcfQdWiOfdtlfkqLjkjlKzTnN5nSVC5qxPMRFatMUrAnaw7az1Pk SDKOQsIp19loX5A6ivS7KGuEk1NzHnWelVSxd+P3T5mJ3DZhUdbcSvcXt0L8ZG+JjowT J0x4hlBVSmPqdcyTtO9bHaaNaEbtLPIuFv6+xddDElvYkNTZ6NQeuqkKALFxhyPp5Gdk 7sZo1pTMGvEiPF1cTSncOmNzSx0IWo7beVsXqjuUMnAKXPCF1B+Jd06uIZ2pu0BNrYHH y8QGX9BgxDUPhVTyeoWAc9UxWR0SbNRCHQgVgNbo7LiADcMgFjuHQqlramVlFXJs63Kv uzOw== X-Gm-Message-State: AJcUukeQCOwjVbHDdoqekyMkL/msrElRTm6I5vgPkLMpAuiQVkIPQC+4 8gZ82GAlDQMXON23xQLItwkWKTcI568= X-Google-Smtp-Source: ALg8bN6vBPaeLJ5V5kBKV5W0zS8PLIm0y66lxROD/TH4s3lVIAWLxXXY0piphalnN8HC7GNm1QawEw== X-Received: by 2002:a17:902:2969:: with SMTP id g96mr17393345plb.295.1545771613387; Tue, 25 Dec 2018 13:00:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2018 07:55:28 +1100 Message-Id: <20181225205529.10874-42-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181225205529.10874-1-richard.henderson@linaro.org> References: <20181225205529.10874-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::633 Subject: [Qemu-devel] [PULL 41/42] tcg: Record register preferences during liveness X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With these preferences, we can arrange for function call arguments to be computed into the proper registers instead of requiring extra moves. Reviewed-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tcg/tcg.c | 197 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 165 insertions(+), 32 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index d40edb4f57..5f8c09b0b4 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2365,6 +2365,21 @@ static void reachable_code_pass(TCGContext *s) #define IS_DEAD_ARG(n) (arg_life & (DEAD_ARG << (n))) #define NEED_SYNC_ARG(n) (arg_life & (SYNC_ARG << (n))) =20 +/* For liveness_pass_1, the register preferences for a given temp. */ +static inline TCGRegSet *la_temp_pref(TCGTemp *ts) +{ + return ts->state_ptr; +} + +/* For liveness_pass_1, reset the preferences for a given temp to the + * maximal regset for its type. + */ +static inline void la_reset_pref(TCGTemp *ts) +{ + *la_temp_pref(ts) + =3D (ts->state =3D=3D TS_DEAD ? 0 : tcg_target_available_regs[ts->= type]); +} + /* liveness analysis: end of function: all temps are dead, and globals should be in memory. */ static void la_func_end(TCGContext *s, int ng, int nt) @@ -2373,9 +2388,11 @@ static void la_func_end(TCGContext *s, int ng, int n= t) =20 for (i =3D 0; i < ng; ++i) { s->temps[i].state =3D TS_DEAD | TS_MEM; + la_reset_pref(&s->temps[i]); } for (i =3D ng; i < nt; ++i) { s->temps[i].state =3D TS_DEAD; + la_reset_pref(&s->temps[i]); } } =20 @@ -2387,11 +2404,13 @@ static void la_bb_end(TCGContext *s, int ng, int nt) =20 for (i =3D 0; i < ng; ++i) { s->temps[i].state =3D TS_DEAD | TS_MEM; + la_reset_pref(&s->temps[i]); } for (i =3D ng; i < nt; ++i) { s->temps[i].state =3D (s->temps[i].temp_local ? TS_DEAD | TS_MEM : TS_DEAD); + la_reset_pref(&s->temps[i]); } } =20 @@ -2401,7 +2420,12 @@ static void la_global_sync(TCGContext *s, int ng) int i; =20 for (i =3D 0; i < ng; ++i) { - s->temps[i].state |=3D TS_MEM; + int state =3D s->temps[i].state; + s->temps[i].state =3D state | TS_MEM; + if (state =3D=3D TS_DEAD) { + /* If the global was previously dead, reset prefs. */ + la_reset_pref(&s->temps[i]); + } } } =20 @@ -2412,6 +2436,29 @@ static void la_global_kill(TCGContext *s, int ng) =20 for (i =3D 0; i < ng; i++) { s->temps[i].state =3D TS_DEAD | TS_MEM; + la_reset_pref(&s->temps[i]); + } +} + +/* liveness analysis: note live globals crossing calls. */ +static void la_cross_call(TCGContext *s, int nt) +{ + TCGRegSet mask =3D ~tcg_target_call_clobber_regs; + int i; + + for (i =3D 0; i < nt; i++) { + TCGTemp *ts =3D &s->temps[i]; + if (!(ts->state & TS_DEAD)) { + TCGRegSet *pset =3D la_temp_pref(ts); + TCGRegSet set =3D *pset; + + set &=3D mask; + /* If the combination is not possible, restart. */ + if (set =3D=3D 0) { + set =3D tcg_target_available_regs[ts->type] & mask; + } + *pset =3D set; + } } } =20 @@ -2423,16 +2470,23 @@ static void liveness_pass_1(TCGContext *s) int nb_globals =3D s->nb_globals; int nb_temps =3D s->nb_temps; TCGOp *op, *op_prev; + TCGRegSet *prefs; + int i; + + prefs =3D tcg_malloc(sizeof(TCGRegSet) * nb_temps); + for (i =3D 0; i < nb_temps; ++i) { + s->temps[i].state_ptr =3D prefs + i; + } =20 /* ??? Should be redundant with the exit_tb that ends the TB. */ la_func_end(s, nb_globals, nb_temps); =20 QTAILQ_FOREACH_REVERSE_SAFE(op, &s->ops, TCGOpHead, link, op_prev) { - int i, nb_iargs, nb_oargs; + int nb_iargs, nb_oargs; TCGOpcode opc_new, opc_new2; bool have_opc_new2; TCGLifeData arg_life =3D 0; - TCGTemp *arg_ts; + TCGTemp *ts; TCGOpcode opc =3D op->opc; const TCGOpDef *def =3D &tcg_op_defs[opc]; =20 @@ -2440,6 +2494,7 @@ static void liveness_pass_1(TCGContext *s) case INDEX_op_call: { int call_flags; + int nb_call_regs; =20 nb_oargs =3D TCGOP_CALLO(op); nb_iargs =3D TCGOP_CALLI(op); @@ -2448,8 +2503,8 @@ static void liveness_pass_1(TCGContext *s) /* pure functions can be removed if their result is unused= */ if (call_flags & TCG_CALL_NO_SIDE_EFFECTS) { for (i =3D 0; i < nb_oargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts->state !=3D TS_DEAD) { + ts =3D arg_temp(op->args[i]); + if (ts->state !=3D TS_DEAD) { goto do_not_remove_call; } } @@ -2457,16 +2512,20 @@ static void liveness_pass_1(TCGContext *s) } do_not_remove_call: =20 - /* output args are dead */ + /* Output args are dead. */ for (i =3D 0; i < nb_oargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts->state & TS_DEAD) { + ts =3D arg_temp(op->args[i]); + if (ts->state & TS_DEAD) { arg_life |=3D DEAD_ARG << i; } - if (arg_ts->state & TS_MEM) { + if (ts->state & TS_MEM) { arg_life |=3D SYNC_ARG << i; } - arg_ts->state =3D TS_DEAD; + ts->state =3D TS_DEAD; + la_reset_pref(ts); + + /* Not used -- it will be tcg_target_call_oarg_regs[i]= . */ + op->output_pref[i] =3D 0; } =20 if (!(call_flags & (TCG_CALL_NO_WRITE_GLOBALS | @@ -2476,18 +2535,42 @@ static void liveness_pass_1(TCGContext *s) la_global_sync(s, nb_globals); } =20 - /* record arguments that die in this helper */ + /* Record arguments that die in this helper. */ for (i =3D nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts && arg_ts->state & TS_DEAD) { + ts =3D arg_temp(op->args[i]); + if (ts && ts->state & TS_DEAD) { arg_life |=3D DEAD_ARG << i; } } - /* input arguments are live for preceding opcodes */ - for (i =3D nb_oargs; i < nb_iargs + nb_oargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts) { - arg_ts->state &=3D ~TS_DEAD; + + /* For all live registers, remove call-clobbered prefs. */ + la_cross_call(s, nb_temps); + + nb_call_regs =3D ARRAY_SIZE(tcg_target_call_iarg_regs); + + /* Input arguments are live for preceding opcodes. */ + for (i =3D 0; i < nb_iargs; i++) { + ts =3D arg_temp(op->args[i + nb_oargs]); + if (ts && ts->state & TS_DEAD) { + /* For those arguments that die, and will be alloc= ated + * in registers, clear the register set for that a= rg, + * to be filled in below. For args that will be on + * the stack, reset to any available reg. + */ + *la_temp_pref(ts) + =3D (i < nb_call_regs ? 0 : + tcg_target_available_regs[ts->type]); + ts->state &=3D ~TS_DEAD; + } + } + + /* For each input argument, add its input register to pref= s. + If a temp is used once, this produces a single set bit.= */ + for (i =3D 0; i < MIN(nb_call_regs, nb_iargs); i++) { + ts =3D arg_temp(op->args[i + nb_oargs]); + if (ts) { + tcg_regset_set_reg(*la_temp_pref(ts), + tcg_target_call_iarg_regs[i]); } } } @@ -2496,7 +2579,9 @@ static void liveness_pass_1(TCGContext *s) break; case INDEX_op_discard: /* mark the temporary as dead */ - arg_temp(op->args[0])->state =3D TS_DEAD; + ts =3D arg_temp(op->args[0]); + ts->state =3D TS_DEAD; + la_reset_pref(ts); break; =20 case INDEX_op_add2_i32: @@ -2600,43 +2685,91 @@ static void liveness_pass_1(TCGContext *s) break; =20 do_not_remove: - /* output args are dead */ for (i =3D 0; i < nb_oargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts->state & TS_DEAD) { + ts =3D arg_temp(op->args[i]); + + /* Remember the preference of the uses that followed. */ + op->output_pref[i] =3D *la_temp_pref(ts); + + /* Output args are dead. */ + if (ts->state & TS_DEAD) { arg_life |=3D DEAD_ARG << i; } - if (arg_ts->state & TS_MEM) { + if (ts->state & TS_MEM) { arg_life |=3D SYNC_ARG << i; } - arg_ts->state =3D TS_DEAD; + ts->state =3D TS_DEAD; + la_reset_pref(ts); } =20 - /* if end of basic block, update */ + /* If end of basic block, update. */ if (def->flags & TCG_OPF_BB_EXIT) { la_func_end(s, nb_globals, nb_temps); } else if (def->flags & TCG_OPF_BB_END) { la_bb_end(s, nb_globals, nb_temps); } else if (def->flags & TCG_OPF_SIDE_EFFECTS) { la_global_sync(s, nb_globals); + if (def->flags & TCG_OPF_CALL_CLOBBER) { + la_cross_call(s, nb_temps); + } } =20 - /* record arguments that die in this opcode */ + /* Record arguments that die in this opcode. */ for (i =3D nb_oargs; i < nb_oargs + nb_iargs; i++) { - arg_ts =3D arg_temp(op->args[i]); - if (arg_ts->state & TS_DEAD) { + ts =3D arg_temp(op->args[i]); + if (ts->state & TS_DEAD) { arg_life |=3D DEAD_ARG << i; } } - /* input arguments are live for preceding opcodes */ + + /* Input arguments are live for preceding opcodes. */ for (i =3D nb_oargs; i < nb_oargs + nb_iargs; i++) { - arg_temp(op->args[i])->state &=3D ~TS_DEAD; + ts =3D arg_temp(op->args[i]); + if (ts->state & TS_DEAD) { + /* For operands that were dead, initially allow + all regs for the type. */ + *la_temp_pref(ts) =3D tcg_target_available_regs[ts->ty= pe]; + ts->state &=3D ~TS_DEAD; + } + } + + /* Incorporate constraints for this operand. */ + switch (opc) { + case INDEX_op_mov_i32: + case INDEX_op_mov_i64: + /* Note that these are TCG_OPF_NOT_PRESENT and do not + have proper constraints. That said, special case + moves to propagate preferences backward. */ + if (IS_DEAD_ARG(1)) { + *la_temp_pref(arg_temp(op->args[0])) + =3D *la_temp_pref(arg_temp(op->args[1])); + } + break; + + default: + for (i =3D nb_oargs; i < nb_oargs + nb_iargs; i++) { + const TCGArgConstraint *ct =3D &def->args_ct[i]; + TCGRegSet set, *pset; + + ts =3D arg_temp(op->args[i]); + pset =3D la_temp_pref(ts); + set =3D *pset; + + set &=3D ct->u.regs; + if (ct->ct & TCG_CT_IALIAS) { + set &=3D op->output_pref[ct->alias_index]; + } + /* If the combination is not possible, restart. */ + if (set =3D=3D 0) { + set =3D ct->u.regs; + } + *pset =3D set; + } + break; } break; } op->life =3D arg_life; - op->output_pref[0] =3D 0; - op->output_pref[1] =3D 0; } } =20 --=20 2.17.2