From patchwork Fri Jan 8 13:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1423777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=uBMi7fxG; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC3nf6pn2z9sW1 for ; Sat, 9 Jan 2021 00:28:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E7B0386F82C; Fri, 8 Jan 2021 13:28:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E7B0386F82C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610112482; bh=jdkfVxnm77d/9FxqUIJh7ps2p/eDymp5tcJXAfvyw+M=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uBMi7fxGVLOM9RNRDmfnTRPBKB+7S3kZ57rJ+09Y1MuoYxMJ6qmA3t9nXVpPGSZLv ZARjj+tscH/k2B3y63JMIx0QyCtrzX03CSqodWz+cGMxovFTqTz+gQQkDkGAquE/E4 DmHSS4Fiss950MmoftJhaH0TPK1syqm6VNj3LUcI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 29EBE386F467 for ; Fri, 8 Jan 2021 13:28:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 29EBE386F467 Received: by mail-oi1-x22f.google.com with SMTP id s2so11335473oij.2 for ; Fri, 08 Jan 2021 05:28:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jdkfVxnm77d/9FxqUIJh7ps2p/eDymp5tcJXAfvyw+M=; b=LUNXqbNO+vsvbCPiyiFhXrhMEsYU5pvsCc3Hi54DxWGXQG/6UwOyytpP4WX7bK7Wwd 5aRUwONR5bbxDw1fnstIi2S7YY7baDSiwHm9oqt/PT2yRawa4bKrWT5DqYbOUX39pmUL P8j/aMlwkTjk9fUQaQSAx4zolNXx40odC04gTP+zjFw5sUxdm2texbJrcrKOh/Tumlxb 57DxeWwiHGrks9xCuuYQoXB6su10tgyunqx9qIxEdOIKnn2DpXPzg+ju8Fy/N5CC9Eee PyALnjsNt6mE1x+K6JHVVF1t5t+MF117/Jz5let3g0bwxv1dqB5+ZMRuh8pLwcSiIEuC DIpw== X-Gm-Message-State: AOAM5309M85rTMDrXtLfKfCAKWUTviArtZtRfCpT+T4AP8Yc9EMmGm3o l8bFai3rqE3J9q503p1dMRuVhmkJugvBpEftQKY= X-Google-Smtp-Source: ABdhPJxQU8i6r1xBIbj0PZBUy/eqqoR8/au4NgrPHcrZ6VmJ9stY0bJd5HRGWKD7YmMYG1B4/e7p4xZFa2gXjigiBzg= X-Received: by 2002:aca:4d8b:: with SMTP id a133mr2344044oib.79.1610112479475; Fri, 08 Jan 2021 05:27:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 8 Jan 2021 05:27:23 -0800 Message-ID: Subject: [PATCH] x86-64: Use R10 and R11 for profiling large model with PIC To: Uros Bizjak X-Spam-Status: No, score=-3036.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: "gcc-patches@gcc.gnu.org" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On Fri, Jan 8, 2021 at 4:50 AM H.J. Lu wrote: > > On Fri, Jan 8, 2021 at 1:24 AM Uros Bizjak 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. From b2e0bccbdba630a1f7f8b601e19b7302e375e240 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" 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