[Mlir-commits] [llvm] [mlir] [Flang] [OpenMP] Add LLVM lowering support for PRIORITY in TASK (PR #120710)

Kiran Chandramohan llvmlistbot at llvm.org
Fri Dec 20 04:55:08 PST 2024


================
@@ -1958,6 +1963,30 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
                            SharedsSize);
     }
 
+    if (Priority) {
+      //
+      // The return type of "__kmpc_omp_task_alloc" is "kmp_task_t *",
+      // we populate the priority information into the "kmp_task_t" here
+      //
+      // The struct "kmp_task_t" definition is available in kmp.h
+      // kmp_task_t = { shareds, routine, part_id, data1, data2 }
+      // data2 is used for priority
+      //
+      Type *Int32Ty = Builder.getInt32Ty();
+      // kmp_task_t* => { ptr }
+      Type *taskPtr = StructType::get(VoidPtr);
+      Value *taskGEP = Builder.CreateInBoundsGEP(
+          taskPtr, TaskData,
+          {ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, 0)});
+      // kmp_task_t => { ptr, ptr, i32, ptr, ptr }
+      Type *taskStructType = StructType::get(
+          VoidPtr, VoidPtr, Builder.getInt32Ty(), VoidPtr, VoidPtr);
+      Value *priorityData = Builder.CreateInBoundsGEP(
+          taskStructType, taskGEP,
+          {ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, 4)});
+      Builder.CreateStore(Priority, priorityData);
----------------
kiranchandramohan wrote:

Since data2 is another struct ( kmp_cmplrdata), Is this sufficient because priority is the first field of kmp_cmplrdata, or do we have to index into kmp_cmplrdata as well?

```
typedef union kmp_cmplrdata {
  kmp_int32 priority; /**< priority specified by user for the task */
  kmp_routine_entry_t
      destructors; /* pointer to function to invoke deconstructors of
                      firstprivate C++ objects */
  /* future data */
} kmp_cmplrdata_t;

/*  sizeof_kmp_task_t passed as arg to kmpc_omp_task call  */
/*!
 */
typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */
  void *shareds; /**< pointer to block of pointers to shared vars   */
  kmp_routine_entry_t
      routine; /**< pointer to routine to call for executing task */
  kmp_int32 part_id; /**< part id for the task                          */
  kmp_cmplrdata_t
      data1; /* Two known optional additions: destructors and priority */
  kmp_cmplrdata_t data2; /* Process destructors first, priority second */
  /* future data */
  /*  private vars  */
} kmp_task_t;
```

https://github.com/llvm/llvm-project/pull/120710


More information about the Mlir-commits mailing list