public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH] x86-64: Use R10 and R11 for profiling large model with PIC
Date: Fri, 8 Jan 2021 05:27:23 -0800	[thread overview]
Message-ID: <CAMe9rOrcKaGvYsvm3kQi8OP2vRmkcsTasks+otnxtNJJVgt8GA@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOpBTjxr-X3-5kjghTcJycXthojK8V7mQ+tzf5m-Z0Lj3g@mail.gmail.com>

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

On Fri, Jan 8, 2021 at 4:50 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Jan 8, 2021 at 1:24 AM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > > 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;
>
> This is the patch I am checking in.
>

For NO_PROFILE_COUNTERS targets, R11 is a scratch register.  We can use
R10 and R11 to call mcount in large model with PIC.

OK for master?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-x86-64-Use-R10-and-R11-for-profiling-large-model-wit.patch --]
[-- Type: text/x-patch, Size: 2260 bytes --]

From b2e0bccbdba630a1f7f8b601e19b7302e375e240 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 8 Jan 2021 05:20:19 -0800
Subject: [PATCH] x86-64: Use R10 and R11 for profiling large model with PIC

For NO_PROFILE_COUNTERS targets, R11 is a scratch register.  We can use
R10 and R11 to call mcount in large model with PIC.

gcc/

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

gcc/testsuite/

	PR target/98482
	* gcc.target/i386/pr98482-2.c: Updated.
---
 gcc/config/i386/i386.c                    | 10 ++++++++++
 gcc/testsuite/gcc.target/i386/pr98482-2.c |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index d3068462fcd..50380865acd 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -20806,7 +20806,17 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 		       mcount_name);
 	      break;
 	    case CM_LARGE_PIC:
+#ifdef NO_PROFILE_COUNTERS
+	      fprintf (file, "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
+	      fprintf (file, "\tleaq\t1b(%%rip), %%r10\n");
+	      fprintf (file, "\taddq\t%%r11, %%r10\n");
+	      fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n",
+		       mcount_name);
+	      fprintf (file, "\taddq\t%%r11, %%r10\n");
+	      fprintf (file, "\tcall\t*%%r10\n");
+#else
 	      sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
+#endif
 	      break;
 	    case CM_SMALL_PIC:
 	    case CM_MEDIUM_PIC:
diff --git a/gcc/testsuite/gcc.target/i386/pr98482-2.c b/gcc/testsuite/gcc.target/i386/pr98482-2.c
index aed3ca4b6ff..0ee142db12c 100644
--- a/gcc/testsuite/gcc.target/i386/pr98482-2.c
+++ b/gcc/testsuite/gcc.target/i386/pr98482-2.c
@@ -2,8 +2,9 @@
 /* { dg-require-effective-target mfentry } */
 /* { dg-require-effective-target fpic } */
 /* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large" } */
+/* { dg-final { scan-assembler "movabsq\t\\\$__fentry__@PLTOFF, %r11\n\taddq\t%r11, %r10\n\tcall\t\\*%r10" } } */
 
 void
 func (void)
 {
-} /* { dg-message "sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported" } */
+}
-- 
2.29.2


  reply	other threads:[~2021-01-08 13:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08  9:24 [PATCH] x86-64: Use R10 for profiling large model Uros Bizjak
2021-01-08 12:50 ` H.J. Lu
2021-01-08 13:27   ` H.J. Lu [this message]
2021-01-08 14:31     ` [PATCH] x86-64: Use R10 and R11 for profiling large model with PIC Uros Bizjak
2021-01-08 14:43       ` H.J. Lu
2021-01-08 16:45         ` [PATCH] x86-64: Require lp64 for PR target/98482 tests H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOrcKaGvYsvm3kQi8OP2vRmkcsTasks+otnxtNJJVgt8GA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).