From patchwork Wed Feb 6 10:47:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 218543 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A541B2C02CA for ; Wed, 6 Feb 2013 21:47:53 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360752474; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=xrGIRzuUQ0+r35CtqN2O jBjU7Ik=; b=H3CtkD0Ta93BEVkeYg9O22PuSV0As0BGLXnYgtwEt471pODo3K+2 XP63Jx/YIcIuk8aCHzqlY6iYcFjVbQs7Be3gIngoHY4ySl0fI89BX4gO+GXwxrq1 XUZC8le54gF2UqNSTwkvBLAWF74klr28WIqG9xmMQJ1deUHMAGPdSSM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ruX+vfdpkNOoEBSK+pBfNkx2/pkm2AM/e5ft73CZm5Wjot7YqGaLpDYHZs6RnQ 73HS/RlLqO5s2i5geKYxi4nECFNubXPSwb4TiFqYf0fDx51KVjMs5KhgqWalHvCb kMpI07SAo3bKZ/5h4sPwXJD2m8B2WTr0yNylvcMBL85tQ=; Received: (qmail 25880 invoked by alias); 6 Feb 2013 10:47:44 -0000 Received: (qmail 25814 invoked by uid 22791); 6 Feb 2013 10:47:43 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO, TW_TM X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Feb 2013 10:47:36 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5D4E02E619; Wed, 6 Feb 2013 05:47:35 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id U+TizUHGOB01; Wed, 6 Feb 2013 05:47:35 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 2B1072E616; Wed, 6 Feb 2013 05:47:35 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 268D13FF09; Wed, 6 Feb 2013 05:47:35 -0500 (EST) Date: Wed, 6 Feb 2013 05:47:35 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Preliminary work to implement pragma Loop_Optimize Message-ID: <20130206104735.GA20595@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 This is the front-end implementation of the new Loop_Optimize pragma, which makes it possible for the programmer to control the optimizations applied to loops on an individual basis. Tested on x86_64-pc-linux-gnu, committed on trunk 2013-02-06 Eric Botcazou * snames.ads-tmpl (Name_Loop_Optimize, Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector): New pragma-related names. (Pragma_Id): Add Pragma_Loop_Optimize value. * par-prag.adb (Prag): Handle Pragma_Loop_Optimize. * sem_prag.adb (Check_Loop_Invariant_Variant_Placement): Rename to... (Check_Loop_Pragma_Placement): ...this. (Analyze_Pragma) : Adjust to above renaming. : Likewise. : Implement new pragma Loop_Optimize. (Sig_Flags): Add Pragma_Loop_Optimize. * gnat_rm.texi (Implementation Defined Pragmas): Add Loop_Optimize. * gnat_ugn.texi (Vectorization of loops): Mention Loop_Optimize. Index: gnat_rm.texi =================================================================== --- gnat_rm.texi (revision 195794) +++ gnat_rm.texi (working copy) @@ -176,6 +176,7 @@ * Pragma Linker_Destructor:: * Pragma Linker_Section:: * Pragma Long_Float:: +* Pragma Loop_Optimize:: * Pragma Machine_Attribute:: * Pragma Main:: * Pragma Main_Storage:: @@ -925,6 +926,7 @@ * Pragma Linker_Destructor:: * Pragma Linker_Section:: * Pragma Long_Float:: +* Pragma Loop_Optimize:: * Pragma Machine_Attribute:: * Pragma Main:: * Pragma Main_Storage:: @@ -3845,6 +3848,55 @@ @cite{DEC Ada Language Reference Manual}, section 3.5.7b. Note that to use this pragma, the standard runtime libraries must be recompiled. +@node Pragma Loop_Optimize +@unnumberedsec Pragma Loop_Optimize +@findex Loop_Optimize +@noindent +Syntax: + +@smallexample @c ada +pragma Loop_Optimize (OPTIMIZATION_HINT @{, OPTIMIZATION_HINT@}); + +OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector +@end smallexample + +@noindent +This pragma must appear immediately within a loop statement. It allows the +programmer to specify optimization hints for the enclosing loop. The hints +are not mutually exclusive and can be freely mixed, but not all combinations +will yield a sensible outcome. + +There are four supported optimization hints for a loop: +@itemize @bullet +@item No_Unroll + +The loop must not be unrolled. This is a strong hint: the compiler will not +unroll a loop marked with this hint. + +@item Unroll + +The loop should be unrolled. This is a weak hint: the compiler will try to +apply unrolling to this loop preferably to other optimizations, notably +vectorization, but there is no guarantee that the loop will be unrolled. + +@item No_Vector + +The loop must not be vectorized. This is a strong hint: the compiler will not +vectorize a loop marked with this hint. + +@item Vector + +The loop should be vectorized. This is a weak hint: the compiler will try to +apply vectorization to this loop preferably to other optimizations, notably +unrolling, but there is no guarantee that the loop will be vectorized. + +@end itemize + +These hints do not void the need to pass the appropriate switches to the +compiler in order to enable the relevant optimizations, that is to say +@option{-funroll-loops} for unrolling and @option{-ftree-vectorize} for +vectorization. + @node Pragma Machine_Attribute @unnumberedsec Pragma Machine_Attribute @findex Machine_Attribute Index: gnat_ugn.texi =================================================================== --- gnat_ugn.texi (revision 195798) +++ gnat_ugn.texi (working copy) @@ -10978,6 +10978,17 @@ bounds of the array, the more fallback code it needs to generate in order to fix things up at run time. +It is possible to specify that a given loop should be subject to vectorization +preferably to other optimizations by means of pragma @code{Loop_Optimize}: + +@smallexample @c ada + pragma Loop_Optimize (Vector); +@end smallexample + +@noindent +placed immediately within the loop will convey the appropriate hint to the +compiler for this loop. + You can obtain information about the vectorization performed by the compiler by specifying @option{-ftree-vectorizer-verbose=N}. For more details of this switch, see @ref{Debugging Options,,Options for Debugging Your Program Index: par-prag.adb =================================================================== --- par-prag.adb (revision 195798) +++ par-prag.adb (working copy) @@ -1203,6 +1203,7 @@ Pragma_Locking_Policy | Pragma_Long_Float | Pragma_Loop_Invariant | + Pragma_Loop_Optimize | Pragma_Loop_Variant | Pragma_Machine_Attribute | Pragma_Main | Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 195798) +++ sem_prag.adb (working copy) @@ -618,9 +618,9 @@ -- Common processing for first argument of pragma Interrupt_Handler or -- pragma Attach_Handler. - procedure Check_Loop_Invariant_Variant_Placement; - -- Verify whether pragma Loop_Invariant or pragma Loop_Variant appear - -- immediately within a construct restricted to loops. + procedure Check_Loop_Pragma_Placement; + -- Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant + -- appear immediately within a construct restricted to loops. procedure Check_Is_In_Decl_Part_Or_Package_Spec; -- Check that pragma appears in a declarative part, or in a package @@ -1922,11 +1922,11 @@ end if; end Check_Interrupt_Or_Attach_Handler; - -------------------------------------------- - -- Check_Loop_Invariant_Variant_Placement -- - -------------------------------------------- + --------------------------------- + -- Check_Loop_Pragma_Placement -- + --------------------------------- - procedure Check_Loop_Invariant_Variant_Placement is + procedure Check_Loop_Pragma_Placement is procedure Placement_Error (Constr : Node_Id); pragma No_Return (Placement_Error); -- Node Constr denotes the last loop restricted construct before we @@ -1955,7 +1955,7 @@ Prev : Node_Id; Stmt : Node_Id; - -- Start of processing for Check_Loop_Invariant_Variant_Placement + -- Start of processing for Check_Loop_Pragma_Placement begin Prev := N; @@ -2011,7 +2011,7 @@ return; end if; end loop; - end Check_Loop_Invariant_Variant_Placement; + end Check_Loop_Pragma_Placement; ------------------------------------------- -- Check_Is_In_Decl_Part_Or_Package_Spec -- @@ -12341,7 +12341,7 @@ GNAT_Pragma; S14_Pragma; Check_Arg_Count (1); - Check_Loop_Invariant_Variant_Placement; + Check_Loop_Pragma_Placement; -- Completely ignore if disabled @@ -12370,6 +12370,30 @@ Analyze (N); end Loop_Invariant; + ------------------- + -- Loop_Optimize -- + ------------------- + + -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } ); + + -- OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector + + when Pragma_Loop_Optimize => Loop_Optimize : declare + Hint : Node_Id; + + begin + GNAT_Pragma; + Check_At_Least_N_Arguments (1); + Check_No_Identifiers; + Hint := First (Pragma_Argument_Associations (N)); + while Present (Hint) loop + Check_Arg_Is_One_Of (Hint, Name_No_Unroll, Name_Unroll, + Name_No_Vector, Name_Vector); + Next (Hint); + end loop; + Check_Loop_Pragma_Placement; + end Loop_Optimize; + ------------------ -- Loop_Variant -- ------------------ @@ -12388,7 +12412,7 @@ GNAT_Pragma; S14_Pragma; Check_At_Least_N_Arguments (1); - Check_Loop_Invariant_Variant_Placement; + Check_Loop_Pragma_Placement; -- Completely ignore if disabled @@ -16598,6 +16622,7 @@ Pragma_Locking_Policy => -1, Pragma_Long_Float => -1, Pragma_Loop_Invariant => -1, + Pragma_Loop_Optimize => -1, Pragma_Loop_Variant => -1, Pragma_Machine_Attribute => -1, Pragma_Main => -1, Index: snames.ads-tmpl =================================================================== --- snames.ads-tmpl (revision 195798) +++ snames.ads-tmpl (working copy) @@ -408,6 +408,7 @@ Name_Locking_Policy : constant Name_Id := N + $; Name_Long_Float : constant Name_Id := N + $; -- VMS Name_Loop_Invariant : constant Name_Id := N + $; -- GNAT + Name_Loop_Optimize : constant Name_Id := N + $; -- GNAT Name_Loop_Variant : constant Name_Id := N + $; -- GNAT Name_No_Run_Time : constant Name_Id := N + $; -- GNAT Name_No_Strict_Aliasing : constant Name_Id := N + $; -- GNAT @@ -727,6 +728,8 @@ Name_No_Specification_Of_Aspect : constant Name_Id := N + $; Name_No_Task_Attributes : constant Name_Id := N + $; Name_No_Task_Attributes_Package : constant Name_Id := N + $; + Name_No_Unroll : constant Name_Id := N + $; + Name_No_Vector : constant Name_Id := N + $; Name_Nominal : constant Name_Id := N + $; Name_On : constant Name_Id := N + $; Name_Optional : constant Name_Id := N + $; @@ -762,10 +765,12 @@ Name_Unit_Name : constant Name_Id := N + $; Name_Unknown : constant Name_Id := N + $; Name_Unrestricted : constant Name_Id := N + $; + Name_Unroll : constant Name_Id := N + $; Name_Uppercase : constant Name_Id := N + $; Name_User : constant Name_Id := N + $; Name_Variant : constant Name_Id := N + $; Name_VAX_Float : constant Name_Id := N + $; + Name_Vector : constant Name_Id := N + $; Name_VMS : constant Name_Id := N + $; Name_Vtable_Ptr : constant Name_Id := N + $; Name_Working_Storage : constant Name_Id := N + $; @@ -1705,6 +1710,7 @@ Pragma_Locking_Policy, Pragma_Long_Float, Pragma_Loop_Invariant, + Pragma_Loop_Optimize, Pragma_Loop_Variant, Pragma_No_Run_Time, Pragma_No_Strict_Aliasing,