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 03/16] tcg: Change ts->mem_reg to ts->mem_base
Date: Thu, 19 Sep 2013 14:24:55 -0700	[thread overview]
Message-ID: <1379625908-27964-4-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1379625908-27964-1-git-send-email-rth@twiddle.net>

Chain the temporaries together via pointers intstead of indices.
The mem_reg value is now mem_base->reg.  This will be important later.

This does require that the frame pointer have a global temporary
allocated for it.  This is simple bar the existing reserved_regs check.

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

diff --git a/tcg/tcg.c b/tcg/tcg.c
index c72a144..8fc5588 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -307,13 +307,6 @@ void tcg_prologue_init(TCGContext *s)
 #endif
 }
 
-void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size)
-{
-    s->frame_start = start;
-    s->frame_end = start + size;
-    s->frame_reg = reg;
-}
-
 void tcg_func_start(TCGContext *s)
 {
     int i;
@@ -347,19 +340,15 @@ static inline void tcg_temp_alloc(TCGContext *s, int n)
         tcg_abort();
 }
 
-static inline int tcg_global_reg_new_internal(TCGType type, int reg,
-                                              const char *name)
+static int tcg_global_reg_new_internal(TCGContext *s, TCGType type,
+                                       int reg, const char *name)
 {
-    TCGContext *s = &tcg_ctx;
     TCGTemp *ts;
     int idx;
 
-#if TCG_TARGET_REG_BITS == 32
-    if (type != TCG_TYPE_I32)
-        tcg_abort();
-#endif
-    if (tcg_regset_test_reg(s->reserved_regs, reg))
+    if (TCG_TARGET_REG_BITS == 32 && type != TCG_TYPE_I32) {
         tcg_abort();
+    }
     idx = s->nb_globals;
     tcg_temp_alloc(s, s->nb_globals + 1);
     ts = &s->temps[s->nb_globals];
@@ -373,19 +362,34 @@ static inline int tcg_global_reg_new_internal(TCGType type, int reg,
     return idx;
 }
 
+void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size)
+{
+    s->frame_start = start;
+    s->frame_end = start + size;
+    s->frame_temp = tcg_global_reg_new_internal(s, TCG_TYPE_PTR, reg, "_frame");
+}
+
 TCGv_i32 tcg_global_reg_new_i32(int reg, const char *name)
 {
+    TCGContext *s = &tcg_ctx;
     int idx;
 
-    idx = tcg_global_reg_new_internal(TCG_TYPE_I32, reg, name);
+    if (tcg_regset_test_reg(s->reserved_regs, reg)) {
+        tcg_abort();
+    }
+    idx = tcg_global_reg_new_internal(s, TCG_TYPE_I32, reg, name);
     return MAKE_TCGV_I32(idx);
 }
 
 TCGv_i64 tcg_global_reg_new_i64(int reg, const char *name)
 {
+    TCGContext *s = &tcg_ctx;
     int idx;
 
-    idx = tcg_global_reg_new_internal(TCG_TYPE_I64, reg, name);
+    if (tcg_regset_test_reg(s->reserved_regs, reg)) {
+        tcg_abort();
+    }
+    idx = tcg_global_reg_new_internal(s, TCG_TYPE_I64, reg, name);
     return MAKE_TCGV_I64(idx);
 }
 
@@ -394,7 +398,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
 {
     TCGContext *s = &tcg_ctx;
     TCGTemp *ts, *base_ts = &s->temps[GET_TCGV_PTR(base)];
-    int idx, reg = base_ts->reg;
+    int idx;
 
     idx = s->nb_globals;
 #if TCG_TARGET_REG_BITS == 32
@@ -406,7 +410,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
         ts->type = TCG_TYPE_I32;
         ts->fixed_reg = 0;
         ts->mem_allocated = 1;
-        ts->mem_reg = reg;
+        ts->mem_base = base_ts;
 #ifdef TCG_TARGET_WORDS_BIGENDIAN
         ts->mem_offset = offset + 4;
 #else
@@ -421,7 +425,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
         ts->type = TCG_TYPE_I32;
         ts->fixed_reg = 0;
         ts->mem_allocated = 1;
-        ts->mem_reg = reg;
+        ts->mem_base = base_ts;
 #ifdef TCG_TARGET_WORDS_BIGENDIAN
         ts->mem_offset = offset;
 #else
@@ -441,7 +445,7 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
         ts->type = type;
         ts->fixed_reg = 0;
         ts->mem_allocated = 1;
-        ts->mem_reg = reg;
+        ts->mem_base = base_ts;
         ts->mem_offset = offset;
         ts->name = name;
         s->nb_globals++;
@@ -1519,7 +1523,8 @@ static void dump_regs(TCGContext *s)
             printf("%s", tcg_target_reg_names[ts->reg]);
             break;
         case TEMP_VAL_MEM:
-            printf("%d(%s)", (int)ts->mem_offset, tcg_target_reg_names[ts->mem_reg]);
+            printf("%d(%s)", (int)ts->mem_offset,
+                   tcg_target_reg_names[ts->mem_base->reg]);
             break;
         case TEMP_VAL_CONST:
             printf("$0x%" TCG_PRIlx, ts->val);
@@ -1592,7 +1597,7 @@ static void temp_allocate_frame(TCGContext *s, int temp)
         tcg_abort();
     }
     ts->mem_offset = s->current_frame_offset;
-    ts->mem_reg = s->frame_reg;
+    ts->mem_base = &s->temps[s->frame_temp];
     ts->mem_allocated = 1;
     s->current_frame_offset += sizeof(tcg_target_long);
 }
@@ -1610,7 +1615,7 @@ static inline void tcg_reg_sync(TCGContext *s, int reg)
         if (!ts->mem_allocated) {
             temp_allocate_frame(s, temp);
         }
-        tcg_out_st(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+        tcg_out_st(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
     }
     ts->mem_coherent = 1;
 }
@@ -1823,7 +1828,8 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
         || ts->val_type == TEMP_VAL_MEM) {
         ts->reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs);
         if (ts->val_type == TEMP_VAL_MEM) {
-            tcg_out_ld(s, ts->type, ts->reg, ts->mem_reg, ts->mem_offset);
+            tcg_out_ld(s, ts->type, ts->reg,
+                       ts->mem_base->reg, ts->mem_offset);
             ts->mem_coherent = 1;
         } else if (ts->val_type == TEMP_VAL_CONST) {
             tcg_out_movi(s, ts->type, ts->reg, ts->val);
@@ -1841,7 +1847,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
         if (!ots->mem_allocated) {
             temp_allocate_frame(s, args[0]);
         }
-        tcg_out_st(s, ots->type, ts->reg, ots->mem_reg, ots->mem_offset);
+        tcg_out_st(s, ots->type, ts->reg, ots->mem_base->reg, ots->mem_offset);
         if (IS_DEAD_ARG(1)) {
             temp_dead(s, args[1]);
         }
@@ -1912,7 +1918,7 @@ static void tcg_reg_alloc_op(TCGContext *s,
         ts = &s->temps[arg];
         if (ts->val_type == TEMP_VAL_MEM) {
             reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs);
-            tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+            tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
             ts->val_type = TEMP_VAL_REG;
             ts->reg = reg;
             ts->mem_coherent = 1;
@@ -2101,7 +2107,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
                 reg = tcg_reg_alloc(s, tcg_target_available_regs[ts->type], 
                                     s->reserved_regs);
                 /* XXX: not correct if reading values from the stack */
-                tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+                tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
                 tcg_out_st(s, ts->type, reg, TCG_REG_CALL_STACK, stack_offset);
             } else if (ts->val_type == TEMP_VAL_CONST) {
                 reg = tcg_reg_alloc(s, tcg_target_available_regs[ts->type], 
@@ -2131,7 +2137,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
                     tcg_out_mov(s, ts->type, reg, ts->reg);
                 }
             } else if (ts->val_type == TEMP_VAL_MEM) {
-                tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+                tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
             } else if (ts->val_type == TEMP_VAL_CONST) {
                 /* XXX: sign extend ? */
                 tcg_out_movi(s, ts->type, reg, ts->val);
@@ -2150,7 +2156,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
     const_func_arg = 0;
     if (ts->val_type == TEMP_VAL_MEM) {
         reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs);
-        tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+        tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
         func_arg = reg;
         tcg_regset_set_reg(allocated_regs, reg);
     } else if (ts->val_type == TEMP_VAL_REG) {
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 554a4ee..b99302a 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -393,7 +393,7 @@ typedef struct TCGTemp {
     TCGTempType val_type;
     int reg;
     tcg_target_long val;
-    int mem_reg;
+    struct TCGTemp *mem_base;
     intptr_t mem_offset;
     unsigned int fixed_reg:1;
     unsigned int mem_coherent:1;
@@ -444,7 +444,7 @@ struct TCGContext {
     intptr_t current_frame_offset;
     intptr_t frame_start;
     intptr_t frame_end;
-    int frame_reg;
+    int frame_temp;
 
     uint8_t *code_ptr;
     TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */
-- 
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 ` Richard Henderson [this message]
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 ` [Qemu-devel] [RFC 07/16] tcg: Change reg_to_temp to TCGTemp pointer Richard Henderson
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-4-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).