public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch,AVR]: Better log output with -mdeb
@ 2011-09-28 16:29 Georg-Johann Lay
  2011-09-29 11:27 ` [Patch,AVR]: Better log output with -mdeb/-mdebug= Georg-Johann Lay
  0 siblings, 1 reply; 8+ messages in thread
From: Georg-Johann Lay @ 2011-09-28 16:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 2575 bytes --]

This is a tentative patch for better support of logging information for avr BE
developers.

There are situations where it is more convenient to let the compiler produce
information than to debug into the compiler. One example are -da dumps.

This patch proposes a better support to print information by means of a
printf-like function via %-codes.

The current debug output with avr-gcc's option -mdeb produces bulk of
information that is very hard to read because
 - there is much output
 - there is no information on current_function_decl
 - there is no information on current pass name/number
 - there is no print-like function so the trees, rtxes so that it is
   tedious to get formatted output.

For example, the following call to avr_edump

static int
avr_OS_main_function_p (tree func)
{
  avr_edump ("%?: %t\n", func);
  return avr_lookup_function_attribute1 (func, "OS_main");
}

prints additional information in a convenient way (foo is function to be compiled):

avr_OS_main_function_p[foo:pro_and_epilogue(202)]: <function_decl # foo
    type <function_type #
        type <void_type # void VOID
...

Wondering that similar functionality is not provided by GCC itself, I wrote
this patch. GCC's diagnostic seems to be overwhelmingly complicated and not
intended for the purpose mentioned above.

The code is dead code at the moment. No function in the BE uses the new
functions. This patch just adds them.

Moreover; I don't know if avr port maintainers or global reviewers like such
stuff in the compiler... Therefore it's just tentative draft.

Supported %-codes are:

  r: rtx
  t: tree
  T: tree (brief)
  C: enum rtx_code
  m: enum machine_mode
  R: enum reg_class
  L: insn list
  H: location_t

  -- no args --
  A: call abort()
  f: current_function_name()
  F: caller (via __FUNCTION__)
  P: Pass name and number
  ?: Print caller, current function and pass info

  -- same as printf --
  %: %
  c: char
  s: string
  d: int (decimal)
  x: int (hex)

These codes cover great deal of BE developers needs and if something is missing
it can be added easily.

The calling itself is not as straight forward as it could be in the presence of
variadic macros (to get __FUNCTION__), but that should not matter here.

Johann

	* config/avr/avr-protos.h (avr_edump, avr_fdump): New macros.
	(avr__set_caller_e, avr__set_caller_f): New prototypes.
	* config/avr/avr.c: Include tree-pass.h.
	(avr__caller, avr__stream): New static variables.
	(avr__fdump_e, avr__fdump_f, avr__vadump): New static functions.
	(avr__set_caller_e, avr__set_caller_f): New functions.


[-- Attachment #2: better-log-2.diff --]
[-- Type: text/x-patch, Size: 6278 bytes --]

Index: config/avr/avr-protos.h
===================================================================
--- config/avr/avr-protos.h	(revision 179257)
+++ config/avr/avr-protos.h	(working copy)
@@ -111,3 +111,9 @@ extern rtx avr_incoming_return_addr_rtx
 #ifdef REAL_VALUE_TYPE
 extern void asm_output_float (FILE *file, REAL_VALUE_TYPE n);
 #endif
+
+#define avr_edump (avr__set_caller_e (__FUNCTION__))
+#define avr_fdump (avr__set_caller_f (__FUNCTION__))
+
+extern int (*avr__set_caller_e (const char*))(const char*, ...);
+extern int (*avr__set_caller_f (const char*))(FILE*, const char*, ...);
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 179257)
+++ config/avr/avr.c	(working copy)
@@ -7810,5 +7810,233 @@ avr_expand_builtin (tree exp, rtx target
   gcc_unreachable ();
 }
 
+\f
+/***********************************************************************
+ ** Logging, for BE developers only
+ ***********************************************************************/
+
+#include "tree-pass.h"
+
+static const char* avr__caller = "?";
+static FILE* avr__stream;
+
+static void avr__vadump (FILE*, const char*, va_list);
+
+static int
+avr__fdump_f (FILE *stream, const char* fmt, ...)
+{
+  va_list ap;
+        
+  va_start (ap, fmt);
+  if (stream)
+    avr__vadump (stream, fmt, ap);
+  va_end (ap);
+    
+  return 1;
+}
+
+int (*
+avr__set_caller_f (const char* caller)
+     )(FILE*, const char*, ...)
+{
+  avr__caller = caller;
+
+  return avr__fdump_f;
+}
+
+static int
+avr__fdump_e (const char* fmt, ...)
+{
+  va_list ap;
+        
+  va_start (ap, fmt);
+  avr__vadump (stderr, fmt, ap);
+  va_end (ap);
+    
+  return 1;
+}
+
+int (*
+avr__set_caller_e (const char* caller)
+     )(const char*, ...)
+{
+  avr__caller = caller;
+  avr__stream = stderr;
+  
+  return avr__fdump_e;
+}
+
+/*
+  -- known %-codes --
+  
+  r: rtx
+  t: tree
+  T: tree (brief)
+  C: enum rtx_code
+  m: enum machine_mode
+  R: enum reg_class
+  L: insn list
+  H: location_t
+
+  -- no args --
+  A: call abort()
+  f: current_function_name()
+  F: caller (via __FUNCTION__)
+  P: Pass name and number
+  ?: Print caller, current function and pass info
+
+  -- same as printf --
+  %: %
+  c: char
+  s: string
+  d: int (decimal)
+  x: int (hex)
+*/
+
+static void
+avr__vadump (FILE *file, const char *fmt, va_list ap)
+{
+  char bs[3] = {'\\', '?', '\0'};
+
+  while (*fmt)
+    {
+      switch (*fmt++)
+        {
+        default:
+          fputc (*(fmt-1), file);
+          break;
+          
+        case '\\':
+          bs[1] = *fmt++;
+          fputs (bs, file);
+          break;
+          
+        case '%':
+          switch (*fmt++)
+            {
+            case '%':
+              fputc ('%', file);
+              break;
+
+            case 't':
+              {
+                tree t = va_arg (ap, tree);
+                if (NULL_TREE == t)
+                  fprintf (file, "<NULL-TREE>");
+                else
+                  {
+                    if (stderr == file)
+                      debug_tree (t);
+                  }
+                break;
+              }
+
+            case 'T':
+              print_node_brief (file, "", va_arg (ap, tree), 3);
+              break;
+
+            case 'd':
+              fprintf (file, "%d", va_arg (ap, int));
+              break;
+
+            case 'x':
+              fprintf (file, "%x", va_arg (ap, int));
+              break;
+                        
+            case 'c':
+              fputc (va_arg (ap, int), file);
+              break;
+                        
+            case 'r':
+              print_inline_rtx (file, va_arg (ap, rtx), 0);
+              break;
+                        
+            case 'L':
+              {
+                rtx insn = va_arg (ap, rtx);
+
+                while (insn)
+                  {
+                    print_inline_rtx (file, insn, 0);
+                    fprintf (file, "\n");
+                    insn = NEXT_INSN (insn);
+                  }
+                break;
+              }
+                        
+            case 'f':
+              if (cfun && cfun->decl)
+                fputs (current_function_name(), file);
+              break;
+                        
+            case 's':
+              {
+                const char *str = va_arg (ap, char*);
+                fputs (str ? str : "(null)", file);
+              }
+              break;
+                        
+            case 'm':
+              fputs (GET_MODE_NAME (va_arg (ap, enum machine_mode)), file);
+              break;
+
+            case 'C':
+              fputs (rtx_name[va_arg (ap, enum rtx_code)], file);
+              break;
+
+            case 'R':
+              fputs (reg_class_names[va_arg (ap, enum reg_class)], file);
+              break;
+    
+            case 'F':
+              fputs (avr__caller, file);
+              break;
+
+            case 'H':
+              {
+                location_t loc = va_arg (ap, location_t);
+
+                if (BUILTINS_LOCATION == loc)
+                  fprintf (file, "<BUILTIN-LOCATION");
+                else if (UNKNOWN_LOCATION == loc)
+                  fprintf (file, "<UNKNOWN-LOCATION>");
+                else
+                  fprintf (file, "%s:%d",
+                           LOCATION_FILE (loc), LOCATION_LINE (loc));
+                
+                break;
+              }
+
+            case '!':
+              if (!current_pass)
+                return;
+              /* FALLTHRU */
+
+            case '?':
+              avr__fdump_f (file, "%F[%f:%P]");
+              break;
+                        
+            case 'P':
+              if (current_pass)
+                fprintf (file, "%s(%d)", 
+                         current_pass->name,
+                         current_pass->static_pass_number);
+              else
+                fprintf (file, "pass=?");
+                        
+              break;
+                        
+            case 'A':
+              abort();
+
+            default:
+              fputc (*(fmt-1), file);
+            }
+          break; /* % */
+        }
+    }
+    
+  fflush (file);
+}
 
 #include "gt-avr.h"


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: Better log output with -mdeb/-mdebug=
  2011-09-28 16:29 [Patch,AVR]: Better log output with -mdeb Georg-Johann Lay
@ 2011-09-29 11:27 ` Georg-Johann Lay
  2011-09-29 13:14   ` Denis Chertykov
  2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
  0 siblings, 2 replies; 8+ messages in thread
From: Georg-Johann Lay @ 2011-09-29 11:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 3502 bytes --]

Georg-Johann Lay wrote:
> This is a tentative patch for better support of logging information for avr BE
> developers.
> 
> There are situations where it is more convenient to let the compiler produce
> information than to debug into the compiler. One example are -da dumps.
> 
> This patch proposes a better support to print information by means of a
> printf-like function via %-codes.
> 
> The current debug output with avr-gcc's option -mdeb produces bulk of
> information that is very hard to read because
>  - there is much output
>  - there is no information on current_function_decl
>  - there is no information on current pass name/number
>  - there is no print-like function so the trees, rtxes so that it is
>    tedious to get formatted output.
> 
> For example, the following call to avr_edump
> 
> static int
> avr_OS_main_function_p (tree func)
> {
>   avr_edump ("%?: %t\n", func);
>   return avr_lookup_function_attribute1 (func, "OS_main");
> }
> 
> prints additional information in a convenient way (foo is function to be compiled):
> 
> avr_OS_main_function_p[foo:pro_and_epilogue(202)]: <function_decl # foo
>     type <function_type #
>         type <void_type # void VOID
> ...
> 
> Wondering that similar functionality is not provided by GCC itself, I wrote
> this patch. GCC's diagnostic seems to be overwhelmingly complicated and not
> intended for the purpose mentioned above.
> 
> The code is dead code at the moment. No function in the BE uses the new
> functions. This patch just adds them.
> 
> Moreover; I don't know if avr port maintainers or global reviewers like such
> stuff in the compiler... Therefore it's just tentative draft.
> 
> Supported %-codes are:
> 
>   r: rtx
>   t: tree
>   T: tree (brief)
>   C: enum rtx_code
>   m: enum machine_mode
>   R: enum reg_class
>   L: insn list
>   H: location_t
> 
>   -- no args --
>   A: call abort()
>   f: current_function_name()
>   F: caller (via __FUNCTION__)
>   P: Pass name and number
>   ?: Print caller, current function and pass info
> 
>   -- same as printf --
>   %: %
>   c: char
>   s: string
>   d: int (decimal)
>   x: int (hex)
> 
> These codes cover great deal of BE developers needs and if something is missing
> it can be added easily.

Here is now the patch for review.

As Denis proposed in http://gcc.gnu.org/ml/gcc/2011-09/msg00357.html all
additional functions are put in the new file avr-log.c.

-mdebug= is a new command line option that takes a string argument to filter
specific log messages.  The purpose of -mdebug=all is to be similar to -mdeb
and, e.g, -mdebug=rtx_costs,legitimate_address_p is intended to print
information from respective named hooks.

avr.c:avr_option_override calls avr-log.c:avr__set_avr_debug to parse -mdebug
and set bitfield avr_debug accordingly, but using the log functions and
avr_debug is still to come.  This patch just supplies the basis.

I opened PR50566 to collect changes for better logging.

Ok for trunk?

Johann

	PR target/50566
	* config.gcc (extra_objs): Add avr-log.o for $target in:
	avr-*-rtems*, avr-*-*.
	* config/avr/t-avr (avr-log.o): New rule to compile...
	* config/avr/avr-log.c: ...this new file.
	* config/avr/avr.opt (mlog=): New option.
	* config/avr/avr-protos.h (avr_edump, avr_fdump): New macros.
	(avr_log_set_caller_e, avr_log_set_caller_f): New prototypes.
	(avr_log_set_avr_log): New prototype.
	(avr_log_t): New typedef.
	(avr_log): New declaration.
	* config/avr/avr.c (avr_option_override): Call avr_log_set_avr_log.



[-- Attachment #2: better-log-3.diff --]
[-- Type: text/x-patch, Size: 11967 bytes --]

Index: config.gcc
===================================================================
--- config.gcc	(revision 179334)
+++ config.gcc	(working copy)
@@ -939,14 +939,14 @@ avr-*-rtems*)
 	libgcc_tm_file="$libgcc_tm_file avr/avr-lib.h"
 	tmake_file="avr/t-avr t-rtems avr/t-rtems"
 	extra_gcc_objs="driver-avr.o avr-devices.o"
-	extra_objs="avr-devices.o"
+	extra_objs="avr-devices.o avr-log.o"
 	;;
 avr-*-*)
 	tm_file="elfos.h avr/elf.h avr/avr.h dbxelf.h newlib-stdint.h"
 	libgcc_tm_file="$libgcc_tm_file avr/avr-lib.h"
 	use_gcc_stdint=wrap
 	extra_gcc_objs="driver-avr.o avr-devices.o"
-	extra_objs="avr-devices.o"
+	extra_objs="avr-devices.o avr-log.o"
 	;;
 bfin*-elf*)
 	tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h bfin/elf.h"
Index: config/avr/avr-log.c
===================================================================
--- config/avr/avr-log.c	(revision 0)
+++ config/avr/avr-log.c	(revision 0)
@@ -0,0 +1,314 @@
+/* Subroutines for log output for Atmel AVR back end.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+   Contributed by Georg-Johann Lay (avr@gjlay.de)
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+   
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "rtl.h"
+#include "tree.h"
+#include "output.h"
+#include "input.h"
+#include "function.h"
+#include "tm_p.h"
+#include "tree-pass.h"
+
+/* This file supplies some functions for AVR back-end developers
+   with a printf-like interface.  The functions are called through
+   macros avr_edump or avr_fdump from avr-protos.h:
+
+      avr_edump (const char * fmt, ...);
+
+      avr_fdump (FILE * stream, const char * fmt, ...);
+
+   avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
+
+  == known %-codes ==
+  
+  r: rtx
+  t: tree
+  T: tree (brief)
+  C: enum rtx_code
+  m: enum machine_mode
+  R: enum reg_class
+  L: insn list
+  H: location_t
+
+  == no arguments ==
+  
+  A: call abort()
+  f: current_function_name()
+  F: caller (via __FUNCTION__)
+  P: Pass name and number
+  ?: Print caller, current function and pass info
+
+  == same as printf ==
+  
+  %: %
+  c: char
+  s: string
+  d: int (decimal)
+  x: int (hex)
+*/
+
+/* Set according to -mlog= option.  */
+avr_log_t avr_log;
+
+/* The caller as of __FUNCTION__ */
+static const char *avr_log_caller = "?";
+
+/* The worker function implementing the %-codes */
+static void avr_log_vadump (FILE*, const char*, va_list);
+
+/* As we have no variadic macros, avr_edump maps to a call to
+   avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and
+   returns a function pointer to avr_log_fdump_e.  avr_fdump_e
+   gets the printf-like arguments and calls avr_log_vadump, the
+   worker function. avr_fdump works the same way.  */
+
+/* Provide avr_log_fdump_e/f so that avr_log_set_caller_e/_f can return
+   their address.  */
+
+static int
+avr_log_fdump_e (const char *fmt, ...)
+{
+  va_list ap;
+        
+  va_start (ap, fmt);
+  avr_log_vadump (stderr, fmt, ap);
+  va_end (ap);
+    
+  return 1;
+}
+
+static int
+avr_log_fdump_f (FILE *stream, const char *fmt, ...)
+{
+  va_list ap;
+        
+  va_start (ap, fmt);
+  if (stream)
+    avr_log_vadump (stream, fmt, ap);
+  va_end (ap);
+    
+  return 1;
+}
+
+/* Macros avr_edump/avr_fdump map to calls of the following two functions,
+   respectively.  You don't need to call them directly.  */
+
+int (*
+avr_log_set_caller_e (const char *caller)
+     )(const char*, ...)
+{
+  avr_log_caller = caller;
+  
+  return avr_log_fdump_e;
+}
+
+int (*
+avr_log_set_caller_f (const char *caller)
+     )(FILE*, const char*, ...)
+{
+  avr_log_caller = caller;
+
+  return avr_log_fdump_f;
+}
+
+/* Worker function implementing the %-codes and forwarning to
+   respective print/dump function.  */
+
+static void
+avr_log_vadump (FILE *file, const char *fmt, va_list ap)
+{
+  char bs[3] = {'\\', '?', '\0'};
+
+  while (*fmt)
+    {
+      switch (*fmt++)
+        {
+        default:
+          fputc (*(fmt-1), file);
+          break;
+          
+        case '\\':
+          bs[1] = *fmt++;
+          fputs (bs, file);
+          break;
+          
+        case '%':
+          switch (*fmt++)
+            {
+            case '%':
+              fputc ('%', file);
+              break;
+              
+            case 't':
+              {
+                tree t = va_arg (ap, tree);
+                if (NULL_TREE == t)
+                  fprintf (file, "<NULL-TREE>");
+                else
+                  {
+                    if (stderr == file)
+                      debug_tree (t);
+                  }
+                break;
+              }
+              
+            case 'T':
+              print_node_brief (file, "", va_arg (ap, tree), 3);
+              break;
+              
+            case 'd':
+              fprintf (file, "%d", va_arg (ap, int));
+              break;
+              
+            case 'x':
+              fprintf (file, "%x", va_arg (ap, int));
+              break;
+                        
+            case 'c':
+              fputc (va_arg (ap, int), file);
+              break;
+                        
+            case 'r':
+              print_inline_rtx (file, va_arg (ap, rtx), 0);
+              break;
+                        
+            case 'L':
+              {
+                rtx insn = va_arg (ap, rtx);
+
+                while (insn)
+                  {
+                    print_inline_rtx (file, insn, 0);
+                    fprintf (file, "\n");
+                    insn = NEXT_INSN (insn);
+                  }
+                break;
+              }
+                        
+            case 'f':
+              if (cfun && cfun->decl)
+                fputs (current_function_name(), file);
+              break;
+                        
+            case 's':
+              {
+                const char *str = va_arg (ap, char*);
+                fputs (str ? str : "(null)", file);
+              }
+              break;
+                        
+            case 'm':
+              fputs (GET_MODE_NAME (va_arg (ap, enum machine_mode)), file);
+              break;
+              
+            case 'C':
+              fputs (rtx_name[va_arg (ap, enum rtx_code)], file);
+              break;
+              
+            case 'R':
+              fputs (reg_class_names[va_arg (ap, enum reg_class)], file);
+              break;
+              
+            case 'F':
+              fputs (avr_log_caller, file);
+              break;
+              
+            case 'H':
+              {
+                location_t loc = va_arg (ap, location_t);
+                
+                if (BUILTINS_LOCATION == loc)
+                  fprintf (file, "<BUILTIN-LOCATION");
+                else if (UNKNOWN_LOCATION == loc)
+                  fprintf (file, "<UNKNOWN-LOCATION>");
+                else
+                  fprintf (file, "%s:%d",
+                           LOCATION_FILE (loc), LOCATION_LINE (loc));
+                
+                break;
+              }
+              
+            case '!':
+              if (!current_pass)
+                return;
+              /* FALLTHRU */
+              
+            case '?':
+              avr_log_fdump_f (file, "%F[%f:%P]");
+              break;
+                        
+            case 'P':
+              if (current_pass)
+                fprintf (file, "%s(%d)", 
+                         current_pass->name,
+                         current_pass->static_pass_number);
+              else
+                fprintf (file, "pass=?");
+                        
+              break;
+                        
+            case 'A':
+              fflush (file);
+              abort();
+              
+            default:
+              fputc (*(fmt-1), file);
+            }
+          break; /* % */
+        }
+    }
+    
+  fflush (file);
+}
+
+
+/* Called from avr.c:avr_option_override().
+   Parse argument of -mlog= and set respective fields in avr_log.  */
+
+void
+avr_log_set_avr_log (void)
+{
+  if (avr_log_details)
+    {
+      /* Adding , at beginning and end of string makes searching easier.  */
+      
+      char *str = (char*) alloca (3 + strlen (avr_log_details));
+      
+      str[0] = ',';
+      strcat (stpcpy (str+1, avr_log_details), ",");
+      
+#define SET_DUMP_DETAIL(S)                                              \
+      avr_log.S = (TARGET_ALL_DEBUG                                     \
+                   || NULL != strstr (str, "," #S ",")                  \
+                   || NULL != strstr (str, ",all,"))
+
+      SET_DUMP_DETAIL (rtx_costs);
+      SET_DUMP_DETAIL (legitimate_address_p);
+      SET_DUMP_DETAIL (legitimize_address);
+      SET_DUMP_DETAIL (legitimize_reload_address);
+      SET_DUMP_DETAIL (constraints);
+
+#undef SET_DUMP_DETAIL
+    }
+}
Index: config/avr/avr.opt
===================================================================
--- config/avr/avr.opt	(revision 179316)
+++ config/avr/avr.opt	(working copy)
@@ -29,6 +29,9 @@ Target RejectNegative Joined Var(avr_mcu
 mdeb
 Target Report Undocumented Mask(ALL_DEBUG)
 
+mlog=
+Target RejectNegative Joined Undocumented Var(avr_log_details)
+
 mint8
 Target Report Mask(INT8)
 Use an 8-bit 'int' type
Index: config/avr/t-avr
===================================================================
--- config/avr/t-avr	(revision 179316)
+++ config/avr/t-avr	(working copy)
@@ -30,6 +30,10 @@ avr-c.o: $(srcdir)/config/avr/avr-c.c \
   $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_COMMON_H)
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
 
+avr-log.o: $(srcdir)/config/avr/avr-log.c \
+  $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(INPUT_H)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
+
 $(srcdir)/config/avr/avr-tables.opt: $(srcdir)/config/avr/genopt.sh \
   $(srcdir)/config/avr/avr-mcus.def
 	$(SHELL) $(srcdir)/config/avr/genopt.sh $(srcdir)/config/avr > \
Index: config/avr/avr-protos.h
===================================================================
--- config/avr/avr-protos.h	(revision 179316)
+++ config/avr/avr-protos.h	(working copy)
@@ -111,3 +111,24 @@ extern rtx avr_incoming_return_addr_rtx
 #ifdef REAL_VALUE_TYPE
 extern void asm_output_float (FILE *file, REAL_VALUE_TYPE n);
 #endif
+
+/* From avr-log.c */
+
+#define avr_edump (avr_log_set_caller_e (__FUNCTION__))
+#define avr_fdump (avr_log_set_caller_f (__FUNCTION__))
+
+extern int (*avr_log_set_caller_e (const char*))(const char*, ...);
+extern int (*avr_log_set_caller_f (const char*))(FILE*, const char*, ...);
+
+extern void avr_log_set_avr_log (void);
+
+typedef struct
+{
+  unsigned rtx_costs :1;
+  unsigned legitimate_address_p :1;
+  unsigned legitimize_address :1;
+  unsigned legitimize_reload_address :1;
+  unsigned constraints :1;
+} avr_log_t;
+
+extern avr_log_t avr_log;
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 179316)
+++ config/avr/avr.c	(working copy)
@@ -359,6 +359,8 @@ avr_option_override (void)
   zero_reg_rtx = gen_rtx_REG (QImode, ZERO_REGNO);
 
   init_machine_status = avr_init_machine_status;
+
+  avr_log_set_avr_log();
 }
 
 /* Function to set up the backend function structure.  */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: Better log output with -mdeb/-mdebug=
  2011-09-29 11:27 ` [Patch,AVR]: Better log output with -mdeb/-mdebug= Georg-Johann Lay
@ 2011-09-29 13:14   ` Denis Chertykov
  2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
  1 sibling, 0 replies; 8+ messages in thread
From: Denis Chertykov @ 2011-09-29 13:14 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-patches, Eric Weddington

2011/9/29 Georg-Johann Lay <avr@gjlay.de>:
> Georg-Johann Lay wrote:
>> This is a tentative patch for better support of logging information for avr BE
>> developers.
>>
>> There are situations where it is more convenient to let the compiler produce
>> information than to debug into the compiler. One example are -da dumps.
>>
>> This patch proposes a better support to print information by means of a
>> printf-like function via %-codes.
>>
>> The current debug output with avr-gcc's option -mdeb produces bulk of
>> information that is very hard to read because
>>  - there is much output
>>  - there is no information on current_function_decl
>>  - there is no information on current pass name/number
>>  - there is no print-like function so the trees, rtxes so that it is
>>    tedious to get formatted output.
>>
>> For example, the following call to avr_edump
>>
>> static int
>> avr_OS_main_function_p (tree func)
>> {
>>   avr_edump ("%?: %t\n", func);
>>   return avr_lookup_function_attribute1 (func, "OS_main");
>> }
>>
>> prints additional information in a convenient way (foo is function to be compiled):
>>
>> avr_OS_main_function_p[foo:pro_and_epilogue(202)]: <function_decl # foo
>>     type <function_type #
>>         type <void_type # void VOID
>> ...
>>
>> Wondering that similar functionality is not provided by GCC itself, I wrote
>> this patch. GCC's diagnostic seems to be overwhelmingly complicated and not
>> intended for the purpose mentioned above.
>>
>> The code is dead code at the moment. No function in the BE uses the new
>> functions. This patch just adds them.
>>
>> Moreover; I don't know if avr port maintainers or global reviewers like such
>> stuff in the compiler... Therefore it's just tentative draft.
>>
>> Supported %-codes are:
>>
>>   r: rtx
>>   t: tree
>>   T: tree (brief)
>>   C: enum rtx_code
>>   m: enum machine_mode
>>   R: enum reg_class
>>   L: insn list
>>   H: location_t
>>
>>   -- no args --
>>   A: call abort()
>>   f: current_function_name()
>>   F: caller (via __FUNCTION__)
>>   P: Pass name and number
>>   ?: Print caller, current function and pass info
>>
>>   -- same as printf --
>>   %: %
>>   c: char
>>   s: string
>>   d: int (decimal)
>>   x: int (hex)
>>
>> These codes cover great deal of BE developers needs and if something is missing
>> it can be added easily.
>
> Here is now the patch for review.
>
> As Denis proposed in http://gcc.gnu.org/ml/gcc/2011-09/msg00357.html all
> additional functions are put in the new file avr-log.c.
>
> -mdebug= is a new command line option that takes a string argument to filter
> specific log messages.  The purpose of -mdebug=all is to be similar to -mdeb
> and, e.g, -mdebug=rtx_costs,legitimate_address_p is intended to print
> information from respective named hooks.
>
> avr.c:avr_option_override calls avr-log.c:avr__set_avr_debug to parse -mdebug
> and set bitfield avr_debug accordingly, but using the log functions and
> avr_debug is still to come.  This patch just supplies the basis.
>
> I opened PR50566 to collect changes for better logging.
>
> Ok for trunk?

Ok.
Please apply.

Denis

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n]
  2011-09-29 11:27 ` [Patch,AVR]: Better log output with -mdeb/-mdebug= Georg-Johann Lay
  2011-09-29 13:14   ` Denis Chertykov
@ 2011-09-29 15:26   ` Georg-Johann Lay
  2011-09-29 18:37     ` Denis Chertykov
                       ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Georg-Johann Lay @ 2011-09-29 15:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 785 bytes --]

This is the second patch in this series.

Functions that formerly used fprintf/debug_rtx now use avr_edump and the use
sites of TARGET_ALL_DEBUG are mapped to respective flags of avr_log.

avr_log_vadump uses %b to print bool.

The patch adds outputs for the results of avr_rtx_costs and wraps the worker
function.

Ok to apply?

Johann

	PR target/50566
	* config/avr/avr-log.c (avr_log_vadump): Use %b to print bool.
	* config/avr/avr.c (avr_rtx_costs_1): New static function, renamed
	from avr_rtx_costs.
	(avr_legitimate_address_p): Use avr_edump to print log information
	filtered by avr_log.
	(extra_constraint_Q): Ditto.
	(avr_legitimize_address): Ditto.
	(avr_rtx_costs): Ditto.  Rewrite as wrapper for avr_rtx_costs_1.
	(final_prescan_insn): Use avr_log.rtx_costs as filter.


[-- Attachment #2: better-log-4.diff --]
[-- Type: text/x-patch, Size: 7563 bytes --]

Index: config/avr/avr-log.c
===================================================================
--- config/avr/avr-log.c	(revision 179344)
+++ config/avr/avr-log.c	(working copy)
@@ -42,6 +42,7 @@
 
   == known %-codes ==
   
+  b: bool  
   r: rtx
   t: tree
   T: tree (brief)
@@ -190,6 +191,10 @@ avr_log_vadump (FILE *file, const char *
               fprintf (file, "%x", va_arg (ap, int));
               break;
                         
+            case 'b':
+              fprintf (file, "%s", va_arg (ap, int) ? "true" : "false");
+              break;
+                        
             case 'c':
               fputc (va_arg (ap, int), file);
               break;
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 179344)
+++ config/avr/avr.c	(working copy)
@@ -1193,27 +1193,7 @@ avr_cannot_modify_jumps_p (void)
 bool
 avr_legitimate_address_p (enum machine_mode mode, rtx x, bool strict)
 {
-  enum reg_class r = NO_REGS;
-  
-  if (TARGET_ALL_DEBUG)
-    {
-      fprintf (stderr, "mode: (%s) %s %s %s %s:",
-	       GET_MODE_NAME(mode),
-	       strict ? "(strict)": "",
-	       reload_completed ? "(reload_completed)": "",
-	       reload_in_progress ? "(reload_in_progress)": "",
-	       reg_renumber ? "(reg_renumber)" : "");
-      if (GET_CODE (x) == PLUS
-	  && REG_P (XEXP (x, 0))
-	  && GET_CODE (XEXP (x, 1)) == CONST_INT
-	  && INTVAL (XEXP (x, 1)) >= 0
-	  && INTVAL (XEXP (x, 1)) <= MAX_LD_OFFSET (mode)
-	  && reg_renumber
-	  )
-	fprintf (stderr, "(r%d ---> r%d)", REGNO (XEXP (x, 0)),
-		 true_regnum (XEXP (x, 0)));
-      debug_rtx (x);
-    }
+  reg_class_t r = NO_REGS;
   
   if (REG_P (x) && (strict ? REG_OK_FOR_BASE_STRICT_P (x)
                     : REG_OK_FOR_BASE_NOSTRICT_P (x)))
@@ -1247,10 +1227,27 @@ avr_legitimate_address_p (enum machine_m
     {
       r = POINTER_REGS;
     }
-  if (TARGET_ALL_DEBUG)
+
+  if (avr_log.legitimate_address_p)
     {
-      fprintf (stderr, "   ret = %c\n", r + '0');
+      avr_edump ("\n%?: ret=%d=%R, mode=%m strict=%d "
+                 "reload_completed=%d reload_in_progress=%d %s:",
+                 !!r, r, mode, strict, reload_completed, reload_in_progress,
+                 reg_renumber ? "(reg_renumber)" : "");
+      
+      if (GET_CODE (x) == PLUS
+          && REG_P (XEXP (x, 0))
+          && CONST_INT_P (XEXP (x, 1))
+          && IN_RANGE (INTVAL (XEXP (x, 1)), 0, MAX_LD_OFFSET (mode))
+          && reg_renumber)
+        {
+          avr_edump ("(r%d ---> r%d)", REGNO (XEXP (x, 0)),
+                     true_regnum (XEXP (x, 0)));
+        }
+      
+      avr_edump ("\n%r\n", x);
     }
+  
   return r == NO_REGS ? 0 : (int)r;
 }
 
@@ -1260,30 +1257,35 @@ avr_legitimate_address_p (enum machine_m
 rtx
 avr_legitimize_address (rtx x, rtx oldx, enum machine_mode mode)
 {
+  bool big_offset_p = false;
+  
   x = oldx;
-  if (TARGET_ALL_DEBUG)
+  
+  if (GET_CODE (oldx) == PLUS
+      && REG_P (XEXP (oldx, 0)))
     {
-      fprintf (stderr, "legitimize_address mode: %s", GET_MODE_NAME(mode));
-      debug_rtx (oldx);
+      if (REG_P (XEXP (oldx, 1)))
+        x = force_reg (GET_MODE (oldx), oldx);
+      else if (CONST_INT_P (XEXP (oldx, 1)))
+        {
+	  int offs = INTVAL (XEXP (oldx, 1));
+          if (frame_pointer_rtx != XEXP (oldx, 0)
+              && offs > MAX_LD_OFFSET (mode))
+            {
+              big_offset_p = true;
+              x = force_reg (GET_MODE (oldx), oldx);
+            }
+        }
     }
   
-  if (GET_CODE (oldx) == PLUS
-      && REG_P (XEXP (oldx,0)))
+  if (avr_log.legitimize_address)
     {
-      if (REG_P (XEXP (oldx,1)))
-	x = force_reg (GET_MODE (oldx), oldx);
-      else if (GET_CODE (XEXP (oldx, 1)) == CONST_INT)
-	{
-	  int offs = INTVAL (XEXP (oldx,1));
-	  if (frame_pointer_rtx != XEXP (oldx,0))
-	    if (offs > MAX_LD_OFFSET (mode))
-	      {
-		if (TARGET_ALL_DEBUG)
-		  fprintf (stderr, "force_reg (big offset)\n");
-		x = force_reg (GET_MODE (oldx), oldx);
-	      }
-	}
+      avr_edump ("\n%?: mode=%m\n %r\n", mode, oldx);
+
+      if (x != oldx)
+        avr_edump (" %s --> %r\n", big_offset_p ? "(big offset)" : "", x);
     }
+
   return x;
 }
 
@@ -1711,7 +1713,7 @@ void
 final_prescan_insn (rtx insn, rtx *operand ATTRIBUTE_UNUSED,
                     int num_operands ATTRIBUTE_UNUSED)
 {
-  if (TARGET_ALL_DEBUG)
+  if (avr_log.rtx_costs)
     {
       rtx set = single_set (insn);
 
@@ -5825,14 +5827,15 @@ avr_operand_rtx_cost (rtx x, enum machin
   return total;
 }
 
-/* The AVR backend's rtx_cost function.  X is rtx expression whose cost
-   is to be calculated.  Return true if the complete cost has been
-   computed, and false if subexpressions should be scanned.  In either
-   case, *TOTAL contains the cost result.  */
+/* Worker function for AVR backend's rtx_cost function.
+   X is rtx expression whose cost is to be calculated.
+   Return true if the complete cost has been computed.
+   Return false if subexpressions should be scanned.
+   In either case, *TOTAL contains the cost result.  */
 
 static bool
-avr_rtx_costs (rtx x, int codearg, int outer_code ATTRIBUTE_UNUSED,
-	       int opno ATTRIBUTE_UNUSED, int *total, bool speed)
+avr_rtx_costs_1 (rtx x, int codearg, int outer_code ATTRIBUTE_UNUSED,
+                 int opno ATTRIBUTE_UNUSED, int *total, bool speed)
 {
   enum rtx_code code = (enum rtx_code) codearg;
   enum machine_mode mode = GET_MODE (x);
@@ -6551,6 +6554,25 @@ avr_rtx_costs (rtx x, int codearg, int o
   return false;
 }
 
+
+/* Implement `TARGET_RTX_COSTS'.  */
+
+static bool
+avr_rtx_costs (rtx x, int codearg, int outer_code,
+	       int opno, int *total, bool speed)
+{
+  bool done = avr_rtx_costs_1 (x, codearg, outer_code,
+                               opno, total, speed);
+
+  if (avr_log.rtx_costs)
+    {
+      avr_edump ("\n%?=%b (%s) total=%d, outer=%C:\n%r\n",
+                 done, speed ? "speed" : "size", *total, outer_code, x);
+    }
+
+  return done;
+}
+
 /* Calculate the cost of a memory address.  */
 
 static int
@@ -6576,6 +6598,8 @@ avr_address_cost (rtx x, bool speed ATTR
 int
 extra_constraint_Q (rtx x)
 {
+  int ok = 0;
+  
   if (GET_CODE (XEXP (x,0)) == PLUS
       && REG_P (XEXP (XEXP (x,0), 0))
       && GET_CODE (XEXP (XEXP (x,0), 1)) == CONST_INT
@@ -6584,23 +6608,21 @@ extra_constraint_Q (rtx x)
     {
       rtx xx = XEXP (XEXP (x,0), 0);
       int regno = REGNO (xx);
-      if (TARGET_ALL_DEBUG)
-	{
-	  fprintf (stderr, ("extra_constraint:\n"
-			    "reload_completed: %d\n"
-			    "reload_in_progress: %d\n"),
-		   reload_completed, reload_in_progress);
-	  debug_rtx (x);
-	}
-      if (regno >= FIRST_PSEUDO_REGISTER)
-	return 1;		/* allocate pseudos */
-      else if (regno == REG_Z || regno == REG_Y)
-	return 1;		/* strictly check */
-      else if (xx == frame_pointer_rtx
-	       || xx == arg_pointer_rtx)
-	return 1;		/* XXX frame & arg pointer checks */
+      
+      ok = (/* allocate pseudos */
+            regno >= FIRST_PSEUDO_REGISTER
+            /* strictly check */
+            || regno == REG_Z || regno == REG_Y
+            /* XXX frame & arg pointer checks */
+            || xx == frame_pointer_rtx
+            || xx == arg_pointer_rtx);
+      
+      if (avr_log.constraints)
+        avr_edump ("\n%?=%d reload_completed=%d reload_in_progress=%d\n %r\n",
+                   ok, reload_completed, reload_in_progress, x);
     }
-  return 0;
+
+  return ok;
 }
 
 /* Convert condition code CONDITION to the valid AVR condition code.  */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n]
  2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
@ 2011-09-29 18:37     ` Denis Chertykov
  2011-09-30 12:54     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n] Georg-Johann Lay
  2011-09-30 14:58     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [4/n] Georg-Johann Lay
  2 siblings, 0 replies; 8+ messages in thread
From: Denis Chertykov @ 2011-09-29 18:37 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-patches, Eric Weddington

2011/9/29 Georg-Johann Lay <avr@gjlay.de>:
> This is the second patch in this series.
>
> Functions that formerly used fprintf/debug_rtx now use avr_edump and the use
> sites of TARGET_ALL_DEBUG are mapped to respective flags of avr_log.
>
> avr_log_vadump uses %b to print bool.
>
> The patch adds outputs for the results of avr_rtx_costs and wraps the worker
> function.
>
> Ok to apply?
>
> Johann
>
>        PR target/50566
>        * config/avr/avr-log.c (avr_log_vadump): Use %b to print bool.
>        * config/avr/avr.c (avr_rtx_costs_1): New static function, renamed
>        from avr_rtx_costs.
>        (avr_legitimate_address_p): Use avr_edump to print log information
>        filtered by avr_log.
>        (extra_constraint_Q): Ditto.
>        (avr_legitimize_address): Ditto.
>        (avr_rtx_costs): Ditto.  Rewrite as wrapper for avr_rtx_costs_1.
>        (final_prescan_insn): Use avr_log.rtx_costs as filter.


Approved.

Denis.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n]
  2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
  2011-09-29 18:37     ` Denis Chertykov
@ 2011-09-30 12:54     ` Georg-Johann Lay
  2011-09-30 14:42       ` Weddington, Eric
  2011-09-30 14:58     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [4/n] Georg-Johann Lay
  2 siblings, 1 reply; 8+ messages in thread
From: Georg-Johann Lay @ 2011-09-30 12:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

This adds log output to avr_address_cost.

Ok for trunk?

Johann

	PR target/50566
	* config/avr/avr-protos.h (avr_log_t): New field address_cost.
	* config/avr/avr.c (avr_address_cost): Use it.
	* config/avr/avr-log.c (avr_log_set_avr_log): Initialize it.
	(avr_log_vadump): Unknown %-codes finish printing.


[-- Attachment #2: better-log-5.diff --]
[-- Type: text/x-patch, Size: 2469 bytes --]

Index: config/avr/avr-log.c
===================================================================
--- config/avr/avr-log.c	(revision 179378)
+++ config/avr/avr-log.c	(working copy)
@@ -283,7 +283,12 @@ avr_log_vadump (FILE *file, const char *
               abort();
               
             default:
-              fputc (*(fmt-1), file);
+              /* Unknown %-code: Stop printing */
+              
+              fprintf (file, "??? %%%c ???\n", *(fmt-1));
+              fmt = "";
+              
+              break;
             }
           break; /* % */
         }
@@ -318,6 +323,7 @@ avr_log_set_avr_log (void)
       SET_DUMP_DETAIL (legitimize_address);
       SET_DUMP_DETAIL (legitimize_reload_address);
       SET_DUMP_DETAIL (constraints);
+      SET_DUMP_DETAIL (address_cost);
 
 #undef SET_DUMP_DETAIL
     }
Index: config/avr/avr-protos.h
===================================================================
--- config/avr/avr-protos.h	(revision 179378)
+++ config/avr/avr-protos.h	(working copy)
@@ -129,6 +129,7 @@ typedef struct
   unsigned legitimize_address :1;
   unsigned legitimize_reload_address :1;
   unsigned constraints :1;
+  unsigned address_cost :1;
 } avr_log_t;
 
 extern avr_log_t avr_log;
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 179378)
+++ config/avr/avr.c	(working copy)
@@ -6573,23 +6573,33 @@ avr_rtx_costs (rtx x, int codearg, int o
   return done;
 }
 
-/* Calculate the cost of a memory address.  */
+
+/* Implement `TARGET_ADDRESS_COST'.  */
 
 static int
 avr_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
 {
+  int cost = 4;
+  
   if (GET_CODE (x) == PLUS
-      && GET_CODE (XEXP (x,1)) == CONST_INT
-      && (REG_P (XEXP (x,0)) || GET_CODE (XEXP (x,0)) == SUBREG)
-      && INTVAL (XEXP (x,1)) >= 61)
-    return 18;
-  if (CONSTANT_ADDRESS_P (x))
+      && CONST_INT_P (XEXP (x, 1))
+      && (REG_P (XEXP (x, 0))
+          || GET_CODE (XEXP (x, 0)) == SUBREG))
+    {
+      if (INTVAL (XEXP (x, 1)) >= 61)
+        cost = 18;
+    }
+  else if (CONSTANT_ADDRESS_P (x))
     {
-      if (optimize > 0 && io_address_operand (x, QImode))
-	return 2;
-      return 4;
+      if (optimize > 0
+          && io_address_operand (x, QImode))
+        cost = 2;
     }
-  return 4;
+
+  if (avr_log.address_cost)
+    avr_edump ("\n%?: %d = %r\n", cost, x);
+  
+  return cost;
 }
 
 /* Test for extra memory constraint 'Q'.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n]
  2011-09-30 12:54     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n] Georg-Johann Lay
@ 2011-09-30 14:42       ` Weddington, Eric
  0 siblings, 0 replies; 8+ messages in thread
From: Weddington, Eric @ 2011-09-30 14:42 UTC (permalink / raw)
  To: Georg-Johann Lay, gcc-patches; +Cc: Denis Chertykov



> -----Original Message-----
> From: Georg-Johann Lay [mailto:avr@gjlay.de]
> Sent: Friday, September 30, 2011 6:18 AM
> To: gcc-patches@gcc.gnu.org
> Cc: Denis Chertykov; Weddington, Eric
> Subject: Re: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog=
> [3/n]
> 
> This adds log output to avr_address_cost.
> 
> Ok for trunk?
> 
> Johann
> 
> 	PR target/50566
> 	* config/avr/avr-protos.h (avr_log_t): New field address_cost.
> 	* config/avr/avr.c (avr_address_cost): Use it.
> 	* config/avr/avr-log.c (avr_log_set_avr_log): Initialize it.
> 	(avr_log_vadump): Unknown %-codes finish printing.

Please commit.

Eric

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [4/n]
  2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
  2011-09-29 18:37     ` Denis Chertykov
  2011-09-30 12:54     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n] Georg-Johann Lay
@ 2011-09-30 14:58     ` Georg-Johann Lay
  2 siblings, 0 replies; 8+ messages in thread
From: Georg-Johann Lay @ 2011-09-30 14:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

This is the patch to add log output to LEGITIMIZE_RELOAD_ADDRESS.

The code is moved from macro in avr.h to a new function in avr.c.

Functionality is the same, but IMO it's more convenient to have it as function
than as a quite long macro.

Ok for trunk?

	PR target/50566
	* config/avr/avr-protos.h (avr_legitimize_reload_address): New
	prototype.
	* config/avr/avr.h (LEGITIMIZE_RELOAD_ADDRESS): Copy worker code
	from here...
	* config/avr/avr.c (avr_legitimize_reload_address) ...to this new
	function.  Log if avr_log.legitimize_reload_address.

[-- Attachment #2: better-log-lra.diff --]
[-- Type: text/x-patch, Size: 6968 bytes --]

Index: config/avr/avr-protos.h
===================================================================
--- config/avr/avr-protos.h	(revision 179378)
+++ config/avr/avr-protos.h	(working copy)
@@ -106,6 +106,7 @@ extern RTX_CODE avr_normalize_condition
 extern void out_shift_with_cnt (const char *templ, rtx insn,
 				rtx operands[], int *len, int t_len);
 extern rtx avr_incoming_return_addr_rtx (void);
+extern rtx avr_legitimize_reload_address (rtx, enum machine_mode, int, int, int, int, rtx (*)(rtx,int));
 #endif /* RTX_CODE */
 
 #ifdef REAL_VALUE_TYPE
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 179378)
+++ config/avr/avr.c	(working copy)
@@ -1290,6 +1290,87 @@ avr_legitimize_address (rtx x, rtx oldx,
 }
 
 
+/* Implement `LEGITIMIZE_RELOAD_ADDRESS'.  */
+/* This will allow register R26/27 to be used where it is no worse than normal
+   base pointers R28/29 or R30/31.  For example, if base offset is greater
+   than 63 bytes or for R++ or --R addressing.  */
+
+rtx
+avr_legitimize_reload_address (rtx x, enum machine_mode mode,
+                               int opnum, int type, int addr_type,
+                               int ind_levels ATTRIBUTE_UNUSED,
+                               rtx (*mk_memloc)(rtx,int))
+{
+  if (avr_log.legitimize_reload_address)
+    avr_edump ("\n%?:%m %r\n", mode, x);
+  
+  if (1 && (GET_CODE (x) == POST_INC
+            || GET_CODE (x) == PRE_DEC))
+    {
+      push_reload (XEXP (x, 0), XEXP (x, 0), &XEXP (x, 0), &XEXP (x, 0),
+                   POINTER_REGS, GET_MODE (x), GET_MODE (x), 0, 0,
+                   opnum, RELOAD_OTHER);
+      
+      if (avr_log.legitimize_reload_address)
+        avr_edump (" RCLASS = %R\n IN = %r\n OUT = %r\n",
+                   POINTER_REGS, XEXP (x, 0), XEXP (x, 0));
+      
+      return x;
+    }
+  
+  if (GET_CODE (x) == PLUS
+      && REG_P (XEXP (x, 0))
+      && 0 == reg_equiv_constant (REGNO (XEXP (x, 0)))
+      && CONST_INT_P (XEXP (x, 1))
+      && INTVAL (XEXP (x, 1)) >= 1)
+    {
+      bool fit = INTVAL (XEXP (x, 1)) <= MAX_LD_OFFSET (mode);
+      
+      if (fit)
+        {
+          if (reg_equiv_address (REGNO (XEXP (x, 0))) != 0)
+            {
+              int regno = REGNO (XEXP (x, 0));
+              rtx mem = mk_memloc (x, regno);
+              
+              push_reload (XEXP (mem, 0), NULL_RTX, &XEXP (mem, 0), NULL,
+                           POINTER_REGS, Pmode, VOIDmode, 0, 0,
+                           1, addr_type);
+              
+              if (avr_log.legitimize_reload_address)
+                avr_edump (" RCLASS = %R\n IN = %r\n OUT = %r\n",
+                           POINTER_REGS, XEXP (mem, 0), NULL_RTX);
+              
+              push_reload (mem, NULL_RTX, &XEXP (x, 0), NULL,
+                           BASE_POINTER_REGS, GET_MODE (x), VOIDmode, 0, 0,
+                           opnum, type);
+              
+              if (avr_log.legitimize_reload_address)
+                avr_edump (" RCLASS = %R\n IN = %r\n OUT = %r\n",
+                           BASE_POINTER_REGS, mem, NULL_RTX);
+              
+              return x;
+            }
+        }
+      else if (! (frame_pointer_needed
+                  && XEXP (x, 0) == frame_pointer_rtx))
+        {
+          push_reload (x, NULL_RTX, &x, NULL,
+                       POINTER_REGS, GET_MODE (x), VOIDmode, 0, 0,
+                       opnum, type);
+          
+          if (avr_log.legitimize_reload_address)
+            avr_edump (" RCLASS = %R\n IN = %r\n OUT = %r\n",
+                       POINTER_REGS, x, NULL_RTX);
+          
+          return x;
+        }
+    }
+  
+  return NULL_RTX;
+}
+
+
 /* Helper function to print assembler resp. track instruction
    sequence lengths.
    
Index: config/avr/avr.h
===================================================================
--- config/avr/avr.h	(revision 179378)
+++ config/avr/avr.h	(working copy)
@@ -385,51 +385,17 @@ typedef struct avr_args {
   (REGNO (X) >= FIRST_PSEUDO_REGISTER || REG_OK_FOR_BASE_STRICT_P(X))
 
 #define REG_OK_FOR_BASE_STRICT_P(X) REGNO_OK_FOR_BASE_P (REGNO (X))
-
-/* LEGITIMIZE_RELOAD_ADDRESS will allow register R26/27 to be used, where it
-   is no worse than normal base pointers R28/29 and R30/31. For example:
-   If base offset is greater than 63 bytes or for R++ or --R addressing.  */
-   
-#define LEGITIMIZE_RELOAD_ADDRESS(X, MODE, OPNUM, TYPE, IND_LEVELS, WIN)    \
-do {									    \
-  if (1&&(GET_CODE (X) == POST_INC || GET_CODE (X) == PRE_DEC))	    \
-    {									    \
-      push_reload (XEXP (X,0), XEXP (X,0), &XEXP (X,0), &XEXP (X,0),	    \
-	           POINTER_REGS, GET_MODE (X),GET_MODE (X) , 0, 0,	    \
-		   OPNUM, RELOAD_OTHER);				    \
-      goto WIN;								    \
-    }									    \
-  if (GET_CODE (X) == PLUS						    \
-      && REG_P (XEXP (X, 0))						    \
-      && (reg_equiv_constant (REGNO (XEXP (X, 0))) == 0)		    \
-      && GET_CODE (XEXP (X, 1)) == CONST_INT				    \
-      && INTVAL (XEXP (X, 1)) >= 1)					    \
-    {									    \
-      int fit = INTVAL (XEXP (X, 1)) <= (64 - GET_MODE_SIZE (MODE));	    \
-      if (fit)								    \
-	{								    \
-          if (reg_equiv_address (REGNO (XEXP (X, 0))) != 0)		    \
-	    {								    \
-	      int regno = REGNO (XEXP (X, 0));				    \
-	      rtx mem = make_memloc (X, regno);				    \
-	      push_reload (XEXP (mem,0), NULL, &XEXP (mem,0), NULL,         \
-		           POINTER_REGS, Pmode, VOIDmode, 0, 0,		    \
-		           1, ADDR_TYPE (TYPE));			    \
-	      push_reload (mem, NULL_RTX, &XEXP (X, 0), NULL,		    \
-		           BASE_POINTER_REGS, GET_MODE (X), VOIDmode, 0, 0, \
-		           OPNUM, TYPE);				    \
-	      goto WIN;							    \
-	    }								    \
-	}								    \
-      else if (! (frame_pointer_needed && XEXP (X,0) == frame_pointer_rtx)) \
-	{								    \
-	  push_reload (X, NULL_RTX, &X, NULL,				    \
-		       POINTER_REGS, GET_MODE (X), VOIDmode, 0, 0,	    \
-		       OPNUM, TYPE);					    \
-          goto WIN;							    \
-	}								    \
-    }									    \
-} while(0)
+#define LEGITIMIZE_RELOAD_ADDRESS(X,MODE,OPNUM,TYPE,IND_L,WIN)          \
+  do {                                                                  \
+    rtx new_x = avr_legitimize_reload_address (X, MODE, OPNUM, TYPE,    \
+                                               ADDR_TYPE (TYPE),        \
+                                               IND_L, make_memloc);     \
+    if (new_x)                                                          \
+      {                                                                 \
+        X = new_x;                                                      \
+        goto WIN;                                                       \
+      }                                                                 \
+  } while (0)
 
 #define BRANCH_COST(speed_p, predictable_p) 0
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-09-30 14:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 16:29 [Patch,AVR]: Better log output with -mdeb Georg-Johann Lay
2011-09-29 11:27 ` [Patch,AVR]: Better log output with -mdeb/-mdebug= Georg-Johann Lay
2011-09-29 13:14   ` Denis Chertykov
2011-09-29 15:26   ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [2/n] Georg-Johann Lay
2011-09-29 18:37     ` Denis Chertykov
2011-09-30 12:54     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [3/n] Georg-Johann Lay
2011-09-30 14:42       ` Weddington, Eric
2011-09-30 14:58     ` [Patch,AVR]: PR50566: Better log output with -mdeb/-mlog= [4/n] Georg-Johann Lay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).