CACAO
peephole.c
Go to the documentation of this file.
1 /* Peephole optimization routines and tables
2 
3  Copyright (C) 2001,2002,2003 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 
23 #include "config.h"
24 
25 #include <assert.h>
26 #include <stdlib.h>
27 
28 #include "vm/jit/intrp/intrp.h"
29 
30 #include "vm/options.hpp"
31 
32 
33 /* the numbers in this struct are primitive indices */
34 typedef struct Combination {
35  int prefix;
36  int lastprim;
38 } Combination;
39 
41 #include <java-peephole.i>
42  {-1,-1,-1} /* unnecessary; just to shut up lcc if the file is empty */
43 };
44 
45 int use_super = 1; /* turned off by option -p */
46 
47 typedef struct Peeptable_entry {
53 
54 #define HASH_SIZE 1024
55 #define hash(_i1,_i2) (((((Cell)(_i1))+((Cell)(_i2))))&(HASH_SIZE-1))
56 
58 
60 {
61  Cell i;
62  Peeptable_entry **pt = (Peeptable_entry **)calloc(HASH_SIZE,sizeof(Peeptable_entry *));
63  size_t static_supers = sizeof(peephole_table)/sizeof(peephole_table[0]);
64 
65  if (opt_static_supers < static_supers)
66  static_supers = opt_static_supers;
67 
68  for (i=0; i<static_supers; i++) {
69  Combination *c = &peephole_table[i];
70  Peeptable_entry *p = (Peeptable_entry *)malloc(sizeof(Peeptable_entry));
71  Cell h;
72  p->prefix = c->prefix;
73  p->lastprim = c->lastprim;
75  h = hash(p->prefix,p->lastprim);
76  p->next = pt[h];
77  pt[h] = p;
78  }
79  return (Cell)pt;
80 }
81 
82 void init_peeptable(void)
83 {
85 }
86 
88 {
89  Peeptable_entry **pt = (Peeptable_entry **)peeptable;
90  Peeptable_entry *p;
91 
92  if (use_super == 0)
93  return -1;
94  for (p = pt[hash(inst1,inst2)]; p != NULL; p = p->next)
95  if (inst1 == p->prefix && inst2 == p->lastprim)
96  return p->combination_prim;
97  return -1;
98 }
#define hash(_i1, _i2)
Definition: peephole.c:55
int lastprim
Definition: peephole.c:36
int combination_prim
Definition: peephole.c:37
Cell prepare_peephole_table(Inst insts[])
Definition: peephole.c:59
s8 Cell
Definition: intrp.h:42
Inst * vm_prim
Definition: md.c:48
struct Peeptable_entry Peeptable_entry
struct Peeptable_entry * next
Definition: peephole.c:48
#define HASH_SIZE
Definition: peephole.c:54
void init_peeptable(void)
Definition: peephole.c:82
Combination peephole_table[]
Definition: peephole.c:40
Definition: peephole.c:47
struct Combination Combination
void * Inst
Definition: intrp.h:58
int use_super
Definition: peephole.c:45
MIIterator i
u4 combination_prim
Definition: peephole.c:51
ptrint peephole_opt(ptrint inst1, ptrint inst2, Cell peeptable)
Definition: peephole.c:87
uint32_t u4
Definition: types.hpp:46
int prefix
Definition: peephole.c:35
u4 prefix
Definition: peephole.c:49
uintptr_t ptrint
Definition: types.hpp:54
u4 lastprim
Definition: peephole.c:50
Cell peeptable
Definition: peephole.c:57