clover: Append implicit arguments to the kernel argument list.
authorJan Vesely <jan.vesely@rutgers.edu>
Wed, 8 Oct 2014 14:43:01 +0000 (17:43 +0300)
committerFrancisco Jerez <currojerez@riseup.net>
Sat, 11 Oct 2014 22:50:13 +0000 (01:50 +0300)
[ Francisco Jerez: Split off from a larger patch, and take a slightly
  different approach for passing the implicit arguments around. ]

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/llvm/invocation.cpp

index 7bca0d68357d5cabd38d3e3f3156ccceab1dafbd..212b4e48f622e13aa6c7269bff088ddfaaeee061 100644 (file)
@@ -308,24 +308,20 @@ namespace {
       bitcode_ostream.flush();
 
       for (unsigned i = 0; i < kernels.size(); ++i) {
-         llvm::Function *kernel_func;
-         std::string kernel_name;
-         compat::vector<module::argument> args;
-
-         kernel_func = kernels[i];
-         kernel_name = kernel_func->getName();
-
-         for (llvm::Function::arg_iterator I = kernel_func->arg_begin(),
-                                      E = kernel_func->arg_end(); I != E; ++I) {
-            llvm::Argument &arg = *I;
+         llvm::Function *kernel_func = kernels[i];
+         const std::string kernel_name = kernel_func->getName();
 #if HAVE_LLVM < 0x0302
-            llvm::TargetData TD(kernel_func->getParent());
+         llvm::TargetData TD(kernel_func->getParent());
 #elif HAVE_LLVM < 0x0305
-            llvm::DataLayout TD(kernel_func->getParent()->getDataLayout());
+         llvm::DataLayout TD(kernel_func->getParent()->getDataLayout());
 #else
-            llvm::DataLayout TD(mod);
+         llvm::DataLayout TD(mod);
 #endif
+         compat::vector<module::argument> args;
 
+         for (llvm::Function::arg_iterator I = kernel_func->arg_begin(),
+                                      E = kernel_func->arg_end(); I != E; ++I) {
+            llvm::Argument &arg = *I;
             llvm::Type *arg_type = arg.getType();
             const unsigned arg_store_size = TD.getTypeStoreSize(arg_type);
 
@@ -384,6 +380,26 @@ namespace {
             }
          }
 
+         // Append implicit arguments.  XXX - The types, ordering and
+         // vector size of the implicit arguments should depend on the
+         // target according to the selected calling convention.
+         llvm::Type *size_type =
+            TD.getSmallestLegalIntType(mod->getContext(), sizeof(cl_uint) * 8);
+
+         args.push_back(
+            module::argument(module::argument::scalar, sizeof(cl_uint),
+                             TD.getTypeStoreSize(size_type),
+                             TD.getABITypeAlignment(size_type),
+                             module::argument::zero_ext,
+                             module::argument::grid_dimension));
+
+         args.push_back(
+            module::argument(module::argument::scalar, sizeof(cl_uint),
+                             TD.getTypeStoreSize(size_type),
+                             TD.getABITypeAlignment(size_type),
+                             module::argument::zero_ext,
+                             module::argument::grid_offset));
+
          m.syms.push_back(module::symbol(kernel_name, 0, i, args ));
       }