From 4cfa46c8af9b89461914a1fd2f843a9b17e996dc Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Wed, 3 Nov 2004 08:04:56 -0700 Subject: [PATCH] stmt.c (expand_case): Speed up code to detect duplicate case label targets and count unique case... * stmt.c (expand_case): Speed up code to detect duplicate case label targets and count unique case label targets. From-SVN: r90027 --- gcc/ChangeLog | 5 +++++ gcc/stmt.c | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e71cba6cfb4..cbc5bc6f5c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-11-03 Jeff Law + + * stmt.c (expand_case): Speed up code to detect duplicate case + label targets and count unique case label targets. + 2004-11-03 Kazu Hirata * cppdefault.c, cppdefault.h, timevar.h: Update copyright. diff --git a/gcc/stmt.c b/gcc/stmt.c index f9efbfee0b2..08dabdef1cf 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -2317,7 +2317,7 @@ expand_case (tree exp) { tree minval = NULL_TREE, maxval = NULL_TREE, range = NULL_TREE; rtx default_label = 0; - struct case_node *n, *m; + struct case_node *n; unsigned int count, uniq; rtx index; rtx table_label; @@ -2354,6 +2354,7 @@ expand_case (tree exp) if (index_type != error_mark_node) { tree elt; + bitmap label_bitmap; /* cleanup_tree_cfg removes all SWITCH_EXPR with their index expressions being INTEGER_CST. */ @@ -2392,6 +2393,7 @@ expand_case (tree exp) uniq = 0; count = 0; + label_bitmap = BITMAP_XMALLOC (); for (n = case_list; n; n = n->right) { /* Count the elements and track the largest and smallest @@ -2412,17 +2414,18 @@ expand_case (tree exp) if (! tree_int_cst_equal (n->low, n->high)) count++; - /* Count the number of unique case node targets. */ - uniq++; + /* If we have not seen this label yet, then increase the + number of unique case node targets seen. */ lab = label_rtx (n->code_label); - for (m = case_list; m != n; m = m->right) - if (label_rtx (m->code_label) == lab) - { - uniq--; - break; - } + if (!bitmap_bit_p (label_bitmap, CODE_LABEL_NUMBER (lab))) + { + bitmap_set_bit (label_bitmap, CODE_LABEL_NUMBER (lab)); + uniq++; + } } + BITMAP_XFREE (label_bitmap); + /* cleanup_tree_cfg removes all SWITCH_EXPR with a single destination, such as one with a default case only. */ gcc_assert (count != 0);