* @brief Backend IRG modification routines.
* @author Sebastian Hack, Daniel Grund, Matthias Braun, Christian Wuerdig
* @date 04.05.2005
- * @version $Id$
*
* This file contains the following IRG modifications for be routines:
* - insertion of Perm nodes
#include "irgraph_t.h"
#include "irgopt.h"
#include "irgmod.h"
-#include "irprintf_t.h"
+#include "irprintf.h"
#include "irgwalk.h"
#include "be_t.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
+static int cmp_node_nr(const void *a, const void *b)
+{
+ ir_node **p1 = (ir_node**)a;
+ ir_node **p2 = (ir_node**)b;
+ long n1 = get_irn_node_nr(*p1);
+ long n2 = get_irn_node_nr(*p2);
+ return (n1>n2) - (n1<n2);
+}
+
/*
___ _ ____
|_ _|_ __ ___ ___ _ __| |_ | _ \ ___ _ __ _ __ ___
*/
-ir_node *insert_Perm_after(ir_graph *irg, const arch_register_class_t *cls,
+ir_node *insert_Perm_before(ir_graph *irg, const arch_register_class_t *cls,
ir_node *pos)
{
- be_lv_t *lv = be_get_irg_liveness(irg);
- ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
- ir_nodeset_t live;
- ir_nodeset_iterator_t iter;
+ be_lv_t *lv = be_get_irg_liveness(irg);
+ ir_nodeset_t live;
- ir_node *irn, *perm, **nodes;
+ ir_node *perm, **nodes;
size_t i, n;
- DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos));
+ DBG((dbg, LEVEL_1, "Insert Perm before: %+F\n", pos));
ir_nodeset_init(&live);
- be_liveness_nodes_live_at(lv, cls, pos, &live);
+ be_liveness_nodes_live_before(lv, cls, pos, &live);
n = ir_nodeset_size(&live);
if (n == 0) {
i++;
}
ir_nodeset_destroy(&live);
+ /* make the input order deterministic */
+ qsort(nodes, n, sizeof(nodes[0]), cmp_node_nr);
+ ir_node *const bl = get_nodes_block(pos);
perm = be_new_Perm(cls, bl, n, nodes);
- sched_add_after(pos, perm);
+ sched_add_before(pos, perm);
free(nodes);
for (i = 0; i < n; ++i) {
ir_node *perm_op = get_irn_n(perm, i);
- const arch_register_t *reg = arch_get_irn_register(perm_op);
be_ssa_construction_env_t senv;
ir_mode *mode = get_irn_mode(perm_op);
ir_node *proj = new_r_Proj(perm, mode, i);
- arch_set_irn_register(proj, reg);
be_ssa_construction_init(&senv, irg);
be_ssa_construction_add_copy(&senv, perm_op);
*/
static void remove_empty_block(ir_node *block)
{
- const ir_edge_t *edge, *next;
- int i, arity;
- ir_node *node;
- ir_node *pred;
- ir_node *succ_block;
- ir_node *jump = NULL;
- ir_graph *irg = get_irn_irg(block);
+ int i;
+ int arity;
+ ir_node *pred;
+ ir_node *succ_block;
+ ir_node *jump = NULL;
+ ir_graph *irg = get_irn_irg(block);
+ ir_entity *entity;
if (irn_visited_else_mark(block))
return;
if (jump == NULL)
goto check_preds;
+ entity = get_Block_entity(block);
pred = get_Block_cfgpred(block, 0);
succ_block = NULL;
- foreach_out_edge_safe(jump, edge, next) {
+ foreach_out_edge_safe(jump, edge) {
int pos = get_edge_src_pos(edge);
assert(succ_block == NULL);
succ_block = get_edge_src_irn(edge);
- if (has_Block_entity(succ_block) && has_Block_entity(block)) {
+ if (get_Block_entity(succ_block) != NULL && entity != NULL) {
/*
* Currently we can add only one label for a block.
* Therefore we cannot combine them if both block already have one.
set_irn_n(succ_block, pos, pred);
}
- if (has_Block_entity(block)) {
+ if (entity != NULL) {
/* move the label to the successor block */
- ir_entity *entity = get_Block_entity(block);
set_Block_entity(succ_block, entity);
}
/* there can be some non-scheduled Pin nodes left in the block, move them
* to the succ block (Pin) or pred block (Sync) */
- foreach_out_edge_safe(block, edge, next) {
- node = get_edge_src_irn(edge);
+ foreach_out_edge_safe(block, edge) {
+ ir_node *const node = get_edge_src_irn(edge);
if (node == jump)
continue;
if (blocks_removed) {
/* invalidate analysis info */
- clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE);
- set_irg_extblk_inconsistent(irg);
+ clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE);
}
return blocks_removed;
}
/* kill projs */
if (get_irn_mode(node) == mode_T) {
- const ir_edge_t *edge;
- const ir_edge_t *next_edge;
- foreach_out_edge_safe(node, edge, next_edge) {
+ foreach_out_edge_safe(node, edge) {
ir_node *proj = get_edge_src_irn(edge);
if (!is_Proj(proj))
continue;