Commit 096c9237 authored by Matthias Braun's avatar Matthias Braun
Browse files

move callee get/set code from irnode to cgana

parent 5fee0ad2
......@@ -71,6 +71,36 @@ FIRM_API void free_irp_callee_info(void);
*/
FIRM_API void opt_call_addrs(void);
/** Sets, get and remove the callee information for a Call node.
*
* The callee information lists all method entities that can be called
* from this node. If the address expression can not be analyzed fully,
* e.g., as entities can be called that are not in the compilation unit,
* the array contains the unknown_entity. The array contains only entities
* with peculiarity_existent, but with all kinds of visibility. The entities
* not necessarily contain an irg.
*
* The array is only accessible if callee information is valid. See flag
* in graph.
*
* The memory allocated for the array is managed automatically, i.e., it must
* not be freed if the Call node is removed from the graph.
*
* @param node A Call node.
*/
FIRM_API int cg_call_has_callees(const ir_node *node);
/** Returns the number of callees of Call node @p node. */
FIRM_API size_t cg_get_call_n_callees(const ir_node *node);
/** Returns callee number @p pos of Call node @p node. */
FIRM_API ir_entity *cg_get_call_callee(const ir_node *node, size_t pos);
/** Sets the full callee array.
*
* The passed array is copied. */
FIRM_API void cg_set_call_callee_arr(ir_node *node, size_t n, ir_entity **arr);
/** Frees callee array of call node @p node */
FIRM_API void cg_remove_call_callee_arr(ir_node *node);
/** @} */
#include "end.h"
......
......@@ -373,42 +373,6 @@ FIRM_API void set_SymConst_symbol(ir_node *node, union symconst_symbol sym);
/** @} */
/** @addtogroup Call
* @{
*/
/** Sets, get and remove the callee information for a Call node.
*
* The callee information lists all method entities that can be called
* from this node. If the address expression can not be analyzed fully,
* e.g., as entities can be called that are not in the compilation unit,
* the array contains the unknown_entity. The array contains only entities
* with peculiarity_existent, but with all kinds of visibility. The entities
* not necessarily contain an irg.
*
* The array is only accessible if callee information is valid. See flag
* in graph.
*
* The memory allocated for the array is managed automatically, i.e., it must
* not be freed if the Call node is removed from the graph.
*
* @param node A Call node.
*/
FIRM_API int Call_has_callees(const ir_node *node);
/** Returns the number of callees of Call node @p node. */
FIRM_API size_t get_Call_n_callees(const ir_node *node);
/** Returns callee number @p pos of Call node @p node. */
FIRM_API ir_entity *get_Call_callee(const ir_node *node, size_t pos);
/** Sets the full callee array.
*
* The passed array is copied. */
FIRM_API void set_Call_callee_arr(ir_node *node, size_t n, ir_entity **arr);
/** Frees callee array of call node @p node */
FIRM_API void remove_Call_callee_arr(ir_node *node);
/** @} */
/** Returns a human readable string for the ir_builtin_kind. */
FIRM_API const char *get_builtin_kind_name(ir_builtin_kind kind);
......
......@@ -14,6 +14,7 @@
#include "irnode_t.h"
#include "irmode_t.h"
#include "array.h"
#include "cgana.h"
#include "irprog.h"
#include "entity_t.h"
......@@ -72,8 +73,8 @@ static ptr_access_kind analyze_arg(ir_node *arg, ptr_access_kind bits)
size_t n_params = get_Call_n_params(succ);
/* simply look into ALL possible callees */
for (int c = get_Call_n_callees(succ); c-- > 0; ) {
meth_ent = get_Call_callee(succ, c);
for (int c = cg_get_call_n_callees(succ); c-- > 0; ) {
meth_ent = cg_get_call_callee(succ, c);
/* unknown_entity is used to signal that we don't know what is called */
if (is_unknown_entity(meth_ent)) {
......
......@@ -168,8 +168,9 @@ static void ana_Call(ir_node *n, void *env)
return;
ir_graph *irg = get_irn_irg(n);
for (size_t i = 0, n_callees = get_Call_n_callees(n); i < n_callees; ++i) {
ir_entity *callee_e = get_Call_callee(n, i);
for (size_t i = 0, n_callees = cg_get_call_n_callees(n); i < n_callees;
++i) {
ir_entity *callee_e = cg_get_call_callee(n, i);
ir_graph *callee = get_entity_irg(callee_e);
if (callee) {
......
......@@ -42,6 +42,41 @@ static void *MARK = &MARK;
static pset *entities = NULL;
int cg_call_has_callees(const ir_node *node)
{
assert(is_Call(node));
return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
(node->attr.call.callee_arr != NULL));
}
size_t cg_get_call_n_callees(const ir_node *node)
{
assert(is_Call(node) && node->attr.call.callee_arr);
return ARR_LEN(node->attr.call.callee_arr);
}
ir_entity *cg_get_call_callee(const ir_node *node, size_t pos)
{
assert(pos < cg_get_call_n_callees(node));
return node->attr.call.callee_arr[pos];
}
void cg_set_call_callee_arr(ir_node *node, size_t n, ir_entity **arr)
{
assert(is_Call(node));
if (node->attr.call.callee_arr==NULL || cg_get_call_n_callees(node) != n) {
ir_graph *const irg = get_irn_irg(node);
node->attr.call.callee_arr = NEW_ARR_D(ir_entity*, get_irg_obstack(irg), n);
}
memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
}
void cg_remove_call_callee_arr(ir_node *node)
{
assert(is_Call(node));
node->attr.call.callee_arr = NULL;
}
/*--------------------------------------------------------------------------*/
/* The analysis */
/*--------------------------------------------------------------------------*/
......@@ -600,7 +635,7 @@ static void callee_walker(ir_node *call, void *env)
}
++i;
}
set_Call_callee_arr(call, ARR_LEN(arr), arr);
cg_set_call_callee_arr(call, ARR_LEN(arr), arr);
DEL_ARR_F(arr);
del_pset(methods);
}
......@@ -643,10 +678,9 @@ static void sel_methods_dispose(void)
static void destruct_walker(ir_node *node, void *env)
{
(void) env;
if (is_Call(node)) {
remove_Call_callee_arr(node);
}
(void)env;
if (is_Call(node))
cg_remove_call_callee_arr(node);
}
size_t cgana(ir_entity ***free_methods)
......
......@@ -24,6 +24,7 @@
#include "tv_t.h"
#include "irprintf.h"
#include "error.h"
#include "cgana.h"
#include "irdom.h"
......@@ -247,11 +248,11 @@ void dump_irnode_to_file(FILE *const F, const ir_node *const n)
ir_fprintf(F, " result %d type: %+F\n", i, res_type);
}
}
if (Call_has_callees(n)) {
if (cg_call_has_callees(n)) {
fprintf(F, " possible callees:\n");
for (size_t i = 0, n_callees = get_Call_n_callees(n);
for (size_t i = 0, n_callees = cg_get_call_n_callees(n);
i < n_callees; i++) {
const ir_entity *callee = get_Call_callee(n, i);
const ir_entity *callee = cg_get_call_callee(n, i);
ir_fprintf(F, " %zu: %s\n", i, get_ent_dump_name(callee));
}
}
......
......@@ -736,42 +736,6 @@ const char *get_builtin_kind_name(ir_builtin_kind kind)
#undef X
}
int Call_has_callees(const ir_node *node)
{
assert(is_Call(node));
return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
(node->attr.call.callee_arr != NULL));
}
size_t get_Call_n_callees(const ir_node *node)
{
assert(is_Call(node) && node->attr.call.callee_arr);
return ARR_LEN(node->attr.call.callee_arr);
}
ir_entity *get_Call_callee(const ir_node *node, size_t pos)
{
assert(pos < get_Call_n_callees(node));
return node->attr.call.callee_arr[pos];
}
void set_Call_callee_arr(ir_node *node, size_t n, ir_entity ** arr)
{
assert(is_Call(node));
if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
ir_graph *const irg = get_irn_irg(node);
node->attr.call.callee_arr = NEW_ARR_D(ir_entity*, get_irg_obstack(irg), n);
}
memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
}
void remove_Call_callee_arr(ir_node *node)
{
assert(is_Call(node));
node->attr.call.callee_arr = NULL;
}
int (is_binop)(const ir_node *node)
{
return is_binop_(node);
......
......@@ -11,6 +11,7 @@
#include <string.h>
#include "error.h"
#include "cgana.h"
#include "irop_t.h"
#include "irnode_t.h"
#include "irhooks.h"
......@@ -446,7 +447,7 @@ static void call_copy_attr(ir_graph *irg, const ir_node *old_node,
ir_node *new_node)
{
default_copy_attr(irg, old_node, new_node);
remove_Call_callee_arr(new_node);
cg_remove_call_callee_arr(new_node);
}
/**
......
......@@ -11,6 +11,7 @@
*/
#include "iroptimize.h"
#include "cgana.h"
#include "irgraph_t.h"
#include "irnode_t.h"
#include "type_t.h"
......@@ -173,9 +174,9 @@ static int can_escape(ir_node *n)
size_t k;
/* go through all possible callees */
for (k = get_Call_n_callees(succ); k > 0;) {
for (k = cg_get_call_n_callees(succ); k > 0;) {
size_t j;
ent = get_Call_callee(succ, --k);
ent = cg_get_call_callee(succ, --k);
if (is_unknown_entity(ent)) {
/* we don't know what will be called, a possible escape */
......
......@@ -83,8 +83,8 @@ void gc_irgs(size_t n_keep, ir_entity ** keep_arr)
/* iterate calls */
for (node = (ir_node*)get_irn_link(node); node != NULL;
node = (ir_node*)get_irn_link(node)) {
for (size_t i = get_Call_n_callees(node); i > 0;) {
ir_entity *ent = get_Call_callee(node, --i);
for (size_t i = cg_get_call_n_callees(node); i > 0;) {
ir_entity *ent = cg_get_call_callee(node, --i);
if (get_entity_irg(ent) && get_entity_link(ent) != MARK) {
set_entity_link(ent, MARK);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment