aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-01-18 10:21:12 +0100
committerJakub Jelinek <jakub@redhat.com>2024-06-20 12:05:55 +0200
commit9b58a85de42eed538a866146a36bb3221daf5590 (patch)
tree9429333d4331980433ef3388bd057620d931c0f7
parentc845244dd7afae95689b8dd02a62c18932441583 (diff)
downloadgcc-9b58a85de42eed538a866146a36bb3221daf5590.zip
gcc-9b58a85de42eed538a866146a36bb3221daf5590.tar.gz
gcc-9b58a85de42eed538a866146a36bb3221daf5590.tar.bz2
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.c (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)
-rw-r--r--gcc/config/i386/i386.c62
-rw-r--r--gcc/testsuite/gcc.target/i386/pr113122-1.c10
-rw-r--r--gcc/testsuite/gcc.target/i386/pr113122-2.c11
-rw-r--r--gcc/testsuite/gcc.target/i386/pr113122-3.c9
-rw-r--r--gcc/testsuite/gcc.target/i386/pr113122-4.c10
5 files changed, 90 insertions, 12 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 2a27c52..e2d259d 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -20848,7 +20848,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)
@@ -20859,12 +20862,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);
@@ -20876,7 +20896,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);
@@ -20889,23 +20913,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 0000000..959b007
--- /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 0000000..7423a77
--- /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 0000000..71aa240
--- /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 0000000..00621e4
--- /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)
+{
+}