From patchwork Mon Apr 23 17:53:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 903096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476727-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ispras.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uVNXhwl8"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40VDcp5RPlz9rxs for ; Tue, 24 Apr 2018 03:54:50 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=gU3NeouJaMFpqMzt2Qp0UEzKeivrB2zczKx3k23HgkLaPuLlHPii2 r//oAZW+7egGFWRQMORQchM9weWwb/QOZ/XTn6qg8DcFCPbUTitSMi9xMPGEtVJA u2fdM+9LKquW7q9d7gmVLO5f6ljMF9J6YQ012LitYs9C72AkyCT+7Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=ZB8WS+H12TH4ca8zzBSHt9o9exw=; b=uVNXhwl8JKXT8/tR8Nig IcQ3U56t1kYw0MJvrBn786fFgiDyvvQLTCnkqjnsffAYZEsSugtZ4CE+zT/uhj1k m3WcA9O86nHXhyuJwNJyRP1or8OWjXzsI+wrDdV/bOGe+Pp7/OHmUg25Q+ZTJdXK dARqNGKLph/DaALESDIKPYg= Received: (qmail 74677 invoked by alias); 23 Apr 2018 17:54:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 74622 invoked by uid 89); 23 Apr 2018 17:54:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=arrangements, usual, residing, Reg X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Apr 2018 17:54:30 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 69FBA203C9; Mon, 23 Apr 2018 20:54:27 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Cc: Sandra Loosemore , Michael Matz , Alexander Monakov Subject: [PATCH 1/2] extend.texi: update Global Register Variables section Date: Mon, 23 Apr 2018 20:53:47 +0300 Message-Id: <20180423175348.26101-2-amonakov@ispras.ru> In-Reply-To: <20180423175348.26101-1-amonakov@ispras.ru> References: <20180423175348.26101-1-amonakov@ispras.ru> This rewrites global register vars doc to reflect that the register is no longer reserved exclusively, but in fact is available for general allocation, and also adds the requirement to properly inform the compiler where inline asms are accessing the variable. This: -@item The register is not saved and restored by any functions. is reworded to verbosely spell out gotchas related to calls/returns. * extend.texi (Global Register Variables): Rewrite the bullet list. Note that the register is available for allocation. Note that access via inline asm must use constraints. Add note about async-signal handlers. Remove paragraph about automagic register selection. --- gcc/doc/extend.texi | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 5571d05d93b..f663741e36c 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -9549,11 +9549,21 @@ After defining a global register variable, for the current compilation unit: @itemize @bullet -@item The register is reserved entirely for this use, and will not be -allocated for any other purpose. -@item The register is not saved and restored by any functions. -@item Stores into this register are never deleted even if they appear to be -dead, but references may be deleted, moved or simplified. +@item If the register is a call-saved register, call ABI is affected: +the register will not be restored in function epilogue sequences after +the variable has been assigned. Therefore, functions cannot safely +return to callers that assume standard ABI. +@item Conversely, if the register is a call-clobbered register, making +calls to functions that use standard ABI may lose contents of the variable. +Such calls may be created by the compiler even if none are evident in +the original program, for example when libgcc functions are used to +make up for unavailable instructions. +@item Accesses to the variable may be optimized as usual and the register +remains available for allocation and use in any computations, provided that +observable values of the variable are not affected. +@item If the variable is referenced in inline assembly, the type of access +must be provided to the compiler via constraints (@pxref{Constraints}). +Accesses from basic asms are not supported. @end itemize Note that these points @emph{only} apply to code that is compiled with the @@ -9595,7 +9605,10 @@ the comparison function unless the @code{qsort} function itself is rebuilt. Similarly, it is not safe to access the global register variables from signal handlers or from more than one thread of control. Unless you recompile them specially for the task at hand, the system library routines may -temporarily use the register for other things. +temporarily use the register for other things. Furthermore, since the register +is not reserved exclusively for the variable, accessing it from handlers of +asynchronous signals may observe unrelated temporary values residing in the +register. @cindex register variable after @code{longjmp} @cindex global register after @code{longjmp} @@ -9610,10 +9623,6 @@ should make other arrangements to save the values of the global register variables, and to restore them in a @code{longjmp}. This way, the same thing happens regardless of what @code{longjmp} does. -Eventually there may be a way of asking the compiler to choose a register -automatically, but first we need to figure out how it should choose and -how to enable you to guide the choice. No solution is evident. - @node Local Register Variables @subsubsection Specifying Registers for Local Variables @anchor{Local Reg Vars}