diff mbox series

[1/5] tcg: Add an index to TCGTemp

Message ID 20210119183428.556706-2-richard.henderson@linaro.org
State New
Headers show
Series tcg: Dynamically allocate temporaries | expand

Commit Message

Richard Henderson Jan. 19, 2021, 6:34 p.m. UTC
This allows to break the tie between the memory location
of TCGTemp and TCGContext->temps[].  Which is the first
step to allowing the array to be reallocated.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 include/tcg/tcg.h |  5 ++---
 tcg/tcg.c         | 10 ++++++++--
 2 files changed, 10 insertions(+), 5 deletions(-)

-- 
2.25.1
diff mbox series

Patch

diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 504c5e9bb0..5ef644ceae 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -497,6 +497,7 @@  typedef enum TCGTempKind {
 } TCGTempKind;
 
 typedef struct TCGTemp {
+    unsigned int index:16;
     TCGReg reg:8;
     TCGTempVal val_type:8;
     TCGType base_type:8;
@@ -721,9 +722,7 @@  static inline void *tcg_splitwx_to_rw(const void *rx)
 
 static inline size_t temp_idx(TCGTemp *ts)
 {
-    ptrdiff_t n = ts - tcg_ctx->temps;
-    tcg_debug_assert(n >= 0 && n < tcg_ctx->nb_temps);
-    return n;
+    return ts->index;
 }
 
 static inline TCGArg temp_arg(TCGTemp *ts)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 8f8badb61c..4a8dfb8f67 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1204,11 +1204,17 @@  void tcg_func_start(TCGContext *s)
     QSIMPLEQ_INIT(&s->labels);
 }
 
-static inline TCGTemp *tcg_temp_alloc(TCGContext *s)
+static TCGTemp *tcg_temp_alloc(TCGContext *s)
 {
     int n = s->nb_temps++;
+    TCGTemp *ret;
+
     tcg_debug_assert(n < TCG_MAX_TEMPS);
-    return memset(&s->temps[n], 0, sizeof(TCGTemp));
+    ret = &s->temps[n];
+    memset(ret, 0, sizeof(TCGTemp));
+    ret->index = n;
+
+    return ret;
 }
 
 static inline TCGTemp *tcg_global_alloc(TCGContext *s)