From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 12DB43858C31; Sat, 2 Mar 2024 00:38:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12DB43858C31 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709339901; bh=JfFJ89JVc/U0ibe9MinC+3eNpgsJeeDoEM18RKQA9w0=; h=From:To:Subject:Date:From; b=DkceeaPO0Ih+vvZh0dFug8rfylnvc2lpW8+xdMswSgZgedYINs8gaSIlc7039+br6 kTHlT/3R1KNv7SMib+4ZJsDkaBpALvmxW3RNVJFNn76fE9kjp/wGNfkAFXMaxmN9pA kyZf6fdAh7v7KPQPLjLypecwVBgoRrPy0jsJX2ig= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8384] i386: Add -masm=intel profiling support [PR113122] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 432708c306838fe1444da0df7d629a60468c0c73 X-Git-Newrev: 8b2a4022af095d1e4fadc2489d4b9ea13966ec5c Message-Id: <20240302003821.12DB43858C31@sourceware.org> Date: Sat, 2 Mar 2024 00:38:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8b2a4022af095d1e4fadc2489d4b9ea13966ec5c commit r13-8384-g8b2a4022af095d1e4fadc2489d4b9ea13966ec5c Author: Jakub Jelinek 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 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) +{ +}