pike.git / src / peep.c

version» Context lines:

pike.git/src/peep.c:52:      static int asm_opt(void);      /* Output buffer. The optimization eye is at the end of the buffer. */   dynamic_buffer instrbuf;   long num_instrs = 0;         void init_bytecode(void)   { -  initialize_buf(&instrbuf); +  buffer_init(&instrbuf); +  buffer_ensure_space(&instrbuf, 512);    num_instrs = 0;   }      void exit_bytecode(void)   {    ptrdiff_t e, length;    p_instr *c;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       for(e=0;e<length;e++) {    free_string(dmalloc_touch_named(struct pike_string *, c[e].file,    "exit_bytecode"));   #ifdef PIKE_DEBUG    c[e].file = (void *)(ptrdiff_t)~0;   #endif    }       toss_buffer(&instrbuf);
pike.git/src/peep.c:84:      /* insert_opcode{,0,1,2}() append an opcode to the instrbuf. */      ptrdiff_t insert_opcode(p_instr *opcode)   {    /* Note: Steals references from opcode. */    p_instr *p = (p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf);    if (!p) Pike_fatal("Out of memory in peep.\n");    *p = *opcode;    num_instrs++; -  return p - (p_instr *)instrbuf.s.str; +  return p - (p_instr *)buffer_ptr(&instrbuf);   }      ptrdiff_t insert_opcode2(unsigned int f,    INT32 b,    INT32 c,    INT_TYPE current_line,    struct pike_string *current_file)   {    p_instr *p;      #ifdef PIKE_DEBUG    if(!hasarg2(f) && c)    Pike_fatal("hasarg2(%d) is wrong!\n",f);   #endif       p=(p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf);         #ifdef PIKE_DEBUG -  if(!instrbuf.s.len) +  if(!buffer_content_length(&instrbuf))    Pike_fatal("Low make buf space failed!!!!!!\n");   #endif       p->opcode=f;    p->line=current_line;    copy_shared_string(p->file, dmalloc_touch_named(struct pike_string *,    current_file,    "insert_opcode"));    p->arg=b;    p->arg2=c;    -  return p - (p_instr *)instrbuf.s.str; +  return p - (p_instr *)buffer_ptr(&instrbuf);   }      ptrdiff_t insert_opcode1(unsigned int f,    INT32 b,    INT_TYPE current_line,    struct pike_string *current_file)   {   #ifdef PIKE_DEBUG    if(!hasarg(f) && b)    Pike_fatal("hasarg(%d) is wrong!\n",f);
pike.git/src/peep.c:147:    Pike_fatal("hasarg(%d) is wrong!\n",f);   #endif    return insert_opcode1(f,0,current_line, current_file);   }         void update_arg(int instr,INT32 arg)   {    p_instr *p;   #ifdef PIKE_DEBUG -  if(instr > (long)instrbuf.s.len / (long)sizeof(p_instr) || instr < 0) +  if(instr > (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr) || instr < 0)    Pike_fatal("update_arg outside known space.\n");   #endif -  p=(p_instr *)instrbuf.s.str; +  p=(p_instr *)buffer_ptr(&instrbuf);    p[instr].arg=arg;   }      #ifndef FLUSH_CODE_GENERATOR_STATE   #define FLUSH_CODE_GENERATOR_STATE()   #endif      /**** Bytecode Generator *****/      INT32 assemble(int store_linenumbers)
pike.git/src/peep.c:179: Inside #if defined(PIKE_DEBUG)
   INT32 max_pointer=-1;    int synch_depth = 0;    size_t fun_start = Pike_compiler->new_program->num_program;   #endif    int relabel;    int reoptimize = relabel = !(debug_options & NO_PEEP_OPTIMIZING);    struct lex *lex;    CHECK_COMPILER();    lex = &THIS_COMPILATION->lex;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);      #ifdef PIKE_DEBUG    if((a_flag > 1 && store_linenumbers) || a_flag > 2)    {    for (e = 0; e < length; e++) {    if (c[e].opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr, "~~~%4ld %4lx %*s", (long)c[e].line,    (unsigned long)e, synch_depth, "");    dump_instr(c+e);    fprintf(stderr,"\n");
pike.git/src/peep.c:289:    }   #endif /* PIKE_DEBUG */    }      #ifdef PIKE_DEBUG    if (max_pointer > max_label) {    fprintf(stderr,    "Reference to undefined label %d > %d\n"    "Bad instructions are marked with '***':\n",    max_pointer, max_label); -  c=(p_instr *)instrbuf.s.str; +  c=(p_instr *)buffer_ptr(&instrbuf);    for(e=0;e<length;e++,c++) {    if (c->opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr, " * %4ld %4lx ",    (long)c->line, (unsigned long)e);    dump_instr(c);    if ((instrs[c->opcode - F_OFFSET].flags & I_POINTER) &&    (c->arg > max_label)) {    fprintf(stderr, " ***\n");    } else {    fprintf(stderr, "\n");
pike.git/src/peep.c:311: Inside #if defined(PIKE_DEBUG)
   if (c->opcode == F_SYNCH_MARK) synch_depth++;    }       Pike_fatal("Reference to undefined label %d > %d\n",    max_pointer, max_label);    }   #endif /* PIKE_DEBUG */      #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++) +  for (c = (p_instr *) buffer_ptr(&instrbuf), e = 0; e < length; e++, c++)    if (c->opcode == F_ENTRY) c->opcode = F_NOP;   #endif       labels=xalloc(sizeof(INT32) * 4 * (max_label+2));    jumps = labels + max_label + 2;    aliases = jumps + max_label + 2;    uses = aliases + max_label + 2;    while(relabel)    {    /* First do the relabel pass. */    /* Set labels, jumps and aliases to all -1. */    memset(labels, 0xff, ((max_label + 2) * 3) * sizeof(INT32));    memset(uses, 0x00, (max_label + 2) * sizeof(INT32));    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);    for(e=0;e<length;e++)    if(c[e].opcode == F_LABEL && c[e].arg>=0) {    INT32 l = c[e].arg;    labels[l]=(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++;
pike.git/src/peep.c:454: Inside #if 1 and #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if (a_flag > 3)    fprintf(stderr, "Rerunning optimizer.\n");   #endif   #else /* !1 */    relabel = 0;   #endif /* 1 */    }       /* Time to create the actual bytecode. */ -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       for(e=0;e<=max_label;e++) labels[e]=jumps[e]=-1;         #ifdef START_NEW_FUNCTION    START_NEW_FUNCTION(store_linenumbers);   #endif      #ifdef ALIGN_PIKE_FUNCTION_BEGINNINGS    while( ( (((INT32) PIKE_PC)+4) & (ALIGN_PIKE_JUMPS-1)))
pike.git/src/peep.c:489:    synch_depth = 0;   #endif    FLUSH_CODE_GENERATOR_STATE();    for(e=0;e<length;e++)    {   #ifdef PIKE_DEBUG   # ifdef DISASSEMBLE_CODE    size_t opcode_start = PIKE_PC;   # endif    -  if (c != (((p_instr *)instrbuf.s.str)+e)) { +  if (c != (((p_instr *)buffer_ptr(&instrbuf))+e)) {    Pike_fatal("Instruction loop deviates. "    "0x%04"PRINTPTRDIFFT"x != 0x%04"PRINTPTRDIFFT"x\n", -  e, c - ((p_instr *)instrbuf.s.str)); +  e, c - ((p_instr *)buffer_ptr(&instrbuf)));    }    if(((a_flag > 2) && store_linenumbers) ||    (a_flag > 3) ||    (lex->pragmas & ID_DISASSEMBLE))    {    if (c->opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr, "===%4ld %4lx %*s", (long)c->line,    (unsigned long)PIKE_PC, synch_depth, "");    dump_instr(c);    fprintf(stderr,"\n");
pike.git/src/peep.c:869: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    if(hasarg(f))    Pike_fatal("hasarg(%d /* %s */) is wrong!\n",f,get_f_name(f));   #endif    return insopt2(f,0,0,cl, cf);   }      #ifdef PIKE_DEBUG   static void debug(void)   { -  if (num_instrs != (long)instrbuf.s.len / (long)sizeof(p_instr)) { +  if (num_instrs != (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr)) {    Pike_fatal("PEEP: instrbuf lost count (%d != %d)\n", -  num_instrs, (long)instrbuf.s.len / (long)sizeof(p_instr)); +  num_instrs, (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr));    } -  if(instrbuf.s.len) +  if(buffer_content_length(&instrbuf))    {    p_instr *p; -  p=(p_instr *)low_make_buf_space(0, &instrbuf); +  p=(p_instr *)buffer_dst(&instrbuf);    if(!p[-1].file)    Pike_fatal("No file name on last instruction!\n");    }   }   #else   #define debug()   #endif         /* Offset from the end of instrbuf backwards. */   static inline p_instr *instr(int offset)   {    if (offset >= num_instrs) return NULL; -  return ((p_instr *)low_make_buf_space(0, &instrbuf)) - (offset + 1); +  return ((p_instr *)buffer_dst(&instrbuf)) - (offset + 1);   }      static inline int opcode(int offset)   {    p_instr *a;    a=instr(offset);    if(a) return a->opcode;    return -1;   }   
pike.git/src/peep.c:944:   static void pop_n_opcodes(int n)   {    int e;    p_instr *p;      #ifdef PIKE_DEBUG    if (n > num_instrs)    Pike_fatal("Popping out of instructions.\n");   #endif    -  p = ((p_instr *)low_make_buf_space(0, &instrbuf)) - n; +  p = ((p_instr *)buffer_dst(&instrbuf)) - n;    for (e = 0; e < n; e++) {    free_string(dmalloc_touch_named(struct pike_string *, p[e].file,    "pop_n_opcodes"));    }    num_instrs -= n;    low_make_buf_space(-((INT32)sizeof(p_instr))*n, &instrbuf);   }         /* NOTE: Called with opcodes in reverse order! */
pike.git/src/peep.c:1073:   {    int relabel = 0;      #ifdef PIKE_DEBUG    if(a_flag > 3)    {    p_instr *c;    ptrdiff_t e, length;    int synch_depth = 0;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       fprintf(stderr,"Before peep optimization:\n");    for(e=0;e<length;e++,c++)    {    if (c->opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr,"<<<%4ld: %*s",(long)c->line,synch_depth,"");    dump_instr(c);    fprintf(stderr,"\n");    if (c->opcode == F_SYNCH_MARK) synch_depth++;    }    }   #endif    -  len=instrbuf.s.len/sizeof(p_instr); -  instructions=(p_instr *)instrbuf.s.str; -  instrbuf.s.str=0; +  len=buffer_content_length(&instrbuf)/sizeof(p_instr); +  instructions=(p_instr *)buffer_ptr(&instrbuf);    init_bytecode();       for(eye = 0; advance();)    {   #ifdef PIKE_DEBUG    if(a_flag>6) {    int e;    fprintf(stderr, "#%ld,%ld:", (long)eye, stack_depth);    for(e = 4;e--;) {    fprintf(stderr," ");
pike.git/src/peep.c:1120:       free(instructions);      #ifdef PIKE_DEBUG    if(a_flag > 4)    {    p_instr *c;    ptrdiff_t e, length;    int synch_depth = 0;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       fprintf(stderr,"After peep optimization:\n");    for(e=0;e<length;e++,c++)    {    if (c->opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr,">>>%4ld: %*s",(long)c->line,synch_depth,"");    dump_instr(c);    fprintf(stderr,"\n");    if (c->opcode == F_SYNCH_MARK) synch_depth++;    }    }   #endif       return relabel;   }