GPGPU: Pass host iterators to kernel
authorTobias Grosser <tobias@grosser.es>
Thu, 28 Jul 2016 06:47:56 +0000 (06:47 +0000)
committerTobias Grosser <tobias@grosser.es>
Thu, 28 Jul 2016 06:47:56 +0000 (06:47 +0000)
llvm-svn: 276962

polly/lib/CodeGen/PPCGCodeGeneration.cpp
polly/test/GPGPU/host-control-flow.ll

index 3a6b80b..f8cf3b7 100644 (file)
@@ -911,6 +911,24 @@ Value *GPUNodeBuilder::createLaunchParameters(ppcg_kernel *Kernel,
     Index++;
   }
 
+  int NumHostIters = isl_space_dim(Kernel->space, isl_dim_set);
+
+  for (long i = 0; i < NumHostIters; i++) {
+    isl_id *Id = isl_space_get_dim_id(Kernel->space, isl_dim_set, i);
+    Value *Val = IDToValue[Id];
+    isl_id_free(Id);
+    Instruction *Param = new AllocaInst(
+        Val->getType(), Launch + "_param_" + std::to_string(Index),
+        EntryBlock->getTerminator());
+    Builder.CreateStore(Val, Param);
+    Value *Slot = Builder.CreateGEP(
+        Parameters, {Builder.getInt64(0), Builder.getInt64(Index)});
+    Value *ParamTyped =
+        Builder.CreatePointerCast(Param, Builder.getInt8PtrTy());
+    Builder.CreateStore(ParamTyped, Slot);
+    Index++;
+  }
+
   auto Location = EntryBlock->getTerminator();
   return new BitCastInst(Parameters, Builder.getInt8PtrTy(),
                          Launch + "_params_i8ptr", Location);
index 7f41a11..19f37b6 100644 (file)
 ; IR-LABEL: polly.loop_header:                                ; preds = %polly.loop_header, %polly.loop_preheader
 ; IR-NEXT:   %polly.indvar = phi i64 [ 0, %polly.loop_preheader ], [ %polly.indvar_next, %polly.loop_header ]
 ; ...
+; IR:  store i64 %polly.indvar, i64* %polly_launch_0_param_1
+; IR-NEXT:  %6 = getelementptr [2 x i8*], [2 x i8*]* %polly_launch_0_params, i64 0, i64 1
+; IR-NEXT:  %7 = bitcast i64* %polly_launch_0_param_1 to i8*
+; IR-NEXT:  store i8* %7, i8** %6
 ; IR: call i8* @polly_getKernel
 ; ...
 ; IR: call void @polly_freeKernel