- for(i = get_Block_n_cfgpreds(bb) - 1; i >= 0; --i) {
- ir_node *pred = get_Block_cfgpred_block(bb, i);
- size_t pred_idx = (int)get_irn_link(pred);
-
- // matrix[pred_idx + idx*size] += 1.0/(double)get_Block_n_cfg_outs(pred);
- matrix[pred_idx + idx * size] += get_cf_probability(bb, i, loop_weight);
+ dfs_free(dfs);
+
+ /*
+ * Add an edge from end to start.
+ * The problem is then an eigenvalue problem:
+ * Solve A*x = 1*x => (A-I)x = 0
+ */
+ s = set_find_freq(freqs, get_irg_start_block(irg));
+
+ e = set_find_freq(freqs, get_irg_end_block(irg));
+ if (e->idx >= 0)
+ gs_matrix_set(mat, s->idx, e->idx, 1.0);
+
+ /*
+ * Also add an edge for each kept block to start.
+ *
+ * This avoid strange results for e.g. an irg containing a exit()-call
+ * which block has no cfg successor.
+ */
+ n_keepalives = get_End_n_keepalives(end);
+ for (idx = n_keepalives - 1; idx >= 0; --idx) {
+ ir_node *keep = get_End_keepalive(end, idx);
+
+ if (is_Block(keep) && get_Block_n_cfg_outs(keep) == 0) {
+ freq_t *k = set_find_freq(freqs, keep);
+ if (k->idx >= 0)
+ gs_matrix_set(mat, s->idx, k->idx, 1.0);