File:  [gforth] / gforth / engine / peephole.c
Revision 1.2: download - view: text, annotated - select for diffs
Tue Feb 27 21:17:11 2001 UTC (21 years, 9 months ago) by anton
Branches: MAIN
CVS tags: HEAD
good start at profiling for peephole optimization
backtrace now also works for calls done with CALL

    1: /* Peephole optimization routines and tables
    2: 
    3:   Copyright (C) 2001 Free Software Foundation, Inc.
    4: 
    5:   This file is part of Gforth.
    6: 
    7:   Gforth is free software; you can redistribute it and/or
    8:   modify it under the terms of the GNU General Public License
    9:   as published by the Free Software Foundation; either version 2
   10:   of the License, or (at your option) any later version.
   11: 
   12:   This program is distributed in the hope that it will be useful,
   13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15:   GNU General Public License for more details.
   16: 
   17:   You should have received a copy of the GNU General Public License
   18:   along with this program; if not, write to the Free Software
   19:   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: */
   21: 
   22: #include "config.h"
   23: #include "forth.h"
   24: #include <stdlib.h>
   25: 
   26: /* the numbers in this struct are primitive indices */
   27: typedef struct Combination {
   28:   int prefix;
   29:   int lastprim;
   30:   int combination_prim;
   31: } Combination;
   32: 
   33: Combination peephole_table[] = {
   34: #include "peephole.i"
   35: };
   36: 
   37: Xt *primtable(Label symbols[], Cell size)
   38: {
   39: #ifdef DIRECT_THREADED
   40:   return symbols;
   41: #else /* !defined(DIRECT_THREADED) */
   42:   Xt *xts = (Xt *)malloc(size*sizeof(Xt));
   43:   Cell i;
   44: 
   45:   for (i=0; i<size; i++)
   46:     xts[i] = &symbols[i];
   47:   return xts;
   48: #endif /* !defined(DIRECT_THREADED) */
   49: }
   50: 
   51: /* we are currently using a simple linear search; we can refine this
   52:    once the interface has settled and this works */
   53: 
   54: Cell prepare_peephole_table(Xt xts[])
   55: {
   56:   return (Cell)xts;
   57: }
   58: 
   59: Xt peephole_opt(Xt xt1, Xt xt2, Cell peeptable)
   60: {
   61:   Xt *xts = (Xt *)peeptable;
   62:   Cell i;
   63: 
   64:   for (i=0; i<(sizeof(peephole_table)/sizeof(Combination)); i++) {
   65:     Combination *c = &peephole_table[i];
   66:     if (xt1 == xts[c->prefix] && xt2 == xts[c->lastprim])
   67:       return xts[c->combination_prim];
   68:   }
   69:   return 0;
   70: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>