sim: cgen: inline cgen_init logic
authorMike Frysinger <vapier@gentoo.org>
Sat, 5 Jun 2021 14:21:46 +0000 (10:21 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 9 Jun 2021 22:21:28 +0000 (18:21 -0400)
This function has done only one thing: post-process command line
settings to see if profiling or tracing has been enabled, and if
so, set the run_fast_p flag in the simulator state.  That flag is
only used in one place: to select the fast or slow cgen engine.
By inlining the run_fast_p logic to the one place it's used, we
can delete a good amount of logic specific to cgen ports: both
the call to cgen_init and the conditional simulator state.  This
in turn allows us to have a single simulator state struct across
all ports so we can share objects more between them, and makes
the sim_open calls look more consistent.

20 files changed:
sim/bpf/ChangeLog
sim/bpf/sim-if.c
sim/common/ChangeLog
sim/common/cgen-defs.h
sim/common/cgen-run.c
sim/common/cgen-utils.c
sim/common/sim-base.h
sim/cris/ChangeLog
sim/cris/sim-if.c
sim/frv/ChangeLog
sim/frv/sim-if.c
sim/iq2000/ChangeLog
sim/iq2000/sim-if.c
sim/lm32/ChangeLog
sim/lm32/sim-if.c
sim/m32r/ChangeLog
sim/m32r/sim-if.c
sim/or1k/ChangeLog
sim/or1k/sim-if.c
sim/or1k/traps.c

index f5f57162599449899edd70ac2b0044f2a717adc0..42143db129d8ecfcaae695b4c1d7b051fc1417c7 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-main.h (struct sim_state): Delete.
index 185e96dd7b93df27d75e5b8a62973fefbd18ae29..436cc86f415d357526ee72b78a5ed750324bc4c7 100644 (file)
@@ -175,10 +175,6 @@ sim_open (SIM_OPEN_KIND kind,
     bpf_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after bpf_cgen_cpu_open.  */
-  cgen_init (sd);
-
   /* XXX do eBPF sim specific initializations.  */
 
   return sd;
index 576b02f386239dad7f96b7700fdda64c6cc5d5cd..dbe9236056ddc4598e7169182b2a1274bc3ddc70 100644 (file)
@@ -1,3 +1,12 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * cgen-defs.h (STATE_RUN_FAST_P, CGEN_STATE, cgen_init): Delete.
+       * cgen-run.c (cgen_get_fast_p): New function.
+       (sim_resume): Move fast_p up and call cgen_get_fast_p.
+       * cgen-utils.c (cgen_init): Delete.
+       * sim-base.h: Delete cgen-sim.h include.
+       (struct sim_state): Delete cgen_state and STATE_CGEN_STATE.
+
 2021-06-08  Mike Frysinger  <vapier@gentoo.org>
 
        * Make-common.in (IGEN_RUN): New variable.
index dab2f9ff16de1c4b83ff1b65163ea4b22e940936..520c29cb3b9f3242796d696af4b124a86455e694 100644 (file)
@@ -138,22 +138,8 @@ typedef enum {
 #define ENDSWITCH(N)
 #endif
 \f
-/* Simulator state.  */
-
-/* CGEN_STATE contains additional state information not present in
-   sim_state_base.  */
-
-typedef struct cgen_state {
-  /* Non-zero if no tracing or profiling is selected.  */
-  int run_fast_p;
-#define STATE_RUN_FAST_P(sd) (STATE_CGEN_STATE (sd).run_fast_p)
-} CGEN_STATE;
-\f
 /* Various utilities.  */
 
-/* Called after sim_post_argv_init to do any cgen initialization.  */
-extern void cgen_init (SIM_DESC);
-
 /* Return the name of an insn.  */
 extern CPU_INSN_NAME_FN cgen_insn_name;
 
index 443b62a0bbc37007ea0ea6d44f3a52e3fb312f23..9420942af8ad74291f61573d3e1b4b8ef8e004cf 100644 (file)
@@ -51,6 +51,24 @@ static void prime_cpu (SIM_CPU *, int);
 static void engine_run_1 (SIM_DESC, int, int);
 static void engine_run_n (SIM_DESC, int, int, int, int);
 
+/* If no profiling or tracing has been enabled, run in fast mode.  */
+static int
+cgen_get_fast_p (SIM_DESC sd)
+{
+  int i, c;
+  int run_fast_p = 1;
+
+  for (c = 0; c < MAX_NR_PROCESSORS; ++c)
+    {
+      SIM_CPU *cpu = STATE_CPU (sd, c);
+
+      if (PROFILE_ANY_P (cpu) || TRACE_ANY_P (cpu))
+       return 0;
+    }
+
+  return 1;
+}
+
 /* sim_resume for cgen */
 
 void
@@ -59,9 +77,13 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
   sim_engine *engine = STATE_ENGINE (sd);
   jmp_buf buf;
   int jmpval;
+  static int fast_p = -1;
 
   ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
 
+  if (fast_p == -1)
+    fast_p = cgen_get_fast_p (sd);
+
   /* we only want to be single stepping the simulator once */
   if (engine->stepper != NULL)
     {
@@ -102,7 +124,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal)
                          && STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
                       ? 0
                       : 8); /*FIXME: magic number*/
-      int fast_p = STATE_RUN_FAST_P (sd);
 
       sim_events_preprocess (sd, last_cpu_nr >= nr_cpus, next_cpu_nr >= nr_cpus);
       if (next_cpu_nr >= nr_cpus)
index 890ed0218d1a5a0f8f99f8c566cfe00dcff7be1a..13107904678c9ef9222dbf6ebd09f687e23fb938 100644 (file)
@@ -89,41 +89,6 @@ const CGEN_INSN cgen_virtual_insn_table[] =
   { & virtual_insn_entries[5] }
 };
 
-/* Initialize cgen things.
-   This is called after sim_post_argv_init.  */
-
-void
-cgen_init (SIM_DESC sd)
-{
-  int i, c;
-
-  /* If no profiling or tracing has been enabled, run in fast mode.  */
-  {
-    int run_fast_p = 1;
-
-    for (c = 0; c < MAX_NR_PROCESSORS; ++c)
-      {
-       SIM_CPU *cpu = STATE_CPU (sd, c);
-
-       for (i = 0; i < MAX_PROFILE_VALUES; ++i)
-         if (CPU_PROFILE_FLAGS (cpu) [i])
-           {
-             run_fast_p = 0;
-             break;
-           }
-       for (i = 0; i < MAX_TRACE_VALUES; ++i)
-         if (CPU_TRACE_FLAGS (cpu) [i])
-           {
-             run_fast_p = 0;
-             break;
-           }
-       if (! run_fast_p)
-         break;
-      }
-    STATE_RUN_FAST_P (sd) = run_fast_p;
-  }
-}
-
 /* Return the name of insn number I.  */
 
 const char *
index 7dbf2943385a3dc77a35973b7bd5d879b9030616..054b2ba0c6ebd886957922a03f30b10b555fb5fa 100644 (file)
@@ -88,10 +88,6 @@ typedef struct _sim_cpu sim_cpu;
 #include "sim-cpu.h"
 #include "sim-assert.h"
 
-#ifdef CGEN_ARCH
-# include "cgen-sim.h"
-#endif
-
 struct sim_state {
   /* All the cpus for this instance.  */
   sim_cpu *cpu[MAX_NR_PROCESSORS];
@@ -217,12 +213,6 @@ struct sim_state {
   void *arch_data;
 #define STATE_ARCH_DATA(sd) ((sd)->arch_data)
 
-#ifdef CGEN_ARCH
-  /* Various cgen runtime state.  */
-  CGEN_STATE cgen_state;
-#endif
-#define STATE_CGEN_STATE(sd) ((sd)->cgen_state)
-
   /* Marker for those wanting to do sanity checks.
      This should remain the last member of this struct to help catch
      miscompilation errors.  */
index 5482e083193ec0609aaffc9a4ba1743678a6fc83..c0bb314e10f30ee0d2b0025aa1bb77a9852b5977 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-24  Mike Frysinger  <vapier@gentoo.org>
 
        * cris-desc.c, cris-desc.h, cris-opc.h: Moved to opcodes/.
index 6613a93ecc554a4afaff7a76015770e4098d2ba7..c6dcc23c938aac7d3dc23dc45521d133d14e59a3 100644 (file)
@@ -940,10 +940,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 #endif
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after cris_cgen_cpu_open.  */
-  cgen_init (sd);
-
   cris_set_callbacks (callback);
 
   return sd;
index 4ca57d3f4fd48a27aa191c47d831b5d4889e63f9..060b0a24073e921b9bd9f5336ce806d9fc395de7 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-29  Mike Frysinger  <vapier@gentoo.org>
 
        * cache.h (frv_cache_unlock): New prototype.
index c5fd93f0b310ef7a269ace030ef25c6a1b843858..8ac9665f4cfc65b74bda7457ab36c0e74e3f98c5 100644 (file)
@@ -147,10 +147,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, bfd *abfd,
     frv_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after frv_cgen_cpu_open.  */
-  cgen_init (sd);
-
   /* CPU specific initialization.  */
   for (i = 0; i < MAX_NR_PROCESSORS; ++i)
     {
index d5805edfad7d9b69818bd37bd62ad9d3be4d20b8..2e80084aed3688e4cf43b9dfe0f5a8ffb10bd385 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-main.h (struct sim_state): Delete.
index b363eb04a21888018666c67a10cd6520be6d7a76..679d5164033a99632f9acc6a63f0b003992fb2e1 100644 (file)
@@ -122,10 +122,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
     iq2000_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after iq2000_cgen_cpu_open.  */
-  cgen_init (sd);
-
   return sd;
 }
 \f
index c014a6d8b53ac041770cb56572da70dd99418945..90920635f4ede4835678d30046203d479d2eea13 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-main.h (struct sim_state): Delete.
index 1cccf626b67031978428b627d9fe9845bca115d3..3d4ee35d7462e29659cb6d6e999b9f04b89aa17b 100644 (file)
@@ -182,10 +182,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
     lm32_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after lm32_cgen_cpu_open.  */
-  cgen_init (sd);
-
   return sd;
 }
 \f
index 04d342defeb14f7952c99ff8e9e0a0c850d8d9b5..f9d3079fcd87d080ae311ee9ff933a904081c69d 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-main.h (struct sim_state): Delete.
index a6d8c486168c1f41a42574a349314b486158a9a5..e08a5d461af2af027dc263aca88ac11748cd23c7 100644 (file)
@@ -124,10 +124,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
     m32r_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after m32r_cgen_cpu_open.  */
-  cgen_init (sd);
-
   for (c = 0; c < MAX_NR_PROCESSORS; ++c)
     {
       /* Only needed for profiling, but the structure member is small.  */
index 3484c07055da5d7d5653ee693ab8bcb9e51849ea..689f038a38960705f74264fd6d6929d5b9a053d1 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete cgen_init call.
+       * traps.c (or1k32bf_fpu_error): Replace STATE_RUN_FAST_P with
+       PROFILE_ANY_P and TRACE_ANY_P.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-main.h: Move or1k-opc.h include.
index 005124b9ad7f645cd1f4f097d14dfe9d2fe956bf..e6342ee42c0f7b9e8496b86bfc66231d21d55743 100644 (file)
@@ -238,10 +238,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
     or1k_cgen_init_dis (cd);
   }
 
-  /* Initialize various cgen things not done by common framework.
-     Must be done after or1k_cgen_cpu_open.  */
-  cgen_init (sd);
-
   /* Do some final OpenRISC sim specific initializations.  */
   for (c = 0; c < MAX_NR_PROCESSORS; ++c)
     {
index 7f5a38f68befcf10269e8d064111edc6e2f08f40..bb428fa4a8860ada67dead6abdfcaaa304d34bcb 100644 (file)
@@ -104,7 +104,7 @@ or1k32bf_fpu_error (CGEN_FPU* fpu, int status)
             per-instruction callbacks are not triggered which would allow
             us to track the PC.  This means we cannot track which
             instruction caused the FPU error.  */
-         if (STATE_RUN_FAST_P (sd) == 1)
+         if (!PROFILE_ANY_P (current_cpu) && !TRACE_ANY_P (current_cpu))
            sim_io_eprintf
              (sd, "WARNING: ignoring fpu error caught in fast mode.\n");
          else
This page took 0.035765 seconds and 4 git commands to generate.