From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>
Subject: [Qemu-devel] [PATCH 11/13] tcg: sync globals for pure helpers instead of saving them
Date: Thu, 27 Sep 2012 19:15:11 +0200 [thread overview]
Message-ID: <1348766113-18373-12-git-send-email-aurelien@aurel32.net> (raw)
In-Reply-To: <1348766113-18373-1-git-send-email-aurelien@aurel32.net>
Pure helpers are allowed to read globals, but not to modify them. In
that case, instead of moving all the globals to memory, just synchronize
them.
Also update the documentation to make it more clear.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
tcg/README | 15 ++++++++++-----
tcg/tcg.c | 33 ++++++++++++++++++++++++++++-----
2 files changed, 38 insertions(+), 10 deletions(-)
Note: this is a change of behavior, but the new one is still compliant
with the documentation. Currently only cris, i386 and s390x have PURE
only helpers. I have checked they are really PURE, and also did some
tests on cris and i386.
diff --git a/tcg/README b/tcg/README
index 27846f1..d61daa1 100644
--- a/tcg/README
+++ b/tcg/README
@@ -77,11 +77,16 @@ destroyed, but local temporaries and globals are preserved.
Using the tcg_gen_helper_x_y it is possible to call any function
taking i32, i64 or pointer types. By default, before calling a helper,
all globals are stored at their canonical location and it is assumed
-that the function can modify them. This can be overridden by the
-TCG_CALL_CONST function modifier. By default, the helper is allowed to
-modify the CPU state or raise an exception. This can be overridden by
-the TCG_CALL_PURE function modifier, in which case the call to the
-function is removed if the return value is not used.
+that the function can modify them. The helper is allowed to modify
+the CPU state or raise an exception.
+
+This can be overridden by the TCG_CALL_CONST and TCG_CALL_PURE function
+modifiers. A PURE helper can read globals but cannot modify them nor the
+CPU state and cannot raise an exception. It can be removed if the return
+value is not used. For that the globals are synchronized with their canonical
+location, but the associated registers are not freed nor reloaded afterwise.
+A CONST helper is a PURE helper which in addition cannot read globals, they
+are not synchronized nor stored. Note that CONST implies PURE.
On some TCG targets (e.g. x86), several calling conventions are
supported.
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 2f973e8..1c5ab81 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1280,11 +1280,14 @@ static void tcg_liveness_analysis(TCGContext *s)
dead_temps[arg] = 1;
mem_temps[arg] = 0;
}
-
+
if (!(call_flags & TCG_CALL_CONST)) {
+ /* globals should be synced to memory */
+ memset(mem_temps, 1, s->nb_globals);
+ }
+ if (!(call_flags & (TCG_CALL_CONST | TCG_CALL_PURE))) {
/* globals should go back to memory */
memset(dead_temps, 1, s->nb_globals);
- memset(mem_temps, 1, s->nb_globals);
}
/* input args are live */
@@ -1623,6 +1626,23 @@ static void save_globals(TCGContext *s, TCGRegSet allocated_regs)
}
}
+/* sync globals to their canonical location and assume they can be
+ read by the following code. 'allocated_regs' is used in case a
+ temporary registers needs to be allocated to store a constant. */
+static void sync_globals(TCGContext *s, TCGRegSet allocated_regs)
+{
+ int i;
+
+ for (i = 0; i < s->nb_globals; i++) {
+#ifdef USE_LIVENESS_ANALYSIS
+ assert(s->temps[i].val_type != TEMP_VAL_REG || s->temps[i].fixed_reg ||
+ s->temps[i].mem_coherent);
+#else
+ temp_sync(s, i, allocated_regs);
+#endif
+ }
+}
+
/* at the end of a basic block, we assume all temporaries are dead and
all globals are stored at their canonical location. */
static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs)
@@ -2070,9 +2090,12 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
}
}
- /* store globals and free associated registers (we assume the call
- can modify any global. */
- if (!(flags & TCG_CALL_CONST)) {
+ /* sync or save globals */
+ if (flags & TCG_CALL_CONST) {
+ /* nothing to do */
+ } else if (flags & TCG_CALL_PURE) {
+ sync_globals(s, allocated_regs);
+ } else {
save_globals(s, allocated_regs);
}
--
1.7.10.4
next prev parent reply other threads:[~2012-09-27 17:16 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-27 17:15 [Qemu-devel] [PATCH 00/13] tcg: rework liveness analysis and register allocator Aurelien Jarno
2012-09-27 17:15 ` [Qemu-devel] [PATCH 01/13] tcg: add temp_dead() Aurelien Jarno
2012-09-27 18:19 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 02/13] tcg: add tcg_reg_sync() Aurelien Jarno
2012-09-27 18:24 ` Richard Henderson
2012-09-27 20:00 ` Aurelien Jarno
2012-09-27 17:15 ` [Qemu-devel] [PATCH 03/13] tcg: add temp_sync() Aurelien Jarno
2012-09-27 18:30 ` Richard Henderson
2012-09-27 20:02 ` Aurelien Jarno
2012-09-27 17:15 ` [Qemu-devel] [PATCH 04/13] tcg: sync output arguments on liveness request Aurelien Jarno
2012-09-27 18:39 ` Richard Henderson
2012-09-27 20:05 ` Aurelien Jarno
2012-09-27 20:10 ` Richard Henderson
2012-09-27 20:25 ` Aurelien Jarno
2012-09-27 17:15 ` [Qemu-devel] [PATCH 05/13] tcg: rework liveness analysis Aurelien Jarno
2012-09-27 18:54 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 06/13] tcg: improve tcg_reg_alloc_movi() Aurelien Jarno
2012-09-27 18:55 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 07/13] tcg: rewrite tcg_reg_alloc_mov() Aurelien Jarno
2012-09-27 19:09 ` Richard Henderson
2012-09-27 20:17 ` Aurelien Jarno
2012-09-27 22:18 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 08/13] tcg: always mark dead input arguments as dead Aurelien Jarno
2012-09-27 19:10 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 09/13] tcg: start with local temps in TEMP_VAL_MEM state Aurelien Jarno
2012-09-27 19:10 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 10/13] tcg: don't explicitely save globals and temps Aurelien Jarno
2012-09-27 19:13 ` Richard Henderson
2012-09-27 20:23 ` Aurelien Jarno
2012-09-27 17:15 ` Aurelien Jarno [this message]
2012-09-27 19:39 ` [Qemu-devel] [PATCH 11/13] tcg: sync globals for pure helpers instead of saving them Richard Henderson
2012-09-27 20:34 ` Aurelien Jarno
2012-09-27 22:02 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 12/13] tcg: fix some op flags Aurelien Jarno
2012-09-27 19:44 ` Richard Henderson
2012-09-27 17:15 ` [Qemu-devel] [PATCH 13/13] tcg: rework TCG ops flags Aurelien Jarno
2012-09-27 19:56 ` Richard Henderson
2012-09-27 20:37 ` Aurelien Jarno
2012-09-27 22:00 ` Richard Henderson
2012-09-27 23:08 ` Aurelien Jarno
2012-09-27 23:11 ` Richard Henderson
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=1348766113-18373-12-git-send-email-aurelien@aurel32.net \
--to=aurelien@aurel32.net \
--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).