From patchwork Thu Nov 20 14:24:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 412729 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B19A7140170 for ; Fri, 21 Nov 2014 01:25:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=CvLVyW42UycioGVIIDzlCP2MafA0wRG91SVOe0lhnV4b04RXa0 nwUG6MJEITUWowtrlS9Wrsj9J329jyQusuToNtwwpQTw1FSnY7UjiG4bwyJ+YbH1 QxtdugGoIJLI3as92PCtbbpwjYcBFPCBV7hn9DYgfSuNlEuEaCze7DNBE= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=+e2KKWAu5E1QOGxMMClp06nXYMM=; b=ubbUlpc9JdUf/yhYA/t9 1ywXwxTVhOCMLoHOlXbRdQnLk3Ai4Kb5RiZyII5snC3QM5ajmdN9MXaI8zZxAtT8 KZaQqwO/CzQAmnoV2JX1meno228/bmoJH8FY95u3iY/BISQX+EfLv1Cdd3J3Ye2G BiSo+zg9xMhYt0sY5QOTCf8= Received: (qmail 4486 invoked by alias); 20 Nov 2014 14:24:41 -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 4419 invoked by uid 89); 20 Nov 2014 14:24:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 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 (AES256-SHA encrypted) ESMTPS; Thu, 20 Nov 2014 14:24:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EF2DD116BA4; Thu, 20 Nov 2014 09:24:37 -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 lj4NDworXplt; Thu, 20 Nov 2014 09:24:37 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id DF993116B97; Thu, 20 Nov 2014 09:24:37 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id DE82391A7D; Thu, 20 Nov 2014 09:24:37 -0500 (EST) Date: Thu, 20 Nov 2014 09:24:37 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Inter-unit inlining of expression functions with -gnatn1 Message-ID: <20141120142437.GA6455@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This enables inter-unit inlining of expression functions with -gnatn1, or more simply with -O1/-O2 -gnatn. These functions are automatically candidates for inlining, but there were actually inlined across units only with -gnatn2, or more simply -O3 -gnatn. The following program must compile without warnings with -O -gnatn -Winline: with Q; use Q; procedure P (I : Integer) is begin if Process (I) /= 2 * I then raise Program_Error; end if; end; package Q is function Process (I : Integer) return Integer; pragma Inline (Process); end Q; with R; use R; package body Q is function Process (I : Integer) return Integer is begin return Process2 (I) + Process3 (I); end; end Q; package R is function Process2 (I : Integer) return Integer; function Process3 (I : Integer) return Integer is (I); private function Process2 (I : Integer) return Integer is (I); end R; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-11-20 Eric Botcazou * inline.adb (Add_Inlined_Subprogram): Insert all programs generated as a body or whose declaration was provided along with the body. Index: inline.adb =================================================================== --- inline.adb (revision 217842) +++ inline.adb (working copy) @@ -454,6 +454,7 @@ procedure Add_Inlined_Subprogram (Index : Subp_Index) is E : constant Entity_Id := Inlined.Table (Index).Name; + Decl : constant Node_Id := Parent (Declaration_Node (E)); Pack : constant Entity_Id := Get_Code_Unit_Entity (E); procedure Register_Backend_Inlined_Subprogram (Subp : Entity_Id); @@ -486,14 +487,17 @@ begin -- If the subprogram is to be inlined, and if its unit is known to be -- inlined or is an instance whose body will be analyzed anyway or the - -- subprogram has been generated by the compiler, and if it is declared + -- subprogram was generated as a body by the compiler (for example an + -- initialization procedure) or its declaration was provided along with + -- the body (for example an expression function), and if it is declared -- at the library level not in the main unit, and if it can be inlined -- by the back-end, then insert it in the list of inlined subprograms. if Is_Inlined (E) and then (Is_Inlined (Pack) or else Is_Generic_Instance (Pack) - or else Is_Internal (E)) + or else Nkind (Decl) = N_Subprogram_Body + or else Present (Corresponding_Body (Decl))) and then not In_Main_Unit_Or_Subunit (E) and then not Is_Nested (E) and then not Has_Initialized_Type (E)