Commit d0e69402 by Robert Dewar Committed by Arnaud Charlet

exp_ch9.adb, [...]: Minor reformatting and code clean up.

2014-01-29  Robert Dewar  <dewar@adacore.com>

	* exp_ch9.adb, sem_ch7.ads, s-regexp.adb, sem_ch13.adb: Minor
	reformatting and code clean up.
	* gnat_ugn.texi: Add documentation section on Atomic Variables
	and Optimization.

From-SVN: r207253
parent 5627964c
2014-01-29 Robert Dewar <dewar@adacore.com>
* exp_ch9.adb, sem_ch7.ads, s-regexp.adb, sem_ch13.adb: Minor
reformatting and code clean up.
* gnat_ugn.texi: Add documentation section on Atomic Variables
and Optimization.
2014-01-29 Hristian Kirtchev <kirtchev@adacore.com> 2014-01-29 Hristian Kirtchev <kirtchev@adacore.com>
* einfo.adb Flag264 is now unused. * einfo.adb Flag264 is now unused.
......
...@@ -8874,13 +8874,14 @@ package body Exp_Ch9 is ...@@ -8874,13 +8874,14 @@ package body Exp_Ch9 is
procedure Expand_Entry_Declaration (Comp : Entity_Id) is procedure Expand_Entry_Declaration (Comp : Entity_Id) is
Bdef : Entity_Id; Bdef : Entity_Id;
Edef : Entity_Id; Edef : Entity_Id;
begin begin
E_Count := E_Count + 1; E_Count := E_Count + 1;
Comp_Id := Defining_Identifier (Comp); Comp_Id := Defining_Identifier (Comp);
Edef := Edef :=
Make_Defining_Identifier (Loc, Make_Defining_Identifier (Loc,
Build_Selected_Name (Prot_Typ, Comp_Id, 'E')); Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
Sub := Sub :=
Make_Subprogram_Declaration (Loc, Make_Subprogram_Declaration (Loc,
Specification => Specification =>
......
...@@ -10176,6 +10176,7 @@ some guidelines on debugging optimized code. ...@@ -10176,6 +10176,7 @@ some guidelines on debugging optimized code.
* Other Optimization Switches:: * Other Optimization Switches::
* Optimization and Strict Aliasing:: * Optimization and Strict Aliasing::
* Aliased Variables and Optimization:: * Aliased Variables and Optimization::
* Atomic Variables and Optimization::
* Passive Task Optimization:: * Passive Task Optimization::
@ifset vms @ifset vms
...@@ -11022,6 +11023,80 @@ inhibits optimizations that assume the value cannot be assigned. ...@@ -11022,6 +11023,80 @@ inhibits optimizations that assume the value cannot be assigned.
This means that the above example will in fact "work" reliably, This means that the above example will in fact "work" reliably,
that is, it will produce the expected results. that is, it will produce the expected results.
@node Atomic Variables and Optimization
@subsection Atomic Variables and Optimization
@cindex Atomic
There are two considerations with regard to performance when
atomic variables are used.
First, the RM only guarantees that access to atomic variables
be atomic, it has nothing to say about how this is achieved,
though there is a strong implication that this should not be
achieved by explicit locking code. Indeed GNAT will never
generate any locking code for atomic variable access (it will
simply reject any attempt to make a variable or type atomic
if the atomic access cannot be achieved without such locking code).
That being said, it is important to understand that you cannot
assume that the entire variable will always be accessed. Consider
this example:
@smallexample @c ada
type R is record
A,B,C,D : Character;
end record;
for R'Size use 32;
for R'Alignment use 4;
RV : R;
pragma Atomic (RV);
X : Character;
...
X := RV.B;
@end smallexample
@noindent
You cannot assume that the reference to @code{RV.B}
will read the entire 32-bit
variable with a single load instruction. It is perfectly legitimate if
the hardware allows it to do a byte read of just the B field. This read
is still atomic, which is all the RM requires. GNAT can and does take
advantage of this, depending on the architecture and optimization level.
Any assumption to the contrary is non-portable and risky. Even if you
examine the assembly language and see a full 32-bit load, this might
change in a future version of the compiler.
If your application requires that all accesses to @code{RV} in this
example be full 32-bit loads, you need to make a copy for the access
as in:
@smallexample @c ada
declare
RV_Copy : constant R := RV;
begin
X := RV_Copy.B;
end;
@end smallexample
@noindent
Now the reference to RV must read the whole variable.
Actually one can imagine some compiler which figures
out that the whole copy is not required (because only
the B field is actually accessed), but GNAT
certainly won't do that, and we don't know of any
compiler that would not handle this right, and the
above code will in practice work portably across
all architectures (that permit the Atomic declaration).
The second issue with atomic variables has to do with
the possible requirement of generating synchronization
code. For more details on this, consult the sections on
the pragmas Enable/Disable_Atomic_Synchronization in the
GNAT Reference Manual. If performance is critical, and
such synchronization code is not required, it may be
useful to disable it.
@node Passive Task Optimization @node Passive Task Optimization
@subsection Passive Task Optimization @subsection Passive Task Optimization
@cindex Passive Task @cindex Passive Task
...@@ -2242,8 +2242,7 @@ package body Sem_Ch13 is ...@@ -2242,8 +2242,7 @@ package body Sem_Ch13 is
Expression => Relocate_Node (Expr))), Expression => Relocate_Node (Expr))),
Pragma_Name => Name_Refined_Global); Pragma_Name => Name_Refined_Global);
Decorate_Aspect_And_Pragma Decorate_Aspect_And_Pragma (Aspect, Aitem, Delayed => True);
(Aspect, Aitem, Delayed => True);
Insert_Delayed_Pragma (Aitem); Insert_Delayed_Pragma (Aitem);
goto Continue; goto Continue;
......
...@@ -35,13 +35,13 @@ package Sem_Ch7 is ...@@ -35,13 +35,13 @@ package Sem_Ch7 is
procedure Analyze_Package_Body_Contract (Body_Id : Entity_Id); procedure Analyze_Package_Body_Contract (Body_Id : Entity_Id);
-- Analyze all delayed aspects chained on the contract of package body -- Analyze all delayed aspects chained on the contract of package body
-- Body_Id as if they appeared at the end of a declarative region. The -- Body_Id as if they appeared at the end of a declarative region. The
-- aspects in consideration are: -- aspects that are considered are:
-- Refined_State -- Refined_State
procedure Analyze_Package_Contract (Pack_Id : Entity_Id); procedure Analyze_Package_Contract (Pack_Id : Entity_Id);
-- Analyze all delayed aspects chained on the contract of package Pack_Id -- Analyze all delayed aspects chained on the contract of package Pack_Id
-- as if they appeared at the end of a declarative region. The aspects in -- as if they appeared at the end of a declarative region. The aspects
-- consideration are: -- that are considered are:
-- Initial_Condition -- Initial_Condition
-- Initializes -- Initializes
-- Part_Of -- Part_Of
...@@ -59,7 +59,7 @@ package Sem_Ch7 is ...@@ -59,7 +59,7 @@ package Sem_Ch7 is
-- On entrance to a package body, make declarations in package spec -- On entrance to a package body, make declarations in package spec
-- immediately visible. -- immediately visible.
--
-- When compiling the body of a package, both routines are called in -- When compiling the body of a package, both routines are called in
-- succession. When compiling the body of a child package, the call -- succession. When compiling the body of a child package, the call
-- to Install_Private_Declaration is immediate for private children, -- to Install_Private_Declaration is immediate for private children,
...@@ -86,17 +86,16 @@ package Sem_Ch7 is ...@@ -86,17 +86,16 @@ package Sem_Ch7 is
-- calling stubs. -- calling stubs.
procedure New_Private_Type (N : Node_Id; Id : Entity_Id; Def : Node_Id); procedure New_Private_Type (N : Node_Id; Id : Entity_Id; Def : Node_Id);
-- Common processing for private type declarations and for formal -- Common processing for private type declarations and for formal private
-- private type declarations. For private types, N and Def are the type -- type declarations. For private types, N and Def are the type declaration
-- declaration node; for formal private types, Def is the formal type -- node; for formal private types, Def is the formal type definition.
-- definition.
procedure Uninstall_Declarations (P : Entity_Id); procedure Uninstall_Declarations (P : Entity_Id);
-- At the end of a package declaration or body, declarations in the -- At the end of a package declaration or body, declarations in the visible
-- visible part are no longer immediately visible, and declarations in -- part are no longer immediately visible, and declarations in the private
-- the private part are not visible at all. For inner packages, place -- part are not visible at all. For inner packages, place visible entities
-- visible entities at the end of their homonym chains. For compilation -- at the end of their homonym chains. For compilation units, make
-- units, make all entities invisible. In both cases, exchange private -- all entities invisible. In both cases, exchange private and visible
-- and visible declarations to restore order of elaboration. -- declarations to restore order of elaboration.
end Sem_Ch7; end Sem_Ch7;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment