[flang-commits] [flang] [llvm] [mlir] [Flang] Add lowering support for depobj in depend clause (PR #124523)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Jan 31 10:29:19 PST 2025


================
@@ -2049,19 +2049,61 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
       Builder.CreateStore(Priority, CmplrData);
     }
 
-    Value *DepArray = nullptr;
+    Value *DepAlloca = nullptr;
+    Value *stackSave = nullptr;
+    Value *depSize = Builder.getInt32(Dependencies.size());
     if (Dependencies.size()) {
       InsertPointTy OldIP = Builder.saveIP();
       Builder.SetInsertPoint(
           &OldIP.getBlock()->getParent()->getEntryBlock().back());
 
       Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size());
-      DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
+
+      // Used to keep a count of other dependence type apart from DEPOBJ
+      size_t otherDepTypeCount = 0;
+      SmallVector<Value *> objsVal;
+      // Load all the value of DEPOBJ object from omp_depend_t object
+      for (const DependData &dep : Dependencies) {
+        if (dep.isTypeDepObj) {
+          Value *loadDepVal = Builder.CreateLoad(VoidPtr, dep.DepVal);
+          Value *depValGEP =
+              Builder.CreateGEP(DependInfo, loadDepVal, Builder.getInt64(-1));
+          Value *obj =
+              Builder.CreateConstInBoundsGEP2_64(DependInfo, depValGEP, 0, 0);
+          Value *objVal = Builder.CreateLoad(Builder.getInt64Ty(), obj);
+          objsVal.push_back(objVal);
+        } else {
+          otherDepTypeCount++;
+        }
+      }
+
+      // Add all the values and use it as the size for DependInfo alloca
+      if (objsVal.size() > 0) {
+        depSize = objsVal[0];
+        for (size_t i = 1; i < objsVal.size(); i++)
+          depSize = Builder.CreateAdd(depSize, objsVal[i]);
+        if (otherDepTypeCount > 0)
+          depSize =
+              Builder.CreateAdd(depSize, Builder.getInt64(otherDepTypeCount));
+      }
+
+      if (!isa<ConstantInt>(depSize)) {
+        // stackSave to save the stack pointer
+        if (!stackSave)
+          stackSave = Builder.CreateStackSave();
+        DepAlloca = Builder.CreateAlloca(DependInfo, depSize, "dep.addr");
+        ((AllocaInst *)DepAlloca)->setAlignment(Align(16));
----------------
tblah wrote:

Why 16?

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


More information about the flang-commits mailing list