public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8384] i386: Add -masm=intel profiling support [PR113122]
@ 2024-03-02  0:38 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-03-02  0:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8b2a4022af095d1e4fadc2489d4b9ea13966ec5c

commit r13-8384-g8b2a4022af095d1e4fadc2489d4b9ea13966ec5c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jan 18 10:21:12 2024 +0100

    i386: Add -masm=intel profiling support [PR113122]
    
    x86_function_profiler emits assembly directly into file and only emits
    AT&T syntax.  The following patch adjusts it to emit MASM syntax
    if -masm=intel.
    As it doesn't use asm_fprintf, I can't use {|} syntax for the dialects.
    
    I've tested using
    for i in -mcmodel=large "-mcmodel=large -fpic" "" -fpic "-m32 -fpic" "-m32"; do
    ./xgcc -B ./ -c -O2 -fprofile $i -masm=att pr113122.c -o pr113122.o1;
    ./xgcc -B ./ -c -O2 -fprofile $i -masm=intel pr113122.c -o pr113122.o2;
    objdump -dr pr113122.o1 > /tmp/1; objdump -dr pr113122.o2 > /tmp/2;
    diff -up /tmp/1 /tmp/2; done
    that the emitted sequences are identical after assembly.
    
    2024-01-18  Jakub Jelinek  <jakub@redhat.com>
    
            PR target/113122
            * config/i386/i386.cc (x86_function_profiler): Add -masm=intel
            support.  Add missing space after , in emitted assembly in some
            cases.  Formatting fixes.
    
            * gcc.target/i386/pr113122-1.c: New test.
            * gcc.target/i386/pr113122-2.c: New test.
            * gcc.target/i386/pr113122-3.c: New test.
            * gcc.target/i386/pr113122-4.c: New test.
    
    (cherry picked from commit d4a2d91b46b2cf758b249a4545e34287e90da23b)

Diff:
---
 gcc/config/i386/i386.cc                    | 62 ++++++++++++++++++++++++------
 gcc/testsuite/gcc.target/i386/pr113122-1.c | 10 +++++
 gcc/testsuite/gcc.target/i386/pr113122-2.c | 11 ++++++
 gcc/testsuite/gcc.target/i386/pr113122-3.c |  9 +++++
 gcc/testsuite/gcc.target/i386/pr113122-4.c | 10 +++++
 5 files changed, 90 insertions(+), 12 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 56cc15de93d..a3a295a303e 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21811,7 +21811,10 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
   if (TARGET_64BIT)
     {
 #ifndef NO_PROFILE_COUNTERS
-      fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
+      if (ASSEMBLER_DIALECT == ASM_INTEL)
+	fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno);
+      else
+	fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno);
 #endif
 
       if (!TARGET_PECOFF)
@@ -21822,12 +21825,29 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 	      /* NB: R10 is caller-saved.  Although it can be used as a
 		 static chain register, it is preserved when calling
 		 mcount for nested functions.  */
-	      fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
-		       mcount_name);
+	      if (ASSEMBLER_DIALECT == ASM_INTEL)
+		fprintf (file, "1:\tmovabs\tr10, OFFSET FLAT:%s\n"
+			       "\tcall\tr10\n", mcount_name);
+	      else
+		fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
+			 mcount_name);
 	      break;
 	    case CM_LARGE_PIC:
 #ifdef NO_PROFILE_COUNTERS
-	      fprintf (file, "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
+	      if (ASSEMBLER_DIALECT == ASM_INTEL)
+		{
+		  fprintf (file, "1:movabs\tr11, "
+				 "OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n");
+		  fprintf (file, "\tlea\tr10, 1b[rip]\n");
+		  fprintf (file, "\tadd\tr10, r11\n");
+		  fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n",
+			   mcount_name);
+		  fprintf (file, "\tadd\tr10, r11\n");
+		  fprintf (file, "\tcall\tr10\n");
+		  break;
+		}
+	      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);
@@ -21839,7 +21859,11 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
 	      break;
 	    case CM_SMALL_PIC:
 	    case CM_MEDIUM_PIC:
-	      fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
+	      if (ASSEMBLER_DIALECT == ASM_INTEL)
+		fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n",
+			 mcount_name);
+	      else
+		fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
 	      break;
 	    default:
 	      x86_print_call_or_nop (file, mcount_name);
@@ -21852,23 +21876,37 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
   else if (flag_pic)
     {
 #ifndef NO_PROFILE_COUNTERS
-      fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
-	       LPREFIX, labelno);
+      if (ASSEMBLER_DIALECT == ASM_INTEL)
+	fprintf (file,
+		 "\tlea\t" PROFILE_COUNT_REGISTER ", %sP%d@GOTOFF[ebx]\n",
+		 LPREFIX, labelno);
+      else
+	fprintf (file,
+		 "\tleal\t%sP%d@GOTOFF(%%ebx), %%" PROFILE_COUNT_REGISTER "\n",
+		 LPREFIX, labelno);
 #endif
-      fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
+      if (ASSEMBLER_DIALECT == ASM_INTEL)
+	fprintf (file, "1:\tcall\t[DWORD PTR %s@GOT[ebx]]\n", mcount_name);
+      else
+	fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
     }
   else
     {
 #ifndef NO_PROFILE_COUNTERS
-      fprintf (file, "\tmovl\t$%sP%d,%%" PROFILE_COUNT_REGISTER "\n",
-	       LPREFIX, labelno);
+      if (ASSEMBLER_DIALECT == ASM_INTEL)
+	fprintf (file,
+		 "\tmov\t" PROFILE_COUNT_REGISTER ", OFFSET FLAT:%sP%d\n",
+		 LPREFIX, labelno);
+      else
+	fprintf (file, "\tmovl\t$%sP%d, %%" PROFILE_COUNT_REGISTER "\n",
+		 LPREFIX, labelno);
 #endif
       x86_print_call_or_nop (file, mcount_name);
     }
 
   if (flag_record_mcount
-	|| lookup_attribute ("fentry_section",
-                                DECL_ATTRIBUTES (current_function_decl)))
+      || lookup_attribute ("fentry_section",
+			   DECL_ATTRIBUTES (current_function_decl)))
     {
       const char *sname = "__mcount_loc";
 
diff --git a/gcc/testsuite/gcc.target/i386/pr113122-1.c b/gcc/testsuite/gcc.target/i386/pr113122-1.c
new file mode 100644
index 00000000000..959b007d63a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr113122-1.c
@@ -0,0 +1,10 @@
+/* PR target/113122 */
+/* { dg-do assemble { target { *-*-linux* && lp64 } } } */
+/* { dg-require-effective-target mfentry } */
+/* { dg-require-effective-target masm_intel } */
+/* { dg-options "-fprofile -mfentry -O2 -mcmodel=large -masm=intel" } */
+
+void
+func (void)
+{
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr113122-2.c b/gcc/testsuite/gcc.target/i386/pr113122-2.c
new file mode 100644
index 00000000000..7423a77fa9c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr113122-2.c
@@ -0,0 +1,11 @@
+/* PR target/113122 */
+/* { dg-do assemble { target { *-*-linux* && lp64 } } } */
+/* { dg-require-effective-target mfentry } */
+/* { dg-require-effective-target masm_intel } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large -masm=intel" } */
+
+void
+func (void)
+{
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr113122-3.c b/gcc/testsuite/gcc.target/i386/pr113122-3.c
new file mode 100644
index 00000000000..71aa240ba98
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr113122-3.c
@@ -0,0 +1,9 @@
+/* PR target/113122 */
+/* { dg-do assemble { target *-*-linux* } } */
+/* { dg-require-effective-target masm_intel } */
+/* { dg-options "-fprofile -O2 -masm=intel" } */
+
+void
+func (void)
+{
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr113122-4.c b/gcc/testsuite/gcc.target/i386/pr113122-4.c
new file mode 100644
index 00000000000..00621e4cfa3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr113122-4.c
@@ -0,0 +1,10 @@
+/* PR target/113122 */
+/* { dg-do assemble { target *-*-linux* } } */
+/* { dg-require-effective-target masm_intel } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fpic -fprofile -O2 -masm=intel" } */
+
+void
+func (void)
+{
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-02  0:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02  0:38 [gcc r13-8384] i386: Add -masm=intel profiling support [PR113122] Jakub Jelinek

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