-#ifdef USE_GSL
- freq->freq = ZERO(gsl_vector_get(x, idx)) ? 0.0 : gsl_vector_get(x, idx);
-#else
- freq->freq = ZERO(x[idx]) ? 0.0 : x[idx];
-#endif
- /* Get the minimum non-zero execution frequency. */
- if(freq->freq != 0.0)
- ef->min_non_zero = MIN(ef->min_non_zero, freq->freq);
- }
+ dfs_free(dfs);
+
+ /*
+ * Add a loop 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);
+
+ /* solve the system and delete the matrix */
+ solve_lgs(mat, x, size);
+ gs_delete_matrix(mat);
+
+ /*
+ * compute the normalization factor.
+ * 1.0 / exec freq of start block.
+ */
+ norm = x[s->idx] != 0.0 ? 1.0 / x[s->idx] : 1.0;
+
+ ef->max = 0.0;
+ set_foreach(freqs, freq) {
+ int idx = freq->idx;
+
+ /* take abs because it sometimes can be -0 in case of endless loops */
+ freq->freq = fabs(x[idx]) * norm;
+
+ /* get the maximum exec freq */
+ ef->max = MAX(ef->max, freq->freq);
+
+ /* Get the minimum non-zero execution frequency. */
+ if(freq->freq > 0.0)
+ ef->min_non_zero = MIN(ef->min_non_zero, freq->freq);
+ }