CACAO
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
source
cacao
src
vm
jit
intrp
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
;
37
int
combination_prim
;
38
}
Combination
;
39
40
Combination
peephole_table
[] = {
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
{
48
struct
Peeptable_entry
*
next
;
49
u4
prefix
;
50
u4
lastprim
;
51
u4
combination_prim
;
52
}
Peeptable_entry
;
53
54
#define HASH_SIZE 1024
55
#define hash(_i1,_i2) (((((Cell)(_i1))+((Cell)(_i2))))&(HASH_SIZE-1))
56
57
Cell
peeptable
;
58
59
Cell
prepare_peephole_table
(
Inst
insts[])
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
;
74
p->
combination_prim
= c->
combination_prim
;
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
{
84
peeptable
=
prepare_peephole_table
(
vm_prim
);
85
}
86
87
ptrint
peephole_opt
(
ptrint
inst1,
ptrint
inst2,
Cell
peeptable
)
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
}
hash
#define hash(_i1, _i2)
Definition:
peephole.c:55
Combination::lastprim
int lastprim
Definition:
peephole.c:36
Combination::combination_prim
int combination_prim
Definition:
peephole.c:37
prepare_peephole_table
Cell prepare_peephole_table(Inst insts[])
Definition:
peephole.c:59
Cell
s8 Cell
Definition:
intrp.h:42
vm_prim
Inst * vm_prim
Definition:
md.c:48
Peeptable_entry
struct Peeptable_entry Peeptable_entry
Peeptable_entry::next
struct Peeptable_entry * next
Definition:
peephole.c:48
HASH_SIZE
#define HASH_SIZE
Definition:
peephole.c:54
intrp.h
init_peeptable
void init_peeptable(void)
Definition:
peephole.c:82
peephole_table
Combination peephole_table[]
Definition:
peephole.c:40
Peeptable_entry
Definition:
peephole.c:47
Combination
struct Combination Combination
Inst
void * Inst
Definition:
intrp.h:58
use_super
int use_super
Definition:
peephole.c:45
i
MIIterator i
Definition:
LivetimeAnalysisPass.cpp:149
Peeptable_entry::combination_prim
u4 combination_prim
Definition:
peephole.c:51
peephole_opt
ptrint peephole_opt(ptrint inst1, ptrint inst2, Cell peeptable)
Definition:
peephole.c:87
u4
uint32_t u4
Definition:
types.hpp:46
Combination::prefix
int prefix
Definition:
peephole.c:35
options.hpp
Peeptable_entry::prefix
u4 prefix
Definition:
peephole.c:49
Combination
Definition:
peephole.c:34
ptrint
uintptr_t ptrint
Definition:
types.hpp:54
Peeptable_entry::lastprim
u4 lastprim
Definition:
peephole.c:50
peeptable
Cell peeptable
Definition:
peephole.c:57
Generated on Fri Aug 4 2017 03:01:53 for CACAO by
1.8.5