This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: Dump rtl in assembly
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH]: Dump rtl in assembly
- From: Stephane Carrez <Stephane dot Carrez at worldnet dot fr>
- Date: Mon, 07 Aug 2000 00:44:38 +0200
Hi!
While developping the 68hc11 port, I found that it was quite useful
to be able to dump the RTL in the assembly file, as an assembly comment.
By doing so, it becomes easier to find a problem in the generated code
(because you directly see the asm instruction with the rtl pattern above it;
then you switch to other RTL dump to find out the problem).
The following patch introduces a new option -dZ (??? need some debug letter)
do dump the RTL in the assembly file. It's easy in fact, we just have to
print the ASM_COMMENT_START at beginning of each rtl line. In final_scan_insn,
we configure 'print-rtl' to do that, dump the insn in the asm file and
restore 'print-rtl' (for normal dumps).
To avoid major changes in the print_rtl operation, I've added a simple
string global variable 'print_rtx_head' which is empty by default and
set to ASM_COMMENT_START by final_prescan_insn.
The asm rtl dump is not generated even when you specify -da (I thought it was
better). It must be explicitly activated.
Do you agree to integrate this patch?
Stephane
ChangeLog for gcc/ChangeLog
2000-08-06 Stephane Carrez <Stephane.Carrez@worldnet.fr>
* flags.h (flag_dump_rtl_in_asm): Declare.
* toplev.c (flag_dump_rtl_in_asm): Define.
(decode_d_option): Set flag_dump_rtl_in_asm if -dZ is specified.
* rtl.h (print_rtx_head): Declare.
* print-rtl.c (print_rtx_head): Define.
(print_rtx): Print the string pointed to by print_rtx_head
at beginning of each dump line.
(print_rtl): Likewise.
(print_rtl_single): Likewise.
* final.c (final_scan_insn): Dump the insn in the assembly
file for debugging.
diff -Nrup --exclude-from=gcc-exclude.lst /src/gnu/cygnus/gcc/gcc/rtl.h gcc/gcc/rtl.h
--- /src/gnu/cygnus/gcc/gcc/rtl.h Sun Aug 6 11:38:37 2000
+++ gcc/gcc/rtl.h Sun Aug 6 12:09:31 2000
@@ -1728,6 +1761,7 @@ extern void schedule_insns PARAMS ((FIL
extern void fix_sched_param PARAMS ((const char *, const char *));
/* In print-rtl.c */
+extern char *print_rtx_head;
extern void debug_rtx PARAMS ((rtx));
extern void debug_rtx_list PARAMS ((rtx, int));
extern void debug_rtx_range PARAMS ((rtx, rtx));
diff -Nrup --exclude-from=gcc-exclude.lst /src/gnu/cygnus/gcc/gcc/final.c gcc/gcc/final.c
--- /src/gnu/cygnus/gcc/gcc/final.c Sun Aug 6 11:35:24 2000
+++ gcc/gcc/final.c Sun Aug 6 12:09:26 2000
@@ -2924,6 +2926,14 @@ final_scan_insn (insn, file, optimize, p
extract_insn (insn);
cleanup_subreg_operands (insn);
+ /* Dump the insn in the assembly for debugging. */
+ if (flag_dump_rtl_in_asm)
+ {
+ print_rtx_head = ASM_COMMENT_START;
+ print_rtl_single (asm_out_file, insn);
+ print_rtx_head = "";
+ }
+
if (! constrain_operands (1))
fatal_insn_not_found (insn);
diff -Nrup --exclude-from=gcc-exclude.lst /src/gnu/cygnus/gcc/gcc/flags.h gcc/gcc/flags.h
--- /src/gnu/cygnus/gcc/gcc/flags.h Tue Aug 1 23:10:30 2000
+++ gcc/gcc/flags.h Sun Aug 6 12:09:26 2000
@@ -462,6 +462,8 @@ extern int flag_verbose_asm;
extern int flag_debug_asm;
+extern int flag_dump_rtl_in_asm;
+
/* -fgnu-linker specifies use of the GNU linker for initializations.
-fno-gnu-linker says that collect will be used. */
extern int flag_gnu_linker;
diff -Nrup --exclude-from=gcc-exclude.lst /src/gnu/cygnus/gcc/gcc/print-rtl.c gcc/gcc/print-rtl.c
--- /src/gnu/cygnus/gcc/gcc/print-rtl.c Sun Aug 6 11:37:41 2000
+++ gcc/gcc/print-rtl.c Sun Aug 6 12:09:29 2000
@@ -55,6 +55,11 @@ static int indent;
static void print_rtx PARAMS ((rtx));
+/* String printed at beginning of each RTL when it is dumped.
+ This string is set to ASM_COMMENT_START when the RTL is dumped in
+ the assembly output file. */
+char *print_rtx_head = "";
+
/* Nonzero means suppress output of instruction numbers and line number
notes in debugging dumps.
This must be defined here so that programs like gencodes can be linked. */
@@ -77,8 +82,9 @@ print_rtx (in_rtx)
if (sawclose)
{
- fprintf (outfile, "\n%s",
- (xspaces + (sizeof xspaces - 1 - indent * 2)));
+ fprintf (outfile, "\n%s%s",
+ print_rtx_head,
+ (xspaces + (sizeof xspaces - 1 - indent * 2)));
sawclose = 0;
}
@@ -253,7 +259,8 @@ print_rtx (in_rtx)
indent += 2;
if (sawclose)
{
- fprintf (outfile, "\n%s",
+ fprintf (outfile, "\n%s%s",
+ print_rtx_head,
(xspaces + (sizeof xspaces - 1 - indent * 2)));
sawclose = 0;
}
@@ -270,7 +277,8 @@ print_rtx (in_rtx)
indent -= 2;
}
if (sawclose)
- fprintf (outfile, "\n%s",
+ fprintf (outfile, "\n%s%s",
+ print_rtx_head,
(xspaces + (sizeof xspaces - 1 - indent * 2)));
fputs ("] ", outfile);
@@ -566,7 +574,10 @@ print_rtl (outf, rtx_first)
sawclose = 0;
if (rtx_first == 0)
- fputs ("(nil)\n", outf);
+ {
+ fputs (print_rtx_head, outf);
+ fputs ("(nil)\n", outf);
+ }
else
switch (GET_CODE (rtx_first))
{
@@ -580,12 +591,14 @@ print_rtl (outf, rtx_first)
if (! flag_dump_unnumbered
|| GET_CODE (tmp_rtx) != NOTE || NOTE_LINE_NUMBER (tmp_rtx) < 0)
{
+ fputs (print_rtx_head, outfile);
print_rtx (tmp_rtx);
fprintf (outfile, "\n");
}
break;
default:
+ fputs (print_rtx_head, outfile);
print_rtx (rtx_first);
}
}
@@ -603,6 +616,7 @@ print_rtl_single (outf, x)
if (! flag_dump_unnumbered
|| GET_CODE (x) != NOTE || NOTE_LINE_NUMBER (x) < 0)
{
+ fputs (print_rtx_head, outfile);
print_rtx (x);
putc ('\n', outf);
return 1;
diff -Nrup --exclude-from=gcc-exclude.lst /src/gnu/cygnus/gcc/gcc/toplev.c gcc/gcc/toplev.c
--- /src/gnu/cygnus/gcc/gcc/toplev.c Sun Aug 6 11:39:18 2000
+++ gcc/gcc/toplev.c Sun Aug 6 12:09:32 2000
@@ -779,6 +783,10 @@ int flag_verbose_asm = 0;
int flag_debug_asm = 0;
+/* -dZ causes the rtl to be emited as a comment in assembly. */
+
+int flag_dump_rtl_in_asm = 0;
+
/* -fgnu-linker specifies use of the GNU linker for initializations.
(Or, more generally, a linker that handles initializations.)
-fno-gnu-linker says that collect2 will be used. */
@@ -3930,6 +3939,9 @@ decode_d_option (arg)
case 'A':
flag_debug_asm = 1;
break;
+ case 'Z':
+ flag_dump_rtl_in_asm = 1;
+ break;
case 'm':
flag_print_mem = 1;
break;