Commit 7c36344d authored by Matthias Braun's avatar Matthias Braun
Browse files

- fix most of the -Wunreachable-code and -Wlogical-op warnings

- rework ir_phase API
(sorry for mixing these 2 things into 1 commit)

[r27285]
parent ea75e9d3
......@@ -46,7 +46,6 @@ typedef struct ir_loop ir_loop, *ir_loop_ptr;
typedef struct ir_region ir_region, *ir_region_ptr;
typedef struct ir_reg_tree ir_reg_tree, *ir_reg_tree_ptr;
typedef struct ir_entity ir_entity, *ir_entity_ptr;
typedef struct _ir_phase ir_phase, *ir_phase_ptr;
typedef struct _ir_extblk ir_extblk, *ir_extblk_ptr;
typedef struct ir_exec_freq ir_exec_freq, *ir_exec_freq_ptr;
typedef struct ir_cdep ir_cdep, *ir_cdep_ptr;
......
......@@ -182,10 +182,6 @@ void edges_init_dbg(int do_dbg);
*/
ir_graph_pass_t *irg_verify_edges_pass(const char *name, unsigned assert_on_problem);
/************************************************************************/
/* Begin Old Interface */
/************************************************************************/
const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos);
#define edges_reroute(old, nw, irg) edges_reroute_kind(old, nw, EDGE_KIND_NORMAL, irg)
......@@ -272,8 +268,4 @@ void irg_block_edges_walk(ir_node *block, irg_walk_func *pre, irg_walk_func *pos
*/
void edges_reset_private_data(ir_graph *irg, int offset, unsigned size);
/************************************************************************/
/* End Old Interface */
/************************************************************************/
#endif
......@@ -126,8 +126,6 @@ void set_current_ir_graph(ir_graph *graph);
* (get_irn_*, set_irn_*) is influenced by this flag. */
int get_interprocedural_view(void);
void set_interprocedural_view(int state);
#else
#define get_interprocedural_view() 0
#endif
/**
......
......@@ -27,6 +27,7 @@
#include "array.h"
#include "pqueue.h"
#include "error.h"
/*
* Implements a heap.
......@@ -131,13 +132,10 @@ void *pqueue_pop_front(pqueue_t *q)
{
switch (ARR_LEN(q->elems)) {
case 0:
assert(0 && "Attempt to retrieve element from empty priority queue.");
return NULL;
break;
panic("Attempt to retrieve element from empty priority queue.");
case 1:
ARR_SHRINKLEN(q->elems, 0);
return q->elems[0].data;
break;
default: {
void *data = q->elems[0].data;
int len = ARR_LEN(q->elems) - 1;
......
......@@ -31,6 +31,7 @@
#include "set.h"
#include "pdeq.h"
#include "hashptr.h"
#include "error.h"
#include "irprog_t.h"
#include "irgraph_t.h"
......@@ -265,10 +266,12 @@ static void precompute_cond_evaluation(void)
/* both are exceptions */
if ((get_ProjX_probability(p0) == Cond_prob_exception_taken) &&
(get_ProjX_probability(p1) == Cond_prob_exception_taken) ) {
assert(0 && "I tried to avoid these!");
panic("I tried to avoid these!");
#if 0
/* It's a */
set_ProjX_probability(p0, Cond_prob_normal);
set_ProjX_probability(p1, Cond_prob_normal);
#endif
}
/* p0 is exception */
......
......@@ -243,7 +243,7 @@ void heights_recompute(heights_t *h)
heights_t *heights_new(ir_graph *irg)
{
heights_t *res = XMALLOC(heights_t);
phase_init(&res->ph, "heights", irg, PHASE_DEFAULT_GROWTH, irn_height_init, NULL);
phase_init(&res->ph, irg, irn_height_init);
res->dump_handle = dump_add_node_info_callback(height_dump_cb, res);
heights_recompute(res);
......@@ -252,7 +252,7 @@ heights_t *heights_new(ir_graph *irg)
void heights_free(heights_t *h)
{
phase_free(&h->ph);
phase_deinit(&h->ph);
dump_remv_node_info_callback(h->dump_handle);
xfree(h);
}
......@@ -49,25 +49,29 @@ static unsigned *mere_get_backarray(ir_node *n)
switch (get_irn_opcode(n)) {
case iro_Block:
if (!get_Block_matured(n)) return NULL;
#ifdef INTERPROCEDURAL_VIEW
if (get_interprocedural_view() && n->attr.block.in_cg) {
assert(n->attr.block.cg_backedge && "backedge array not allocated!");
return n->attr.block.cg_backedge;
} else {
assert(n->attr.block.backedge && "backedge array not allocated!");
return n->attr.block.backedge;
}
break;
#endif
assert(n->attr.block.backedge && "backedge array not allocated!");
return n->attr.block.backedge;
case iro_Phi:
assert(n->attr.phi.u.backedge && "backedge array not allocated!");
return n->attr.phi.u.backedge;
break;
case iro_Filter:
#ifdef INTERPROCEDURAL_VIEW
if (get_interprocedural_view()) {
assert(n->attr.filter.backedge && "backedge array not allocated!");
return n->attr.filter.backedge;
}
#endif
break;
default:
break;
default: ;
}
return NULL;
}
......@@ -122,9 +126,11 @@ void fix_backedges(struct obstack *obst, ir_node *n)
if (opc == iro_Phi)
n->attr.phi.u.backedge = arr;
else if (opc == iro_Block) {
#ifdef INTERPROCEDURAL_VIEW
if (!get_interprocedural_view())
n->attr.block.backedge = arr;
else
#endif
n->attr.block.cg_backedge = arr;
}
else if (opc == iro_Filter)
......
......@@ -666,8 +666,10 @@ int construct_cf_backedges(ir_graph *irg)
struct obstack temp;
int i;
#ifdef INTERPROCEDURAL_VIEW
assert(!get_interprocedural_view() &&
"use construct_ip_cf_backedges()");
#endif
max_loop_depth = 0;
current_ir_graph = irg;
......
......@@ -76,12 +76,12 @@ typedef struct _bl_info_t {
#define get_block_info(lv, bl) ((bl_info_t *) phase_get_irn_data(&(lv)->ph, bl))
struct _lv_chk_t {
ir_phase ph;
ir_phase ph;
const dfs_t *dfs;
int n_blocks;
bitset_t *back_edge_src;
bitset_t *back_edge_tgt;
bl_info_t **map;
int n_blocks;
bitset_t *back_edge_src;
bitset_t *back_edge_tgt;
bl_info_t **map;
DEBUG_ONLY(firm_dbg_module_t *dbg;)
};
......@@ -251,7 +251,7 @@ lv_chk_t *lv_chk_new(ir_graph *irg, const dfs_t *dfs)
compute_doms(irg);
stat_ev_tim_push();
phase_init(&res->ph, "liveness check", irg, PHASE_DEFAULT_GROWTH, init_block_data, NULL);
phase_init(&res->ph, irg, init_block_data);
obst = phase_obst(&res->ph);
FIRM_DBG_REGISTER(res->dbg, "ir.ana.lvchk");
......@@ -310,7 +310,7 @@ lv_chk_t *lv_chk_new(ir_graph *irg, const dfs_t *dfs)
void lv_chk_free(lv_chk_t *lv)
{
phase_free(&lv->ph);
phase_deinit(&lv->ph);
xfree(lv);
}
......
......@@ -31,8 +31,10 @@
#include "irloop_t.h"
#include "irprog_t.h"
#include "error.h"
void add_loop_son(ir_loop *loop, ir_loop *son) {
void add_loop_son(ir_loop *loop, ir_loop *son)
{
loop_element lson;
assert(loop && loop->kind == k_ir_loop);
assert(get_kind(son) == k_ir_loop);
......@@ -42,7 +44,8 @@ void add_loop_son(ir_loop *loop, ir_loop *son) {
loop->flags |= loop_outer_loop;
}
void add_loop_node(ir_loop *loop, ir_node *n) {
void add_loop_node(ir_loop *loop, ir_node *n)
{
loop_element ln;
ln.node = n;
assert(loop && loop->kind == k_ir_loop);
......@@ -50,7 +53,8 @@ void add_loop_node(ir_loop *loop, ir_node *n) {
loop->n_nodes++;
}
void add_loop_irg(ir_loop *loop, ir_graph *irg) {
void add_loop_irg(ir_loop *loop, ir_graph *irg)
{
loop_element ln;
ln.irg = irg;
assert(loop && loop->kind == k_ir_loop);
......@@ -64,7 +68,8 @@ void add_loop_irg(ir_loop *loop, ir_graph *irg) {
* @param loop the loop to mature
* @param obst an obstack, where the new arrays are allocated on
*/
void mature_loops(ir_loop *loop, struct obstack *obst) {
void mature_loops(ir_loop *loop, struct obstack *obst)
{
loop_element *new_children = DUP_ARR_D(loop_element, obst, loop->children);
DEL_ARR_F(loop->children);
loop->children = new_children;
......@@ -84,24 +89,28 @@ void mature_loops(ir_loop *loop, struct obstack *obst) {
}
/* Returns outer loop, itself if outermost. */
ir_loop *(get_loop_outer_loop)(const ir_loop *loop) {
ir_loop *(get_loop_outer_loop)(const ir_loop *loop)
{
return _get_loop_outer_loop(loop);
}
/* Returns nesting depth of this loop */
int (get_loop_depth)(const ir_loop *loop) {
int (get_loop_depth)(const ir_loop *loop)
{
return _get_loop_depth(loop);
}
/* Returns the number of inner loops */
int (get_loop_n_sons)(const ir_loop *loop) {
int (get_loop_n_sons)(const ir_loop *loop)
{
return _get_loop_n_sons(loop);
}
/* Returns the pos`th loop_node-child *
* TODO: This method isn`t very efficient ! *
* Returns NULL if there isn`t a pos`th loop_node */
ir_loop *get_loop_son(ir_loop *loop, int pos) {
ir_loop *get_loop_son(ir_loop *loop, int pos)
{
int child_nr = 0, loop_nr = -1;
assert(loop && loop->kind == k_ir_loop);
......@@ -116,7 +125,8 @@ ir_loop *get_loop_son(ir_loop *loop, int pos) {
}
/* Returns the number of nodes in the loop */
int get_loop_n_nodes(const ir_loop *loop) {
int get_loop_n_nodes(const ir_loop *loop)
{
assert(loop); assert(loop->kind == k_ir_loop);
return loop->n_nodes;
}
......@@ -124,7 +134,8 @@ int get_loop_n_nodes(const ir_loop *loop) {
/* Returns the pos'th ir_node-child *
* TODO: This method isn't very efficient ! *
* Returns NULL if there isn't a pos'th ir_node */
ir_node *get_loop_node(const ir_loop *loop, int pos) {
ir_node *get_loop_node(const ir_loop *loop, int pos)
{
int child_nr, node_nr = -1;
assert(loop && loop->kind == k_ir_loop);
......@@ -137,12 +148,12 @@ ir_node *get_loop_node(const ir_loop *loop, int pos) {
return loop -> children[child_nr].node;
}
assert(0 && "no child at pos found");
return NULL;
panic("no child at pos found");
}
/* Returns the number of elements contained in loop. */
int get_loop_n_elements(const ir_loop *loop) {
int get_loop_n_elements(const ir_loop *loop)
{
assert(loop && loop->kind == k_ir_loop);
return(ARR_LEN(loop->children));
}
......@@ -153,12 +164,14 @@ This may be a loop_node or a ir_node. The caller of this function has
to check the *(loop_element.kind) field for "k_ir_node" or "k_ir_loop"
and then select the appropriate "loop_element.node" or "loop_element.son".
*/
loop_element get_loop_element(const ir_loop *loop, int pos) {
loop_element get_loop_element(const ir_loop *loop, int pos)
{
assert(loop && loop->kind == k_ir_loop && pos < ARR_LEN(loop->children));
return(loop -> children[pos]);
}
int get_loop_element_pos(const ir_loop *loop, void *le) {
int get_loop_element_pos(const ir_loop *loop, void *le)
{
int i, n;
assert(loop && loop->kind == k_ir_loop);
......@@ -173,15 +186,18 @@ int get_loop_element_pos(const ir_loop *loop, void *le) {
/**
* Sets the loop for a node.
*/
void set_irn_loop(ir_node *n, ir_loop *loop) {
void set_irn_loop(ir_node *n, ir_loop *loop)
{
n->loop = loop;
}
ir_loop *(get_irn_loop)(const ir_node *n) {
ir_loop *(get_irn_loop)(const ir_node *n)
{
return _get_irn_loop(n);
}
int get_loop_loop_nr(const ir_loop *loop) {
int get_loop_loop_nr(const ir_loop *loop)
{
assert(loop && loop->kind == k_ir_loop);
#ifdef DEBUG_libfirm
return loop->loop_nr;
......@@ -190,26 +206,32 @@ int get_loop_loop_nr(const ir_loop *loop) {
#endif
}
void set_loop_link(ir_loop *loop, void *link) {
void set_loop_link(ir_loop *loop, void *link)
{
assert(loop && loop->kind == k_ir_loop);
loop->link = link;
}
void *get_loop_link(const ir_loop *loop) {
void *get_loop_link(const ir_loop *loop)
{
assert(loop && loop->kind == k_ir_loop);
return loop->link;
}
int (is_ir_loop)(const void *thing) {
int (is_ir_loop)(const void *thing)
{
return _is_ir_loop(thing);
}
/* The outermost loop is remarked in the surrounding graph. */
void (set_irg_loop)(ir_graph *irg, ir_loop *loop) {
void (set_irg_loop)(ir_graph *irg, ir_loop *loop)
{
_set_irg_loop(irg, loop);
}
/* Returns the root loop info (if exists) for an irg. */
ir_loop *(get_irg_loop)(const ir_graph *irg) {
ir_loop *(get_irg_loop)(const ir_graph *irg)
{
return _get_irg_loop(irg);
}
......@@ -217,7 +239,8 @@ ir_loop *(get_irg_loop)(const ir_graph *irg) {
* Allocates a new loop as son of father on the given obstack.
* If father is equal NULL, a new root loop is created.
*/
ir_loop *alloc_loop(ir_loop *father, struct obstack *obst) {
ir_loop *alloc_loop(ir_loop *father, struct obstack *obst)
{
ir_loop *son;
son = OALLOCZ(obst, ir_loop);
......
......@@ -64,7 +64,8 @@ const char *get_ir_alias_relation_name(ir_alias_relation rel)
X(ir_no_alias);
X(ir_may_alias);
X(ir_sure_alias);
default: assert(0); return "UNKNOWN";
default:
panic("UNKNOWN alias relation");
}
#undef X
}
......
......@@ -396,6 +396,16 @@ static int is_outermost_Start(ir_node *n)
return 0;
}
static inline int is_ip_Filter(ir_node *n)
{
#ifdef INTERPROCEDURAL_VIEW
return is_Filter(n) && get_interprocedural_view();
#else
(void) n;
return 0;
#endif
}
/* When to walk from nodes to blocks. Only for Control flow operations? */
static inline int get_start_index(ir_node *n)
{
......@@ -405,13 +415,13 @@ static inline int get_start_index(ir_node *n)
#if BLOCK_BEFORE_NODE
/* This version assures, that all nodes are ordered absolutely. This allows
to undef all nodes in the heap analysis if the block is false, which means
not reachable.
I.e., with this code, the order on the loop tree is correct. But a (single)
test showed the loop tree is deeper. */
if (get_irn_op(n) == op_Phi ||
is_Block(n) ||
(is_Filter(n) && get_interprocedural_view()) || (
to undef all nodes in the heap analysis if the block is false, which
means not reachable.
I.e., with this code, the order on the loop tree is correct. But a
(single) test showed the loop tree is deeper. */
if (get_irn_op(n) == op_Phi ||
is_Block(n) ||
(is_ip_Filter(n)) || (
get_irg_pinned(get_irn_irg(n)) == op_pin_state_floats &&
get_irn_pinned(n) == op_pin_state_floats
))
......@@ -446,7 +456,7 @@ static inline int is_possible_loop_head(ir_node *n)
ir_op *op = get_irn_op(n);
return ((op == op_Block) ||
(op == op_Phi) ||
((op == op_Filter) && get_interprocedural_view()));
(is_ip_Filter(n)));
}
/**
......@@ -947,8 +957,10 @@ int construct_backedges(ir_graph *irg)
ir_loop *head_rem;
struct obstack temp;
#ifdef INTERPROCEDURAL_VIEW
assert(!get_interprocedural_view() &&
"not implemented, use construct_ip_backedges()");
#endif
max_loop_depth = 0;
current_ir_graph = irg;
......
......@@ -46,6 +46,11 @@ struct vrp_env_t {
waitq *workqueue;
};
static vrp_attr *get_vrp_attr(const ir_node *node)
{
return (vrp_attr*) get_or_set_irn_phase_info(node, PHASE_VRP);
}
static int vrp_update_node(ir_node *node)
{
tarval *new_bits_set = get_tarval_bad();
......@@ -55,21 +60,16 @@ static int vrp_update_node(ir_node *node)
enum range_types new_range_type = VRP_UNDEFINED;
int something_changed = 0;
vrp_attr *vrp;
ir_phase *phase;
if (!mode_is_int(get_irn_mode(node))) {
return 0; /* we don't optimize for non-int-nodes*/
}
phase = get_irg_phase(get_irn_irg(node), PHASE_VRP);
ir_printf("update_vrp for %d called\n", get_irn_node_nr(node));
vrp = phase_get_or_set_irn_data(phase, node);
vrp = get_vrp_attr(node);
/* TODO: Check if all predecessors have valid VRP information*/
switch (get_irn_opcode(node)) {
case iro_Const: {
tarval *tv = get_Const_tarval(node);
......@@ -87,8 +87,8 @@ static int vrp_update_node(ir_node *node)
left = get_And_left(node);
right = get_And_right(node);
vrp_left = phase_get_or_set_irn_data(phase, left);
vrp_right = phase_get_or_set_irn_data(phase, right);
vrp_left = get_vrp_attr(left);
vrp_right = get_vrp_attr(right);
new_bits_set = tarval_and(vrp_left->bits_set, vrp_right->bits_set);
new_bits_not_set = tarval_or(vrp_left->bits_not_set, vrp_right->bits_not_set);
......@@ -99,8 +99,8 @@ static int vrp_update_node(ir_node *node)
int overflow_top, overflow_bottom;
tarval *new_top, *new_bottom;
vrp_attr *vrp_left, *vrp_right;
vrp_left = phase_get_or_set_irn_data(phase, get_Add_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Add_right(node));
vrp_left = get_vrp_attr(get_Add_left(node));
vrp_right = get_vrp_attr(get_Add_right(node));
if (vrp_left->range_type == VRP_UNDEFINED || vrp_right->range_type ==
VRP_UNDEFINED || vrp_left->range_type == VRP_VARYING ||
......@@ -131,8 +131,8 @@ static int vrp_update_node(ir_node *node)
int overflow_top, overflow_bottom;
tarval *new_top, *new_bottom;
vrp_attr *vrp_left, *vrp_right;
vrp_left = phase_get_or_set_irn_data(phase, get_Sub_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Sub_right(node));
vrp_left = get_vrp_attr(get_Sub_left(node));
vrp_right = get_vrp_attr(get_Sub_right(node));
if (vrp_left->range_type == VRP_UNDEFINED || vrp_right->range_type ==
VRP_UNDEFINED) {
......@@ -164,8 +164,8 @@ static int vrp_update_node(ir_node *node)
left = get_Or_left(node);
right = get_Or_right(node);
vrp_left = phase_get_or_set_irn_data(phase, get_Or_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Or_right(node));
vrp_left = get_vrp_attr(get_Or_left(node));
vrp_right = get_vrp_attr(get_Or_right(node));
new_bits_set = tarval_or(vrp_left->bits_set, vrp_right->bits_set);
new_bits_not_set = tarval_and(vrp_left->bits_not_set, vrp_right->bits_not_set);
......@@ -177,8 +177,8 @@ static int vrp_update_node(ir_node *node)
vrp_attr *vrp_left, *vrp_right;
ir_node *right = get_Rotl_right(node);
vrp_left = phase_get_or_set_irn_data(phase, get_Rotl_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Rotl_right(node));
vrp_left = get_vrp_attr(get_Rotl_left(node));
vrp_right = get_vrp_attr(get_Rotl_right(node));
/* We can only compute this if the right value is a constant*/
if (is_Const(right)) {
......@@ -195,8 +195,8 @@ static int vrp_update_node(ir_node *node)
case iro_Shl: {
vrp_attr *vrp_left, *vrp_right;
ir_node *right = get_Shl_right(node);
vrp_left = phase_get_or_set_irn_data(phase, get_Shl_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Shl_right(node));
vrp_left = get_vrp_attr(get_Shl_left(node));
vrp_right = get_vrp_attr(get_Shl_right(node));
/* We can only compute this if the right value is a constant*/
if (is_Const(right)) {
......@@ -221,8 +221,8 @@ static int vrp_update_node(ir_node *node)
vrp_attr *vrp_left, *vrp_right;
ir_node *right = get_Shr_right(node);
vrp_left = phase_get_or_set_irn_data(phase, get_Shr_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Shr_right(node));
vrp_left = get_vrp_attr(get_Shr_left(node));
vrp_right = get_vrp_attr(get_Shr_right(node));
/* We can only compute this if the right value is a constant*/
if (is_Const(right)) {
......@@ -246,8 +246,8 @@ static int vrp_update_node(ir_node *node)
vrp_attr *vrp_left, *vrp_right;
ir_node *right = get_Shrs_right(node);
vrp_left = phase_get_or_set_irn_data(phase, get_Shrs_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Shrs_right(node));
vrp_left = get_vrp_attr(get_Shrs_left(node));
vrp_right = get_vrp_attr(get_Shrs_right(node));
/* We can only compute this if the right value is a constant*/
if (is_Const(right)) {
......@@ -271,8 +271,8 @@ static int vrp_update_node(ir_node *node)
tarval *bits_set, *bits_not_set;
vrp_attr *vrp_left, *vrp_right;
vrp_left = phase_get_or_set_irn_data(phase, get_Eor_left(node));
vrp_right = phase_get_or_set_irn_data(phase, get_Eor_right(node));
vrp_left = get_vrp_attr(get_Eor_left(node));
vrp_right = get_vrp_attr(get_Eor_right(node));
bits_not_set = tarval_or(
tarval_and(vrp_left->bits_set, vrp_right->bits_set),
......@@ -289,7 +289,7 @@ static int vrp_update_node(ir_node *node)
}
case iro_Id: {
vrp_attr *vrp_pred = phase_get_or_set_irn_data(phase, get_Id_pred(node));
vrp_attr *vrp_pred = get_vrp_attr(get_Id_pred(node));
new_bits_set = vrp_pred->bits_set;
new_bits_not_set = vrp_pred->bits_not_set;
new_range_top = vrp_pred->range_top;
......@@ -299,7 +299,7 @@ static int vrp_update_node(ir_node *node)
}
case iro_Not: {
vrp_attr *vrp_pred = phase_get_or_set_irn_data(phase, get_Not_op(node));
vrp_attr *vrp_pred = get_vrp_attr(get_Not_op(node));
new_bits_set = tarval_or(vrp_pred->bits_not_set, vrp->bits_set);
new_bits_not_set = tarval_or(vrp_pred->bits_set, vrp->bits_not_set);
break;
......@@ -308,7 +308,7 @@ static int vrp_update_node(ir_node *node)
case iro_Conv: {
ir_node *pred = get_Conv_op(node);
ir_mode *old_mode = get_irn_mode(pred);
vrp_attr *vrp_pred = phase_get_or_set_irn_data(phase, pred);
vrp_attr *vrp_pred = get_vrp_attr(pred);
ir_mode *new_mode;
tarval *bits_not_set;
......@@ -382,7 +382,7 @@ static int vrp_update_node(ir_node *node)
int i;
ir_node *pred = get_Phi_pred(node,0);
vrp_attr *vrp_pred = phase_get_or_set_irn_data(phase, pred);
vrp_attr *vrp_pred = get_vrp_attr(pred);
new_range_top = vrp_pred->range_top;
new_range_bottom = vrp_pred->range_bottom;
new_range_type = vrp_pred->range_type;
......@@ -394,7 +394,7 @@ static int vrp_update_node(ir_node *node)
for (i = 1; i < num; i++) {