/*
- * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
- *
* This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
*/
/**
#include "xmalloc.h"
#include "debug.h"
#include "error.h"
-#include "opt_manage.h"
static unsigned get_vnum(const ir_node *node)
{
*/
bool is_address_taken(ir_node *sel)
{
- int i, input_nr, k;
+ int input_nr;
ir_mode *emode, *mode;
ir_node *value;
ir_entity *ent;
if (! is_const_sel(sel))
return true;
- for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(sel); i-- > 0; ) {
ir_node *succ = get_irn_out(sel, i);
switch (get_irn_opcode(succ)) {
if (pred == sel) {
/* we found one input */
- for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) {
+ for (unsigned k = get_irn_n_outs(succ); k-- > 0; ) {
ir_node *proj = get_irn_out(succ, k);
if (is_Proj(proj) && get_Proj_proj(proj) == input_nr) {
*/
static bool link_all_leave_sels(ir_entity *ent, ir_node *sel)
{
- int i;
bool is_leave = true;
- for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(sel); i-- > 0; ) {
ir_node *succ = get_irn_out(sel, i);
if (is_Sel(succ)) {
ir_node *irg_frame;
ir_type *frame_tp;
size_t mem_idx;
- int i;
long static_link_arg;
int res = 0;
if (is_method_entity(ent)) {
ir_graph *inner_irg = get_entity_irg(ent);
ir_node *args;
- int j;
- assure_irg_outs(inner_irg);
+ assure_irg_properties(inner_irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS);
args = get_irg_args(inner_irg);
- for (j = get_irn_n_outs(args) - 1; j >= 0; --j) {
+ for (unsigned j = get_irn_n_outs(args); j-- > 0; ) {
ir_node *arg = get_irn_out(args, j);
if (get_Proj_proj(arg) == static_link_arg) {
- int k;
- for (k = get_irn_n_outs(arg) - 1; k >= 0; --k) {
+ for (unsigned k = get_irn_n_outs(arg); k-- > 0; ) {
ir_node *succ = get_irn_out(arg, k);
if (is_Sel(succ)) {
* equal ADDRESS_TAKEN.
*/
irg_frame = get_irg_frame(irg);
- for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(irg_frame); i-- > 0; ) {
ir_node *succ = get_irn_out(irg_frame, i);
if (is_Sel(succ)) {
pset_insert_ptr(sels, sel);
key = find_path(sel, 0);
- path = (path_t*)set_find(pathes, key, path_size(key), path_hash(key));
+ path = set_find(path_t, 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));
+ (void)set_insert(path_t, 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));
val = new_rd_Conv(get_irn_dbg_info(node), block, val, mode);
mem = get_Load_mem(node);
- turn_into_tuple(node, pn_Load_max+1);
- set_Tuple_pred(node, pn_Load_M, mem);
- set_Tuple_pred(node, pn_Load_res, val);
- set_Tuple_pred(node, pn_Load_X_regular, new_r_Jmp(block));
- set_Tuple_pred(node, pn_Load_X_except, new_r_Bad(irg, mode_X));
+ ir_node *const in[] = {
+ [pn_Load_M] = mem,
+ [pn_Load_res] = val,
+ [pn_Load_X_regular] = new_r_Jmp(block),
+ [pn_Load_X_except] = new_r_Bad(irg, mode_X),
+ };
+ turn_into_tuple(node, ARRAY_SIZE(in), in);
} else if (is_Store(node)) {
DB((dbg, SET_LEVEL_3, " checking %+F for replacement ", node));
set_value(vnum, val);
mem = get_Store_mem(node);
- turn_into_tuple(node, pn_Store_max+1);
- set_Tuple_pred(node, pn_Store_M, mem);
- set_Tuple_pred(node, pn_Store_X_regular, new_r_Jmp(block));
- set_Tuple_pred(node, pn_Store_X_except, new_r_Bad(irg, mode_X));
+ ir_node *const in[] = {
+ [pn_Store_M] = mem,
+ [pn_Store_X_regular] = new_r_Jmp(block),
+ [pn_Store_X_except] = new_r_Bad(irg, mode_X),
+ };
+ turn_into_tuple(node, ARRAY_SIZE(in), in);
}
}
*
* @param irg The current ir graph.
*/
-static ir_graph_properties_t do_scalar_replacement(ir_graph *irg)
+void scalar_replacement_opt(ir_graph *irg)
{
unsigned nvals;
- int i;
- scalars_t key, *value;
+ scalars_t key;
ir_node *irg_frame;
ir_mode **modes;
set *set_ent;
pset *sels;
ir_type *ent_type, *frame_tp;
+ assure_irg_properties(irg,
+ IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE
+ | IR_GRAPH_PROPERTY_CONSISTENT_OUTS);
+
/* we use the link field to store the VNUM */
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
sels = pset_new_ptr(8);
frame_tp = get_irg_frame_type(irg);
- for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(irg_frame); i-- > 0; ) {
ir_node *succ = get_irn_out(irg_frame, i);
if (is_Sel(succ)) {
ent_type = get_entity_type(ent);
key.ent = ent;
- set_insert(set_ent, &key, sizeof(key), hash_ptr(key.ent));
+ (void)set_insert(scalars_t, set_ent, &key, sizeof(key), hash_ptr(key.ent));
#ifdef DEBUG_libfirm
if (is_Array_type(ent_type)) {
if (nvals > 0) {
do_scalar_replacements(irg, sels, nvals, modes);
- foreach_set(set_ent, scalars_t*, value) {
+ foreach_set(set_ent, scalars_t, value) {
free_entity(value->ent);
}
ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
- return 0;
-}
-
-static optdesc_t opt_scalar_rep = {
- "scalar-replace",
- IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE | IR_GRAPH_PROPERTY_CONSISTENT_OUTS,
- do_scalar_replacement,
-};
-
-void scalar_replacement_opt(ir_graph *irg)
-{
- perform_irg_optimization(irg, &opt_scalar_rep);
+ confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
}
ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)