Mercurial > hg > CbC > old > device
changeset 118:07b91b625f84 assignment-opt
assignment optimization
author | kono |
---|---|
date | Fri, 21 Mar 2003 18:35:13 +0900 |
parents | 2d5a203cc3a6 |
children | b815fcd57b9d |
files | Makefile mc-code-ia32.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c |
diffstat | 6 files changed, 167 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri Mar 21 15:18:51 2003 +0900 +++ b/Makefile Fri Mar 21 18:35:13 2003 +0900 @@ -29,6 +29,32 @@ conv/null.c: conv_func.tbl conv_func.pl perl conv_func.pl +check-all: + make check TARGET=test/basic + make check TARGET=test/call + make check TARGET=test/fact0 + make check TARGET=test/float + make check TARGET=test/ifdef + make check TARGET=test/int + make check TARGET=test/macro + make check TARGET=test/regargs + make check TARGET=test/simp + make check TARGET=test/simp0 + make check TARGET=test/tmp + make check TARGET=test/tmp10 + make check TARGET=test/tmp11 + make check TARGET=test/tmp7 + make check TARGET=test/tmp8 + make check TARGET=test/tmp9 + +check: + -gcc $(TARGET).c -o b.out + -b.out > $(TARGET).gcc.out + -$(MC) -s $(TARGET).c + -gcc $(TARGET).s + -a.out > $(TARGET).$(MC).out + -diff $(TARGET).gcc.out $(TARGET).$(MC).out + tar : make clean tar cBf - . | gzip > ../comp.tgz @@ -41,7 +67,7 @@ mc-code-powerpc.c clean : - -rm -f mc mc-ia32 mc-powerpc *.bak *.s *.o *.cc mc mc1 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ + -rm -f mc mc-ia32 mc-powerpc *.bak *.s *.o *.cc mc mc1 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out mc1 : b00.s b01.s mc-codegen.o mc-tree.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o $(CONVERTER)
--- a/mc-code-ia32.c Fri Mar 21 15:18:51 2003 +0900 +++ b/mc-code-ia32.c Fri Mar 21 18:35:13 2003 +0900 @@ -1068,7 +1068,7 @@ } void -code_assign(int e2,int byte) { +code_assign(int e2,int byte,int creg) { if (byte) use_data_reg(creg,1); printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0)); }
--- a/mc-code-powerpc.c Fri Mar 21 15:18:51 2003 +0900 +++ b/mc-code-powerpc.c Fri Mar 21 18:35:13 2003 +0900 @@ -695,7 +695,8 @@ if (car(e2)==REGISTER) { printf("\taddi %s,%s,%d\n", register_name(cadr(e2)),register_name(cadr(e2)), caddr(e1)); - printf("\tmr %s,%s\n",register_name(cadr(reg)),register_name(e2)); + if (cadr(reg)!=e2) + printf("\tmr %s,%s\n",register_name(cadr(reg)),register_name(e2)); regv[reg]=1; return; } @@ -1191,7 +1192,7 @@ int function(int e1) { - int e2,e3,e4,e5,nargs,t,r0,r1; + int e2,e3,e4,e5,nargs,t,r0,r1,greg; int arg,reg_arg,freg_arg,arg_assign; int reg_arg_list=0,ret_type,special_lvar; NMTBL *fn; @@ -1246,9 +1247,22 @@ e5 = list2(LVAR,special_lvar); } else { special_lvar = new_lvar(size_of_double); - g_expr_u(assign_expr0((e5=list2(LVAR,special_lvar)),e4,t,t)); - e4 = e5; - reg_arg_list = list2(e5,reg_arg_list); + if (simple_args(list2(e4,0))) { + greg = freg; + arg = get_input_fregister_var(freg_arg,0); + use_var(arg); freg = cadr(arg); + g_expr(assign_expr0( + (e5=list2(LVAR,special_lvar)),e4,t,t)); + e4 = list2(DREGISTER,freg); + reg_arg_list = list2(e5,reg_arg_list); + freg = greg; + } else { + g_expr(assign_expr0( + (e5=list2(LVAR,special_lvar)),e4,t,t)); + reg_arg_list = list2(e5,reg_arg_list); + e4 = list2(DREGISTER,freg); + } + /* freg should not change until XXX */ } r0=get_input_register_var(reg_arg,0); r1=get_input_register_var(reg_arg+1,0); @@ -1272,7 +1286,7 @@ } use_var(arg); /* protect from input register free */ reg_arg_list = list2(arg,reg_arg_list); - g_expr_u(assign_expr0(arg,e4,t,t)); + g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ freg_arg++; nargs += size_of_double/size_of_int; continue; @@ -1394,7 +1408,7 @@ } void -code_assign(int e2,int byte) { +code_assign(int e2,int byte,int creg) { char *drn=register_name(e2); char *crn=register_name(creg);
--- a/mc-code.h Fri Mar 21 15:18:51 2003 +0900 +++ b/mc-code.h Fri Mar 21 18:35:13 2003 +0900 @@ -73,7 +73,7 @@ extern void code_assign_gvar(int e2,int reg,int byte); extern void code_assign_lvar(int e2,int reg,int byte); extern void code_assign_register(int e2,int byte,int reg); -extern void code_assign(int e2,int byte); +extern void code_assign(int e2,int byte,int reg); extern void code_register_assop(int e2,int op,int byte); extern void code_assop(int op,int byte); extern void tosop(int op,int oreg);
--- a/mc-codegen.c Fri Mar 21 15:18:51 2003 +0900 +++ b/mc-codegen.c Fri Mar 21 18:35:13 2003 +0900 @@ -921,15 +921,62 @@ } void +assign_opt(int e5,int e2,int e4,int byte) +{ + int reg; + /* e2=e4 */ + if (e5==REGISTER) { + reg = cadr(e4); + switch(car(e2)) { + case GVAR: code_assign_gvar(e2,reg,byte); return; + case LVAR: code_assign_lvar(lvar(cadr(e2)),reg,byte); return; + case REGISTER: code_assign_register(cadr(e2),byte,reg); return; + } + g_expr(e2); + code_assign(e2,byte,reg); + return; + } + /* e2 is register now */ + if (car(e2)!=REGISTER) error(-1); + reg = cadr(e2); + switch(e5) { + case CRGVAR: code_crgvar(e4,reg); return; + case RGVAR: code_rgvar(e4,reg); return; + case CRLVAR: code_crlvar(lvar(cadr(e4)),reg); return; + case RLVAR: code_rlvar(lvar(cadr(e4)),reg); return; + case GVAR: code_gvar(e4,reg); return; + case LVAR: code_lvar(lvar(cadr(e4)),reg); return; + case CONST: code_const(cadr(e4),reg); return; + case ADDRESS: + if (car(cadr(e4))==STRING) code_string(cadr(e4),reg); + else code_gvar(cadr(e4),reg); + return; + case FNAME: code_fname((NMTBL*)cadr(e4),reg); return; + case STRING: code_string(e4,reg); return; + case DEFAULT: error(-1); + } +} + +void assign(int e1) { - int e2,e3,e4,byte; + int e2,e4,byte,e5; byte=(car(e1) == CASS); /* e2=e4 */ e2 = cadr(e1); - e3 = cadr(e2); - e4 = caddr(e1); + e4 = caddr(e1);e5=car(e4); + if (!use && ( + (e5==REGISTER) || + (car(e2)==REGISTER&&( + e5== CRGVAR || e5== CRLVAR || e5== RGVAR || e5== RLVAR || + e5== GVAR || e5== LVAR || + e5== CONST || e5== FNAME || e5== STRING || + (e5==ADDRESS&&car(cadr(e4))==STRING) || + (e5==ADDRESS&&car(cadr(e4))==GVAR) )))) { + assign_opt(e5,e2,e4,byte); + return; + } switch(car(e2)) { case GVAR: /* i=3 */ g_expr(e4); @@ -949,22 +996,64 @@ emit_push(); g_expr(e4); e2 = emit_pop(0); - code_assign(e2,byte); + code_assign(e2,byte,creg); emit_pop_free(e2); regv[creg]=1; return; } void +dassign_opt(int e5,int e2,int e4,int d) +{ + int reg; + /* e2=e4 */ + if (e5==DREGISTER) { + reg = cadr(e4); + switch(car(e2)) { + case GVAR: /* i=3 */ + code_dassign_gvar(e2,reg,d); + return; + case LVAR: + code_dassign_lvar(lvar(cadr(e2)),reg,d); + return; + case DREGISTER: + if (reg!=cadr(e2)) + code_dassign_fregister(cadr(e2),d,reg); + return; + } + g_expr(e2); + code_dassign(e2,reg,d); + return; + } + /* e2 is register now */ + if (car(e2)!=DREGISTER) error(-1); + reg = cadr(e2); + switch(e5) { + case DRGVAR: code_drgvar(e4,d,reg); return; + case DRLVAR: code_drlvar(lvar(cadr(e4)),d,reg); return; + case DCONST: code_dconst(e4,reg); return; + case DEFAULT: + error(-1); + } +} + +void dassign(int e1) { - int e2,e3,e4,d; + int e2,e3,e4,d,e5; /* e2=e4 */ e2 = cadr(e1); e3 = cadr(e2); - e4 = caddr(e1); + e4 = caddr(e1); e5=car(e4); d = (car(e1)==LASS)?2:(car(e1)==DASS)?1:0; + if (!use && ( + (e5==DREGISTER) || + (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST)) + )) { + dassign_opt(e5,e2,e4,d); + return; + } switch(car(e2)) { case GVAR: g_expr(e4);
--- a/mc-parse.c Fri Mar 21 15:18:51 2003 +0900 +++ b/mc-parse.c Fri Mar 21 18:35:13 2003 +0900 @@ -1742,6 +1742,7 @@ unsigned_value(int e2,int type) { if(scalar(type)) return e2; + if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(unsigned)dcadr(e2)); if(type==FLOAT||type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2U); error(TYERR); return e2; } @@ -2127,8 +2128,10 @@ conv->prefix_(sym); getsym(); e=rvalue(expr13()); - if(type==FLOAT||type==DOUBLE) + if(type==FLOAT||type==DOUBLE) { return list2(DMINUS,e); + return(car(e)==DCONST?dlist2(DCONST,-dcadr(e)):list2(DMINUS,e)); + } if(!integral(type)) error(TYERR); return(car(e)==CONST?list2(CONST,-cadr(e)):list2(MINUS,e)); @@ -2548,7 +2551,25 @@ } return dlist2(DCONST,d); } + if(car(e1)==DCONST) { + if ((op==SUB||op==ADD)&&dcadr(e1)==0.0) { + return e2; + } else if (op==MUL&&dcadr(e1)==1.0) { + return e2; + } else if (op==MUL&&-dcadr(e1)==1.0) { + return list2(DMINUS,e2); + } + } if(car(e2)==DCONST) { + if ((op==SUB||op==ADD)&&dcadr(e2)==0.0) { + return e1; + } + if ((op==DIV||op==MUL)&&dcadr(e2)==1.0) { + return e1; + } + if ((op==DIV||op==MUL)&&-dcadr(e2)==1.0) { + return list2(DMINUS,e1); + } if (op==SUB) { op=ADD; dcadr(e2) = -dcadr(e2); } else if(op==DIV) {