[PATCH] D49130: Fix OpenCL Work-Item function arguments in Polly

Michal Babej via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 06:58:23 PDT 2018


franz created this revision.
franz added a project: Polly.
Herald added subscribers: llvm-commits, kbarton, Anastasia, yaxunl, nemanjai.
Herald added a reviewer: bollu.

Work-Item related OpenCL functions usually return size_t type, which is different for 64bit and 32bit SPIR IR. Polly used i32 type everywhere, causing it to fail on assertions.

Also changes the dimension to be always i32 type.


Repository:
  rPLO Polly

https://reviews.llvm.org/D49130

Files:
  lib/CodeGen/PPCGCodeGeneration.cpp


Index: lib/CodeGen/PPCGCodeGeneration.cpp
===================================================================
--- lib/CodeGen/PPCGCodeGeneration.cpp
+++ lib/CodeGen/PPCGCodeGeneration.cpp
@@ -580,7 +580,7 @@
   /// Insert function calls to retrieve the SPIR group/local ids.
   ///
   /// @param The kernel to generate the function calls for.
-  void insertKernelCallsSPIR(ppcg_kernel *Kernel);
+  void insertKernelCallsSPIR(ppcg_kernel *Kernel, bool SizeTypeIs64bit);
 
   /// Setup the creation of functions referenced by the GPU kernel.
   ///
@@ -2120,40 +2120,40 @@
   }
 }
 
-void GPUNodeBuilder::insertKernelCallsSPIR(ppcg_kernel *Kernel) {
+void GPUNodeBuilder::insertKernelCallsSPIR(ppcg_kernel *Kernel, bool SizeTypeIs64bit) {
   const char *GroupName[3] = {"_Z12get_group_idj",
                               "_Z12get_group_idj",
                               "_Z12get_group_idj"};
 
   const char *LocalName[3] = {"_Z12get_local_idj",
                               "_Z12get_local_idj",
                               "_Z12get_local_idj"};
+  IntegerType *SizeType = SizeTypeIs64bit ? Builder.getInt64Ty() : Builder.getInt32Ty();
 
-  auto createFunc = [this](const char *Name, __isl_take isl_id *Id, int Dim) mutable {
+  auto createFunc = [this](const char *Name, __isl_take isl_id *Id, int Dim, IntegerType *SizeType) mutable {
     Module *M = Builder.GetInsertBlock()->getParent()->getParent();
     Function *FN = M->getFunction(Name);
 
     // If FN is not available, declare it.
     if (!FN) {
       GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
       std::vector<Type *> Args;
       Args.push_back(Builder.getInt32Ty());
-      FunctionType *Ty = FunctionType::get(Builder.getInt32Ty(), Args, false);
+      FunctionType *Ty = FunctionType::get(SizeType, Args, false);
       FN = Function::Create(Ty, Linkage, Name, M);
       FN->setCallingConv(CallingConv::SPIR_FUNC);
     }
 
     Value *Val = Builder.CreateCall(FN, {Builder.getInt32(Dim)});
-    Val = Builder.CreateIntCast(Val, Builder.getInt64Ty(), false, Name);
     IDToValue[Id] = Val;
     KernelIDs.insert(std::unique_ptr<isl_id, IslIdDeleter>(Id));
   };
 
   for (int i = 0; i < Kernel->n_grid; ++i)
-    createFunc(GroupName[i], isl_id_list_get_id(Kernel->block_ids, i), i);
+    createFunc(GroupName[i], isl_id_list_get_id(Kernel->block_ids, i), i, SizeType);
 
   for (int i = 0; i < Kernel->n_block; ++i)
-    createFunc(LocalName[i], isl_id_list_get_id(Kernel->thread_ids, i), i);
+    createFunc(LocalName[i], isl_id_list_get_id(Kernel->thread_ids, i), i, SizeType);
 }
 
 void GPUNodeBuilder::prepareKernelArguments(ppcg_kernel *Kernel, Function *FN) {
@@ -2333,8 +2333,10 @@
     insertKernelIntrinsics(Kernel);
     break;
   case GPUArch::SPIR32:
+    insertKernelCallsSPIR(Kernel, false);
+    break;
   case GPUArch::SPIR64:
-    insertKernelCallsSPIR(Kernel);
+    insertKernelCallsSPIR(Kernel, true);
     break;
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49130.154781.patch
Type: text/x-patch
Size: 2945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/8befae58/attachment.bin>


More information about the llvm-commits mailing list