Mercurial > hg > CbC > old > device
changeset 117:2d5a203cc3a6
lvar reuse
author | kono |
---|---|
date | Fri, 21 Mar 2003 15:18:51 +0900 |
parents | b14ff9671c90 |
children | 07b91b625f84 |
files | Changes mc-code-ia32.c mc-code-powerpc.c mc-codegen.c mc-parse.c mc.h |
diffstat | 6 files changed, 124 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Fri Mar 21 04:41:02 2003 +0900 +++ b/Changes Fri Mar 21 15:18:51 2003 +0900 @@ -2383,4 +2383,14 @@ 値がいるのではないか? - +Fri Mar 21 12:22:11 JST 2003 + + <------r1_offset------------------------------> + <------------lvar_offset-------> + r+ +------------+---+---------------+----------+--------------+----+ - + caller arg xx register save local callee arg xx + reg_save disp max_func_args*size_of_int + +ということだったみたいね。ようやっと self compile が通りました。 + +free_glist を作るか....
--- a/mc-code-ia32.c Fri Mar 21 04:41:02 2003 +0900 +++ b/mc-code-ia32.c Fri Mar 21 15:18:51 2003 +0900 @@ -452,6 +452,7 @@ return dreg; } else if (xreg<= -REG_LVAR_OFFSET) { code_rlvar(lvar(xreg+REG_LVAR_OFFSET),dreg); + free_lvar(xreg+REG_LVAR_OFFSET); regv[dreg]=1; return dreg; } @@ -1125,6 +1126,7 @@ regv[dreg]=1; } else if (oreg<= -REG_LVAR_OFFSET) { code_rlvar(lvar(oreg+REG_LVAR_OFFSET),dreg); + free_lvar(oreg+REG_LVAR_OFFSET); oreg = dreg; regv[dreg]=1; } @@ -1520,7 +1522,7 @@ int init; init=0; for(n=ntable;n < &ntable[GSYMS];n++) { - if (n->sc == GVAR && n->dsp != -1) { + if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) { /* n->dsp = -1 means initialized global */ if (init==0) { data_mode(0); @@ -1838,6 +1840,7 @@ if ((xreg=pop_fregister())==-1) { } else if (xreg<= -REG_LVAR_OFFSET) { code_drlvar(lvar(REG_LVAR_OFFSET+xreg),1,freg); + free_lvar(xreg+REG_LVAR_OFFSET); /* pushed order is reversed. We don't need this for comutable operator, but it is ok to do this. */ printf("\tfxch\t%%st(1)\n");
--- a/mc-code-powerpc.c Fri Mar 21 04:41:02 2003 +0900 +++ b/mc-code-powerpc.c Fri Mar 21 15:18:51 2003 +0900 @@ -219,6 +219,7 @@ code_save_input_registers(); } + int get_register(void) { /* 使われていないレジスタを調べる */ @@ -489,6 +490,7 @@ if (xreg<= -REG_LVAR_OFFSET) { reg = get_register(); code_rlvar(lvar(REG_LVAR_OFFSET+xreg),reg); + free_lvar(REG_LVAR_OFFSET+xreg); xreg = reg; regv[xreg]=1; } @@ -1246,6 +1248,7 @@ 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); } r0=get_input_register_var(reg_arg,0); r1=get_input_register_var(reg_arg+1,0); @@ -1297,6 +1300,7 @@ arg = car(reg_arg_list); if (car(arg)==DREGISTER) free_fregister(cadr(arg)); else if (car(arg)==REGISTER) free_register(cadr(arg)); + else if (car(arg)==LVAR) free_lvar(cadr(arg)); } if (ret_type==DOUBLE||ret_type==FLOAT) { set_freg(RET_FREGISTER,0); @@ -2124,6 +2128,7 @@ char *frn = fregister_name(freg); char *crn = register_name(creg); int d = new_lvar(size_of_double); + free_lvar(d); d = lvar(d); printf("\tfctiwz %s,%s\n",frn,frn); printf("\tstfd %s,lo16(%d+L_%d)(r30)\n",frn,d,lvar_offset_label); @@ -2430,6 +2435,7 @@ if (xreg<= -REG_LVAR_OFFSET) { reg = get_fregister(); code_drlvar(lvar(REG_LVAR_OFFSET+xreg),1,reg); + free_lvar(REG_LVAR_OFFSET+xreg); fregv[reg]=1; xreg=reg; } return xreg;
--- a/mc-codegen.c Fri Mar 21 04:41:02 2003 +0900 +++ b/mc-codegen.c Fri Mar 21 15:18:51 2003 +0900 @@ -590,6 +590,7 @@ } else { g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); *target = append4(*target,t,ty,e1); + *use=list3(t,*use,e1); } } @@ -788,6 +789,7 @@ } if (!is_simple(car(s0))) { g_expr_u(assign_expr0((e4=list2(LVAR,new_lvar(sz))),s0,ty,ty)); + use=list3(ty,use,e1); cadddr(e2)=e4; s0=e4; } else if (is_same_type(t0,s0)) { @@ -825,13 +827,14 @@ } /* 並列代入を実行 */ - parallel_assign(&target,&source,&processing,&use); while (use) { if (car(caddr(use))==REGISTER) free_register(cadr(caddr(use))); else if (car(caddr(use))==DREGISTER) free_fregister(cadr(caddr(use))); + else if (car(caddr(use))==LVAR) + free_lvar(cadr(caddr(use))); use=cadr(use); } if(target) error(-1);
--- a/mc-parse.c Fri Mar 21 04:41:02 2003 +0900 +++ b/mc-parse.c Fri Mar 21 15:18:51 2003 +0900 @@ -143,6 +143,7 @@ (nptr++)->sc = 0; } emit_init(); + init_free_lvar_list(); mode=TOP; lfree= HEAPSIZE; chptrsave = chsave = 0; @@ -716,11 +717,66 @@ } int -new_lvar(int sz) +new_lvar0(int sz) { return disp -= sz; } +static int lvar_list,lvar_free_list; + +int +new_lvar(int size) +{ + int lvar,plvar; + + for (plvar = 0,lvar = lvar_free_list;lvar;lvar = cadr(lvar)) { + if (caddr(lvar)==size) { + if (plvar) cadr(plvar) = cadr(lvar); + else lvar_free_list = cadr(lvar); + break; + } + plvar = lvar; + } + if (!lvar) { + lvar_list = glist3((lvar=new_lvar0(size)),lvar_list,size); + } else { + cadr(lvar) = lvar_list; lvar_list = lvar; + lvar = car(lvar_list); + } + return lvar; +} + +void +free_lvar(int disp) +{ + int lvar,plvar; + + for (plvar = 0,lvar = lvar_list;lvar;lvar = cadr(lvar)) { + if (car(lvar)==disp) { + if (plvar) cadr(plvar) = cadr(lvar); + else lvar_list = cadr(lvar); + break; + } + plvar = lvar; + } + if (!lvar) error(-1); + cadr(lvar) = lvar_free_list; lvar_free_list = lvar; +} + +void +init_free_lvar_list() +{ + int lvar; + while((lvar=lvar_list)) { + lvar_list=cadr(lvar_list); + free_glist3(lvar); + } + while((lvar=lvar_free_list)) { + lvar_free_list=cadr(lvar_free_list); + free_glist3(lvar); + } +} + static NMTBL * def(NMTBL *n) { @@ -3764,10 +3820,19 @@ return e; } +static int free_glist2_list = 0; +static int free_glist3_list = 0; + int glist2(int e1,int e2) { int smode,ret; + if (free_glist2_list) { + ret = free_glist2_list; + free_glist2_list = cadr(free_glist2_list); + car(ret)=e1; cadr(ret)=e2; + return ret; + } smode = mode; mode = GDECL; ret = list2(e1,e2); @@ -3775,10 +3840,27 @@ return ret; } +void +free_glist2(int e1) +{ + if (e1==gfree) { + gfree-=2; + } else { + cadr(e1) = free_glist2_list; + free_glist2_list = e1; + } +} + int glist3(int e1,int e2,int e3) { int smode,ret; + if (free_glist3_list) { + ret = free_glist3_list; + free_glist3_list = cadr(free_glist3_list); + car(ret)=e1; cadr(ret)=e2; caddr(ret)=e3; + return ret; + } smode = mode; mode = GDECL; ret = list3(e1,e2,e3); @@ -3786,6 +3868,17 @@ return ret; } +void +free_glist3(int e1) +{ + if (e1==gfree) { + gfree-=3; + } else { + cadr(e1) = free_glist3_list; + free_glist3_list = e1; + } +} + int rplacad(int e, int n) {
--- a/mc.h Fri Mar 21 04:41:02 2003 +0900 +++ b/mc.h Fri Mar 21 15:18:51 2003 +0900 @@ -317,6 +317,9 @@ EXTERN int fwdlabel(void); EXTERN int glist2(int e1,int e2); EXTERN int glist3(int e1,int e2,int e3); +EXTERN void free_glist2(int e1); +EXTERN void free_glist3(int e1); +EXTERN int integral(int t); EXTERN int integral(int t); EXTERN int list2(int e1, int e2); EXTERN int list3(int e1, int e2, int e3); @@ -333,5 +336,7 @@ EXTERN void fwddef(int l); EXTERN int new_lvar(int size); +EXTERN void free_lvar(int lvar); +EXTERN void init_free_lvar_list(); /* end */