From patchwork Thu Jun 23 18:02:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 639817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rb8bm1f1mz9s9d for ; Fri, 24 Jun 2016 04:08:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=QTzsqhH6; dkim-atps=neutral Received: from localhost ([::1]:38523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG93Z-00078Z-Ry for incoming@patchwork.ozlabs.org; Thu, 23 Jun 2016 14:08:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8yb-0001h6-3A for qemu-devel@nongnu.org; Thu, 23 Jun 2016 14:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG8yU-0000BD-So for qemu-devel@nongnu.org; Thu, 23 Jun 2016 14:03:41 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:34666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8yU-0000B7-N1 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 14:03:34 -0400 Received: by mail-qk0-x242.google.com with SMTP id j2so17148572qkf.1 for ; Thu, 23 Jun 2016 11:03:34 -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:in-reply-to:references; bh=PakODp6yGEKQ7oYtGF/HZ7eMA3RtazZDGIO6QzWjmf0=; b=QTzsqhH6m+SFWNcyryNRM4NBhw8nNyaWQIiVXEObJ4Ba3t4sNQso1GhjJ5ebl02omL L0hDcxYzxoBs3PmB1dqdBavv7c2U8HHoPgKytApEUkI+zMHl66qPdjYvci8CG2NURtDN RSwOO1qlzYVaKSbRTX2xCMWPL7vKk+loC0OL1O7vHMBwEGy1rfeaFKIlLgF1+wicPdL/ YHno/aI/Q9oV+iDss5DuXsF/ndpoyDGxBL1If7ElyZHwQIDNEaoIhAzz9UJOdL4vEWjD oQOPFwrtbHTjhmj4SQtgvlETS865FDnWOwrjuBQiSiQJqbEdbRhPxt/JMnWQxHNO2geg kOng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PakODp6yGEKQ7oYtGF/HZ7eMA3RtazZDGIO6QzWjmf0=; b=Zz5BzRMlrFVqAbCkHOm0X3loN/O8FNDubKingegeaIGWgJVbWqE3pG/6yWrPaO2M2Z Uak7mc4TPa6BhUATKDA8R98LyY+Eaxv+d2O9d6lbRs76lXfQeQ1+NXxj/k0selEZ3t9I Ynq477vWmRW7SAF6VERCzt2/tUkiRACvUS1wMKr8HTEdTi3fS2iQWvS85VlnDxqx1F0e 96sy3hB+bG4wM8R2fml4r2dehiUdCqIf0kXYKfBrhL6OAtTo6cvtrSqhniXfl9z/FX/C szPoysI1THj3/l7y/M9zWdbCXG3YmAmuYm9sH0fi0ZXQGCjk+9lIrwAxSTqUcpUVC3wF jwCw== X-Gm-Message-State: ALyK8tIrSKUP6IkgWbyIDK6KQF2iqZG8lg/cwanHJWSu9SvbqYbSXRU80REIk2q1HFdyOQ== X-Received: by 10.237.54.5 with SMTP id e5mr34827444qtb.41.1466705014128; Thu, 23 Jun 2016 11:03:34 -0700 (PDT) Received: from bigtime.com (71-37-54-227.tukw.qwest.net. [71.37.54.227]) by smtp.gmail.com with ESMTPSA id 13sm519937qki.3.2016.06.23.11.03.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2016 11:03:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 23 Jun 2016 11:02:59 -0700 Message-Id: <1466704982-5919-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466704982-5919-1-git-send-email-rth@twiddle.net> References: <1466704982-5919-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::242 Subject: [Qemu-devel] [PATCH 1/4] tcg: Compress liveness data to 16 bits 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: aurelien@aurel32.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This reduces both memory usage and per-insn cacheline usage during code generation. Signed-off-by: Richard Henderson --- tcg/tcg.c | 58 ++++++++++++++++++++++------------------------------------ tcg/tcg.h | 16 ++++++++++------ 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 44de991..4b117fd 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1331,7 +1331,7 @@ static inline void tcg_la_bb_end(TCGContext *s, uint8_t *dead_temps, } } -/* Liveness analysis : update the opc_dead_args array to tell if a +/* Liveness analysis : update the opc_arg_life array to tell if a given input arguments is dead. Instructions updating dead temporaries are removed. */ static void tcg_liveness_analysis(TCGContext *s) @@ -1340,9 +1340,8 @@ static void tcg_liveness_analysis(TCGContext *s) int oi, oi_prev, nb_ops; nb_ops = s->gen_next_op_idx; - s->op_dead_args = tcg_malloc(nb_ops * sizeof(uint16_t)); - s->op_sync_args = tcg_malloc(nb_ops * sizeof(uint8_t)); - + s->op_arg_life = tcg_malloc(nb_ops * sizeof(TCGLifeData)); + dead_temps = tcg_malloc(s->nb_temps); mem_temps = tcg_malloc(s->nb_temps); tcg_la_func_end(s, dead_temps, mem_temps); @@ -1351,8 +1350,7 @@ static void tcg_liveness_analysis(TCGContext *s) int i, nb_iargs, nb_oargs; TCGOpcode opc_new, opc_new2; bool have_opc_new2; - uint16_t dead_args; - uint8_t sync_args; + TCGLifeData arg_life = 0; TCGArg arg; TCGOp * const op = &s->gen_op_buf[oi]; @@ -1384,15 +1382,13 @@ static void tcg_liveness_analysis(TCGContext *s) do_not_remove_call: /* output args are dead */ - dead_args = 0; - sync_args = 0; for (i = 0; i < nb_oargs; i++) { arg = args[i]; if (dead_temps[arg]) { - dead_args |= (1 << i); + arg_life |= DEAD_ARG << i; } if (mem_temps[arg]) { - sync_args |= (1 << i); + arg_life |= SYNC_ARG << i; } dead_temps[arg] = 1; mem_temps[arg] = 0; @@ -1413,7 +1409,7 @@ static void tcg_liveness_analysis(TCGContext *s) arg = args[i]; if (arg != TCG_CALL_DUMMY_ARG) { if (dead_temps[arg]) { - dead_args |= (1 << i); + arg_life |= DEAD_ARG << i; } } } @@ -1422,8 +1418,6 @@ static void tcg_liveness_analysis(TCGContext *s) arg = args[i]; dead_temps[arg] = 0; } - s->op_dead_args[oi] = dead_args; - s->op_sync_args[oi] = sync_args; } } break; @@ -1534,15 +1528,13 @@ static void tcg_liveness_analysis(TCGContext *s) } else { do_not_remove: /* output args are dead */ - dead_args = 0; - sync_args = 0; for (i = 0; i < nb_oargs; i++) { arg = args[i]; if (dead_temps[arg]) { - dead_args |= (1 << i); + arg_life |= DEAD_ARG << i; } if (mem_temps[arg]) { - sync_args |= (1 << i); + arg_life |= SYNC_ARG << i; } dead_temps[arg] = 1; mem_temps[arg] = 0; @@ -1560,7 +1552,7 @@ static void tcg_liveness_analysis(TCGContext *s) for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { arg = args[i]; if (dead_temps[arg]) { - dead_args |= (1 << i); + arg_life |= DEAD_ARG << i; } } /* input arguments are live for preceding opcodes */ @@ -1568,11 +1560,10 @@ static void tcg_liveness_analysis(TCGContext *s) arg = args[i]; dead_temps[arg] = 0; } - s->op_dead_args[oi] = dead_args; - s->op_sync_args[oi] = sync_args; } break; } + s->op_arg_life[oi] = arg_life; } } #else @@ -1911,11 +1902,11 @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs) save_globals(s, allocated_regs); } -#define IS_DEAD_ARG(n) ((dead_args >> (n)) & 1) -#define NEED_SYNC_ARG(n) ((sync_args >> (n)) & 1) +#define IS_DEAD_ARG(n) (arg_life & (DEAD_ARG << (n))) +#define NEED_SYNC_ARG(n) (arg_life & (SYNC_ARG << (n))) static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, - uint16_t dead_args, uint8_t sync_args) + TCGLifeData arg_life) { TCGTemp *ots; tcg_target_ulong val; @@ -1944,8 +1935,7 @@ static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, } static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, - const TCGArg *args, uint16_t dead_args, - uint8_t sync_args) + const TCGArg *args, TCGLifeData arg_life) { TCGRegSet allocated_regs; TCGTemp *ts, *ots; @@ -2030,8 +2020,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, static void tcg_reg_alloc_op(TCGContext *s, const TCGOpDef *def, TCGOpcode opc, - const TCGArg *args, uint16_t dead_args, - uint8_t sync_args) + const TCGArg *args, TCGLifeData arg_life) { TCGRegSet allocated_regs; int i, k, nb_iargs, nb_oargs; @@ -2196,8 +2185,7 @@ static void tcg_reg_alloc_op(TCGContext *s, #endif static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs, - const TCGArg * const args, uint16_t dead_args, - uint8_t sync_args) + const TCGArg * const args, TCGLifeData arg_life) { int flags, nb_regs, i; TCGReg reg; @@ -2417,8 +2405,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) TCGArg * const args = &s->gen_opparam_buf[op->args]; TCGOpcode opc = op->opc; const TCGOpDef *def = &tcg_op_defs[opc]; - uint16_t dead_args = s->op_dead_args[oi]; - uint8_t sync_args = s->op_sync_args[oi]; + TCGLifeData arg_life = s->op_arg_life[oi]; oi_next = op->next; #ifdef CONFIG_PROFILER @@ -2428,11 +2415,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) switch (opc) { case INDEX_op_mov_i32: case INDEX_op_mov_i64: - tcg_reg_alloc_mov(s, def, args, dead_args, sync_args); + tcg_reg_alloc_mov(s, def, args, arg_life); break; case INDEX_op_movi_i32: case INDEX_op_movi_i64: - tcg_reg_alloc_movi(s, args, dead_args, sync_args); + tcg_reg_alloc_movi(s, args, arg_life); break; case INDEX_op_insn_start: if (num_insns >= 0) { @@ -2457,8 +2444,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) tcg_out_label(s, arg_label(args[0]), s->code_ptr); break; case INDEX_op_call: - tcg_reg_alloc_call(s, op->callo, op->calli, args, - dead_args, sync_args); + tcg_reg_alloc_call(s, op->callo, op->calli, args, arg_life); break; default: /* Sanity check that we've not introduced any unhandled opcodes. */ @@ -2468,7 +2454,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) /* Note: in order to speed up the code, it would be much faster to have specialized register allocator functions for some common argument patterns */ - tcg_reg_alloc_op(s, def, opc, args, dead_args, sync_args); + tcg_reg_alloc_op(s, def, opc, args, arg_life); break; } #ifdef CONFIG_DEBUG_TCG diff --git a/tcg/tcg.h b/tcg/tcg.h index 66d7fc0..cc14560 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -505,6 +505,14 @@ typedef struct TCGTempSet { unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)]; } TCGTempSet; +/* While we limit helpers to 6 arguments, for 32-bit hosts, with padding, + this imples a max of 6*2 (64-bit in) + 2 (64-bit out) = 14 operands. + There are never more than 2 outputs, which means that we can store all + dead + sync data within 16 bits. */ +#define DEAD_ARG 4 +#define SYNC_ARG 1 +typedef uint16_t TCGLifeData; + typedef struct TCGOp { TCGOpcode opc : 8; @@ -538,12 +546,8 @@ struct TCGContext { uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_addr if !USE_DIRECT_JUMP */ /* liveness analysis */ - uint16_t *op_dead_args; /* for each operation, each bit tells if the - corresponding argument is dead */ - uint8_t *op_sync_args; /* for each operation, each bit tells if the - corresponding output argument needs to be - sync to memory. */ - + TCGLifeData *op_arg_life; + TCGRegSet reserved_regs; intptr_t current_frame_offset; intptr_t frame_start;