* @file
* @brief Scalar replacement of compounds.
* @author Beyhan Veliev, Michael Beck
- * @version $Id$
*/
#include "config.h"
#include "irgmod.h"
#include "irnode_t.h"
#include "irpass.h"
-#include "irtools.h"
+#include "util.h"
#include "xmalloc.h"
#include "debug.h"
#include "error.h"
-#include "opt_manage.h"
static unsigned get_vnum(const ir_node *node)
{
if (ent_mode != mode) {
if (ent_mode == NULL ||
get_mode_size_bits(ent_mode) != get_mode_size_bits(mode) ||
- get_mode_sort(ent_mode) != get_mode_sort(mode) ||
get_mode_arithmetic(ent_mode) != irma_twos_complement ||
get_mode_arithmetic(mode) != irma_twos_complement)
return false;
*/
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));
*
* @param irg The current ir graph.
*/
-static ir_graph_state_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;
-}
-
-optdesc_t opt_scalar_rep = {
- "scalar-replace",
- IR_GRAPH_STATE_NO_UNREACHABLE_BLOCKS | IR_GRAPH_STATE_CONSISTENT_OUTS,
- do_scalar_replacement,
-};
-
-int scalar_replacement_opt(ir_graph *irg)
-{
- perform_irg_optimization(irg, &opt_scalar_rep);
- return 1;
+ confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);
}
ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)
{
- return def_graph_pass_ret(name ? name : "scalar_rep",
- scalar_replacement_opt);
+ return def_graph_pass(name ? name : "scalar_rep", scalar_replacement_opt);
}
void firm_init_scalar_replace(void)