diff mbox

[4/5] tcg: don't build tcg/tcg.o, tcg/optimize.o, or translate-all.o when TCG disabled

Message ID 1315000083-20576-5-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori Sept. 2, 2011, 9:48 p.m. UTC
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 Makefile.target         |    6 +++---
 exec.c                  |   44 +++++++++++++++++++++++++++++---------------
 target-i386/op_helper.c |    2 +-
 translate-all.c         |   12 +++---------
 4 files changed, 36 insertions(+), 28 deletions(-)

Comments

Blue Swirl Sept. 3, 2011, 12:07 p.m. UTC | #1
On Fri, Sep 2, 2011 at 9:48 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  Makefile.target         |    6 +++---
>  exec.c                  |   44 +++++++++++++++++++++++++++++---------------
>  target-i386/op_helper.c |    2 +-
>  translate-all.c         |   12 +++---------
>  4 files changed, 36 insertions(+), 28 deletions(-)
>
> diff --git a/Makefile.target b/Makefile.target
> index 70f52cc..0a786b4 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -67,11 +67,11 @@ all: $(PROGS) stap
>
>  #########################################################
>  # cpu emulator library
> -libobj-y = exec.o translate-all.o cpu-exec.o
> -libobj-y += tcg/tcg.o tcg/optimize.o
> +libobj-y = exec.o cpu-exec.o
>  libobj-y += fpu/softfloat.o
>  libobj-y += op_helper.o helper.o
> -libobj-$(CONFIG_TCG) += translate.o
> +libobj-$(CONFIG_TCG) += translate.o translate-all.o
> +libobj-$(CONFIG_TCG) += tcg/tcg.o tcg/optimize.o
>  ifeq ($(TARGET_BASE_ARCH), i386)
>  libobj-y += cpuid.o
>  endif
> diff --git a/exec.c b/exec.c
> index 578da0e..c7decb9 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -574,15 +574,17 @@ static void code_gen_alloc(unsigned long tb_size)
>    size. */
>  void tcg_exec_init(unsigned long tb_size)
>  {
> -    cpu_gen_init();
> -    code_gen_alloc(tb_size);
> -    code_gen_ptr = code_gen_buffer;
> -    page_init();
> +    if (tcg_enabled()) {
> +        cpu_gen_init();
> +        code_gen_alloc(tb_size);
> +        code_gen_ptr = code_gen_buffer;
> +        page_init();
>  #if !defined(CONFIG_USER_ONLY) || !defined(CONFIG_USE_GUEST_BASE)
>     /* There's no guest base to take into account, so go ahead and
>        initialize the prologue now.  */
> -    tcg_prologue_init(&tcg_ctx);
> +        tcg_prologue_init(&tcg_ctx);
>  #endif
> +    }
>  }
>
>  bool tcg_in_use(void)
> @@ -992,7 +994,6 @@ TranslationBlock *tb_gen_code(CPUState *env,
>     uint8_t *tc_ptr;
>     tb_page_addr_t phys_pc, phys_page2;
>     target_ulong virt_page2;
> -    int code_gen_size;
>
>     phys_pc = get_page_addr_code(env, pc);
>     tb = tb_alloc(pc);
> @@ -1009,8 +1010,11 @@ TranslationBlock *tb_gen_code(CPUState *env,
>     tb->cs_base = cs_base;
>     tb->flags = flags;
>     tb->cflags = cflags;
> -    cpu_gen_code(env, tb, &code_gen_size);
> -    code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
> +    if (tcg_enabled()) {
> +        int code_gen_size;
> +        cpu_gen_code(env, tb, &code_gen_size);
> +        code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));

This line is (in original already) longer than 80 chars, please break it.

> +    }
>
>     /* check next page if needed */
>     virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK;
> @@ -1090,7 +1094,9 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
>                 restore the CPU state */
>
>                 current_tb_modified = 1;
> -                cpu_restore_state(current_tb, env, env->mem_io_pc);
> +                if (tcg_enabled()) {
> +                    cpu_restore_state(current_tb, env, env->mem_io_pc);
> +                }
>                 cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
>                                      &current_flags);
>             }
> @@ -1198,9 +1204,11 @@ static void tb_invalidate_phys_page(tb_page_addr_t addr,
>                    restore the CPU state */
>
>             current_tb_modified = 1;
> -            cpu_restore_state(current_tb, env, pc);
> -            cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
> -                                 &current_flags);
> +            if (tcg_enabled()) {
> +                cpu_restore_state(current_tb, env, pc);
> +                cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
> +                                     &current_flags);
> +            }
>         }
>  #endif /* TARGET_HAS_PRECISE_SMC */
>         tb_phys_invalidate(tb, addr);
> @@ -3427,7 +3435,9 @@ static void check_watchpoint(int offset, int len_mask, int flags)
>                     cpu_abort(env, "check_watchpoint: could not find TB for "
>                               "pc=%p", (void *)env->mem_io_pc);
>                 }
> -                cpu_restore_state(tb, env, env->mem_io_pc);
> +                if (tcg_enabled()) {
> +                    cpu_restore_state(tb, env, env->mem_io_pc);
> +                }
>                 tb_phys_invalidate(tb, -1);
>                 if (wp->flags & BP_STOP_BEFORE_ACCESS) {
>                     env->exception_index = EXCP_DEBUG;
> @@ -4668,7 +4678,9 @@ void cpu_io_recompile(CPUState *env, void *retaddr)
>                   retaddr);
>     }
>     n = env->icount_decr.u16.low + tb->icount;
> -    cpu_restore_state(tb, env, (unsigned long)retaddr);
> +    if (tcg_enabled()) {
> +        cpu_restore_state(tb, env, (unsigned long)retaddr);
> +    }
>     /* Calculate how many instructions had been executed before the fault
>        occurred.  */
>     n = n - env->icount_decr.u16.low;
> @@ -4763,7 +4775,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)
>     cpu_fprintf(f, "TB flush count      %d\n", tb_flush_count);
>     cpu_fprintf(f, "TB invalidate count %d\n", tb_phys_invalidate_count);
>     cpu_fprintf(f, "TLB flush count     %d\n", tlb_flush_count);
> -    tcg_dump_info(f, cpu_fprintf);
> +    if (tcg_enabled()) {
> +        tcg_dump_info(f, cpu_fprintf);
> +    }
>  }
>
>  #define MMUSUFFIX _cmmu
> diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
> index 1bbc3b5..7d90ea7 100644
> --- a/target-i386/op_helper.c
> +++ b/target-i386/op_helper.c
> @@ -5015,7 +5015,7 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
>             /* now we have a real cpu fault */
>             pc = (unsigned long)retaddr;
>             tb = tb_find_pc(pc);
> -            if (tb) {
> +            if (tb && tcg_enabled()) {
>                 /* the PC is inside the translated code. It means that we have
>                    a virtual CPU fault */
>                 cpu_restore_state(tb, env, pc);
> diff --git a/translate-all.c b/translate-all.c
> index ecb035a..041c108 100644
> --- a/translate-all.c
> +++ b/translate-all.c
> @@ -67,9 +67,7 @@ int cpu_gen_code(CPUState *env, TranslationBlock *tb, int *gen_code_size_ptr)
>  #endif
>     tcg_func_start(s);
>
> -    if (tcg_enabled()) {
> -        gen_intermediate_code(env, tb);
> -    }
> +    gen_intermediate_code(env, tb);
>
>     /* generate machine code */
>     gen_code_buf = tb->tc_ptr;
> @@ -125,9 +123,7 @@ int cpu_restore_state(TranslationBlock *tb,
>  #endif
>     tcg_func_start(s);
>
> -    if (tcg_enabled()) {
> -        gen_intermediate_code_pc(env, tb);
> -    }
> +    gen_intermediate_code_pc(env, tb);
>
>     if (use_icount) {
>         /* Reset the cycle counter to the start of the block.  */
> @@ -157,9 +153,7 @@ int cpu_restore_state(TranslationBlock *tb,
>         j--;
>     env->icount_decr.u16.low -= gen_opc_icount[j];
>
> -    if (tcg_enabled()) {
> -        restore_state_to_opc(env, tb, j);
> -    }
> +    restore_state_to_opc(env, tb, j);
>
>  #ifdef CONFIG_PROFILER
>     s->restore_time += profile_getclock() - ti;
> --
> 1.7.4.1
>
>
>
diff mbox

Patch

diff --git a/Makefile.target b/Makefile.target
index 70f52cc..0a786b4 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -67,11 +67,11 @@  all: $(PROGS) stap
 
 #########################################################
 # cpu emulator library
-libobj-y = exec.o translate-all.o cpu-exec.o
-libobj-y += tcg/tcg.o tcg/optimize.o
+libobj-y = exec.o cpu-exec.o
 libobj-y += fpu/softfloat.o
 libobj-y += op_helper.o helper.o
-libobj-$(CONFIG_TCG) += translate.o
+libobj-$(CONFIG_TCG) += translate.o translate-all.o
+libobj-$(CONFIG_TCG) += tcg/tcg.o tcg/optimize.o
 ifeq ($(TARGET_BASE_ARCH), i386)
 libobj-y += cpuid.o
 endif
diff --git a/exec.c b/exec.c
index 578da0e..c7decb9 100644
--- a/exec.c
+++ b/exec.c
@@ -574,15 +574,17 @@  static void code_gen_alloc(unsigned long tb_size)
    size. */
 void tcg_exec_init(unsigned long tb_size)
 {
-    cpu_gen_init();
-    code_gen_alloc(tb_size);
-    code_gen_ptr = code_gen_buffer;
-    page_init();
+    if (tcg_enabled()) {
+        cpu_gen_init();
+        code_gen_alloc(tb_size);
+        code_gen_ptr = code_gen_buffer;
+        page_init();
 #if !defined(CONFIG_USER_ONLY) || !defined(CONFIG_USE_GUEST_BASE)
     /* There's no guest base to take into account, so go ahead and
        initialize the prologue now.  */
-    tcg_prologue_init(&tcg_ctx);
+        tcg_prologue_init(&tcg_ctx);
 #endif
+    }
 }
 
 bool tcg_in_use(void)
@@ -992,7 +994,6 @@  TranslationBlock *tb_gen_code(CPUState *env,
     uint8_t *tc_ptr;
     tb_page_addr_t phys_pc, phys_page2;
     target_ulong virt_page2;
-    int code_gen_size;
 
     phys_pc = get_page_addr_code(env, pc);
     tb = tb_alloc(pc);
@@ -1009,8 +1010,11 @@  TranslationBlock *tb_gen_code(CPUState *env,
     tb->cs_base = cs_base;
     tb->flags = flags;
     tb->cflags = cflags;
-    cpu_gen_code(env, tb, &code_gen_size);
-    code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
+    if (tcg_enabled()) {
+        int code_gen_size;
+        cpu_gen_code(env, tb, &code_gen_size);
+        code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
+    }
 
     /* check next page if needed */
     virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK;
@@ -1090,7 +1094,9 @@  void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
                 restore the CPU state */
 
                 current_tb_modified = 1;
-                cpu_restore_state(current_tb, env, env->mem_io_pc);
+                if (tcg_enabled()) {
+                    cpu_restore_state(current_tb, env, env->mem_io_pc);
+                }
                 cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
                                      &current_flags);
             }
@@ -1198,9 +1204,11 @@  static void tb_invalidate_phys_page(tb_page_addr_t addr,
                    restore the CPU state */
 
             current_tb_modified = 1;
-            cpu_restore_state(current_tb, env, pc);
-            cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
-                                 &current_flags);
+            if (tcg_enabled()) {
+                cpu_restore_state(current_tb, env, pc);
+                cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
+                                     &current_flags);
+            }
         }
 #endif /* TARGET_HAS_PRECISE_SMC */
         tb_phys_invalidate(tb, addr);
@@ -3427,7 +3435,9 @@  static void check_watchpoint(int offset, int len_mask, int flags)
                     cpu_abort(env, "check_watchpoint: could not find TB for "
                               "pc=%p", (void *)env->mem_io_pc);
                 }
-                cpu_restore_state(tb, env, env->mem_io_pc);
+                if (tcg_enabled()) {
+                    cpu_restore_state(tb, env, env->mem_io_pc);
+                }
                 tb_phys_invalidate(tb, -1);
                 if (wp->flags & BP_STOP_BEFORE_ACCESS) {
                     env->exception_index = EXCP_DEBUG;
@@ -4668,7 +4678,9 @@  void cpu_io_recompile(CPUState *env, void *retaddr)
                   retaddr);
     }
     n = env->icount_decr.u16.low + tb->icount;
-    cpu_restore_state(tb, env, (unsigned long)retaddr);
+    if (tcg_enabled()) {
+        cpu_restore_state(tb, env, (unsigned long)retaddr);
+    }
     /* Calculate how many instructions had been executed before the fault
        occurred.  */
     n = n - env->icount_decr.u16.low;
@@ -4763,7 +4775,9 @@  void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)
     cpu_fprintf(f, "TB flush count      %d\n", tb_flush_count);
     cpu_fprintf(f, "TB invalidate count %d\n", tb_phys_invalidate_count);
     cpu_fprintf(f, "TLB flush count     %d\n", tlb_flush_count);
-    tcg_dump_info(f, cpu_fprintf);
+    if (tcg_enabled()) {
+        tcg_dump_info(f, cpu_fprintf);
+    }
 }
 
 #define MMUSUFFIX _cmmu
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 1bbc3b5..7d90ea7 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -5015,7 +5015,7 @@  void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
             /* now we have a real cpu fault */
             pc = (unsigned long)retaddr;
             tb = tb_find_pc(pc);
-            if (tb) {
+            if (tb && tcg_enabled()) {
                 /* the PC is inside the translated code. It means that we have
                    a virtual CPU fault */
                 cpu_restore_state(tb, env, pc);
diff --git a/translate-all.c b/translate-all.c
index ecb035a..041c108 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -67,9 +67,7 @@  int cpu_gen_code(CPUState *env, TranslationBlock *tb, int *gen_code_size_ptr)
 #endif
     tcg_func_start(s);
 
-    if (tcg_enabled()) {
-        gen_intermediate_code(env, tb);
-    }
+    gen_intermediate_code(env, tb);
 
     /* generate machine code */
     gen_code_buf = tb->tc_ptr;
@@ -125,9 +123,7 @@  int cpu_restore_state(TranslationBlock *tb,
 #endif
     tcg_func_start(s);
 
-    if (tcg_enabled()) {
-        gen_intermediate_code_pc(env, tb);
-    }
+    gen_intermediate_code_pc(env, tb);
 
     if (use_icount) {
         /* Reset the cycle counter to the start of the block.  */
@@ -157,9 +153,7 @@  int cpu_restore_state(TranslationBlock *tb,
         j--;
     env->icount_decr.u16.low -= gen_opc_icount[j];
 
-    if (tcg_enabled()) {
-        restore_state_to_opc(env, tb, j);
-    }
+    restore_state_to_opc(env, tb, j);
 
 #ifdef CONFIG_PROFILER
     s->restore_time += profile_getclock() - ti;