#include "ircons.h"
#include "iredges_t.h"
+#include "statev_t.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
return info != NULL && info->is_definition;
}
-/**
- * @return Whether the node is a use.
- */
-static bool is_use(const be_ssa_construction_env_t *env, ir_node *node)
-{
- constr_info *info = get_info(env, node);
- return info != NULL && info->is_use;
-}
-
/**
* Introduces a definition at the corresponding block.
*/
return search_def_end_of_block(env, dom);
}
+static ir_node *get_def_from_preds(be_ssa_construction_env_t *const env, ir_node *const block)
+{
+ /* Create a phi if the block is in the dominance frontier. */
+ if (Block_block_visited(block)) {
+ return insert_dummy_phi(env, block);
+ } else {
+ return get_def_at_idom(env, block);
+ }
+}
+
/**
* Fixes all operands of a use.
*
* If an operand of the use is a (original) definition,
* it will be replaced by the given definition.
*/
-static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node *def)
+static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node *def, constr_info *const use_info)
{
- constr_info *info = get_info(env, use);
- int arity = get_irn_arity(use);
- int i;
-
- for (i = 0; i < arity; ++i) {
+ int arity = get_irn_arity(use);
+ for (int i = 0; i < arity; ++i) {
ir_node *op = get_irn_n(use, i);
if (is_definition(env, op)) {
}
}
- info->already_processed = true;
+ use_info->already_processed = true;
}
/**
*/
static void process_block(be_ssa_construction_env_t *env, ir_node *block)
{
- ir_node *node;
ir_node *def = NULL;
constr_info *block_info = get_or_set_info(env, block);
DBG((dbg, LEVEL_3, "\tprocessing block %+F\n", block));
sched_foreach(block, node) {
- if (is_use(env, node) && !is_Phi(node)) {
+ constr_info *const info = get_info(env, node);
+ if (!info)
+ continue;
+
+ if (info->is_use && !is_Phi(node)) {
DBG((dbg, LEVEL_3, "\t...found use %+F\n", node));
if (def == NULL) {
/* Create a phi if the block is in the dominance frontier. */
- if (Block_block_visited(block)) {
- def = insert_dummy_phi(env, block);
- }
- else {
- def = get_def_at_idom(env, block);
- }
+ def = get_def_from_preds(env, block);
}
- set_operands(env, node, def);
+ set_operands(env, node, def, info);
}
- if (is_definition(env, node)) {
- constr_info *info = get_info(env, node);
+ if (info->is_definition) {
def = info->u.definition;
DBG((dbg, LEVEL_3, "\t...found definition %+F\n", def));
}
}
}
else {
- ir_node *def = NULL;
-
/* Search the last definition of the block. */
sched_foreach_reverse(block, def) {
- if (is_definition(env, def)) {
- constr_info *info = get_info(env, def);
- def = info->u.definition;
- DBG((dbg, LEVEL_3, "\t...found definition %+F\n", def));
-
+ constr_info const *const info = get_info(env, def);
+ if (info && info->is_definition) {
+ DBG((dbg, LEVEL_3, "\t...found definition %+F\n", info->u.definition));
+ block_info->u.last_definition = info->u.definition;
break;
}
}
- assert(def && "No definition found");
-
- block_info->u.last_definition = def;
+ assert(block_info->u.last_definition && "No definition found");
}
return block_info->u.last_definition;
- } else if (Block_block_visited(block)) {
- ir_node *phi = insert_dummy_phi(env, block);
-
- block_info->u.last_definition = phi;
-
- return phi;
} else {
- ir_node *def = get_def_at_idom(env, block);
-
+ ir_node *const def = get_def_from_preds(env, block);
block_info->u.last_definition = def;
-
return def;
}
}
/**
* Fixes all operands of the given use.
*/
-static void search_def_at_block(be_ssa_construction_env_t *env, ir_node *use)
+static void search_def_at_block(be_ssa_construction_env_t *const env, ir_node *const use, constr_info *const info)
{
ir_node *block = get_nodes_block(use);
constr_info *block_info = get_or_set_info(env, block);
if (has_definition(block)) {
process_block(env, block);
- } else if (Block_block_visited(block)) {
- ir_node *phi = insert_dummy_phi(env, block);
-
- set_operands(env, use, phi);
} else {
- ir_node *def = get_def_at_idom(env, block);
-
- set_operands(env, use, def);
+ ir_node *const def = get_def_from_preds(env, block);
+ set_operands(env, use, def, info);
}
}
ir_node *sb = get_irg_start_block(irg);
int n_blocks = get_Block_dom_max_subtree_pre_num(sb);
- stat_ev_ctx_push_fobj("bessaconstr", irg);
+ stat_ev_ctx_push_fmt("bessaconstr", "%+F", irg);
stat_ev_tim_push();
(void) n_blocks;
}
}
-void be_ssa_construction_set_ignore_uses(be_ssa_construction_env_t *env,
- const ir_nodeset_t *ignore_uses)
-{
- env->ignore_uses = ignore_uses;
-}
-
ir_node **be_ssa_construction_get_new_phis(be_ssa_construction_env_t *env)
{
return env->new_phis;
*
* @see insert_dummy_phi
*/
-static void fix_phi_arguments(be_ssa_construction_env_t *env, ir_node *phi)
+static void fix_phi_arguments(be_ssa_construction_env_t *const env, ir_node *const phi, constr_info *const info)
{
- constr_info *info = get_info(env, phi);
- ir_node *block = get_nodes_block(phi);
- int i;
- int n_preds = get_Block_n_cfgpreds(block);
+ ir_node *block = get_nodes_block(phi);
+ int n_preds = get_Block_n_cfgpreds(block);
DBG((dbg, LEVEL_3, "\tfixing phi arguments %+F\n", phi));
- for (i = 0; i < n_preds; ++i) {
+ for (int i = 0; i < n_preds; ++i) {
ir_node *op = get_irn_n(phi, i);
if (is_definition(env, op) || is_Dummy(op)) {
introduce_definition(env, value);
foreach_out_edge_safe(value, edge) {
- ir_node *use = get_edge_src_irn(edge);
-
- if (env->ignore_uses != NULL &&
- ir_nodeset_contains(env->ignore_uses, use))
- continue;
-
+ ir_node *const use = get_edge_src_irn(edge);
if (is_Anchor(use) || is_End(use))
continue;
continue;
if (is_Phi(use)) {
- fix_phi_arguments(env, use);
+ fix_phi_arguments(env, use, info);
}
else {
DBG((dbg, LEVEL_3, "\tsearching def for %+F at %+F\n", use, get_nodes_block(use)));
- search_def_at_block(env, use);
+ search_def_at_block(env, use, info);
}
stat_ev_cnt_inc(uses);