This commit makes Build_And_Insert_Cuda_Initialization an internal
procedure and creates a new Expand_CUDA_Package procedure which calls
Build_And_Insert_Cuda_Initialization.
This is a small, self-contained refactoring that does not impact any
feature or fix any bug - it just makes future commits that do add new
features smaller and easier to review.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch7.adb (Expand_N_Package_Body): Replace
Build_And_Insert_Cuda_Initialization with Expand_CUDA_Package.
* gnat_cuda.adb (Expand_CUDA_Package): New procedure.
(Build_And_Insert_Cuda_Initialization): Make internal.
* gnat_cuda.ads (Expand_CUDA_Package): New procedure.
(Build_And_Insert_Cuda_Initialization): Remove from spec.
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -5918,12 +5918,7 @@ package body Exp_Ch7 is
Build_Static_Dispatch_Tables (N);
end if;
- -- If procedures marked with CUDA_Global have been defined within N,
- -- we need to register them with the CUDA runtime at program startup.
- -- This requires multiple declarations and function calls which need
- -- to be appended to N's declarations.
-
- Build_And_Insert_CUDA_Initialization (N);
+ Expand_CUDA_Package (N);
Build_Task_Activation_Call (N);
diff --git a/gcc/ada/gnat_cuda.adb b/gcc/ada/gnat_cuda.adb
--- a/gcc/ada/gnat_cuda.adb
+++ b/gcc/ada/gnat_cuda.adb
@@ -66,6 +66,25 @@ package body GNAT_CUDA is
-- least one procedure marked with aspect CUDA_Global. The values are
-- Elists of the marked procedures.
+ procedure Build_And_Insert_CUDA_Initialization (N : Node_Id);
+ -- Builds declarations necessary for CUDA initialization and inserts them
+ -- in N, the package body that contains CUDA_Global nodes. These
+ -- declarations are:
+ --
+ -- * A symbol to hold the pointer P to the CUDA fat binary.
+ --
+ -- * A type definition T for a wrapper that contains the pointer to the
+ -- CUDA fat binary.
+ --
+ -- * An object of the aforementioned type to hold the aforementioned
+ -- pointer.
+ --
+ -- * For each CUDA_Global procedure in the package, a declaration of a C
+ -- string containing the function's name.
+ --
+ -- * A procedure that takes care of calling CUDA functions that register
+ -- CUDA_Global procedures with the runtime.
+
function Get_CUDA_Kernels (Pack_Id : Entity_Id) return Elist_Id;
-- Returns an Elist of all procedures marked with pragma CUDA_Global that
-- are declared within package body Pack_Body. Returns No_Elist if Pack_Id
@@ -94,6 +113,23 @@ package body GNAT_CUDA is
Append_Elmt (Kernel, Kernels);
end Add_CUDA_Kernel;
+ procedure Expand_CUDA_Package (N : Node_Id) is
+ begin
+
+ -- If not compiling for the host, do not do anything.
+
+ if not Debug_Flag_Underscore_C then
+ return;
+ end if;
+
+ -- If procedures marked with CUDA_Global have been defined within N,
+ -- we need to register them with the CUDA runtime at program startup.
+ -- This requires multiple declarations and function calls which need
+ -- to be appended to N's declarations.
+
+ Build_And_Insert_CUDA_Initialization (N);
+ end Expand_CUDA_Package;
+
----------
-- Hash --
----------
@@ -524,7 +560,7 @@ package body GNAT_CUDA is
-- Start of processing for Build_And_Insert_CUDA_Initialization
begin
- if CUDA_Node_List = No_Elist or not Debug_Flag_Underscore_C then
+ if CUDA_Node_List = No_Elist then
return;
end if;
diff --git a/gcc/ada/gnat_cuda.ads b/gcc/ada/gnat_cuda.ads
--- a/gcc/ada/gnat_cuda.ads
+++ b/gcc/ada/gnat_cuda.ads
@@ -82,26 +82,8 @@ package GNAT_CUDA is
-- Kernel is a procedure entity marked with CUDA_Global, Pack_Id is the
-- entity of its parent package body.
- procedure Build_And_Insert_CUDA_Initialization (N : Node_Id);
- -- Builds declarations necessary for CUDA initialization and inserts them
- -- in N, the package body that contains CUDA_Global nodes. These
- -- declarations are:
- --
- -- * A symbol to hold the pointer to the CUDA fat binary
- --
- -- * A type definition for a wrapper that contains the pointer to the
- -- CUDA fat binary
- --
- -- * An object of the aforementioned type to hold the aforementioned
- -- pointer.
- --
- -- * For each CUDA_Global procedure in the package, a declaration of a C
- -- string containing the function's name.
- --
- -- * A function that takes care of calling CUDA functions that register
- -- CUDA_Global procedures with the runtime.
- --
- -- * A boolean that holds the result of the call to the aforementioned
- -- function.
+ procedure Expand_CUDA_Package (N : Node_Id);
+ -- When compiling for the host, generate code to register kernels with the
+ -- CUDA runtime and post-process kernels.
end GNAT_CUDA;