pike.git / src / peep.c

version» Context lines:

pike.git/src/peep.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: peep.c,v 1.106 2005/05/19 22:35:30 mast Exp $ + || $Id: peep.c,v 1.107 2006/02/27 12:12:47 mast Exp $   */      #include "global.h"   #include "stralloc.h"   #include "dynamic_buffer.h"   #include "program.h"   #include "las.h"   #include "docode.h"   #include "pike_embed.h"   #include "pike_error.h"
pike.git/src/peep.c:141:   #ifndef FLUSH_CODE_GENERATOR_STATE   #define FLUSH_CODE_GENERATOR_STATE()   #endif      /**** Bytecode Generator *****/      INT32 assemble(int store_linenumbers)   {    INT32 entry_point;    INT32 max_label=-1,tmp; -  INT32 *labels, *jumps, *uses; +  INT32 *labels, *jumps, *uses, *aliases;    ptrdiff_t e, length;    p_instr *c;   #ifdef PIKE_PORTABLE_BYTECODE    struct pike_string *tripples = NULL;   #endif /* PIKE_PORTABLE_BYTECODE */   #ifdef PIKE_DEBUG    INT32 max_pointer=-1;    int synch_depth = 0;    size_t fun_start = Pike_compiler->new_program->num_program;   #endif
pike.git/src/peep.c:279: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr, "\n");    }    if (c->opcode == F_SYNCH_MARK) synch_depth++;    }       Pike_fatal("Reference to undefined label %d > %d\n",    max_pointer, max_label);    }   #endif /* PIKE_DEBUG */    -  labels=(INT32 *)xalloc(sizeof(INT32) * 3 * (max_label+2)); + #ifndef INS_ENTRY +  /* Replace F_ENTRY with F_NOP if we have no entry prologue. */ +  for (c = (p_instr *) instrbuf.s.str, e = 0; e < length; e++, c++) +  if (c->opcode == F_ENTRY) c->opcode = F_NOP; + #endif +  +  labels=(INT32 *)xalloc(sizeof(INT32) * 4 * (max_label+2));    jumps = labels + max_label + 2;    uses = jumps + max_label + 2; -  +  aliases = uses + max_label + 2;       while(relabel)    {    /* First do the relabel pass. */    for(e=0;e<=max_label;e++)    { -  labels[e]=jumps[e]=-1; +  labels[e]=jumps[e]= aliases[e] = -1;    uses[e]=0;    }       c=(p_instr *)instrbuf.s.str;    length=instrbuf.s.len / sizeof(p_instr);    for(e=0;e<length;e++)    if(c[e].opcode == F_LABEL && c[e].arg>=0) { -  labels[c[e].arg]=DO_NOT_WARN((INT32)e); +  INT32 l = c[e].arg; +  labels[l]=DO_NOT_WARN((INT32)e); +  while (e+1 < length && +  c[e+1].opcode == F_LABEL && c[e+1].arg >= 0) { +  /* aliases is used to compact several labels at the same +  * position to one label. That's necessary for some peep +  * optimizations to work well. */ +  e++; +  labels[c[e].arg] = DO_NOT_WARN((INT32)e); +  aliases[c[e].arg] = l;    } -  +  }       for(e=0;e<length;e++)    {    if(instrs[c[e].opcode-F_OFFSET].flags & I_POINTER)    { -  +  if (aliases[c[e].arg] >= 0) c[e].arg = aliases[c[e].arg]; +     while(1)    {    int tmp;    tmp=labels[c[e].arg];       while(tmp<length &&    (c[tmp].opcode == F_LABEL ||    c[tmp].opcode == F_NOP)) tmp++;       if(tmp>=length) break;
pike.git/src/peep.c:369:       for(e=0;e<=max_label;e++)    {    if(!uses[e] && labels[e]>=0)    {    c[labels[e]].opcode=F_NOP;    reoptimize = 1;    }    }    -  if(!reoptimize) break; +  if(!reoptimize) { + #ifdef PIKE_DEBUG +  if (a_flag > 3) fprintf (stderr, "Optimizer done after relabel.\n"); + #endif +  break; +  }       /* Then do the optimize pass. */       relabel = asm_opt();       reoptimize = 0;    -  if (!relabel) break; +  if (!relabel) { + #ifdef PIKE_DEBUG +  if (a_flag > 3) fprintf (stderr, "Optimizer done after asm_opt.\n"); + #endif +  break; +  }      #if 1   #ifdef PIKE_DEBUG    if (a_flag > 3)    fprintf(stderr, "Rerunning optimizer.\n");   #endif   #else /* !1 */    relabel = 0;   #endif /* 1 */    }
pike.git/src/peep.c:464:    ins_byte((unsigned char)(c->arg));    break;       case F_DATA:    ins_data(c->arg);    break;       case F_ENTRY:   #ifdef INS_ENTRY    INS_ENTRY(); - #endif /* INS_ENTRY */ + #else +  Pike_fatal ("F_ENTRY is supposed to be gone here.\n"); + #endif    break;       case F_LABEL: -  if(c->arg == -1) break; +  if(c->arg == -1) {   #ifdef PIKE_DEBUG -  +  if (!(debug_options & NO_PEEP_OPTIMIZING)) +  Pike_fatal ("Failed to optimize away an unused label.\n"); + #endif +  break; +  } + #ifdef PIKE_DEBUG    if(c->arg > max_label || c->arg < 0)    Pike_fatal("max_label calculation failed!\n");       if(labels[c->arg] != -1)    Pike_fatal("Duplicate label!\n");   #endif    FLUSH_CODE_GENERATOR_STATE();    labels[c->arg] = DO_NOT_WARN((INT32)PIKE_PC);    if ((e+1 < length) &&    (c[1].opcode != F_LABEL) &&