public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] x86-64: Use R10 for profiling large model
@ 2021-01-07 23:49 H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2021-01-07 23:49 UTC (permalink / raw)
  To: gcc-patches

Since R10 is preserved when calling mcount, R10 can be used a scratch
register to call mcount in large model.

gcc/

	PR target/98482
	* config/i386/i386.c (x86_function_profiler): Use R10 to call
	mcount in large model. Sorry for large model with PIC.

gcc/testsuite/

	PR target/98482
	* gcc.target/i386/pr98482-1.c: New test.
	* gcc.target/i386/pr98482-1.c: Likewise.
---
 gcc/config/i386/i386.c                    | 25 +++++++++++++++++++++--
 gcc/testsuite/gcc.target/i386/pr98482-1.c |  9 ++++++++
 gcc/testsuite/gcc.target/i386/pr98482-2.c |  9 ++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr98482-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr98482-2.c

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index fad50e7e537..7a07ab8b5f5 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -20794,8 +20794,29 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
 #endif
 
-      if (!TARGET_PECOFF && flag_pic)
-	fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
+      if (!TARGET_PECOFF)
+	{
+	  switch (ix86_cmodel)
+	    {
+	    case CM_LARGE:
+	      /* NB: R10 can be used as a scratch register here since
+		 R10 is preserved when calling mcount.  */
+	      fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
+		       mcount_name);
+	      break;
+	    case CM_LARGE_PIC:
+	      sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
+	      break;
+	    case CM_SMALL_PIC:
+	    case CM_MEDIUM_PIC:
+	      fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n",
+		       mcount_name);
+	      break;
+	    default:
+	      x86_print_call_or_nop (file, mcount_name);
+	      break;
+	    }
+	}
       else
 	x86_print_call_or_nop (file, mcount_name);
     }
diff --git a/gcc/testsuite/gcc.target/i386/pr98482-1.c b/gcc/testsuite/gcc.target/i386/pr98482-1.c
new file mode 100644
index 00000000000..72d5ccb269c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr98482-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-require-effective-target mfentry } */
+/* { dg-options "-fprofile -mfentry -O2 -mcmodel=large" } */
+/* { dg-final { scan-assembler "movabsq\t\\\$__fentry__, %r10\n\tcall\t\\*%r10" } } */
+
+void
+func (void)
+{
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr98482-2.c b/gcc/testsuite/gcc.target/i386/pr98482-2.c
new file mode 100644
index 00000000000..aed3ca4b6ff
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr98482-2.c
@@ -0,0 +1,9 @@
+/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-require-effective-target mfentry } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large" } */
+
+void
+func (void)
+{
+} /* { dg-message "sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported" } */
-- 
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [PATCH] x86-64: Use R10 for profiling large model
@ 2021-01-08  9:24 Uros Bizjak
  2021-01-08 12:50 ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2021-01-08  9:24 UTC (permalink / raw)
  To: gcc-patches

> Since R10 is preserved when calling mcount, R10 can be used a scratch
> register to call mcount in large model.

Please mention that R10 can be used as a static chain registers and is
preserved when calling mcount for nested functions.

> gcc/
>
> PR target/98482
> * config/i386/i386.c (x86_function_profiler): Use R10 to call
> mcount in large model. Sorry for large model with PIC.
>
> gcc/testsuite/
>
> PR target/98482
> * gcc.target/i386/pr98482-1.c: New test.
> * gcc.target/i386/pr98482-1.c: Likewise.

OK with comment fixes.

Thanks,
Uros.

+    case CM_LARGE:
+      /* NB: R10 can be used as a scratch register here since
+        R10 is preserved when calling mcount.  */

Also mention that R10 can be used as a static chain register and is
preserved when calling mcount for nested functions.

+      fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
+       mcount_name);
+      break;

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

end of thread, other threads:[~2021-01-08 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07 23:49 [PATCH] x86-64: Use R10 for profiling large model H.J. Lu
2021-01-08  9:24 Uros Bizjak
2021-01-08 12:50 ` H.J. Lu

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).