Rework linkage types in firm.
[libfirm] / ir / be / beflags.c
index 19af144..0a3871a 100644 (file)
@@ -35,9 +35,7 @@
  * spilled. So in some situations (for example 2 adc-nodes that use the flags of
  * a single add node on x86) operations have to be repeated to work correctly.
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include "irgwalk.h"
 #include "irnode_t.h"
 #include "error.h"
 
 #include "beflags.h"
-#include "bearch_t.h"
-#include "beirg_t.h"
-#include "besched_t.h"
-#include "benode_t.h"
+#include "bearch.h"
+#include "beirg.h"
+#include "besched.h"
+#include "benode.h"
+#include "belive.h"
 
 static const arch_register_class_t *flag_class = NULL;
 static const arch_register_t       *flags_reg  = NULL;
@@ -74,7 +73,7 @@ static ir_node *default_remat(ir_node *node, ir_node *after)
 }
 
 /**
- * tests wether we can legally move node node after node after
+ * tests whether we can legally move node node after node after
  * (only works for nodes in same block)
  */
 static int can_move(ir_node *node, ir_node *after)
@@ -93,15 +92,15 @@ static int can_move(ir_node *node, ir_node *after)
                        assert(get_irn_n_edges_kind(out, EDGE_KIND_DEP) == 0);
                        foreach_out_edge(out, edge2) {
                                ir_node *out2 = get_edge_src_irn(edge2);
-                               /* phi represents a usage at block end */
-                               if(is_Phi(out2))
+                               /* Phi or End represents a usage at block end. */
+                               if(is_Phi(out2) || is_End(out2))
                                        continue;
                                if(is_Sync(out2)) {
                                        const ir_edge_t *edge3;
                                        foreach_out_edge(out2, edge3) {
                                                ir_node *out3 = get_edge_src_irn(edge3);
-                                               /* phi represents a usage at block end */
-                                               if(is_Phi(out3))
+                                               /* Phi or End represents a usage at block end. */
+                                               if(is_Phi(out3) || is_End(out3))
                                                        continue;
                                                assert(!is_Sync(out3));
                                                if(sched_get_time_step(out3) <= sched_get_time_step(after)) {
@@ -148,8 +147,7 @@ static void rematerialize_or_move(ir_node *flags_needed, ir_node *node,
        if(get_irn_mode(copy) == mode_T) {
                ir_node *block = get_nodes_block(copy);
                ir_mode *mode  = flag_class->mode;
-               value = new_rd_Proj(NULL, current_ir_graph, block,
-                                                       copy, mode, pn);
+               value = new_rd_Proj(NULL, block, copy, mode, pn);
        } else {
                value = copy;
        }
@@ -175,8 +173,10 @@ static void rematerialize_or_move(ir_node *flags_needed, ir_node *node,
                        get_nodes_block(node) != get_nodes_block(flags_needed)) {
                int i;
 
-               for (i = get_irn_arity(copy) - 1; i >= 0; --i) {
-                       be_liveness_update(lv, get_irn_n(copy, i));
+               if (lv != NULL) {
+                       for (i = get_irn_arity(copy) - 1; i >= 0; --i) {
+                               be_liveness_update(lv, get_irn_n(copy, i));
+                       }
                }
        }
 }