From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29483 invoked by alias); 17 Sep 2019 08:06:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29454 invoked by uid 89); 17 Sep 2019 08:06:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=Rev, reversed, libgnat, exp_ch5 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Sep 2019 08:06:34 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D937011781E; Tue, 17 Sep 2019 04:06:32 -0400 (EDT) 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 qm+YlHAKuX2x; Tue, 17 Sep 2019 04:06:32 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id C4E76117802; Tue, 17 Sep 2019 04:06:32 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id C10F96AD; Tue, 17 Sep 2019 04:06:32 -0400 (EDT) Date: Tue, 17 Sep 2019 08:06:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Refine conditions for calling Copy_Bitfield Message-ID: <20190917080632.GA37341@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00963.txt.bz2 --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 467 Avoid calling Copy_Bitfield if there are volatile or independent components that might be read or written. The test is conservative. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-09-17 Bob Duff gcc/ada/ * exp_ch5.adb (Expand_Assign_Array_Loop_Or_Bitfield): Add tests for potential volatile or independent components. * libgnat/s-bituti.adb (Copy_Small_Bitfield, Copy_Large_Bitfield): Move declarations to more appropriate place. --ikeVEW9yuYc//A+q Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" Content-length: 4780 --- gcc/ada/exp_ch5.adb +++ gcc/ada/exp_ch5.adb @@ -1451,20 +1451,35 @@ package body Exp_Ch5 is begin -- Determine whether Copy_Bitfield is appropriate (will work, and will -- be more efficient than component-by-component copy). Copy_Bitfield - -- doesn't work for reversed storage orders. It is efficient only for - -- slices of bit-packed arrays. - - -- Note that Expand_Assign_Array_Bitfield is disabled for now - - if False -- ??? + -- doesn't work for reversed storage orders. It is efficient for slices + -- of bit-packed arrays. Copy_Bitfield can read and write bits that are + -- not part of the objects being copied, so we don't want to use it if + -- there are volatile or independent components. If the Prefix of the + -- slice is a selected component (etc, see below), then it might be a + -- component of an object with some other volatile or independent + -- components, so we disable the optimization in that case as well. + -- We could complicate this code by actually looking for such volatile + -- and independent components. + + -- Note that Expand_Assign_Array_Bitfield is disabled for now. + + if False and then -- ??? + RTE_Available (RE_Copy_Bitfield) and then Is_Bit_Packed_Array (L_Type) and then Is_Bit_Packed_Array (R_Type) - and then RTE_Available (RE_Copy_Bitfield) and then not Reverse_Storage_Order (L_Type) and then not Reverse_Storage_Order (R_Type) and then Ndim = 1 and then not Rev and then Slices + and then not Has_Volatile_Component (L_Type) + and then not Has_Volatile_Component (R_Type) + and then not Has_Independent_Components (L_Type) + and then not Has_Independent_Components (R_Type) + and then not Nkind_In (Prefix (Name (N)), + N_Selected_Component, + N_Indexed_Component, + N_Slice) then return Expand_Assign_Array_Bitfield (N, Larray, Rarray, L_Type, R_Type, Rev); --- gcc/ada/libgnat/s-bituti.adb +++ gcc/ada/libgnat/s-bituti.adb @@ -71,6 +71,29 @@ package body System.Bitfield_Utils is -- set to Src_Value. Src_Value must have high order bits (Size and -- above) zero. The result is returned as the function result. + procedure Copy_Small_Bitfield + (Src_Address : Address; + Src_Offset : Bit_Offset; + Dest_Address : Address; + Dest_Offset : Bit_Offset; + Size : Small_Size); + -- Copy_Bitfield in the case where Size <= Val'Size. + -- The Address values must be aligned as for Val and Val_2. + -- This works for overlapping bit fields. + + procedure Copy_Large_Bitfield + (Src_Address : Address; + Src_Offset : Bit_Offset; + Dest_Address : Address; + Dest_Offset : Bit_Offset; + Size : Bit_Size); + -- Copy_Bitfield in the case where Size > Val'Size. + -- The Address values must be aligned as for Val and Val_2. + -- This works for overlapping bit fields only if the source + -- bit address is greater than or equal to the destination + -- bit address, because it copies forward (from lower to higher + -- bit addresses). + function Get_Bitfield (Src : Val_2; Src_Offset : Bit_Offset; Size : Small_Size) return Val @@ -120,29 +143,6 @@ package body System.Bitfield_Utils is Src_Offset : Bit_Offset; Dest_Address : Address; Dest_Offset : Bit_Offset; - Size : Small_Size); - -- Copy_Bitfield in the case where Size <= Val'Size. - -- The Address values must be aligned as for Val and Val_2. - -- This works for overlapping bit fields. - - procedure Copy_Large_Bitfield - (Src_Address : Address; - Src_Offset : Bit_Offset; - Dest_Address : Address; - Dest_Offset : Bit_Offset; - Size : Bit_Size); - -- Copy_Bitfield in the case where Size > Val'Size. - -- The Address values must be aligned as for Val and Val_2. - -- This works for overlapping bit fields only if the source - -- bit address is greater than or equal to the destination - -- bit address, because it copies forward (from lower to higher - -- bit addresses). - - procedure Copy_Small_Bitfield - (Src_Address : Address; - Src_Offset : Bit_Offset; - Dest_Address : Address; - Dest_Offset : Bit_Offset; Size : Small_Size) is Src : constant Val_2 with Import, Address => Src_Address; --ikeVEW9yuYc//A+q--