Liveness analysis needs to know about registers belonging to the caller
(such as those used to pass parameters, which can be modified by the
callee). This prevents the callee from messing up the data belonging to
the caller.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro>
---
 arch/x86/insn-selector.brg |   26 ++++++++++++++++++++++--
 arch/x86/use-def.c         |   45 ++++++++++++++++++++++++++++++-------------
 2 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg
index 3220ba0..7983dbb 100644
--- a/arch/x86/insn-selector.brg
+++ b/arch/x86/insn-selector.brg
@@ -3222,6 +3222,28 @@ static void insn_select(struct basic_block *bb)
        }
 }
 
+#ifdef CONFIG_X86_32
+static void touch_caller_saved_regs(struct compilation_unit *cu)
+{
+       get_fixed_var(cu, MACH_REG_EAX);
+       get_fixed_var(cu, MACH_REG_ECX);
+       get_fixed_var(cu, MACH_REG_EDX);
+}
+#else /* CONFIG_X86_32 */
+static void touch_caller_saved_regs(struct compilation_unit *cu)
+{
+       get_fixed_var(cu, MACH_REG_RAX);
+       get_fixed_var(cu, MACH_REG_RDI);
+       get_fixed_var(cu, MACH_REG_RSI);
+       get_fixed_var(cu, MACH_REG_RDX);
+       get_fixed_var(cu, MACH_REG_RCX);
+       get_fixed_var(cu, MACH_REG_R8);
+       get_fixed_var(cu, MACH_REG_R9);
+       get_fixed_var(cu, MACH_REG_R10);
+       get_fixed_var(cu, MACH_REG_R11);
+}
+#endif /* CONFIG_X86_32 */
+
 int select_instructions(struct compilation_unit *cu)
 {
        struct basic_block *bb;
@@ -3242,9 +3264,7 @@ int select_instructions(struct compilation_unit *cu)
        /*
         * Let the liveness analysis pass know about caller saved registers.
         */
-       get_fixed_var(cu, MACH_REG_xAX);
-       get_fixed_var(cu, MACH_REG_xCX);
-       get_fixed_var(cu, MACH_REG_xDX);
+       touch_caller_saved_regs(cu);
 
        for_each_basic_block(bb, &cu->bb_list) {
                insn_select(bb);
diff --git a/arch/x86/use-def.c b/arch/x86/use-def.c
index 5d017bc..9f76d13 100644
--- a/arch/x86/use-def.c
+++ b/arch/x86/use-def.c
@@ -10,18 +10,19 @@
 #include "jit/vars.h"
 
 enum {
-       DEF_DST         = 1,
-       DEF_SRC         = 2,
-       DEF_NONE        = 4,
-       DEF_xAX         = 8,
-       DEF_xCX         = 16,
-       DEF_xDX         = 32,
-       USE_DST         = 64,
-       USE_IDX_DST     = 128,  /* destination operand is memindex */
-       USE_IDX_SRC     = 256,  /* source operand is memindex */
-       USE_NONE        = 512,
-       USE_SRC         = 1024,
-       USE_FP          = 2048, /* frame pointer */
+       DEF_DST                 = 1,
+       DEF_SRC                 = 2,
+       DEF_NONE                = 4,
+       DEF_xAX                 = 8,
+       DEF_xCX                 = 16,
+       DEF_xDX                 = 32,
+       USE_DST                 = 64,
+       USE_IDX_DST             = 128,  /* destination operand is memindex */
+       USE_IDX_SRC             = 256,  /* source operand is memindex */
+       USE_NONE                = 512,
+       USE_SRC                 = 1024,
+       USE_FP                  = 2048, /* frame pointer */
+       DEF_CALLER_SAVED        = 4096,
 
 #ifdef CONFIG_X86_32
        DEF_EAX         = DEF_xAX,
@@ -49,8 +50,8 @@ static struct insn_info insn_infos[] = {
        DECLARE_INFO(INSN_ADD_REG_REG, USE_SRC | USE_DST | DEF_DST),
        DECLARE_INFO(INSN_AND_MEMBASE_REG, USE_SRC | USE_DST | DEF_DST),
        DECLARE_INFO(INSN_AND_REG_REG, USE_SRC | USE_DST | DEF_DST),
-       DECLARE_INFO(INSN_CALL_REG, USE_SRC | DEF_xAX | DEF_xCX | DEF_xDX),
-       DECLARE_INFO(INSN_CALL_REL, USE_NONE | DEF_xAX | DEF_xCX | DEF_xDX),
+       DECLARE_INFO(INSN_CALL_REG, USE_SRC | DEF_CALLER_SAVED),
+       DECLARE_INFO(INSN_CALL_REL, USE_NONE | DEF_CALLER_SAVED),
        DECLARE_INFO(INSN_CLTD_REG_REG, USE_SRC | DEF_SRC | DEF_DST),
        DECLARE_INFO(INSN_CMP_IMM_REG, USE_DST),
        DECLARE_INFO(INSN_CMP_MEMBASE_REG, USE_SRC | USE_DST),
@@ -187,6 +188,22 @@ static struct mach_reg_def checkregs[] = {
        { MACH_REG_xAX, DEF_xAX },
        { MACH_REG_xCX, DEF_xCX },
        { MACH_REG_xDX, DEF_xDX },
+
+#ifdef CONFIG_X86_32
+       { MACH_REG_EAX, DEF_CALLER_SAVED },
+       { MACH_REG_ECX, DEF_CALLER_SAVED },
+       { MACH_REG_EDX, DEF_CALLER_SAVED },
+#else
+       { MACH_REG_RAX, DEF_CALLER_SAVED },
+       { MACH_REG_RDI, DEF_CALLER_SAVED },
+       { MACH_REG_RSI, DEF_CALLER_SAVED },
+       { MACH_REG_RDX, DEF_CALLER_SAVED },
+       { MACH_REG_RCX, DEF_CALLER_SAVED },
+       { MACH_REG_R8, DEF_CALLER_SAVED },
+       { MACH_REG_R9, DEF_CALLER_SAVED },
+       { MACH_REG_R10, DEF_CALLER_SAVED },
+       { MACH_REG_R11, DEF_CALLER_SAVED },
+#endif
 };
 
 
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to