From patchwork Thu Jan 18 07:31:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 189019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp179048dyb; Wed, 17 Jan 2024 23:32:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfldGqoaLdPcb26d/t98oQZi+A1fjB3voeAIgEda0Fjt1TmjEJGR0CiZDVdhaJuCUVeiDd X-Received: by 2002:a05:622a:1109:b0:42a:1436:e7d2 with SMTP id e9-20020a05622a110900b0042a1436e7d2mr415518qty.66.1705563170790; Wed, 17 Jan 2024 23:32:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705563170; cv=pass; d=google.com; s=arc-20160816; b=GTml5KrSSrm3Hzff7w5y70a/tm+BmkdhBL52CDWh7l4XktwmUUS4vF1mWo/abaaz0X KbjNIyvvj7guk6kFnZlqPgQ+sa0DPao/gNjmzRx+mjnec9147K1z4vbFbtkTWfrYGNBT TNIIoIsAFdR042f5XfnLgMUkQ/5Y9+J0/sRJaYmbiVojbD18t9OItXzR8Ah3qKhqV9p3 nvmfD3UC9m1kS5yG6Tx7mEbn2RyYJ3Or2YjoHiQGPd7SmxV0/LgbRMlW8xVYnHGJQcHg GObF7fs7XmyErjmlPMoWpnsK69syYu2chOdpvspv3gp1TGdsXBiowXYoDh4gi6q1eHhu 4/kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=8S6QnqfSlaUlg24Zpoi0rJIY5OzePc9FkUhQO5JRdFU=; fh=h2iPLTLlSKmpj4PWOaJAO8af6hiH/htLInOT1vU8M+E=; b=r94gty6Cn0B3PTQxkZPA4s+1SE7gPoh/NK4REodGQuz95GSeuf2qI85OKUwy8L7xme UqJOGPSEwgsIHLNu1b9DABJhQxgq68/bmHFT1nn5yORLt5Thr9ldOyzf9ARanpiQhiXB lEwMtabJQX4bNuF8sRfqwRKi8EQdP+bnk/SaO31skAAwtbcsDT/8bw8h08EfUZdDlhB7 ACw9Vga22bLtt79uOLES31YBZIgdA/VZnV4n5gjir5BXsOAgScxviws7FvkVVVK67pD7 Usgnimd+rCbbwT4euUw02BI8AWSgBpW0niOq1Y1d97jP/U1Ky6023DwOFJq8mxWk5MZ/ 0VsA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uh2bSPSG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m16-20020a05622a055000b004299561a67esi13138362qtx.351.2024.01.17.23.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:32:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uh2bSPSG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8172E3858C56 for ; Thu, 18 Jan 2024 07:32:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A22783858C41 for ; Thu, 18 Jan 2024 07:31:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A22783858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A22783858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705563119; cv=none; b=HohE4aOI0dOEgpHekqQ29VrNwr70HkP7K7z87x3UqN7zt+peK8O6tiwKLiQsYu3yjWNaOZ228vUZTlw/7dGKCl7lZu3TImF0Vy11NiRABMWVzPXav47Q+lduvqNgx9+EuTme8vdR7K8Q4xQN4LpfBi3ctFvjSPTv+RqnAviJEGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705563119; c=relaxed/simple; bh=9e5Robe/HA+tQZkriLWZIodpvL93VP167RxEmLpcbbY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=V9/3ekhUJxPL0aMq6QPak1raZpfVNdGPB4Wl34kIuSC+0GQmBHgFv1UOhGMuIwaA7HlMQ1jZqcGNJs8zvy9PlgH7kpeLZeVoOQNot/VtYYAlztQpBlKkJM7+JMQyMXKvaWTlxuDpMpV3Z/Hcdh0O8MYaGlgylTloNQLbQPpA9DQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705563116; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=8S6QnqfSlaUlg24Zpoi0rJIY5OzePc9FkUhQO5JRdFU=; b=Uh2bSPSGonP93RhXTljRn1KV0g6789syOgIS5HZeB5EVTejpSJih0HlvDoYG6PFJ83k8Rp ri0lPVk+qF6ZEKHn+ps+w0KTIIcUZ26ihVbFiWv+aD5blANZsg+Q6dosiwz6LXZ4VvM1FG LTPUmiPpxUF+gYzEdM3/m5FwoYJLVW8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-HBIqUV6RMEuDzleMZMNO3A-1; Thu, 18 Jan 2024 02:31:52 -0500 X-MC-Unique: HBIqUV6RMEuDzleMZMNO3A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA30985A589; Thu, 18 Jan 2024 07:31:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE52D1120E; Thu, 18 Jan 2024 07:31:51 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 40I7ViC0226802 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 18 Jan 2024 08:31:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40I7VhpP226801; Thu, 18 Jan 2024 08:31:43 +0100 Date: Thu, 18 Jan 2024 08:31:43 +0100 From: Jakub Jelinek To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Add -masm=intel profiling support [PR113122] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788412607013296782 X-GMAIL-MSGID: 1788412607013296782 Hi! 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; Jakub diff -up /tmp/1 /tmp/2; done that the emitted sequences are identical after assembly. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 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. --- gcc/config/i386/i386.cc.jj 2024-01-05 15:22:21.810685516 +0100 +++ gcc/config/i386/i386.cc 2024-01-17 16:52:48.026177278 +0100 @@ -22746,7 +22746,10 @@ x86_function_profiler (FILE *file, int l 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) @@ -22757,12 +22760,29 @@ x86_function_profiler (FILE *file, int l /* 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); @@ -22776,7 +22796,12 @@ x86_function_profiler (FILE *file, int l case CM_MEDIUM_PIC: if (!ix86_direct_extern_access) { - 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]]", + mcount_name); + else + fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", + mcount_name); break; } /* fall through */ @@ -22791,23 +22816,37 @@ x86_function_profiler (FILE *file, int l 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"; --- gcc/testsuite/gcc.target/i386/pr113122-1.c.jj 2024-01-17 17:04:48.572481159 +0100 +++ gcc/testsuite/gcc.target/i386/pr113122-1.c 2024-01-17 17:05:08.444205080 +0100 @@ -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) +{ +} --- gcc/testsuite/gcc.target/i386/pr113122-2.c.jj 2024-01-17 17:05:19.368053314 +0100 +++ gcc/testsuite/gcc.target/i386/pr113122-2.c 2024-01-17 17:05:30.426899673 +0100 @@ -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) +{ +} --- gcc/testsuite/gcc.target/i386/pr113122-3.c.jj 2024-01-17 17:06:12.932320651 +0100 +++ gcc/testsuite/gcc.target/i386/pr113122-3.c 2024-01-17 17:06:46.199870472 +0100 @@ -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) +{ +} --- gcc/testsuite/gcc.target/i386/pr113122-4.c.jj 2024-01-17 17:06:56.327733421 +0100 +++ gcc/testsuite/gcc.target/i386/pr113122-4.c 2024-01-17 17:07:10.229545301 +0100 @@ -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) +{ +}