#include "tree-cfgcleanup.h"
#include "hwint.h"
#include "internal-fn.h"
+#include "diagnostic-core.h"
/* ??? For lang_hooks.types.type_for_mode, but is there a word_mode
type in the GIMPLE type system that is language-independent? */
return clusters.copy ();
unsigned l = clusters.length ();
+
+ /* Note: l + 1 is the number of cases of the switch. */
+ if (l + 1 > (unsigned) param_switch_lower_slow_alg_max_cases)
+ return clusters.copy ();
+
auto_vec<min_cluster_item> min;
min.reserve (l + 1);
return end - start + 1 >= case_values_threshold ();
}
-/* Find bit tests of given CLUSTERS, where all members of the vector
- are of type simple_cluster. MAX_C is the approx max number of cases per
- label. New clusters are returned. */
+/* Find bit tests of given CLUSTERS, where all members of the vector are of
+ type simple_cluster. Use a fast algorithm that might not find the optimal
+ solution (minimal number of clusters on the output). New clusters are
+ returned.
+
+ You should call find_bit_tests () instead of calling this function
+ directly. */
vec<cluster *>
-bit_test_cluster::find_bit_tests (vec<cluster *> &clusters, int max_c)
+bit_test_cluster::find_bit_tests_fast (vec<cluster *> &clusters)
{
- if (!is_enabled () || max_c == 1)
- return clusters.copy ();
+ unsigned l = clusters.length ();
+ vec<cluster *> output;
+
+ output.create (l);
+
+ /* Look at sliding BITS_PER_WORD sized windows in the switch value space
+ and determine if they are suitable for a bit test cluster. Worst case
+ this can examine every value BITS_PER_WORD-1 times. */
+ unsigned k;
+ for (unsigned i = 0; i < l; i += k)
+ {
+ hash_set<basic_block> targets;
+ cluster *start_cluster = clusters[i];
+
+ /* Find the biggest k such that clusters i to i+k-1 can be turned into a
+ one big bit test cluster. */
+ k = 0;
+ while (i + k < l)
+ {
+ cluster *end_cluster = clusters[i + k];
+
+ /* Does value range fit into the BITS_PER_WORD window? */
+ HOST_WIDE_INT w = cluster::get_range (start_cluster->get_low (),
+ end_cluster->get_high ());
+ if (w == 0 || w > BITS_PER_WORD)
+ break;
+
+ /* Check for max # of targets. */
+ if (targets.elements () == m_max_case_bit_tests
+ && !targets.contains (end_cluster->m_case_bb))
+ break;
+
+ targets.add (end_cluster->m_case_bb);
+ k++;
+ }
+ if (is_beneficial (k, targets.elements ()))
+ {
+ output.safe_push (new bit_test_cluster (clusters, i, i + k - 1,
+ i == 0 && k == l));
+ }
+ else
+ {
+ output.safe_push (clusters[i]);
+ /* ??? Might be able to skip more. */
+ k = 1;
+ }
+ }
+
+ return output;
+}
+
+/* Find bit tests of given CLUSTERS, where all members of the vector
+ are of type simple_cluster. Use a slow (quadratic) algorithm that always
+ finds the optimal solution (minimal number of clusters on the output). New
+ clusters are returned.
+
+ You should call find_bit_tests () instead of calling this function
+ directly. */
+
+vec<cluster *>
+bit_test_cluster::find_bit_tests_slow (vec<cluster *> &clusters)
+{
unsigned l = clusters.length ();
auto_vec<min_cluster_item> min;
min.reserve (l + 1);
return output;
}
+/* Find bit tests of given CLUSTERS, where all members of the vector
+ are of type simple_cluster. MAX_C is the approx max number of cases per
+ label. New clusters are returned. */
+
+vec<cluster *>
+bit_test_cluster::find_bit_tests (vec<cluster *> &clusters, int max_c)
+{
+ if (!is_enabled () || max_c == 1)
+ return clusters.copy ();
+
+ unsigned l = clusters.length ();
+
+ /* Note: l + 1 is the number of cases of the switch. */
+ if (l + 1 > (unsigned) param_switch_lower_slow_alg_max_cases)
+ return find_bit_tests_fast (clusters);
+ else
+ return find_bit_tests_slow (clusters);
+}
+
/* Return true when RANGE of case values with UNIQ labels
can build a bit test. */
reset_out_edges_aux (m_switch);
+ if (l > (unsigned) param_switch_lower_slow_alg_max_cases)
+ warning_at (gimple_location (m_switch), OPT_Wdisabled_optimization,
+ "Using faster switch lowering algorithms. "
+ "Number of switch cases (%d) exceeds "
+ "%<--param=switch-lower-slow-alg-max-cases=%d%> limit.",
+ l, param_switch_lower_slow_alg_max_cases);
+
/* Find bit-test clusters. */
vec<cluster *> output = bit_test_cluster::find_bit_tests (clusters, max_c);
- /* Find jump table clusters. */
+ /* Find jump table clusters. We are looking for these in the sequences of
+ simple clusters which we didn't manage to convert into bit-test
+ clusters. */
vec<cluster *> output2;
auto_vec<cluster *> tmp;
output2.create (1);
tree default_label_expr, basic_block default_bb, location_t loc)
final override;
+ /* Find bit tests of given CLUSTERS, where all members of the vector are of
+ type simple_cluster. Use a fast algorithm that might not find the optimal
+ solution (minimal number of clusters on the output). New clusters are
+ returned.
+
+ You should call find_bit_tests () instead of calling this function
+ directly. */
+ static vec<cluster *> find_bit_tests_fast (vec<cluster *> &clusters);
+
+ /* Find bit tests of given CLUSTERS, where all members of the vector
+ are of type simple_cluster. Use a slow (quadratic) algorithm that always
+ finds the optimal solution (minimal number of clusters on the output). New
+ clusters are returned.
+
+ You should call find_bit_tests () instead of calling this function
+ directly. */
+ static vec<cluster *> find_bit_tests_slow (vec<cluster *> &clusters);
+
/* Find bit tests of given CLUSTERS, where all members of the vector
are of type simple_cluster. New clusters are returned. */
static vec<cluster *> find_bit_tests (vec<cluster *> &clusters, int max_c);