From patchwork Sat Feb 6 00:09:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 8240741 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 733AEBEEE5 for ; Sat, 6 Feb 2016 00:16:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BD2820165 for ; Sat, 6 Feb 2016 00:16:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37FA920142 for ; Sat, 6 Feb 2016 00:15:59 +0000 (UTC) Received: from localhost ([::1]:51019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqXe-0000N9-Gl for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Feb 2016 19:15:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqSH-00083R-EL for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRqSF-0006tk-Rc for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:25 -0500 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:35652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqSF-0006td-Ky for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:23 -0500 Received: by mail-qg0-x236.google.com with SMTP id y89so7203350qge.2 for ; Fri, 05 Feb 2016 16:10:23 -0800 (PST) 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=g5zxPCMWukM+rjP1ArOQh2RGmmyqe7i3JMYWvLtj/QU=; b=gWAPzmt8/IKn5Ls7/oJnnE4RHHHf2QId+ZXpYN7XBx40gQw3TzzvDbPXiO0hCfNLfe DGDwDUI3PLDFAynO1xJjPcP6SySlBwYA9GJRZw34DcEg0GivnCzv40IcLysUH5QsB0qc 5SmZ7NoeJE9UqRYT/73neHZHNZJDi4Ev757TuLBwDX+WJsaW+0jX/6/iABifN7AR78JA D0k5Og+4hRG8hf7XUR5Y0sa2YAms3Co5iEr6vYp+LQQlvpc6nehH0SOiLqNfv2w2Jmda gwi3DDd3YZGt4Zdfp/jYdcPlYnPyUuArbEKBPu2Z3O6mWDQo/y2YpNXrAjuKvVv/ul36 puog== 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=g5zxPCMWukM+rjP1ArOQh2RGmmyqe7i3JMYWvLtj/QU=; b=YkPY97DD6WYuthpbaIW/tdWpb0jVe4WBoAnAQfjVFVbHoddQfAqCFcn0u89Q0bTtlR EbFAUcKZnrfSH7FDmnJ9Qb/nIyj/dS8SaQ8Vq8SZbH6/QBaZYCEqzI8mQrw2oSfK6koQ waTHTOXLu2oBlaEzZ9Ls+DScR0V44SP22L/inkfoBMJNePRNdfBWmvjF3DVty+OGbqSw 3NAKuHwnq35pZEms5XtyMR7xUe2VgFNYZRo4w0VhfX4yDbyi8K0n6zE3ZIm5asQqSsDM wx29MFrY20RFDMJnz54KoK3RXBz/Lk9fb5EigdFjBetsGkIr1BQy4QDYWJimMno4Es4d ip7w== X-Gm-Message-State: AG10YOSkFlAonNJjxAK7xECrDZjNdSEHfH2VXnr/2/AFQDtgSc4MDxl8uwpoqk1gYe0K8Q== X-Received: by 10.140.83.175 with SMTP id j44mr19459474qgd.99.1454717423364; Fri, 05 Feb 2016 16:10:23 -0800 (PST) Received: from bigtime.com ([1.129.57.172]) by smtp.gmail.com with ESMTPSA id w66sm9079564qhc.15.2016.02.05.16.10.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Feb 2016 16:10:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 6 Feb 2016 11:09:26 +1100 Message-Id: <1454717370-17516-9-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454717370-17516-1-git-send-email-rth@twiddle.net> References: <1454717370-17516-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:c04::236 Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 08/12] tcg: Change reg_to_temp to TCGTemp pointer 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reviewed-by: Aurelien Jarno Signed-off-by: Richard Henderson --- tcg/tcg.c | 113 ++++++++++++++++++++++++++++++-------------------------------- tcg/tcg.h | 6 ++-- 2 files changed, 57 insertions(+), 62 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index a20b730..baa8a14 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -900,29 +900,32 @@ static void tcg_reg_alloc_start(TCGContext *s) ts->mem_allocated = 0; ts->fixed_reg = 0; } - for(i = 0; i < TCG_TARGET_NB_REGS; i++) { - s->reg_to_temp[i] = -1; - } + + memset(s->reg_to_temp, 0, sizeof(s->reg_to_temp)); } -static char *tcg_get_arg_str_idx(TCGContext *s, char *buf, int buf_size, - int idx) +static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size, + TCGTemp *ts) { - TCGTemp *ts; + int idx = temp_idx(s, ts); - assert(idx >= 0 && idx < s->nb_temps); - ts = &s->temps[idx]; if (idx < s->nb_globals) { pstrcpy(buf, buf_size, ts->name); + } else if (ts->temp_local) { + snprintf(buf, buf_size, "loc%d", idx - s->nb_globals); } else { - if (ts->temp_local) - snprintf(buf, buf_size, "loc%d", idx - s->nb_globals); - else - snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals); + snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals); } return buf; } +static char *tcg_get_arg_str_idx(TCGContext *s, char *buf, + int buf_size, int idx) +{ + assert(idx >= 0 && idx < s->nb_temps); + return tcg_get_arg_str_ptr(s, buf, buf_size, &s->temps[idx]); +} + /* Find helper name. */ static inline const char *tcg_find_helper(TCGContext *s, uintptr_t val) { @@ -1589,10 +1592,10 @@ static void dump_regs(TCGContext *s) } for(i = 0; i < TCG_TARGET_NB_REGS; i++) { - if (s->reg_to_temp[i] >= 0) { + if (s->reg_to_temp[i] != NULL) { printf("%s: %s\n", tcg_target_reg_names[i], - tcg_get_arg_str_idx(s, buf, sizeof(buf), s->reg_to_temp[i])); + tcg_get_arg_str_ptr(s, buf, sizeof(buf), s->reg_to_temp[i])); } } } @@ -1604,29 +1607,26 @@ static void check_regs(TCGContext *s) TCGTemp *ts; char buf[64]; - for(reg = 0; reg < TCG_TARGET_NB_REGS; reg++) { - k = s->reg_to_temp[reg]; - if (k >= 0) { - ts = &s->temps[k]; - if (ts->val_type != TEMP_VAL_REG || - ts->reg != reg) { + for (reg = 0; reg < TCG_TARGET_NB_REGS; reg++) { + ts = s->reg_to_temp[reg]; + if (ts != NULL) { + if (ts->val_type != TEMP_VAL_REG || ts->reg != reg) { printf("Inconsistency for register %s:\n", tcg_target_reg_names[reg]); goto fail; } } } - for(k = 0; k < s->nb_temps; k++) { + for (k = 0; k < s->nb_temps; k++) { ts = &s->temps[k]; - if (ts->val_type == TEMP_VAL_REG && - !ts->fixed_reg && - s->reg_to_temp[ts->reg] != k) { - printf("Inconsistency for temp %s:\n", - tcg_get_arg_str_idx(s, buf, sizeof(buf), k)); + if (ts->val_type == TEMP_VAL_REG && !ts->fixed_reg + && s->reg_to_temp[ts->reg] != ts) { + printf("Inconsistency for temp %s:\n", + tcg_get_arg_str_ptr(s, buf, sizeof(buf), ts)); fail: - printf("reg state:\n"); - dump_regs(s); - tcg_abort(); + printf("reg state:\n"); + dump_regs(s); + tcg_abort(); } } } @@ -1655,15 +1655,12 @@ static void temp_allocate_frame(TCGContext *s, int temp) /* sync register 'reg' by saving it to the corresponding temporary */ static inline void tcg_reg_sync(TCGContext *s, TCGReg reg) { - TCGTemp *ts; - int temp; + TCGTemp *ts = s->reg_to_temp[reg]; - temp = s->reg_to_temp[reg]; - ts = &s->temps[temp]; assert(ts->val_type == TEMP_VAL_REG); if (!ts->mem_coherent && !ts->fixed_reg) { if (!ts->mem_allocated) { - temp_allocate_frame(s, temp); + temp_allocate_frame(s, temp_idx(s, ts)); } tcg_out_st(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); } @@ -1673,13 +1670,12 @@ static inline void tcg_reg_sync(TCGContext *s, TCGReg reg) /* free register 'reg' by spilling the corresponding temporary if necessary */ static void tcg_reg_free(TCGContext *s, TCGReg reg) { - int temp; + TCGTemp *ts = s->reg_to_temp[reg]; - temp = s->reg_to_temp[reg]; - if (temp != -1) { + if (ts != NULL) { tcg_reg_sync(s, reg); - s->temps[temp].val_type = TEMP_VAL_MEM; - s->reg_to_temp[reg] = -1; + ts->val_type = TEMP_VAL_MEM; + s->reg_to_temp[reg] = NULL; } } @@ -1695,7 +1691,7 @@ static TCGReg tcg_reg_alloc(TCGContext *s, TCGRegSet reg1, TCGRegSet reg2) /* first try free registers */ for(i = 0; i < ARRAY_SIZE(tcg_target_reg_alloc_order); i++) { reg = tcg_target_reg_alloc_order[i]; - if (tcg_regset_test_reg(reg_ct, reg) && s->reg_to_temp[reg] == -1) + if (tcg_regset_test_reg(reg_ct, reg) && s->reg_to_temp[reg] == NULL) return reg; } @@ -1714,12 +1710,11 @@ static TCGReg tcg_reg_alloc(TCGContext *s, TCGRegSet reg1, TCGRegSet reg2) /* mark a temporary as dead. */ static inline void temp_dead(TCGContext *s, int temp) { - TCGTemp *ts; + TCGTemp *ts = &s->temps[temp]; - ts = &s->temps[temp]; if (!ts->fixed_reg) { if (ts->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ts->reg] = -1; + s->reg_to_temp[ts->reg] = NULL; } if (temp < s->nb_globals || ts->temp_local) { ts->val_type = TEMP_VAL_MEM; @@ -1733,16 +1728,15 @@ static inline void temp_dead(TCGContext *s, int temp) temporary registers needs to be allocated to store a constant. */ static inline void temp_sync(TCGContext *s, int temp, TCGRegSet allocated_regs) { - TCGTemp *ts; + TCGTemp *ts = &s->temps[temp]; - ts = &s->temps[temp]; if (!ts->fixed_reg) { switch(ts->val_type) { case TEMP_VAL_CONST: ts->reg = tcg_reg_alloc(s, tcg_target_available_regs[ts->type], allocated_regs); ts->val_type = TEMP_VAL_REG; - s->reg_to_temp[ts->reg] = temp; + s->reg_to_temp[ts->reg] = ts; ts->mem_coherent = 0; tcg_out_movi(s, ts->type, ts->reg, ts->val); /* fallthrough*/ @@ -1844,8 +1838,9 @@ static void tcg_reg_alloc_movi(TCGContext *s, const TCGArg *args, tcg_out_movi(s, ots->type, ots->reg, val); } else { /* The movi is not explicitly generated here */ - if (ots->val_type == TEMP_VAL_REG) - s->reg_to_temp[ots->reg] = -1; + if (ots->val_type == TEMP_VAL_REG) { + s->reg_to_temp[ots->reg] = NULL; + } ots->val_type = TEMP_VAL_CONST; ots->val = val; } @@ -1888,7 +1883,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, tcg_out_movi(s, itype, ts->reg, ts->val); ts->mem_coherent = 0; } - s->reg_to_temp[ts->reg] = args[1]; + s->reg_to_temp[ts->reg] = ts; ts->val_type = TEMP_VAL_REG; } @@ -1909,7 +1904,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, } else if (ts->val_type == TEMP_VAL_CONST) { /* propagate constant */ if (ots->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ots->reg] = -1; + s->reg_to_temp[ots->reg] = NULL; } ots->val_type = TEMP_VAL_CONST; ots->val = ts->val; @@ -1923,7 +1918,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, if (IS_DEAD_ARG(1) && !ts->fixed_reg && !ots->fixed_reg) { /* the mov can be suppressed */ if (ots->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ots->reg] = -1; + s->reg_to_temp[ots->reg] = NULL; } ots->reg = ts->reg; temp_dead(s, args[1]); @@ -1939,7 +1934,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, } ots->val_type = TEMP_VAL_REG; ots->mem_coherent = 0; - s->reg_to_temp[ots->reg] = args[0]; + s->reg_to_temp[ots->reg] = ots; if (NEED_SYNC_ARG(0)) { tcg_reg_sync(s, ots->reg); } @@ -1981,7 +1976,7 @@ static void tcg_reg_alloc_op(TCGContext *s, ts->val_type = TEMP_VAL_REG; ts->reg = reg; ts->mem_coherent = 1; - s->reg_to_temp[reg] = arg; + s->reg_to_temp[reg] = ts; } else if (ts->val_type == TEMP_VAL_CONST) { if (tcg_target_const_match(ts->val, ts->type, arg_ct)) { /* constant is OK for instruction */ @@ -1995,7 +1990,7 @@ static void tcg_reg_alloc_op(TCGContext *s, ts->val_type = TEMP_VAL_REG; ts->reg = reg; ts->mem_coherent = 0; - s->reg_to_temp[reg] = arg; + s->reg_to_temp[reg] = ts; } } assert(ts->val_type == TEMP_VAL_REG); @@ -2086,14 +2081,14 @@ static void tcg_reg_alloc_op(TCGContext *s, /* if a fixed register is used, then a move will be done afterwards */ if (!ts->fixed_reg) { if (ts->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ts->reg] = -1; + s->reg_to_temp[ts->reg] = NULL; } ts->val_type = TEMP_VAL_REG; ts->reg = reg; /* temp value is modified, so the value kept in memory is potentially not the same */ ts->mem_coherent = 0; - s->reg_to_temp[reg] = arg; + s->reg_to_temp[reg] = ts; } oarg_end: new_args[i] = reg; @@ -2244,7 +2239,7 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs, arg = args[i]; ts = &s->temps[arg]; reg = tcg_target_call_oarg_regs[i]; - assert(s->reg_to_temp[reg] == -1); + assert(s->reg_to_temp[reg] == NULL); if (ts->fixed_reg) { if (ts->reg != reg) { @@ -2252,12 +2247,12 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs, } } else { if (ts->val_type == TEMP_VAL_REG) { - s->reg_to_temp[ts->reg] = -1; + s->reg_to_temp[ts->reg] = NULL; } ts->val_type = TEMP_VAL_REG; ts->reg = reg; ts->mem_coherent = 0; - s->reg_to_temp[reg] = arg; + s->reg_to_temp[reg] = ts; if (NEED_SYNC_ARG(i)) { tcg_reg_sync(s, reg); } diff --git a/tcg/tcg.h b/tcg/tcg.h index 223d9c6..83da5fb 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -572,9 +572,9 @@ struct TCGContext { TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ - /* tells in which temporary a given register is. It does not take - into account fixed registers */ - int reg_to_temp[TCG_TARGET_NB_REGS]; + /* Tells which temporary holds a given register. + It does not take into account fixed registers */ + TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS]; TCGOp gen_op_buf[OPC_BUF_SIZE]; TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE];