#include "xmalloc.h"
#include "debug.h"
#include "error.h"
+#include "opt_manage.h"
static unsigned get_vnum(const ir_node *node)
{
} path_t;
/** The size of a path in bytes. */
-#define PATH_SIZE(p) (sizeof(*(p)) + sizeof((p)->path[0]) * ((p)->path_len - 1))
+static size_t path_size(path_t *p)
+{
+ return sizeof(*p) + sizeof(p->path[0]) * (p->path_len-1);
+}
typedef struct scalars_t {
ir_entity *ent; /**< A entity for scalar replacement. */
pset_insert_ptr(sels, sel);
key = find_path(sel, 0);
- path = (path_t*)set_find(pathes, key, PATH_SIZE(key), path_hash(key));
+ path = (path_t*)set_find(pathes, key, path_size(key), path_hash(key));
if (path) {
set_vnum(sel, path->vnum);
} else {
key->vnum = vnum++;
- set_insert(pathes, key, PATH_SIZE(key), path_hash(key));
+ set_insert(pathes, key, path_size(key), path_hash(key));
set_vnum(sel, key->vnum);
DB((dbg, SET_LEVEL_3, " %+F represents value %u\n", sel, key->vnum));
*
* @param irg The current ir graph.
*/
-int scalar_replacement_opt(ir_graph *irg)
+static ir_graph_state_t do_scalar_replacement(ir_graph *irg)
{
unsigned nvals;
int i;
set *set_ent;
pset *sels;
ir_type *ent_type, *frame_tp;
- int res = 0;
-
- /* Call algorithm that computes the out edges */
- assure_irg_outs(irg);
/* we use the link field to store the VNUM */
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
ir_entity *ent = get_Sel_entity(succ);
/* we are only interested in entities on the frame, NOT
- on the value type */
- if (get_entity_owner(ent) != frame_tp)
+ parameters */
+ if (get_entity_owner(ent) != frame_tp
+ || is_parameter_entity(ent))
continue;
if (get_entity_link(ent) == NULL || get_entity_link(ent) == ADDRESS_TAKEN)
* neither changed control flow, cf-backedges should be still
* consistent.
*/
- res = 1;
}
del_pset(sels);
del_set(set_ent);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
- return res;
+ return 0;
+}
+
+static optdesc_t opt_scalar_rep = {
+ "scalar-replace",
+ IR_GRAPH_STATE_NO_UNREACHABLE_CODE | IR_GRAPH_STATE_CONSISTENT_OUTS,
+ do_scalar_replacement,
+};
+
+int scalar_replacement_opt(ir_graph *irg)
+{
+ perform_irg_optimization(irg, &opt_scalar_rep);
+ return 1;
}
ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)