1 |
/* |
2 |
* basic-blockinfo.hpp - PowerPC basic block information |
3 |
* |
4 |
* Kheperix (C) 2003 Gwenole Beauchesne |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#ifndef BASIC_BLOCKINFO_H |
22 |
#define BASIC_BLOCKINFO_H |
23 |
|
24 |
struct basic_block_info |
25 |
{ |
26 |
typedef basic_block_info block_info; |
27 |
static const int MAX_TARGETS = 2; |
28 |
|
29 |
struct dependency |
30 |
{ |
31 |
block_info * source; |
32 |
block_info * target; |
33 |
dependency * next; |
34 |
dependency ** prev_p; |
35 |
}; |
36 |
|
37 |
uintptr pc; |
38 |
uintptr end_pc; |
39 |
int32 count; |
40 |
uint32 size; |
41 |
uint32 c1; |
42 |
uint32 c2; |
43 |
|
44 |
// List of blocks we depend on |
45 |
dependency dep[MAX_TARGETS]; |
46 |
|
47 |
// List of blocks that depends on this block |
48 |
dependency * deplist; |
49 |
|
50 |
void init(uintptr start_pc); |
51 |
void remove_dep(dependency *d); |
52 |
void remove_deps(); |
53 |
void create_jmpdep(block_info *tbi, int i); |
54 |
void maybe_create_jmpdep(block_info *tbi); |
55 |
bool intersect(uintptr start, uintptr end); |
56 |
}; |
57 |
|
58 |
inline void |
59 |
basic_block_info::init(uintptr start_pc) |
60 |
{ |
61 |
pc = start_pc; |
62 |
deplist = NULL; |
63 |
for (int i = 0; i < MAX_TARGETS; i++) { |
64 |
dep[i].source = NULL; |
65 |
dep[i].target = NULL; |
66 |
dep[i].next = NULL; |
67 |
dep[i].prev_p = NULL; |
68 |
} |
69 |
} |
70 |
|
71 |
inline void |
72 |
basic_block_info::remove_dep(dependency *d) |
73 |
{ |
74 |
if (d->prev_p) |
75 |
*(d->prev_p) = d->next; |
76 |
if (d->next) |
77 |
d->next->prev_p = d->prev_p; |
78 |
d->prev_p = NULL; |
79 |
d->next = NULL; |
80 |
} |
81 |
|
82 |
inline void |
83 |
basic_block_info::remove_deps() |
84 |
{ |
85 |
for (int i = 0; i < MAX_TARGETS; i++) |
86 |
remove_dep(&dep[i]); |
87 |
} |
88 |
|
89 |
inline void |
90 |
basic_block_info::create_jmpdep(block_info *tbi, int i) |
91 |
{ |
92 |
dep[i].source = this; |
93 |
dep[i].target = tbi; |
94 |
dep[i].next = tbi->deplist; |
95 |
if (dep[i].next) |
96 |
dep[i].next->prev_p = &(dep[i].next); |
97 |
dep[i].prev_p = &(tbi->deplist); |
98 |
tbi->deplist = &(dep[i]); |
99 |
} |
100 |
|
101 |
inline void |
102 |
basic_block_info::maybe_create_jmpdep(block_info *tbi) |
103 |
{ |
104 |
for (int i = 0; i < MAX_TARGETS && dep[i].target != tbi; i++) { |
105 |
if (dep[i].source == NULL) { |
106 |
create_jmpdep(tbi, i); |
107 |
break; |
108 |
} |
109 |
} |
110 |
} |
111 |
|
112 |
inline bool |
113 |
basic_block_info::intersect(uintptr start, uintptr end) |
114 |
{ |
115 |
return (pc >= start && pc < end) || (end_pc >= start && end_pc < end); |
116 |
} |
117 |
|
118 |
#endif /* BASIC_BLOCKINFO_H */ |