[PATCH] Fix -fdump-rtl-sms (PR rtl-optimization/52095)

Jakub Jelinek jakub@redhat.com
Fri Feb 3 18:07:00 GMT 2012


Hi!

On some targets e.g. sms-7.c test fails, because fprintf is called
with %s format and NULL argument, GLIBC prints for that e.g.
SMS loop num: 1, file: (null), line: 0
but it isn't portable.  print-rtl.c guards the locator printing with
            /*  Pretty-print insn locators.  Ignore scoping as it is mostly
                redundant with line number information and do not print anything
                when there is no location information available.  */
            if (INSN_LOCATOR (in_rtx) && insn_file (in_rtx))
              fprintf(outfile, " %s:%i", insn_file (in_rtx), insn_line (in_rtx));
which fixes this, but there are 7 different spots that would need adjusting
in modulo-sched.c, so I've added a helper function for that.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2012-02-03  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/52095
	* modulo-sched.c (dump_insn_locator): New function.
	(loop_canon_p, sms_schedule): Use it.

--- gcc/modulo-sched.c.jj	2011-12-14 08:11:03.000000000 +0100
+++ gcc/modulo-sched.c	2012-02-03 13:45:49.137997767 +0100
@@ -1246,6 +1246,19 @@ loop_single_full_bb_p (struct loop *loop
   return true;
 }
 
+/* Dump file:line from INSN's location info to dump_file.  */
+
+static void
+dump_insn_locator (rtx insn)
+{
+  if (dump_file && INSN_LOCATOR (insn))
+    {
+      const char *file = insn_file (insn);
+      if (file)
+	fprintf (dump_file, " %s:%i", file, insn_line (insn));
+    }
+}
+
 /* A simple loop from SMS point of view; it is a loop that is composed of
    either a single basic block or two BBs - a header and a latch.  */
 #define SIMPLE_SMS_LOOP_P(loop) ((loop->num_nodes < 3 ) 		    \
@@ -1271,9 +1284,9 @@ loop_canon_p (struct loop *loop)
 	{
 	  rtx insn = BB_END (loop->header);
 
-	  fprintf (dump_file, "SMS loop many exits ");
-	  	  fprintf (dump_file, " %s %d (file, line)\n",
-			   insn_file (insn), insn_line (insn));
+	  fprintf (dump_file, "SMS loop many exits");
+	  dump_insn_locator (insn);
+	  fprintf (dump_file, "\n");
 	}
       return false;
     }
@@ -1284,9 +1297,9 @@ loop_canon_p (struct loop *loop)
 	{
 	  rtx insn = BB_END (loop->header);
 
-	  fprintf (dump_file, "SMS loop many BBs. ");
-	  fprintf (dump_file, " %s %d (file, line)\n",
-		   insn_file (insn), insn_line (insn));
+	  fprintf (dump_file, "SMS loop many BBs.");
+	  dump_insn_locator (insn);
+	  fprintf (dump_file, "\n");
 	}
       return false;
     }
@@ -1407,13 +1420,13 @@ sms_schedule (void)
         }
 
       if (dump_file)
-      {
-         rtx insn = BB_END (loop->header);
-
-         fprintf (dump_file, "SMS loop num: %d, file: %s, line: %d\n",
-                  loop->num, insn_file (insn), insn_line (insn));
+	{
+	  rtx insn = BB_END (loop->header);
 
-      }
+	  fprintf (dump_file, "SMS loop num: %d", loop->num);
+	  dump_insn_locator (insn);
+	  fprintf (dump_file, "\n");
+	}
 
       if (! loop_canon_p (loop))
         continue;
@@ -1440,9 +1453,8 @@ sms_schedule (void)
 	{
 	  if (dump_file)
 	    {
-	      fprintf (dump_file, " %s %d (file, line)\n",
-		       insn_file (tail), insn_line (tail));
-	      fprintf (dump_file, "SMS single-bb-loop\n");
+	      dump_insn_locator (tail);
+	      fprintf (dump_file, "\nSMS single-bb-loop\n");
 	      if (profile_info && flag_branch_probabilities)
 	    	{
 	      	  fprintf (dump_file, "SMS loop-count ");
@@ -1543,14 +1555,15 @@ sms_schedule (void)
         continue;
 
       if (dump_file)
-      {
-         rtx insn = BB_END (loop->header);
+	{
+	  rtx insn = BB_END (loop->header);
 
-         fprintf (dump_file, "SMS loop num: %d, file: %s, line: %d\n",
-                  loop->num, insn_file (insn), insn_line (insn));
+	  fprintf (dump_file, "SMS loop num: %d", loop->num);
+	  dump_insn_locator (insn);
+	  fprintf (dump_file, "\n");
 
-         print_ddg (dump_file, g);
-      }
+	  print_ddg (dump_file, g);
+	}
 
       get_ebb_head_tail (loop->header, loop->header, &head, &tail);
 
@@ -1561,9 +1574,8 @@ sms_schedule (void)
 
       if (dump_file)
 	{
-	  fprintf (dump_file, " %s %d (file, line)\n",
-		   insn_file (tail), insn_line (tail));
-	  fprintf (dump_file, "SMS single-bb-loop\n");
+	  dump_insn_locator (tail);
+	  fprintf (dump_file, "\nSMS single-bb-loop\n");
 	  if (profile_info && flag_branch_probabilities)
 	    {
 	      fprintf (dump_file, "SMS loop-count ");
@@ -1705,9 +1717,9 @@ sms_schedule (void)
 
           if (dump_file)
             {
-	      fprintf (dump_file,
-		       "%s:%d SMS succeeded %d %d (with ii, sc)\n",
-		       insn_file (tail), insn_line (tail), ps->ii, stage_count);
+	      dump_insn_locator (tail);
+	      fprintf (dump_file, " SMS succeeded %d %d (with ii, sc)\n",
+		       ps->ii, stage_count);
 	      print_partial_schedule (ps, dump_file);
 	    }
  

	Jakub



More information about the Gcc-patches mailing list