changeset 368:be56772ab12a global-offset

global offset, parallel_rassign fix, save_stack fix.
author kono
date Wed, 07 Jul 2004 23:43:19 +0900
parents 4efbb07f556b
children cd2c80d8cf8b
files Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c
diffstat 5 files changed, 176 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Wed Jul 07 20:50:07 2004 +0900
+++ b/Changes	Wed Jul 07 23:43:19 2004 +0900
@@ -5555,3 +5555,10 @@
 実際、出るコードは変わらないし。
 
 結構、複雑。複雑すぎるんじゃないの?
+
+Wed Jul  7 23:19:35 JST 2004
+
+できたけど、mips の register usage がおかしい。もっと
+レジスタを使えるはず。
+
+save_stack で、regisiter を解放するのを忘れてました。
--- a/mc-code-ia32.c	Wed Jul 07 20:50:07 2004 +0900
+++ b/mc-code-ia32.c	Wed Jul 07 23:43:19 2004 +0900
@@ -736,7 +736,12 @@
 void
 code_gvar(int e1,int creg) {
     use_int(creg);
-    printf("\tmovl $%s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
+    if (cadr(e1)) {
+	printf("\tmovl $%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1),
+		register_name(creg,0));
+    } else {
+	printf("\tmovl $%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0));
+    }
     regv[creg]=1;
 }
 
@@ -744,7 +749,11 @@
 void
 code_rgvar(int e1,int creg) {
     use_int(creg);
-    printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
+    if (cadr(e1)) {
+	printf("\tmovl %s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1),
+		register_name(creg,0));
+    } else
+	printf("\tmovl %s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
@@ -753,8 +762,12 @@
 void
 code_crgvar(int e1,int creg,int sign,int sz){
     use_int(creg);
-    printf("\t%s %s,%s\n",cload(sign,sz),
-	    ((NMTBL*)cadr(e1))->nm,register_name(creg,0));
+    if (cadr(e1)) {
+	printf("\t%s %s+%d,%s\n",cload(sign,sz),
+		((NMTBL*)caddr(e1))->nm,cadr(e1),register_name(creg,0));
+    } else
+	printf("\t%s %s,%s\n",cload(sign,sz),
+		((NMTBL*)caddr(e1))->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
@@ -980,10 +993,17 @@
 void
 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
     use_int(reg);
-    if (sz==1)
-	printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
-    else if (sz==SIZE_OF_SHORT)
-	printf("\tcmpw $0,%s\n",((NMTBL*)cadr(e1))->nm);
+    if (cadr(e1)) {
+	if (sz==1)
+	    printf("\tcmpb $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+	else if (sz==SIZE_OF_SHORT)
+	    printf("\tcmpw $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+    } else {
+	if (sz==1)
+	    printf("\tcmpb $0,%s\n",((NMTBL*)caddr(e1))->nm);
+	else if (sz==SIZE_OF_SHORT)
+	    printf("\tcmpw $0,%s\n",((NMTBL*)caddr(e1))->nm);
+    }
     jcond(label,cond);
 }
 
@@ -1002,7 +1022,10 @@
 void
 code_cmp_rgvar(int e1,int reg,int label,int cond) {
     use_int(reg);
-    printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm);
+    if (cadr(e1))
+	printf("\tcmpl $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+    else
+	printf("\tcmpl $0,%s\n",((NMTBL*)caddr(e1))->nm);
     jcond(label,cond);
 }
 
@@ -1405,7 +1428,10 @@
 code_assign_gvar(int e2,int creg,int byte) {
     use_int(creg);
     if (byte) use_data_reg(creg,1);
-    printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)cadr(e2))->nm);
+    if (cadr(e2)) 
+	printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2));
+    else
+	printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm);
 }
 
 void
@@ -2042,10 +2068,13 @@
 }
 
 extern void
-emit_address(char *s)
+emit_address(char *s,int offset)
 {
     data_mode(0);
-    printf("\t.long %s\n",s);
+    if (offset)
+	printf("\t.long %s+%d\n",s,offset);
+    else
+	printf("\t.long %s\n",s);
 }
 
 extern void
@@ -2177,7 +2206,10 @@
 
 void code_dassign_gvar(int e2,int freg,int d)
 { 
-    printf("\t%s %s\n",fstore(d),((NMTBL*)cadr(e2))->nm);
+    if (cadr(e2)) 
+	printf("\t%s %s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2));
+    else
+	printf("\t%s %s\n",fstore(d),((NMTBL*)caddr(e2))->nm);
 }
 
 void code_dassign_lvar(int e2,int freg,int d)
@@ -2294,7 +2326,10 @@
 
 void code_drgvar(int e2,int d,int freg)
 { 
-    printf("\t%s %s\n",fload(d),((NMTBL*)cadr(e2))->nm);
+    if (cadr(e2))
+	printf("\t%s %s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2));
+    else
+	printf("\t%s %s\n",fload(d),((NMTBL*)caddr(e2))->nm);
 }
 
 
@@ -2305,7 +2340,10 @@
 
 void code_cmp_drgvar(int e2,int reg,int d,int label,int cond)
 { 
-    printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm);
+    if (cadr(e2))
+	printf("\tfcomp %s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2));
+    else
+	printf("\tfcomp %s\n",((NMTBL*)caddr(e2))->nm);
     jcond(label,cond);
 }
 
@@ -2637,11 +2675,16 @@
 void code_cmp_lrgvar(int e1,int e2,int label,int cond)
 {
     char *n,*crn;
-    n = ((NMTBL*)cadr(e1))->nm;
+    n = ((NMTBL*)caddr(e1))->nm;
     use_int(e2);
     crn = register_name(e2,0);
-    printf("\tmovl %s,%s\n",n,crn);
-    printf("\torl  %s+4,%s\n",n,crn);
+    if (cadr(e1)) {
+	printf("\tmovl %s+%d,%s\n",n,cadr(e1),crn);
+	printf("\torl  %s+%d,%s\n",n,cadr(e1)+4,crn);
+    } else {
+	printf("\tmovl %s,%s\n",n,crn);
+	printf("\torl  %s+4,%s\n",n,crn);
+    }
     printf("\ttestl %s,%s\n",crn,crn);
     jcond(label,cond);
 }
@@ -2670,10 +2713,15 @@
 void code_lassign_gvar(int e1,int e2)
 {
     char *n;
-    n = ((NMTBL*)cadr(e1))->nm;
+    n = ((NMTBL*)caddr(e1))->nm;
     use_longlong(e2);
-    printf("\tmovl %s,%s\n",l_eax(e2),n);
-    printf("\tmovl %s,%s+4\n",l_edx(e2),n);
+    if (cadr(e1)) {
+	printf("\tmovl %s,%s+%d\n",l_eax(e2),n,cadr(e1));
+	printf("\tmovl %s,%s+%d\n",l_edx(e2),n,cadr(e1)+4);
+    } else {
+	printf("\tmovl %s,%s\n",l_eax(e2),n);
+	printf("\tmovl %s,%s+4\n",l_edx(e2),n);
+    }
 }
 
 void code_lassign_lvar(int e1,int e2)
@@ -2712,10 +2760,15 @@
 void code_lrgvar(int e1,int e2)
 {
     char *n;
-    n = ((NMTBL*)cadr(e1))->nm;
+    n = ((NMTBL*)caddr(e1))->nm;
     use_longlong(e2);
-    printf("\tmovl %s,%s\n",n,l_eax(e2));
-    printf("\tmovl %s+4,%s\n",n,l_edx(e2));
+    if (cadr(e1)) {
+	printf("\tmovl %s+%d,%s\n",n,cadr(e1),l_eax(e2));
+	printf("\tmovl %s+%d,%s\n",n,cadr(e1)+4,l_edx(e2));
+    } else {
+	printf("\tmovl %s,%s\n",n,l_eax(e2));
+	printf("\tmovl %s+4,%s\n",n,l_edx(e2));
+    }
 }
 
 void code_lrlvar(int e1,int e2)
@@ -3227,7 +3280,9 @@
     } else if (c=='m') {
 	repl = list3(list2(0,0),repl,clobber);
     } else if (c=='i') {
-	if (car(e1)==GVAR||car(e1)==FNAME) {
+	if (car(e1)==GVAR) {
+	    e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0);
+	} else if (car(e1)==FNAME) {
 	    e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
 	} else if (car(e1)==STRING) {
 	    val = emit_string_label();
--- a/mc-code-mips.c	Wed Jul 07 20:50:07 2004 +0900
+++ b/mc-code-mips.c	Wed Jul 07 23:43:19 2004 +0900
@@ -980,6 +980,7 @@
 #if 1
     for(j=0,i=0;i<MAX_REGISTER;i++) if (regs[i]) j++;
     if (j>USAGE_MAX) {
+	// printf("\n# regs:01234567890123456789012");
 	printf("\n# regs:");
 	for(i=0;i<MAX_REGISTER;i++) {  printf("%d",regs[i]); }
     }
@@ -1141,6 +1142,35 @@
     printf("\tla %s,%s\n",rrn,nptr->nm);
 }
 
+static void 
+code_add(int reg,int offset,int r)
+{
+    char *crn = register_name(reg);
+    char *rrn = register_name(r);
+    if (offset==0) {
+        if(r!=reg)
+            printf("\tmove %s,%s\n",crn,rrn);
+    } else
+        printf("\taddu %s,%s,%d\n",crn,rrn,offset);
+}
+
+
+static void 
+code_ld(char *ld,int reg,int offset,int r)
+{
+    char *crn = register_name(reg);
+    char *rrn = register_name(r);
+    printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn);
+}
+
+static void 
+code_ldf(char *ld,char *crn,int offset,int r)
+{
+    char *rrn = register_name(r);
+    printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn);
+}
+
+
 static char *cload(int sz,int sign) { 
     if (sign) {
         return sz==1?"lb":sz==SIZE_OF_SHORT?"lh":"lw"; 
@@ -1163,33 +1193,25 @@
 
 void
 code_gvar(int e1,int reg) {
-    int r;
     use_int(reg);
-    r = get_ptr_cache((NMTBL*)cadr(e1));
-    if(r!=reg)
-	printf("\tmove %s,%s\n",register_name(reg),register_name(r));
+    code_add(reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)));
     return;
 }
 
 void
 code_rgvar(int e1,int reg) {
     use_int(reg);
-    printf("\tlw %s,0(%s)\n",register_name(reg),
-                             register_name(get_ptr_cache((NMTBL*)cadr(e1))));
+    code_ld("lw",reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)));
 }
 
 void
 code_crgvar(int e1,int reg,int sign,int sz){
-    char *crn;
     use_int(reg);
-    crn = register_name(reg);
-    printf("\t%s %s,0(%s)\n",cload(sz,sign),crn,
-                             register_name(get_ptr_cache((NMTBL*)cadr(e1))));
+    code_ld(cload(sz,sign),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)));
     cext(sign,sz,reg);
 }
 
 
-
 void
 code_register(int e2,int reg) {
     use_int(reg);
@@ -1434,12 +1456,8 @@
 
 void
 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
-    int r;
-    char *crn;
     use_int(reg);
-    crn = register_name(reg);
-    r = get_ptr_cache((NMTBL*)cadr(e1));
-    printf("\t%s %s,0(%s)\n",cload(sz,0),crn,register_name(r));
+    code_ld(cload(sz,0),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)));
     cext(0,sz,r);
     cmpreg = reg;
     // printf("\tcmpwi cr0,%s,0\n",crn);
@@ -1462,12 +1480,8 @@
 
 void
 code_cmp_rgvar(int e1,int reg,int label,int cond) {
-    int r;
-    char *crn;
     use_int(reg);
-    crn = register_name(reg);
-    r = get_ptr_cache((NMTBL*)cadr(e1));
-    printf("\tlw %s,0(%s)\n",crn,register_name(r));
+    code_ld("lw",reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)));
     code_cmp_register(reg,label,cond);
 }
 
@@ -1923,8 +1937,8 @@
         printf("\tli.s %s,%12.12g\n",frn,value);
 	break;
     case FRGVAR:
-	r = get_ptr_cache((NMTBL*)cadr(e2));
-	printf("\tlw %s,0(%s)\n",frn,register_name(r));
+	r = get_ptr_cache((NMTBL*)caddr(e2));
+	printf("\tlw %s,%d(%s)\n",frn,cadr(e2),register_name(r));
 	break;
     case FRLVAR:
 	lvar_intro(cadr(e2));
@@ -2411,10 +2425,9 @@
 
 void
 code_assign_gvar(int e2,int creg,int byte) {
-    int r;
     use_int(creg);
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    code_assign(r,byte,creg);
+    code_ldf(cstore(byte),register_name(creg),cadr(e2),
+        get_ptr_cache((NMTBL*)caddr(e2)));
 }
 
 void
@@ -3307,10 +3320,13 @@
 }
 
 extern void
-emit_address(char *s)
+emit_address(char *s,int offset)
 {
     data_mode(0);
-    printf("\t.long %s\n",s);
+    if (offset) 
+	printf("\t.long %s+%d\n",s,offset);
+    else
+	printf("\t.long %s\n",s);
 }
 
 extern void
@@ -3477,22 +3493,21 @@
 void
 code_dassign_gvar(int e2,int freg,int d)
 { 
-    int r;
-    use_float(d,freg);
     if (d) {
          code_lassign_gvar(e2,freg);  set_double(freg); return;
     }
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    printf("\ts.s %s,0(%s)\n",fregister_name(freg),register_name(r));
+    use_float(d,freg);
+    code_ldf("s.s",fregister_name(freg),cadr(e2),
+        get_ptr_cache((NMTBL*)caddr(e2)));
 }
 
 void
 code_dassign_lvar(int e2,int freg,int d)
 { 
-    use_float(d,freg);
     if (d) {
         code_lassign_lvar(e2,freg); set_double(freg); return;
     }
+    use_float(d,freg);
     lvar_intro(e2);
     printf("\ts.s %s,",fregister_name(freg));
     lvar(e2);
@@ -3501,19 +3516,19 @@
 void
 code_dassign(int e2,int freg,int d)
 { 
-    use_float(d,freg);
     if (d) {
         code_lassign(e2,freg); set_double(freg); return;
     }
+    use_float(d,freg);
     printf("\ts.s %s,0(%s)\n",fregister_name(freg),register_name(e2));
 }
 
 void
 code_dassign_dregister(int e2,int d,int freg) {
-    use_float(d,freg);
     if (d) {
         code_lassign_lregister(e2,freg); set_double(freg); return;
     }
+    use_float(d,freg);
     if (e2!=freg) {
 	printf("\tmov.s %s,%s\n",fregister_name(e2),fregister_name(freg));
     }
@@ -3771,15 +3786,14 @@
 void
 code_drgvar(int e2,int d,int freg)
 { 
-    int r;
     if (d) {
          code_lrgvar(e2,freg);
          set_double(freg);
 	 return;
     }
-    r = get_ptr_cache((NMTBL*)cadr(e2));
     use_float(d,freg);
-    printf("\tl.s %s,0(%s)\n",fregister_name(freg),register_name(r));
+    code_ldf("l.s",fregister_name(freg),cadr(e2),
+        get_ptr_cache((NMTBL*)caddr(e2)));
 }
 
 
@@ -3799,13 +3813,10 @@
 void
 code_cmp_drgvar(int e2,int reg,int d,int label,int cond)
 { 
-    int r;
     char *frn,*fr1;
     int g;
     use_float(d,reg);
 
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-
     if (d) {
 	code_save_stacks();
 	set_dreg(RET_DREGISTER,0);
@@ -4392,8 +4403,15 @@
 code_lassign_gvar(int e2,int creg)
 {
     int r;
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    code_lassign(r,creg);
+    use_longlong(creg);
+    r = get_ptr_cache((NMTBL*)caddr(e2));
+#if ENDIAN==0
+    code_ldf(cstore(0),lregister_name_low(creg),cadr(e2),r);
+    code_ldf(cstore(0),lregister_name_high(creg),cadr(e2)+SIZE_OF_INT,r);
+#else
+    code_ldf(cstore(0),lregister_name_high(creg),cadr(e2),r);
+    code_ldf(cstore(0),lregister_name_low(creg),cadr(e2)+SIZE_OF_INT,r);
+#endif
 }
 
 void
@@ -4481,13 +4499,13 @@
     use_longlong(creg);
     crn_h = lregister_name_high(creg);
     crn_l = lregister_name_low(creg);
-    r = get_ptr_cache((NMTBL*)cadr(e1));
+    r = get_ptr_cache((NMTBL*)caddr(e1));
 #if ENDIAN==0
-    printf("\tlw %s,%d(%s)\n",crn_h,SIZE_OF_INT,register_name(r));
-    printf("\tlw %s,0(%s)\n",crn_l,register_name(r));
+    code_ldf("lw",crn_l,cadr(e1),r);
+    code_ldf("lw",crn_h,cadr(e1)+SIZE_OF_INT,r);
 #else
-    printf("\tlw %s,0(%s)\n",crn_h,register_name(r));
-    printf("\tlw %s,%d(%s)\n",crn_l,SIZE_OF_INT,register_name(r));
+    code_ldf("lw",crn_h,cadr(e1),r);
+    code_ldf("lw",crn_l,cadr(e1)+SIZE_OF_INT,r);
 #endif
 }
 
@@ -5152,6 +5170,7 @@
             code_assign_lvar(
                 (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); 
             reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #if FLOAT_CODE
@@ -5160,6 +5179,7 @@
             code_dassign_lvar(
                 (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); 
             freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #endif
@@ -5169,6 +5189,7 @@
             code_lassign_lvar(
                 (lreg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); 
             lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #endif
@@ -5331,7 +5352,9 @@
     } else if (c=='m') {
 	repl = list3(list2(0,0),repl,clobber);
     } else if (c=='i') {
-	if (car(e1)==GVAR||car(e1)==FNAME) {
+	if (car(e1)==GVAR) {
+	    e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0);
+	} else if (car(e1)==FNAME) {
 	    e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
 	} else if (car(e1)==STRING) {
 	    val = emit_string_label();
--- a/mc-code-powerpc.c	Wed Jul 07 20:50:07 2004 +0900
+++ b/mc-code-powerpc.c	Wed Jul 07 23:43:19 2004 +0900
@@ -4795,6 +4795,7 @@
             code_assign_lvar(
                 (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); 
             reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #if FLOAT_CODE
@@ -4803,6 +4804,7 @@
             code_dassign_lvar(
                 (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); 
             freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #endif
@@ -4812,6 +4814,7 @@
             code_lassign_lvar(
                 (lreg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); 
             lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET;
+	    free_register(reg);
         }
     }
 #endif
@@ -5023,7 +5026,9 @@
     } else if (c=='m') {
 	repl = list3(list2(0,0),repl,clobber);
     } else if (c=='i') {
-	if (car(e1)==GVAR||car(e1)==FNAME) {
+	if (car(e1)==GVAR) {
+	    e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0);
+	} else if (car(e1)==FNAME) {
 	    e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
 	} else if (car(e1)==STRING) {
 	    val = emit_string_label();
--- a/mc-codegen.c	Wed Jul 07 20:50:07 2004 +0900
+++ b/mc-codegen.c	Wed Jul 07 23:43:19 2004 +0900
@@ -799,7 +799,7 @@
 extern void
 parallel_rassign(int assigns)
 {
-    int free,tmp,tmp_target,remains,t0,t2,src;
+    int free,tmp,remains,t0,t2,src;
     tmp = 0;
     for(;;) {
 	remains = 0;
@@ -817,24 +817,27 @@
 	    } 
 	}
 	if (remains==0) {
-	    if (tmp) {
-		code_rlvar(tmp,tmp_target);
-	    }
 	    return;
 	}
 	if (free) {  // free target
-	    if (t0!=caddr(free))
-		code_assign_register(t0,0,caddr(free));
+	    if (t0!=caddr(free)) {
+		if (caddr(free)>=0) {
+		    code_assign_register(t0,0,caddr(free));
+		} else {
+		    code_rlvar(caddr(free),t0);
+		}
+	    }
+	    caddr(free)=0;       // mark it done
 	} else {  // no free target
 	    for(free=assigns;free;free=cadr(free)) {
 		if (caddr(free)) break; // not yet done
 	    }
 	    if (!free) error(-1);
 	    tmp = new_lvar(size_of_int);
-	    tmp_target = car(free);
+	    if (tmp>0) error(-1);
 	    code_assign_lvar(tmp,caddr(free),0);
+	    caddr(free) = tmp;
 	}
-	caddr(free)=0;       // mark it done
     }
 }