[PATCH] D141651: [OMPIRBuilder] Pass dependencies to createTask by value

Prabhdeep Soni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 20:16:37 PST 2023


psoni2628 created this revision.
psoni2628 added reviewers: jdoerfert, dcaballe, ftynse, peixin, Meinersbur, kiranchandramohan, kiranktp, shraiysh, clementval, vzakhari.
psoni2628 added projects: clang, OpenMP, LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
psoni2628 requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.

This patch modifies OpenMPIRBuilder::createTask to accept its
`Dependencies` vector by value instead of by reference. This is
necessary because the `OutlineInfo` lambda that uses this `Dependencies`
vector may outlive the original `Dependencies` vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141651

Files:
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp


Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===================================================================
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5092,8 +5092,8 @@
   AllocaInst *InDep = Builder.CreateAlloca(Type::getInt32Ty(M->getContext()));
   OpenMPIRBuilder::DependData DDIn(RTLDependenceKindTy::DepIn,
                                    Type::getInt32Ty(M->getContext()), InDep);
-  SmallVector<OpenMPIRBuilder::DependData *, 4> DDS;
-  DDS.push_back(&DDIn);
+  SmallVector<OpenMPIRBuilder::DependData> DDS;
+  DDS.push_back(DDIn);
   Builder.restoreIP(OMPBuilder.createTask(
       Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB,
       /*Tied=*/false, /*Final*/ nullptr, /*IfCondition*/ nullptr, DDS));
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===================================================================
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1269,7 +1269,7 @@
 OpenMPIRBuilder::createTask(const LocationDescription &Loc,
                             InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB,
                             bool Tied, Value *Final, Value *IfCondition,
-                            ArrayRef<DependData *> Dependencies) {
+                            SmallVector<DependData> Dependencies) {
   if (!updateToLocation(Loc))
     return InsertPointTy();
 
@@ -1423,7 +1423,7 @@
           Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
 
       unsigned P = 0;
-      for (DependData *Dep : Dependencies) {
+      for (const DependData &Dep : Dependencies) {
         Value *Base =
             Builder.CreateConstInBoundsGEP2_64(DepArrayTy, DepArray, 0, P);
         // Store the pointer to the variable
@@ -1431,14 +1431,14 @@
             DependInfo, Base,
             static_cast<unsigned int>(RTLDependInfoFields::BaseAddr));
         Value *DepValPtr =
-            Builder.CreatePtrToInt(Dep->DepVal, Builder.getInt64Ty());
+            Builder.CreatePtrToInt(Dep.DepVal, Builder.getInt64Ty());
         Builder.CreateStore(DepValPtr, Addr);
         // Store the size of the variable
         Value *Size = Builder.CreateStructGEP(
             DependInfo, Base,
             static_cast<unsigned int>(RTLDependInfoFields::Len));
         Builder.CreateStore(Builder.getInt64(M.getDataLayout().getTypeStoreSize(
-                                Dep->DepValueType)),
+                                Dep.DepValueType)),
                             Size);
         // Store the dependency kind
         Value *Flags = Builder.CreateStructGEP(
@@ -1446,7 +1446,7 @@
             static_cast<unsigned int>(RTLDependInfoFields::Flags));
         Builder.CreateStore(
             ConstantInt::get(Builder.getInt8Ty(),
-                             static_cast<unsigned int>(Dep->DepKind)),
+                             static_cast<unsigned int>(Dep.DepKind)),
             Flags);
         ++P;
       }
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===================================================================
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -776,7 +776,7 @@
                            InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB,
                            bool Tied = true, Value *Final = nullptr,
                            Value *IfCondition = nullptr,
-                           ArrayRef<DependData *> Dependencies = {});
+                           SmallVector<DependData> Dependencies = {});
 
   /// Generator for the taskgroup construct
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141651.488852.patch
Type: text/x-patch
Size: 3693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230113/5a4d6cc5/attachment.bin>


More information about the llvm-commits mailing list