qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: blauwirbel@gmail.com, aurelien@aurel32.net
Subject: [Qemu-devel] [RFC 07/16] tcg: Change reg_to_temp to TCGTemp pointer
Date: Thu, 19 Sep 2013 14:24:59 -0700	[thread overview]
Message-ID: <1379625908-27964-8-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1379625908-27964-1-git-send-email-rth@twiddle.net>

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/tcg.c | 113 ++++++++++++++++++++++++++++++--------------------------------
 tcg/tcg.h |   4 +--
 2 files changed, 56 insertions(+), 61 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 7d379ac..35e0c7c 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -809,29 +809,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 = ts - s->temps;
 
-    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]);
+}
+
 static int helper_cmp(const void *p1, const void *p2)
 {
     const TCGHelperInfo *th1 = p1;
@@ -1530,10 +1533,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]));
         }
     }
 }
@@ -1545,29 +1548,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();
         }
     }
 }
@@ -1596,15 +1596,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, ts - s->temps);
         }
         tcg_out_st(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
     }
@@ -1614,13 +1611,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;
     }
 }
 
@@ -1636,7 +1632,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;
     }
 
@@ -1655,12 +1651,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;
@@ -1674,16 +1669,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*/
@@ -1785,8 +1779,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;
     }
@@ -1826,7 +1821,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
         } else if (ts->val_type == TEMP_VAL_CONST) {
             tcg_out_movi(s, ts->type, ts->reg, ts->val);
         }
-        s->reg_to_temp[ts->reg] = args[1];
+        s->reg_to_temp[ts->reg] = ts;
         ts->val_type = TEMP_VAL_REG;
     }
 
@@ -1847,7 +1842,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;
@@ -1858,7 +1853,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]);
@@ -1873,7 +1868,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);
         }
@@ -1915,7 +1910,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, arg_ct)) {
                 /* constant is OK for instruction */
@@ -1929,7 +1924,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);
@@ -2010,14 +2005,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;
@@ -2207,19 +2202,19 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
         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) {
                 tcg_out_mov(s, ts->type, ts->reg, reg);
             }
         } 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 275ea9b..74649fa 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -440,9 +440,9 @@ struct TCGContext {
                                corresponding output argument needs to be
                                sync to memory. */
     
-    /* tells in which temporary a given register is. It does not take
+    /* Tells in which temporary a given register is. It does not take
        into account fixed registers */
-    int reg_to_temp[TCG_TARGET_NB_REGS];
+    TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS];
     TCGRegSet reserved_regs;
     intptr_t current_frame_offset;
     intptr_t frame_start;
-- 
1.8.1.4

  parent reply	other threads:[~2013-09-19 21:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19 21:24 [Qemu-devel] [RFC 00/16] TCG indirect registers Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 01/16] tcg: Change tcg_global_mem_new_* to take a TCGv_ptr Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 02/16] tcg: Introduce TCGTempType Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 03/16] tcg: Change ts->mem_reg to ts->mem_base Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 04/16] tcg: Compress TCGLabelQemuLdst Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 05/16] tcg: More use of TCGReg where appropriate Richard Henderson
2013-09-19 21:24 ` [Qemu-devel] [RFC 06/16] tcg: Remove tcg_get_arg_str_i32/64 Richard Henderson
2013-09-19 21:24 ` Richard Henderson [this message]
2013-09-19 21:25 ` [Qemu-devel] [RFC 08/16] tcg: Change temp_dead argument to TCGTemp Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 09/16] tcg: Change temp_sync " Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 10/16] tcg: Change temp_save " Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 11/16] tcg: Introduce temp_load Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 12/16] tcg: Tidy temporary allocation Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 13/16] tcg: Use temp_idx Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 14/16] tcg: Implement indirect memory registers Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 15/16] target-sparc: Tidy global register initialization Richard Henderson
2013-09-19 21:25 ` [Qemu-devel] [RFC 16/16] target-sparc: Use global registers for the register window Richard Henderson
2013-09-22 17:28 ` [Qemu-devel] [RFC 00/16] TCG indirect registers Max Filippov
2013-09-23 17:23 ` Blue Swirl
2013-09-23 18:06   ` Richard Henderson
2013-09-24 13:32     ` Artyom Tarasenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379625908-27964-8-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).