* [PATCH] sim: cgen: inline cgen_init logic
@ 2021-06-05 14:33 Mike Frysinger
0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2021-06-05 14:33 UTC (permalink / raw)
To: gdb-patches
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.
---
sim/bpf/sim-if.c | 4 ----
sim/common/cgen-defs.h | 14 --------------
sim/common/cgen-run.c | 23 ++++++++++++++++++++++-
sim/common/cgen-utils.c | 35 -----------------------------------
sim/common/sim-base.h | 10 ----------
sim/cris/sim-if.c | 4 ----
sim/frv/sim-if.c | 4 ----
sim/iq2000/sim-if.c | 4 ----
sim/lm32/sim-if.c | 4 ----
sim/m32r/sim-if.c | 4 ----
sim/or1k/sim-if.c | 4 ----
sim/or1k/traps.c | 2 +-
12 files changed, 23 insertions(+), 89 deletions(-)
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index 185e96dd7b93..436cc86f415d 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -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;
diff --git a/sim/common/cgen-defs.h b/sim/common/cgen-defs.h
index dab2f9ff16de..520c29cb3b9f 100644
--- a/sim/common/cgen-defs.h
+++ b/sim/common/cgen-defs.h
@@ -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;
diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c
index 443b62a0bbc3..9420942af8ad 100644
--- a/sim/common/cgen-run.c
+++ b/sim/common/cgen-run.c
@@ -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)
diff --git a/sim/common/cgen-utils.c b/sim/common/cgen-utils.c
index 890ed0218d1a..13107904678c 100644
--- a/sim/common/cgen-utils.c
+++ b/sim/common/cgen-utils.c
@@ -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 *
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index 7dbf2943385a..054b2ba0c6eb 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -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. */
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 6613a93ecc55..c6dcc23c938a 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -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;
diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c
index c5fd93f0b310..8ac9665f4cfc 100644
--- a/sim/frv/sim-if.c
+++ b/sim/frv/sim-if.c
@@ -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)
{
diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c
index b363eb04a218..679d5164033a 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -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
diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c
index 1cccf626b670..3d4ee35d7462 100644
--- a/sim/lm32/sim-if.c
+++ b/sim/lm32/sim-if.c
@@ -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
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index a6d8c486168c..e08a5d461af2 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -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. */
diff --git a/sim/or1k/sim-if.c b/sim/or1k/sim-if.c
index 005124b9ad7f..e6342ee42c0f 100644
--- a/sim/or1k/sim-if.c
+++ b/sim/or1k/sim-if.c
@@ -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)
{
diff --git a/sim/or1k/traps.c b/sim/or1k/traps.c
index 7f5a38f68bef..bb428fa4a886 100644
--- a/sim/or1k/traps.c
+++ b/sim/or1k/traps.c
@@ -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
--
2.31.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-05 14:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 14:33 [PATCH] sim: cgen: inline cgen_init logic Mike Frysinger
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 read-only IMAP folder(s) and NNTP newsgroup(s).