From ff031baabb850aacea256edf02b24bb53a639de5 Mon Sep 17 00:00:00 2001 From: cacao Date: Tue, 3 Nov 1998 21:12:40 +0000 Subject: [PATCH] basic block struct changed --- alpha/ngen.c | 5 +-- ncomp/ncompdef.h | 25 ++++++----- ncomp/nparse.c | 10 +++-- ncomp/nreg.c | 5 +-- ncomp/nstack.c | 105 ++++++++++++++++++++++++++--------------------- 5 files changed, 81 insertions(+), 69 deletions(-) diff --git a/alpha/ngen.c b/alpha/ngen.c index ccec6f461..3e3b430e2 100644 --- a/alpha/ngen.c +++ b/alpha/ngen.c @@ -503,10 +503,9 @@ static void gen_mcode() } src = src->prev; } - s1 = bptr[0].ipc; src = bptr->instack; - len = bptr[1].ipc - s1; - for (iptr = &instr[s1]; + len = bptr->icount; + for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) { diff --git a/ncomp/ncompdef.h b/ncomp/ncompdef.h index 40567a3d8..4ed67c19c 100644 --- a/ncomp/ncompdef.h +++ b/ncomp/ncompdef.h @@ -7,10 +7,8 @@ defines all the constants and data structures of the compiler Authors: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at - Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at - Michael Gschwind EMAIL: cacao@complang.tuwien.ac.at - Last Change: 1997/11/05 + Last Change: 1998/11/03 *******************************************************************************/ @@ -98,16 +96,17 @@ struct instruction { #define BBTYPE_SBR 2 /* subroutine basic block type */ struct basicblock { - int flags; /* used during stack analysis, init with -1 */ - int type; /* basic block type (std, xhandler, subroutine*/ - int ipc; /* intermediate code pc at start of block */ - int mpc; /* machine code pc at start of block */ - stackptr instack; /* stack at begin of basic block */ - stackptr outstack; /* stack at end of basic block */ - int indepth; /* stack depth at begin of basic block */ - int outdepth; /* stack depth end of basic block */ - int pre_count; /* count of predecessor basic blocks */ - branchref *branchrefs; /* list of branches to be patched */ + int flags; /* used during stack analysis, init with -1 */ + int type; /* basic block type (std, xhandler, subroutine*/ + instruction *iinstr; /* pointer to intermediate code instructions */ + int icount; /* number of intermediate code instructions */ + int mpc; /* machine code pc at start of block */ + stackptr instack; /* stack at begin of basic block */ + stackptr outstack; /* stack at end of basic block */ + int indepth; /* stack depth at begin of basic block */ + int outdepth; /* stack depth end of basic block */ + int pre_count; /* count of predecessor basic blocks */ + branchref *branchrefs; /* list of branches to be patched */ }; diff --git a/ncomp/nparse.c b/ncomp/nparse.c index fe9455a70..b2f6ec986 100644 --- a/ncomp/nparse.c +++ b/ncomp/nparse.c @@ -923,7 +923,7 @@ static void parse() /* additional block if target 0 is not first intermediate instruction */ if (!block_index[0] || (block_index[0] > 1)) { - bptr->ipc = 0; + bptr->iinstr = instr; bptr->mpc = -1; bptr->flags = -1; bptr->type = BBTYPE_STD; @@ -937,7 +937,9 @@ static void parse() for (p = 0; p < jcodelength; p++) if (block_index[p] & 1) { - bptr->ipc = block_index[p] >> 1; + bptr->iinstr = instr + (block_index[p] >> 1); + if (b_count != 0) + (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr; bptr->mpc = -1; bptr->flags = -1; bptr->type = BBTYPE_STD; @@ -950,7 +952,9 @@ static void parse() /* allocate additional block at end */ - bptr->ipc = instr_count; + bptr->iinstr = NULL; + (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr; + bptr->icount = 0; bptr->mpc = -1; bptr->flags = -1; bptr->type = BBTYPE_STD; diff --git a/ncomp/nreg.c b/ncomp/nreg.c index a2ac36eee..e70bab465 100644 --- a/ncomp/nreg.c +++ b/ncomp/nreg.c @@ -587,9 +587,8 @@ static void allocate_scratch_registers() if (bptr->flags >= BBREACHED) { dst = bptr->instack; reg_init_temp(); - i = bptr[0].ipc; - len = bptr[1].ipc - i; - iptr = &instr[i]; + iptr = bptr->iinstr; + len = bptr->icount; while (--len >= 0) { src = dst; dst = iptr->dst; diff --git a/ncomp/nstack.c b/ncomp/nstack.c index b10d60ba2..f38690508 100644 --- a/ncomp/nstack.c +++ b/ncomp/nstack.c @@ -191,8 +191,8 @@ static void analyse_stack() b_count = block_count; bptr = block; while (--b_count >= 0) { - if (bptr[1].ipc > bptr[0].ipc) { - iptr = instr + bptr[1].ipc - 1; + if (bptr->icount != 0) { + iptr = bptr->iinstr + bptr->icount - 1; switch (iptr->opc) { case ICMD_RET: case ICMD_RETURN: @@ -288,9 +288,8 @@ static void analyse_stack() deadcode = false; superblockend = false; bptr->flags = BBFINISHED; - i = bptr[0].ipc; - len = bptr[1].ipc - i; - iptr = &instr[i]; + len = bptr->icount; + iptr = bptr->iinstr; b_index = bptr - block; while (--len >= 0) { opcode = iptr->opc; @@ -471,7 +470,9 @@ icmd_iconst_tail: iptr[0].opc = ICMD_IFEQ; icmd_if_icmp_tail: iptr[0].op1 = iptr[1].op1; - iptr[1].opc = ICMD_NOP; + bptr->icount--; + len--; + /* iptr[1].opc = ICMD_NOP; */ OP1_0(TYPE_INT); tbptr = block + block_index[iptr->op1]; MARKREACHED(tbptr, copy); @@ -652,8 +653,10 @@ icmd_lconst_tail: iptr[0].opc = ICMD_IF_LEQ; icmd_lconst_lcmp_tail: iptr[0].op1 = iptr[2].op1; - iptr[1].opc = ICMD_NOP; - iptr[2].opc = ICMD_NOP; + bptr->icount -= 2; + len -= 2; + /* iptr[1].opc = ICMD_NOP; + iptr[2].opc = ICMD_NOP; */ OP1_0(TYPE_LNG); tbptr = block + block_index[iptr->op1]; MARKREACHED(tbptr, copy); @@ -907,16 +910,19 @@ icmd_lconst_lcmp_tail: iptr[3].opc = ICMD_NOP; tbptr[1].flags = BBDELETED; tbptr[2].flags = BBDELETED; - len += 3; + tbptr[1].icount = 0; + tbptr[2].icount = 0; if (tbptr[3].pre_count == 2) { + len += tbptr[3].icount + 3; + bptr->icount += tbptr[3].icount + 3; tbptr[3].flags = BBDELETED; - len += tbptr[4].ipc - tbptr[3].ipc; - tbptr[3].ipc = tbptr[4].ipc; - b_index ++; + tbptr[3].icount = 0; + b_index++; + } + else { + bptr->icount++; + len ++; } - tbptr[1].ipc = tbptr[3].ipc; - tbptr[2].ipc = tbptr[3].ipc; - bptr[1].ipc = tbptr[3].ipc; b_index += 2; break; } @@ -1193,7 +1199,9 @@ icmd_lconst_lcmp_tail: iptr[0].opc = ICMD_IF_LCMPEQ; icmd_lcmp_if_tail: iptr[0].op1 = iptr[1].op1; - iptr[1].opc = ICMD_NOP; + len--; + bptr->icount--; + /* iptr[1].opc = ICMD_NOP; */ OP2_0(TYPE_LNG); tbptr = block + block_index[iptr->op1]; MARKREACHED(tbptr, copy); @@ -1445,9 +1453,9 @@ builtin2: if (block_count > count_max_basic_blocks) count_max_basic_blocks = block_count; count_basic_blocks += block_count; - if (block[block_count].ipc > count_max_javainstr) - count_max_javainstr = block[block_count].ipc; - count_javainstr += block[block_count].ipc; + if ((block[block_count].iinstr - instr) > count_max_javainstr) + count_max_javainstr = block[block_count].iinstr - instr; + count_javainstr += block[block_count].iinstr - instr; if (stack_count > count_upper_bound_new_stack) count_upper_bound_new_stack = stack_count; if ((new - stack) > count_max_new_stack) @@ -1461,7 +1469,7 @@ builtin2: count_block_stack[10]++; else count_block_stack[bptr->indepth]++; - len = bptr[1].ipc - bptr[0].ipc; + len = bptr->icount; if (len <= 10) count_block_size_distribution[len - 1]++; else if (len <= 12) @@ -1638,9 +1646,10 @@ static char *builtin_name(functionptr bptr) static void show_icmd_method() { - int b, i, j; + int b, i, j, last; int deadcode; s4 *s4ptr; + instruction *iptr; printf("\n"); unicode_fprint(stdout, class->name); @@ -1716,16 +1725,18 @@ static void show_icmd_method() else print_stack(block[b].instack); printf("] L%03d(%d):\n", b, block[b].pre_count); - for (i = block[b].ipc; i < block[b + 1].ipc; i++) { + iptr = block[b].iinstr; + i = iptr - instr; + for (last = i + block[b].icount; i < last; i++, iptr++) { printf("["); if (deadcode) { for (j = maxstack; j > 0; j--) printf(" ? "); } else - print_stack(instr[i].dst); - printf("] %4d %s", i, icmd_names[instr[i].opc]); - switch ((int) instr[i].opc) { + print_stack(iptr->dst); + printf("] %4d %s", i, icmd_names[iptr->opc]); + switch ((int) iptr->opc) { case ICMD_IADDCONST: case ICMD_ISUBCONST: case ICMD_IMULCONST: @@ -1746,7 +1757,7 @@ static void show_icmd_method() case ICMD_IFGE_ICONST: case ICMD_IFGT_ICONST: case ICMD_IFLE_ICONST: - printf(" %d", instr[i].val.i); + printf(" %d", iptr->val.i); break; case ICMD_LADDCONST: case ICMD_LSUBCONST: @@ -1760,28 +1771,28 @@ static void show_icmd_method() case ICMD_LSHRCONST: case ICMD_LUSHRCONST: case ICMD_LCONST: - printf(" %ld", instr[i].val.l); + printf(" %ld", iptr->val.l); break; case ICMD_FCONST: - printf(" %f", instr[i].val.f); + printf(" %f", iptr->val.f); break; case ICMD_DCONST: - printf(" %f", instr[i].val.d); + printf(" %f", iptr->val.d); break; case ICMD_ACONST: - printf(" %p", instr[i].val.a); + printf(" %p", iptr->val.a); break; case ICMD_GETFIELD: case ICMD_PUTFIELD: - printf(" %d,", ((fieldinfo *) instr[i].val.a)->offset); + printf(" %d,", ((fieldinfo *) iptr->val.a)->offset); case ICMD_PUTSTATIC: case ICMD_GETSTATIC: printf(" "); unicode_fprint(stdout, - ((fieldinfo *) instr[i].val.a)->name); + ((fieldinfo *) iptr->val.a)->name); break; case ICMD_IINC: - printf(" %d + %d", instr[i].op1, instr[i].val.i); + printf(" %d + %d", iptr->op1, iptr->val.i); break; case ICMD_RET: case ICMD_ILOAD: @@ -1794,15 +1805,15 @@ static void show_icmd_method() case ICMD_FSTORE: case ICMD_DSTORE: case ICMD_ASTORE: - printf(" %d", instr[i].op1); + printf(" %d", iptr->op1); break; case ICMD_NEW: printf(" "); unicode_fprint(stdout, - ((classinfo *) instr[i].val.a)->name); + ((classinfo *) iptr->val.a)->name); break; case ICMD_NEWARRAY: - switch (instr[i].op1) { + switch (iptr->op1) { case 4: printf(" boolean"); break; @@ -1830,16 +1841,16 @@ static void show_icmd_method() } break; case ICMD_ANEWARRAY: - if (instr[i].op1) { + if (iptr->op1) { printf(" "); unicode_fprint(stdout, - ((classinfo *) instr[i].val.a)->name); + ((classinfo *) iptr->val.a)->name); } break; case ICMD_CHECKCAST: case ICMD_INSTANCEOF: - if (instr[i].op1) { - classinfo *c = instr[i].val.a; + if (iptr->op1) { + classinfo *c = iptr->val.a; if (c->flags & ACC_INTERFACE) printf(" (INTERFACE) "); else @@ -1850,7 +1861,7 @@ static void show_icmd_method() case ICMD_BUILTIN3: case ICMD_BUILTIN2: case ICMD_BUILTIN1: - printf(" %s", builtin_name((functionptr) instr[i].val.a)); + printf(" %s", builtin_name((functionptr) iptr->val.a)); break; case ICMD_INVOKEVIRTUAL: case ICMD_INVOKESPECIAL: @@ -1858,10 +1869,10 @@ static void show_icmd_method() case ICMD_INVOKEINTERFACE: printf(" "); unicode_fprint(stdout, - ((methodinfo *) instr[i].val.a)->class->name); + ((methodinfo *) iptr->val.a)->class->name); printf("."); unicode_fprint(stdout, - ((methodinfo *) instr[i].val.a)->name); + ((methodinfo *) iptr->val.a)->name); break; case ICMD_IFEQ: case ICMD_IFNE: @@ -1875,7 +1886,7 @@ static void show_icmd_method() case ICMD_IF_LGE: case ICMD_IF_LGT: case ICMD_IF_LLE: - printf("(%d) L%03d", instr[i].val.i, block_index[instr[i].op1]); + printf("(%d) L%03d", iptr->val.i, block_index[iptr->op1]); break; case ICMD_JSR: case ICMD_GOTO: @@ -1895,10 +1906,10 @@ static void show_icmd_method() case ICMD_IF_LCMPLE: case ICMD_IF_ACMPEQ: case ICMD_IF_ACMPNE: - printf(" L%03d", block_index[instr[i].op1]); + printf(" L%03d", block_index[iptr->op1]); break; case ICMD_TABLESWITCH: - s4ptr = instr[i].val.a; + s4ptr = iptr->val.a; printf(" L%03d;", block_index[*s4ptr++]); /* default */ j = *s4ptr++; /* low */ j = *s4ptr++ - j; /* high */ @@ -1908,7 +1919,7 @@ static void show_icmd_method() } break; case ICMD_LOOKUPSWITCH: - s4ptr = instr[i].val.a; + s4ptr = iptr->val.a; printf(" L%d", block_index[*s4ptr++]); /* default */ j = *s4ptr++; /* count */ while (--j >= 0) { -- 2.25.1