+/**
+ * If an SCC is a Phi only cycle, remove it.
+ */
+static void remove_phi_cycle(scc *pscc, iv_env *env) {
+ ir_node *irn, *next;
+ int j;
+ ir_node *out_rc;
+
+ /* check if this scc contains only Phi, Add or Sub nodes */
+ out_rc = NULL;
+ for (irn = pscc->head; irn; irn = next) {
+ node_entry *e = get_irn_ne(irn, env);
+
+ next = e->next;
+ if (! is_Phi(irn))
+ return;
+
+ for (j = get_irn_arity(irn) - 1; j >= 0; --j) {
+ ir_node *pred = get_irn_n(irn, j);
+ node_entry *pe = get_irn_ne(pred, env);
+
+ if (pe->pscc != e->pscc) {
+ /* not in the same SCC, must be the only input */
+ if (! out_rc) {
+ out_rc = pred;
+ } else if (out_rc != pred) {
+ return;
+ }
+ }
+ }
+ }
+ /* found a Phi cycle */
+ DB((dbg, LEVEL_2, " Found an USELESS Phi cycle:\n "));
+
+ for (irn = pscc->head; irn; irn = next) {
+ node_entry *e = get_irn_ne(irn, env);
+ next = e->next;
+ e->header = NULL;
+ exchange(irn, out_rc);
+ }
+ ++env->replaced;
+}
+
+/**
+ * Process a SCC for the Phi cycle removement.
+ *
+ * @param pscc the SCC
+ * @param env the environment
+ */
+static void process_phi_only_scc(scc *pscc, iv_env *env) {
+ ir_node *head = pscc->head;
+ node_entry *e = get_irn_link(head);
+
+#ifdef DEBUG_libfirm
+ {
+ ir_node *irn, *next;
+
+ DB((dbg, LEVEL_4, " SCC at %p:\n ", pscc));
+ for (irn = pscc->head; irn; irn = next) {
+ node_entry *e = get_irn_link(irn);
+
+ next = e->next;
+
+ DB((dbg, LEVEL_4, " %+F,", irn));
+ }
+ DB((dbg, LEVEL_4, "\n"));
+ }
+#endif
+
+ if (e->next != NULL)
+ remove_phi_cycle(pscc, env);
+}
+
+