[Mlir-commits] [mlir] [MLIR][OpenMP] Preserve debug location in OpenMPIRBuilder calls. (PR #211254)

Abid Qadeer llvmlistbot at llvm.org
Wed Jul 22 06:07:28 PDT 2026


https://github.com/abidh created https://github.com/llvm/llvm-project/pull/211254

Many `OpenMPIRBuilder` entry points take an `OpenMPIRBuilder::LocationDescription`. It has two relevant constructors:

`LocationDescription(const IRBuilderBase &IRB)`  // captures IP and debug loc
`LocationDescription(const InsertPointTy &IP)`   // captures IP only; DL is empty

The OpenMP MLIR-to-LLVM-IR translation constructs the location from `builder` in almost all places (~45 call sites), which selects the first constructor and propagates both the insertion point and the current debug location. A few call sites instead passed `builder.saveIP()`, which selects the second constructor and silently drops the debug location.

Change the 9 offending call sites to pass `builder` instead of `builder.saveIP()`, so the debug location is preserved.

>From c4c1728e3f9af8c60768d41f571a555e76818925 Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Wed, 22 Jul 2026 10:26:43 +0100
Subject: [PATCH] [MLIR][OpenMP] Preserve debug location in OpenMPIRBuilder
 calls.

Many OpenMPIRBuilder entry points take an
OpenMPIRBuilder::LocationDescription. It has two relevant constructors:

LocationDescription(const IRBuilderBase &IRB)  // captures IP *and* debug loc
LocationDescription(const InsertPointTy &IP)   // captures IP only; DL is empty

The OpenMP MLIR-to-LLVM-IR translation constructs the location from
`builder` in almost all places (~45 call sites), which selects the first
constructor and propagates both the insertion point and the current
debug location. A few call sites instead passed `builder.saveIP()`,
which selects the second constructor and silently drops the debug
location.

Change the 9 offending call sites to pass `builder` instead of
`builder.saveIP()`, so the debug location is preserved.
---
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp      | 26 +++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index f2fefa1f5a53f..1e3cbeecdb8c7 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -271,7 +271,7 @@ class LinearClauseProcessor {
     // Emit barrier
     builder.SetInsertPoint(linearExitBB->getTerminator());
     return moduleTranslation.getOpenMPBuilder()->createBarrier(
-        builder.saveIP(), llvm::omp::OMPD_barrier);
+        builder, llvm::omp::OMPD_barrier);
   }
 
   // Emit stores for linear variables. Useful in case of SIMD
@@ -1654,8 +1654,8 @@ static LogicalResult createReductionsAndCleanup(
   llvm::UnreachableInst *tempTerminator = builder.CreateUnreachable();
   builder.SetInsertPoint(tempTerminator);
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy contInsertPoint =
-      ompBuilder->createReductions(builder.saveIP(), allocaIP, reductionInfos,
-                                   isByRef, isNowait, isTeamsReduction);
+      ompBuilder->createReductions(builder, allocaIP, reductionInfos, isByRef,
+                                   isNowait, isTeamsReduction);
 
   if (failed(handleError(contInsertPoint, *op)))
     return failure();
@@ -2003,7 +2003,7 @@ static LogicalResult copyFirstPrivateVars(
   if (insertBarrier && !opIsInSingleThread(op)) {
     llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
     llvm::OpenMPIRBuilder::InsertPointOrErrorTy res =
-        ompBuilder->createBarrier(builder.saveIP(), llvm::omp::OMPD_barrier);
+        ompBuilder->createBarrier(builder, llvm::omp::OMPD_barrier);
     if (failed(handleError(res, *op)))
       return failure();
   }
@@ -4377,7 +4377,7 @@ convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
     return failure();
   }
 
-  moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP(), dds);
+  moduleTranslation.getOpenMPBuilder()->createTaskwait(builder, dds);
   if (dds.DepArray) {
     builder.CreateFree(dds.DepArray);
   }
@@ -4537,7 +4537,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
                                         loopInfo->getPreheader());
     llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterBarrierIP =
         moduleTranslation.getOpenMPBuilder()->createBarrier(
-            builder.saveIP(), llvm::omp::OMPD_barrier);
+            builder, llvm::omp::OMPD_barrier);
     if (failed(handleError(afterBarrierIP, *loopOp)))
       return failure();
     builder.restoreIP(*afterBarrierIP);
@@ -4734,9 +4734,10 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
       builder.SetInsertPoint(tempTerminator);
 
       llvm::OpenMPIRBuilder::InsertPointOrErrorTy contInsertPoint =
-          ompBuilder->createReductions(
-              builder.saveIP(), allocaIP, reductionInfos, isByRef,
-              /*IsNoWait=*/false, /*IsTeamsReduction=*/false);
+          ompBuilder->createReductions(builder, allocaIP, reductionInfos,
+                                       isByRef,
+                                       /*IsNoWait=*/false,
+                                       /*IsTeamsReduction=*/false);
       if (!contInsertPoint)
         return contInsertPoint.takeError();
 
@@ -9698,8 +9699,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
               return failure();
 
             llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-                ompBuilder->createBarrier(builder.saveIP(),
-                                          llvm::omp::OMPD_barrier);
+                ompBuilder->createBarrier(builder, llvm::omp::OMPD_barrier);
             LogicalResult res = handleError(afterIP, *op);
             if (res.succeeded()) {
               // If the barrier generated a cancellation check, the insertion
@@ -9712,7 +9712,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
             if (failed(checkImplementationStatus(*op)))
               return failure();
 
-            ompBuilder->createTaskyield(builder.saveIP());
+            ompBuilder->createTaskyield(builder);
             return success();
           })
           .Case([&](omp::FlushOp op) {
@@ -9727,7 +9727,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
             //
             // The argument list is discarded so that, flush with a list is
             // treated same as a flush without a list.
-            ompBuilder->createFlush(builder.saveIP());
+            ompBuilder->createFlush(builder);
             return success();
           })
           .Case([&](omp::ParallelOp op) {



More information about the Mlir-commits mailing list