Fix gcov mips switch table interaction bug reported to bug-gcc.
authorJim Wilson <wilson@cygnus.com>
Thu, 23 Apr 1998 19:10:52 +0000 (19:10 +0000)
committerJim Wilson <wilson@gcc.gnu.org>
Thu, 23 Apr 1998 19:10:52 +0000 (12:10 -0700)
* profile.c (tablejump_entry_p): New function.
(branch_prob): Add code to recognize MIPS tablejump entry branch.
Use tablejump_entry_p in MIPS and HPPA tablejump checking code.

From-SVN: r19388

gcc/ChangeLog
gcc/profile.c

index 7ad6dfd35e6752466cab5d1c93bf4c221985f0ec..24a5a0836c7028ba4cdf8caade6d56e93dfa35d0 100644 (file)
@@ -1,3 +1,9 @@
+Thu Apr 23 19:09:33 1998  Jim Wilson  <wilson@cygnus.com>
+
+       * profile.c (tablejump_entry_p): New function.
+       (branch_prob): Add code to recognize MIPS tablejump entry branch.
+       Use tablejump_entry_p in MIPS and HPPA tablejump checking code.
+
 Thu Apr 23 15:01:13 1998  Nick Clifton  <nickc@cygnus.com>
 
        * config/arm/arm.c (find_barrier): Return as soon as a barrier is
index bec6ca36d6aa22731a48aa13044aee998bd919e5..8b6fff5be987ee864ece4383adaa1a82fb7f032a 100644 (file)
@@ -413,6 +413,25 @@ output_gcov_string (string, delimiter)
   __write_long (delimiter, bb_file, 4);
 }
 \f
+/* Return TRUE if this insn must be a tablejump entry insn.  This works for
+   the MIPS port, but may give false negatives for some targets.  */
+
+int
+tablejump_entry_p (insn, label)
+     rtx insn, label;
+{
+  rtx next = next_active_insn (insn);
+  enum rtx_code code = GET_CODE (PATTERN (next));
+
+  if (code != ADDR_DIFF_VEC && code != ADDR_VEC)
+    return 0;
+
+  if (PREV_INSN (next) == XEXP (label, 0))
+    return 1;
+
+  return 0;
+}
+
 /* Instrument and/or analyze program behavior based on program flow graph.
    In either case, this function builds a flow graph for the function being
    compiled.  The flow graph is stored in BB_GRAPH.
@@ -711,10 +730,22 @@ branch_prob (f, dump_file)
               We have to handle tablejumps and returns specially anyways, so
               we don't check the JUMP_LABEL at all here.  */
 
+           /* ??? This code should be rewritten.  We need a more elegant way
+              to find the LABEL_REF.  We need a more elegant way to
+              differentiate tablejump entries from computed gotos.
+              We should perhaps reuse code from flow to compute the CFG
+              instead of trying to compute it here.
+
+              We can't use current_function_has_computed_jump, because that
+              is calculated later by flow.  We can't use computed_jump_p,
+              because that returns true for tablejump entry insns for some
+              targets, e.g. HPPA and MIPS.  */
+
            if (GET_CODE (pattern) == PARALLEL)
              {
-               /* This assumes that PARALLEL jumps are tablejump entry
-                  jumps.  */
+               /* This assumes that PARALLEL jumps with a USE are
+                  tablejump entry jumps.  The same assumption can be found
+                  in computed_jump_p.  */
                /* Make an arc from this jump to the label of the
                   jump table.  This will instrument the number of
                   times the switch statement is executed.  */
@@ -755,7 +786,14 @@ branch_prob (f, dump_file)
                     && GET_CODE (XEXP (tem, 0)) == MEM
                     && GET_CODE (XEXP (XEXP (tem, 0), 0)) == PLUS
                     && GET_CODE (XEXP (XEXP (XEXP (tem, 0), 0), 0)) == PC
-                    && GET_CODE (XEXP (tem, 1)) == LABEL_REF)
+                    && GET_CODE (XEXP (tem, 1)) == LABEL_REF
+                    && tablejump_entry_p (insn, XEXP (tem, 1)))
+             dest = label_to_bb[CODE_LABEL_NUMBER (XEXP (XEXP (tem, 1), 0))];
+           /* Recognize the MIPS table jump entry.  */
+           else if (GET_CODE (tem) == PLUS
+                    && GET_CODE (XEXP (tem, 0)) == REG
+                    && GET_CODE (XEXP (tem, 1)) == LABEL_REF
+                    && tablejump_entry_p (insn, XEXP (tem, 1)))
              dest = label_to_bb[CODE_LABEL_NUMBER (XEXP (XEXP (tem, 1), 0))];
            else
              {