[Mlir-commits] [clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)

Pranav Bhandarkar llvmlistbot at llvm.org
Wed Jun 5 14:35:34 PDT 2024


================
@@ -1698,6 +1701,64 @@ void OpenMPIRBuilder::createTaskyield(const LocationDescription &Loc) {
   emitTaskyieldImpl(Loc);
 }
 
+// Processes the dependencies in Dependencies and does the following
+// - Allocates space on the stack of an array of DependInfo objects
+// - Populates each DependInfo object with relevant information of
+//   the corresponding dependence.
+// - All code is inserted in the entry block of the current function.
+static Value *
+emitDepArray(OpenMPIRBuilder &OMPBuilder,
+             SmallVector<OpenMPIRBuilder::DependData> &Dependencies) {
+  // Early return if we have no dependencies to process
+  if (!Dependencies.size())
+    return nullptr;
+
+  IRBuilderBase &Builder = OMPBuilder.Builder;
+  Type *DependInfo = OMPBuilder.DependInfo;
+  Module &M = OMPBuilder.M;
+
+  Value *DepArray = nullptr;
+  if (Dependencies.size()) {
+    OpenMPIRBuilder::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");
+
+    unsigned P = 0;
+    for (const OpenMPIRBuilder::DependData &Dep : Dependencies) {
----------------
bhandarkar-pranav wrote:

Actually, my intention was to switch `OpenMPIRBuilder::createTask` to use this function but i had a couple of other changes to `OpenMPIRBuilder::createTask` in mind so I decided to leave that out and roll it into a different PR. If you prefer, I can make the switch in this PR itself though. Just a preference, no strong opinions on this.

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


More information about the Mlir-commits mailing list