qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 03/32] target/arm: Use DISAS_NORETURN
Date: Wed,  6 Sep 2017 09:05:43 -0700	[thread overview]
Message-ID: <20170906160612.22769-4-richard.henderson@linaro.org> (raw)
In-Reply-To: <20170906160612.22769-1-richard.henderson@linaro.org>

From: Richard Henderson <rth@twiddle.net>

Fold DISAS_EXC and DISAS_TB_JUMP into DISAS_NORETURN.

In both cases all following code is dead.  In the first
case because we have exited the TB via exception; in the
second case because we have exited the TB via goto_tb
and its associated machinery.

Reviewed-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 target/arm/translate.h     |  8 ++------
 target/arm/translate-a64.c | 37 ++++++++++++++++++++-----------------
 target/arm/translate.c     | 14 ++++++++------
 3 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/target/arm/translate.h b/target/arm/translate.h
index 2fe144baa9..90f64d9716 100644
--- a/target/arm/translate.h
+++ b/target/arm/translate.h
@@ -124,12 +124,8 @@ static void disas_set_insn_syndrome(DisasContext *s, uint32_t syn)
  * defer them until after the conditional execution state has been updated.
  * WFI also needs special handling when single-stepping.
  */
-#define DISAS_WFI 4
-#define DISAS_SWI 5
-/* For instructions which unconditionally cause an exception we can skip
- * emitting unreachable code at the end of the TB in the A64 decoder
- */
-#define DISAS_EXC 6
+#define DISAS_WFI 5
+#define DISAS_SWI 6
 /* WFE */
 #define DISAS_WFE 7
 #define DISAS_HVC 8
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
index cb44632d16..881d3c0cbb 100644
--- a/target/arm/translate-a64.c
+++ b/target/arm/translate-a64.c
@@ -304,7 +304,7 @@ static void gen_exception_internal_insn(DisasContext *s, int offset, int excp)
 {
     gen_a64_set_pc_im(s->pc - offset);
     gen_exception_internal(excp);
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 static void gen_exception_insn(DisasContext *s, int offset, int excp,
@@ -312,7 +312,7 @@ static void gen_exception_insn(DisasContext *s, int offset, int excp,
 {
     gen_a64_set_pc_im(s->pc - offset);
     gen_exception(excp, syndrome, target_el);
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 static void gen_ss_advance(DisasContext *s)
@@ -340,7 +340,7 @@ static void gen_step_complete_exception(DisasContext *s)
     gen_ss_advance(s);
     gen_exception(EXCP_UDEF, syn_swstep(s->ss_same_el, 1, s->is_ldex),
                   default_exception_el(s));
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
@@ -371,7 +371,7 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
         tcg_gen_goto_tb(n);
         gen_a64_set_pc_im(dest);
         tcg_gen_exit_tb((intptr_t)tb + n);
-        s->is_jmp = DISAS_TB_JUMP;
+        s->is_jmp = DISAS_NORETURN;
     } else {
         gen_a64_set_pc_im(dest);
         if (s->ss_active) {
@@ -380,7 +380,7 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
             gen_exception_internal(EXCP_DEBUG);
         } else {
             tcg_gen_lookup_and_goto_ptr(cpu_pc);
-            s->is_jmp = DISAS_TB_JUMP;
+            s->is_jmp = DISAS_NORETURN;
         }
     }
 }
@@ -11326,7 +11326,7 @@ void gen_intermediate_code_a64(CPUState *cs, TranslationBlock *tb)
             assert(num_insns == 1);
             gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0),
                           default_exception_el(dc));
-            dc->is_jmp = DISAS_EXC;
+            dc->is_jmp = DISAS_NORETURN;
             break;
         }
 
@@ -11353,21 +11353,25 @@ void gen_intermediate_code_a64(CPUState *cs, TranslationBlock *tb)
         gen_io_end();
     }
 
-    if (unlikely(cs->singlestep_enabled || dc->ss_active)
-        && dc->is_jmp != DISAS_EXC) {
+    if (unlikely(cs->singlestep_enabled || dc->ss_active)) {
         /* Note that this means single stepping WFI doesn't halt the CPU.
          * For conditional branch insns this is harmless unreachable code as
          * gen_goto_tb() has already handled emitting the debug exception
          * (and thus a tb-jump is not possible when singlestepping).
          */
-        assert(dc->is_jmp != DISAS_TB_JUMP);
-        if (dc->is_jmp != DISAS_JUMP) {
+        switch (dc->is_jmp) {
+        default:
             gen_a64_set_pc_im(dc->pc);
-        }
-        if (cs->singlestep_enabled) {
-            gen_exception_internal(EXCP_DEBUG);
-        } else {
-            gen_step_complete_exception(dc);
+            /* fall through */
+        case DISAS_JUMP:
+            if (cs->singlestep_enabled) {
+                gen_exception_internal(EXCP_DEBUG);
+            } else {
+                gen_step_complete_exception(dc);
+            }
+            break;
+        case DISAS_NORETURN:
+            break;
         }
     } else {
         switch (dc->is_jmp) {
@@ -11377,8 +11381,7 @@ void gen_intermediate_code_a64(CPUState *cs, TranslationBlock *tb)
         case DISAS_JUMP:
             tcg_gen_lookup_and_goto_ptr(cpu_pc);
             break;
-        case DISAS_TB_JUMP:
-        case DISAS_EXC:
+        case DISAS_NORETURN:
         case DISAS_SWI:
             break;
         case DISAS_WFE:
diff --git a/target/arm/translate.c b/target/arm/translate.c
index e52a6d7622..b14329dc27 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -297,7 +297,7 @@ static void gen_step_complete_exception(DisasContext *s)
     gen_ss_advance(s);
     gen_exception(EXCP_UDEF, syn_swstep(s->ss_same_el, 1, s->is_ldex),
                   default_exception_el(s));
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 static void gen_singlestep_exception(DisasContext *s)
@@ -1184,7 +1184,7 @@ static void gen_exception_internal_insn(DisasContext *s, int offset, int excp)
     gen_set_condexec(s);
     gen_set_pc_im(s, s->pc - offset);
     gen_exception_internal(excp);
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 static void gen_exception_insn(DisasContext *s, int offset, int excp,
@@ -1193,7 +1193,7 @@ static void gen_exception_insn(DisasContext *s, int offset, int excp,
     gen_set_condexec(s);
     gen_set_pc_im(s, s->pc - offset);
     gen_exception(excp, syn, target_el);
-    s->is_jmp = DISAS_EXC;
+    s->is_jmp = DISAS_NORETURN;
 }
 
 /* Force a TB lookup after an instruction that changes the CPU state.  */
@@ -11974,7 +11974,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)
             /* We always get here via a jump, so know we are not in a
                conditional execution block.  */
             gen_exception_internal(EXCP_KERNEL_TRAP);
-            dc->is_jmp = DISAS_EXC;
+            dc->is_jmp = DISAS_NORETURN;
             break;
         }
 #endif
@@ -12119,6 +12119,9 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)
         default:
             /* FIXME: Single stepping a WFI insn will not halt the CPU. */
             gen_singlestep_exception(dc);
+            break;
+        case DISAS_NORETURN:
+            break;
         }
     } else {
         /* While branches must always occur at the end of an IT block,
@@ -12143,8 +12146,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)
             /* indicate that the hash table must be used to find the next TB */
             tcg_gen_exit_tb(0);
             break;
-        case DISAS_TB_JUMP:
-        case DISAS_EXC:
+        case DISAS_NORETURN:
             /* nothing more to generate */
             break;
         case DISAS_WFI:
-- 
2.13.5

  parent reply	other threads:[~2017-09-06 16:06 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-06 16:05 [Qemu-devel] [PULL 00/32] tcg generic translate loop Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 01/32] tcg: Add generic DISAS_NORETURN Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 02/32] target/i386: Use generic DISAS_* enumerators Richard Henderson
2017-09-06 16:05 ` Richard Henderson [this message]
2017-09-06 16:05 ` [Qemu-devel] [PULL 04/32] target: [tcg] Use a generic enum for DISAS_ values Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 05/32] target/arm: Delay check for magic kernel page Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 06/32] tcg: Add generic translation framework Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 07/32] target/i386: [tcg] Port to DisasContextBase Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 08/32] target/i386: [tcg] Port to init_disas_context Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 09/32] target/i386: [tcg] Port to insn_start Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 10/32] target/i386: [tcg] Port to breakpoint_check Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 11/32] target/i386: [tcg] Port to translate_insn Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 12/32] target/i386: [tcg] Port to tb_stop Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 13/32] target/i386: [tcg] Port to disas_log Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 14/32] target/i386: [tcg] Port to generic translation framework Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 15/32] target/arm: [tcg] Port to DisasContextBase Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 16/32] target/arm: [tcg] Port to init_disas_context Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 17/32] target/arm: [tcg, a64] " Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 18/32] target/arm: [tcg] Port to tb_start Richard Henderson
2017-09-06 16:05 ` [Qemu-devel] [PULL 19/32] target/arm: [tcg] Port to insn_start Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 20/32] target/arm: [tcg, a64] " Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 21/32] target/arm: [tcg, a64] Port to breakpoint_check Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 22/32] target/arm: [tcg] Port to translate_insn Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 23/32] target/arm: [tcg, a64] " Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 24/32] target/arm: [tcg] Port to tb_stop Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 25/32] target/arm: [tcg,a64] " Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 26/32] target/arm: [tcg] Port to disas_log Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 27/32] target/arm: [tcg,a64] " Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 28/32] target/arm: [tcg] Port to generic translation framework Richard Henderson
2017-09-12 16:12   ` Laurent Desnogues
2017-09-12 16:37     ` Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 29/32] target/arm: [a64] Move page and ss checks to init_disas_context Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 30/32] target/arm: Move ss check " Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 31/32] target/arm: Split out thumb_tr_translate_insn Richard Henderson
2017-09-06 16:06 ` [Qemu-devel] [PULL 32/32] target/arm: Perform per-insn cross-page check only for Thumb Richard Henderson
2017-09-07 14:25 ` [Qemu-devel] [PULL 00/32] tcg generic translate loop Peter Maydell

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=20170906160612.22769-4-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).