This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Remove superfluous use of secondary stack on object initialization


This patch improves on the performance of an object initialization with a
build-in-place function call, when the return type is not a definite type
but has only access discriminants and no controlled components.

THe following must execute quietly:

   gcc -c -gnatDG p.adb
   grep secondary_stack p.adb.dg


---
with Discrim; use Discrim;
procedure P is
  I : aliased Integer;
  A_Obj : A_Type := Create (I'Access);
begin
  null;
end;
---
package Discrim is
  type A_Type (IA : access Integer) is limited private;
  function Create (I : access Integer) return A_Type;
private
  type A_Type (IA : access Integer) is limited record
     Not_Dependent_On_IA : Boolean;
  end record;
end;
---
package body Discrim is
  function Create (I : access Integer) return A_Type is
  begin
     return A : A_Type (I) do
        A.Not_Dependent_On_IA := False;
     end return;
  end;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-04-27  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration): If the
	return type is an untagged limited record with only access
	discriminants and no controlled components, the return value does not
	need to use the secondary stack.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]