projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some more cleanup: Put the return type and other specifiers on the same line as the...
[libfirm]
/
ir
/
opt
/
cfopt.c
diff --git
a/ir/opt/cfopt.c
b/ir/opt/cfopt.c
index
4e5cc69
..
e2a658a
100644
(file)
--- a/
ir/opt/cfopt.c
+++ b/
ir/opt/cfopt.c
@@
-50,6
+50,7
@@
#include "irflag_t.h"
#include "firmstat.h"
#include "irflag_t.h"
#include "firmstat.h"
+#include "irpass.h"
#include "iropt_dbg.h"
#include "iropt_dbg.h"
@@
-85,7
+86,8
@@
* Note that the simple case that Block has only these two
* predecessors are already handled in equivalent_node_Block().
*/
* Note that the simple case that Block has only these two
* predecessors are already handled in equivalent_node_Block().
*/
-static int remove_senseless_conds(ir_node *bl) {
+static int remove_senseless_conds(ir_node *bl)
+{
int i, j;
int n = get_Block_n_cfgpreds(bl);
int changed = 0;
int i, j;
int n = get_Block_n_cfgpreds(bl);
int changed = 0;
@@
-102,7
+104,7
@@
static int remove_senseless_conds(ir_node *bl) {
ir_node *cond_j = skip_Proj(pred_j);
if (cond_j == cond_i) {
ir_node *cond_j = skip_Proj(pred_j);
if (cond_j == cond_i) {
- ir_node *jmp = new_r_Jmp(
current_ir_graph,
get_nodes_block(cond_i));
+ ir_node *jmp = new_r_Jmp(get_nodes_block(cond_i));
set_irn_n(bl, i, jmp);
set_irn_n(bl, j, new_Bad());
set_irn_n(bl, i, jmp);
set_irn_n(bl, j, new_Bad());
@@
-130,7
+132,8
@@
typedef struct _merge_env {
* Therefore we also optimize at control flow operations, depending
* how we first reach the Block.
*/
* Therefore we also optimize at control flow operations, depending
* how we first reach the Block.
*/
-static void merge_blocks(ir_node *node, void *ctx) {
+static void merge_blocks(ir_node *node, void *ctx)
+{
int i;
ir_node *new_block;
merge_env *env = ctx;
int i;
ir_node *new_block;
merge_env *env = ctx;
@@
-198,7
+201,8
@@
static void merge_blocks(ir_node *node, void *ctx) {
*
* Must be run in the post walker.
*/
*
* Must be run in the post walker.
*/
-static void remove_unreachable_blocks_and_conds(ir_node *block, void *env) {
+static void remove_unreachable_blocks_and_conds(ir_node *block, void *env)
+{
int i;
int *changed = env;
int i;
int *changed = env;
@@
-225,7
+229,7
@@
static void remove_unreachable_blocks_and_conds(ir_node *block, void *env) {
*changed |= remove_senseless_conds(block);
/* clear the block mark of all non labeled blocks */
*changed |= remove_senseless_conds(block);
/* clear the block mark of all non labeled blocks */
- if (has_Block_
label
(block))
+ if (has_Block_
entity
(block))
set_Block_non_removable(block);
else
set_Block_removable(block);
set_Block_non_removable(block);
else
set_Block_removable(block);
@@
-238,13
+242,14
@@
static void remove_unreachable_blocks_and_conds(ir_node *block, void *env) {
* Links all Proj nodes to their predecessors.
* Collects all switch-Conds in a list.
*/
* Links all Proj nodes to their predecessors.
* Collects all switch-Conds in a list.
*/
-static void collect_nodes(ir_node *n, void *ctx) {
+static void collect_nodes(ir_node *n, void *ctx)
+{
ir_opcode code = get_irn_opcode(n);
merge_env *env = ctx;
if (code == iro_Block) {
/* mark the block as non-removable if it is labeled */
ir_opcode code = get_irn_opcode(n);
merge_env *env = ctx;
if (code == iro_Block) {
/* mark the block as non-removable if it is labeled */
- if (has_Block_
label
(n))
+ if (has_Block_
entity
(n))
set_Block_non_removable(n);
} else {
ir_node *b = get_nodes_block(n);
set_Block_non_removable(n);
} else {
ir_node *b = get_nodes_block(n);
@@
-273,7
+278,8
@@
static void collect_nodes(ir_node *n, void *ctx) {
}
/** Returns true if pred is predecessor of block. */
}
/** Returns true if pred is predecessor of block. */
-static int is_pred_of(ir_node *pred, ir_node *b) {
+static int is_pred_of(ir_node *pred, ir_node *b)
+{
int i;
for (i = get_Block_n_cfgpreds(b) - 1; i >= 0; --i) {
int i;
for (i = get_Block_n_cfgpreds(b) - 1; i >= 0; --i) {
@@
-311,7
+317,8
@@
static int is_pred_of(ir_node *pred, ir_node *b) {
* To perform the test for pos, we must regard predecessors before pos
* as already removed.
**/
* To perform the test for pos, we must regard predecessors before pos
* as already removed.
**/
-static int test_whether_dispensable(ir_node *b, int pos) {
+static int test_whether_dispensable(ir_node *b, int pos)
+{
int i, j, n_preds = 1;
ir_node *pred = get_Block_cfgpred_block(b, pos);
int i, j, n_preds = 1;
ir_node *pred = get_Block_cfgpred_block(b, pos);
@@
-410,7
+417,8
@@
non_dispensable:
* @@@ It is negotiable whether we should do this ... there might end up a copy
* from the Phi in the loop when removing the Phis.
*/
* @@@ It is negotiable whether we should do this ... there might end up a copy
* from the Phi in the loop when removing the Phis.
*/
-static void optimize_blocks(ir_node *b, void *ctx) {
+static void optimize_blocks(ir_node *b, void *ctx)
+{
int i, j, k, n, max_preds, n_preds, p_preds = -1;
ir_node *pred, *phi, *next;
ir_node **in;
int i, j, k, n, max_preds, n_preds, p_preds = -1;
ir_node *pred, *phi, *next;
ir_node **in;
@@
-562,7
+570,7
@@
static void optimize_blocks(ir_node *b, void *ctx) {
/* case 1: Do nothing */
} else if (is_Block_removable(pred) && !Block_block_visited(pred)) {
/* case 2: It's an empty block and not yet visited. */
/* case 1: Do nothing */
} else if (is_Block_removable(pred) && !Block_block_visited(pred)) {
/* case 2: It's an empty block and not yet visited. */
- assert(get_Block_n_cfgpreds(b) > 1 || has_Block_
label
(b));
+ assert(get_Block_n_cfgpreds(b) > 1 || has_Block_
entity
(b));
/* Else it should be optimized by equivalent_node. */
for (j = 0; j < get_Block_n_cfgpreds(pred); j++) {
ir_node *pred_X = get_Block_cfgpred(pred, j);
/* Else it should be optimized by equivalent_node. */
for (j = 0; j < get_Block_n_cfgpreds(pred); j++) {
ir_node *pred_X = get_Block_cfgpred(pred, j);
@@
-592,7
+600,8
@@
static void optimize_blocks(ir_node *b, void *ctx) {
* Block walker: optimize all blocks using the default optimizations.
* This removes Blocks that with only a Jmp predecessor.
*/
* Block walker: optimize all blocks using the default optimizations.
* This removes Blocks that with only a Jmp predecessor.
*/
-static void remove_simple_blocks(ir_node *block, void *ctx) {
+static void remove_simple_blocks(ir_node *block, void *ctx)
+{
ir_node *new_blk = equivalent_node(block);
merge_env *env = ctx;
ir_node *new_blk = equivalent_node(block);
merge_env *env = ctx;
@@
-614,7
+623,8
@@
static void remove_simple_blocks(ir_node *block, void *ctx) {
*
* Expects all Proj's linked to the cond node
*/
*
* Expects all Proj's linked to the cond node
*/
-static int handle_switch_cond(ir_node *cond) {
+static int handle_switch_cond(ir_node *cond)
+{
ir_node *sel = get_Cond_selector(cond);
ir_node *proj1 = get_irn_link(cond);
ir_node *sel = get_Cond_selector(cond);
ir_node *proj1 = get_irn_link(cond);
@@
-627,7
+637,7
@@
static int handle_switch_cond(ir_node *cond) {
/* this Cond has only one Proj: must be the defProj */
assert(get_Cond_default_proj(cond) == get_Proj_proj(proj1));
/* convert it into a Jmp */
/* this Cond has only one Proj: must be the defProj */
assert(get_Cond_default_proj(cond) == get_Proj_proj(proj1));
/* convert it into a Jmp */
- jmp = new_r_Jmp(
current_ir_graph,
blk);
+ jmp = new_r_Jmp(blk);
exchange(proj1, jmp);
return 1;
} else if (get_irn_link(proj2) == NULL) {
exchange(proj1, jmp);
return 1;
} else if (get_irn_link(proj2) == NULL) {
@@
-643,7
+653,7
@@
static int handle_switch_cond(ir_node *cond) {
if (def_num == get_Proj_proj(proj1)) {
/* first one is the defProj */
if (num == get_Proj_proj(proj2)) {
if (def_num == get_Proj_proj(proj1)) {
/* first one is the defProj */
if (num == get_Proj_proj(proj2)) {
- jmp = new_r_Jmp(
current_ir_graph,
blk);
+ jmp = new_r_Jmp(blk);
exchange(proj2, jmp);
exchange(proj1, new_Bad());
return 1;
exchange(proj2, jmp);
exchange(proj1, new_Bad());
return 1;
@@
-651,7
+661,7
@@
static int handle_switch_cond(ir_node *cond) {
} else if (def_num == get_Proj_proj(proj2)) {
/* second one is the defProj */
if (num == get_Proj_proj(proj1)) {
} else if (def_num == get_Proj_proj(proj2)) {
/* second one is the defProj */
if (num == get_Proj_proj(proj1)) {
- jmp = new_r_Jmp(
current_ir_graph,
blk);
+ jmp = new_r_Jmp(blk);
exchange(proj1, jmp);
exchange(proj2, new_Bad());
return 1;
exchange(proj1, jmp);
exchange(proj2, new_Bad());
return 1;
@@
-659,12
+669,12
@@
static int handle_switch_cond(ir_node *cond) {
} else {
/* neither: strange, Cond was not optimized so far */
if (num == get_Proj_proj(proj1)) {
} else {
/* neither: strange, Cond was not optimized so far */
if (num == get_Proj_proj(proj1)) {
- jmp = new_r_Jmp(
current_ir_graph,
blk);
+ jmp = new_r_Jmp(blk);
exchange(proj1, jmp);
exchange(proj2, new_Bad());
return 1;
} else if (num == get_Proj_proj(proj2)) {
exchange(proj1, jmp);
exchange(proj2, new_Bad());
return 1;
} else if (num == get_Proj_proj(proj2)) {
- jmp = new_r_Jmp(
current_ir_graph,
blk);
+ jmp = new_r_Jmp(blk);
exchange(proj2, jmp);
exchange(proj1, new_Bad());
return 1;
exchange(proj2, jmp);
exchange(proj1, new_Bad());
return 1;
@@
-691,7
+701,8
@@
static int handle_switch_cond(ir_node *cond) {
* We use the mark flag to mark removable blocks in the first
* phase.
*/
* We use the mark flag to mark removable blocks in the first
* phase.
*/
-void optimize_cf(ir_graph *irg) {
+void optimize_cf(ir_graph *irg)
+{
int i, j, n, changed;
ir_node **in = NULL;
ir_node *cond, *end = get_irg_end(irg);
int i, j, n, changed;
ir_node **in = NULL;
ir_node *cond, *end = get_irg_end(irg);
@@
-873,3
+884,9
@@
restart:
current_ir_graph = rem;
}
current_ir_graph = rem;
}
+
+/* Creates an ir_graph pass for optimize_cf. */
+ir_graph_pass_t *optimize_cf_pass(const char *name)
+{
+ return def_graph_pass(name ? name : "optimize_cf", optimize_cf);
+} /* optimize_cf_pass */