Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
ef141330
Commit
ef141330
authored
May 04, 2006
by
Sebastian Hack
Browse files
node data constructors can allocate the memory by themselves now.
[r7693]
parent
295b42af
Changes
2
Hide whitespace changes
Inline
Side-by-side
ir/ir/irphase.c
View file @
ef141330
...
...
@@ -18,16 +18,16 @@
#include
"irnode_t.h"
#include
"irphase_t.h"
phase_t
*
phase_init
(
phase_t
*
ph
,
const
char
*
name
,
ir_graph
*
irg
,
size_t
data_size
,
unsigned
growth_factor
,
phase_irn_data_init_t
*
data_init
)
phase_t
*
phase_init
(
phase_t
*
ph
,
const
char
*
name
,
ir_graph
*
irg
,
unsigned
growth_factor
,
phase_irn_data_init_t
*
data_init
)
{
assert
(
growth_factor
>=
1
.
0
&&
"growth factor must greater or equal to 1.0"
);
assert
(
data_init
&&
"You must provide a data constructor"
);
obstack_init
(
&
ph
->
obst
);
ph
->
name
=
name
;
ph
->
growth_factor
=
growth_factor
;
ph
->
data_init
=
data_init
;
ph
->
data_size
=
data_size
;
ph
->
irg
=
irg
;
ph
->
n_data_ptr
=
0
;
ph
->
data_ptr
=
NULL
;
...
...
@@ -52,7 +52,6 @@ phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat)
for
(
i
=
0
,
n
=
phase
->
n_data_ptr
;
i
<
n
;
++
i
)
{
if
(
phase
->
data_ptr
[
i
]
!=
NULL
)
{
stat
->
node_slots_used
++
;
stat
->
node_data_bytes
+=
phase
->
data_size
;
}
}
stat
->
overall_bytes
=
stat
->
node_map_bytes
+
obstack_memory_used
(
&
((
phase_t
*
)
phase
)
->
obst
);
...
...
ir/ir/irphase_t.h
View file @
ef141330
...
...
@@ -32,7 +32,7 @@ typedef struct {
*/
phase_stat_t
*
phase_stat
(
const
phase_t
*
phase
,
phase_stat_t
*
stat
);
typedef
void
(
phase_irn_data_init_t
)(
phase_t
*
phase
,
ir_node
*
irn
,
void
*
data
);
typedef
void
*
(
phase_irn_data_init_t
)(
phase_t
*
phase
,
ir_node
*
irn
,
void
*
old
);
/**
* The default grow factor.
...
...
@@ -49,7 +49,6 @@ struct _phase_t {
ir_graph
*
irg
;
/**< The irg this phase will we applied to. */
unsigned
growth_factor
;
/**< factor to leave room for add. nodes. 256 means 1.0. */
void
*
priv
;
/**< Some pointer private to the user of the phase. */
size_t
data_size
;
/**< The amount of bytes which shall be allocated for each irn. */
size_t
n_data_ptr
;
/**< The length of the data_ptr array. */
void
**
data_ptr
;
/**< Map node indexes to irn data on the obstack. */
phase_irn_data_init_t
*
data_init
;
/**< A callback that is called to initialize newly created node data. */
...
...
@@ -59,14 +58,13 @@ struct _phase_t {
* Initialize a phase object.
* @param name The name of the phase.
* @param irg The graph the phase will run on.
* @param data_size The amount of extra storage in bytes that should be allocated for each node.
* @param growth_factor A factor denoting how many node slots will be additionally allocated,
* if the node => data is full. 256 means 1.0.
* @param irn_data_init A callback that is called to initialize newly created node data.
* @param priv Some private pointer which is kept in the phase and can be retrieved with phase_get_private().
* @return A new phase object.
*/
phase_t
*
phase_init
(
phase_t
*
ph
,
const
char
*
name
,
ir_graph
*
irg
,
size_t
data_size
,
unsigned
growth_factor
,
phase_irn_data_init_t
*
data_init
);
phase_t
*
phase_init
(
phase_t
*
ph
,
const
char
*
name
,
ir_graph
*
irg
,
unsigned
growth_factor
,
phase_irn_data_init_t
*
data_init
);
/**
* Free the phase and all node data associated with it.
...
...
@@ -166,11 +164,10 @@ static INLINE void *_phase_get_or_set_irn_data(phase_t *ph, ir_node *irn)
/* If there has no irn data allocated yet, do that now. */
if
(
!
res
)
{
phase_irn_data_init_t
*
data_init
=
ph
->
data_init
;
ph
->
data_ptr
[
idx
]
=
res
=
phase_alloc
(
ph
,
ph
->
data_size
);
/*
C
all the
irn
data
callback, if there is one
. */
if
(
data_init
)
data_init
(
ph
,
irn
,
res
);
/*
c
all the
node
data
structure allocator/constructor
. */
res
=
ph
->
data_ptr
[
idx
]
=
data_init
(
ph
,
irn
,
NULL
);
}
return
res
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment