[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Add support for explicit deallocation points (PR #154752)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 21 06:02:20 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/include/llvm/Transforms/Utils/CodeExtractor.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/lib/Transforms/IPO/HotColdSplitting.cpp llvm/lib/Transforms/IPO/IROutliner.cpp llvm/lib/Transforms/IPO/OpenMPOpt.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 959c66593..c9ac20715 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4365,20 +4365,20 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
         auto SectionCB = [this, SubStmt](InsertPointTy AllocIP,
                                          InsertPointTy CodeGenIP,
                                          ArrayRef<InsertPointTy> DeallocIPs) {
-          OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
-              *this, SubStmt, AllocIP, CodeGenIP, "section");
+          OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(*this, SubStmt, AllocIP,
+                                                        CodeGenIP, "section");
           return llvm::Error::success();
         };
         SectionCBVector.push_back(SectionCB);
       }
     } else {
-      auto SectionCB = [this, CapturedStmt](
-                           InsertPointTy AllocIP, InsertPointTy CodeGenIP,
-                           ArrayRef<InsertPointTy> DeallocIPs) {
-        OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
-            *this, CapturedStmt, AllocIP, CodeGenIP, "section");
-        return llvm::Error::success();
-      };
+      auto SectionCB =
+          [this, CapturedStmt](InsertPointTy AllocIP, InsertPointTy CodeGenIP,
+                               ArrayRef<InsertPointTy> DeallocIPs) {
+            OMPBuilderCBHelpers::EmitOMPInlinedRegionBody(
+                *this, CapturedStmt, AllocIP, CodeGenIP, "section");
+            return llvm::Error::success();
+          };
       SectionCBVector.push_back(SectionCB);
     }
 
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 68f1365b6..9e9f943aa 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -55,9 +55,9 @@ using namespace omp;
   }
 
 #define BODYGENCB_WRAPPER(cb)                                                  \
-  [&cb](InsertPointTy AllocIP, InsertPointTy CodeGenIP,                       \
+  [&cb](InsertPointTy AllocIP, InsertPointTy CodeGenIP,                        \
         ArrayRef<InsertPointTy> DeallocIPs) -> Error {                         \
-    cb(AllocIP, CodeGenIP, DeallocIPs);                                       \
+    cb(AllocIP, CodeGenIP, DeallocIPs);                                        \
     return Error::success();                                                   \
   }
 
@@ -922,8 +922,8 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
 
     ASSERT_EXPECTED_INIT(
         OpenMPIRBuilder::InsertPointTy, AfterIP,
-        OMPBuilder.createParallel(InsertPointTy(CGBB, CGBB->end()), AllocIP,
-                                  {}, InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+        OMPBuilder.createParallel(InsertPointTy(CGBB, CGBB->end()), AllocIP, {},
+                                  InnerBodyGenCB, PrivCB, FiniCB, nullptr,
                                   nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP);
@@ -1029,18 +1029,18 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
 
     ASSERT_EXPECTED_INIT(
         OpenMPIRBuilder::InsertPointTy, AfterIP1,
-        OMPBuilder.createParallel(InsertPointTy(CGBB, CGBB->end()), AllocIP,
-                                  {}, InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+        OMPBuilder.createParallel(InsertPointTy(CGBB, CGBB->end()), AllocIP, {},
+                                  InnerBodyGenCB, PrivCB, FiniCB, nullptr,
                                   nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP1);
     Builder.CreateBr(NewBB1);
 
-    ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, AfterIP2,
-                         OMPBuilder.createParallel(
-                             InsertPointTy(NewBB1, NewBB1->end()), AllocIP, {},
-                             InnerBodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
-                             OMP_PROC_BIND_default, false));
+    ASSERT_EXPECTED_INIT(
+        OpenMPIRBuilder::InsertPointTy, AfterIP2,
+        OMPBuilder.createParallel(InsertPointTy(NewBB1, NewBB1->end()), AllocIP,
+                                  {}, InnerBodyGenCB, PrivCB, FiniCB, nullptr,
+                                  nullptr, OMP_PROC_BIND_default, false));
 
     Builder.restoreIP(AfterIP2);
     Builder.CreateBr(NewBB2);
@@ -5558,8 +5558,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
   Builder.CreateStore(Builder.getInt32(1), XorReduced);
 
   InsertPointTy FirstBodyIP, FirstBodyAllocaIP;
-  auto FirstBodyGenCB = [&](InsertPointTy InnerAllocIP,
-                            InsertPointTy CodeGenIP,
+  auto FirstBodyGenCB = [&](InsertPointTy InnerAllocIP, InsertPointTy CodeGenIP,
                             ArrayRef<InsertPointTy> DeallocIPs) {
     IRBuilderBase::InsertPointGuard Guard(Builder);
     Builder.restoreIP(CodeGenIP);
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 7e7c5f06b..f5d60a517 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -487,7 +487,8 @@ static LogicalResult handleError(llvm::Expected<T> &result, Operation &op) {
 /// normal operations in the builder.
 static llvm::OpenMPIRBuilder::InsertPointTy findAllocInsertPoints(
     llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation,
-    llvm::SmallVectorImpl<llvm::OpenMPIRBuilder::InsertPointTy> *deallocIPs = nullptr) {
+    llvm::SmallVectorImpl<llvm::OpenMPIRBuilder::InsertPointTy> *deallocIPs =
+        nullptr) {
   // If there is an allocation insertion point on stack, i.e. we are in a nested
   // operation and a specific point was provided by some surrounding operation,
   // use it.
@@ -508,7 +509,7 @@ static llvm::OpenMPIRBuilder::InsertPointTy findAllocInsertPoints(
           builder.GetInsertBlock()->getParent()) {
     if (deallocIPs)
       deallocIPs->insert(deallocIPs->end(), deallocInsertPoints.begin(),
-                        deallocInsertPoints.end());
+                         deallocInsertPoints.end());
     return allocInsertPoint;
   }
 
@@ -2934,8 +2935,8 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
 
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      ompBuilder->createParallel(ompLoc, allocIP, deallocIPs, bodyGenCB,
-                                 privCB, finiCB, ifCond, numThreads, pbKind,
+      ompBuilder->createParallel(ompLoc, allocIP, deallocIPs, bodyGenCB, privCB,
+                                 finiCB, ifCond, numThreads, pbKind,
                                  isCancellable);
 
   if (failed(handleError(afterIP, *opInst)))

``````````

</details>


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


More information about the llvm-branch-commits mailing list