[Mlir-commits] [mlir] 28ffa7f - [flang][OpenMP] Fix missing missing inode issue (#130798)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Mar 13 07:50:42 PDT 2025


Author: Michael Klemm
Date: 2025-03-13T15:50:37+01:00
New Revision: 28ffa7f6a4d609e097a4861090f42c35459e9303

URL: https://github.com/llvm/llvm-project/commit/28ffa7f6a4d609e097a4861090f42c35459e9303
DIFF: https://github.com/llvm/llvm-project/commit/28ffa7f6a4d609e097a4861090f42c35459e9303.diff

LOG: [flang][OpenMP] Fix missing missing inode issue (#130798)

When outlining an offload region, Flang creates a unique name by
querying an inode ID. However, when the name of the actual source file
does not match the logical file in a `#line` preprocessor directive,
code-gen was failing as it could not determine the inode ID. This PR
checks for this condition and if the logical file name does not exist,
the inode is replaced with a hash value created from the source code
itself.

Added: 
    flang/test/Lower/OpenMP/missing-inode.f90

Modified: 
    mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/flang/test/Lower/OpenMP/missing-inode.f90 b/flang/test/Lower/OpenMP/missing-inode.f90
new file mode 100644
index 0000000000000..01e662557cfe6
--- /dev/null
+++ b/flang/test/Lower/OpenMP/missing-inode.f90
@@ -0,0 +1,8 @@
+! RUN: %flang_fc1 -emit-llvm -fopenmp -fopenmp-version=51 -fopenmp-targets=amdgcn-amd-amdhsa -o - %s | FileCheck %s
+program missing_inode
+#line "/this_path_should_not_exist_on_any_system_out_there/and_if_it_does_it_will_break_the/tes.f90" 700
+    ! CHECK:  define internal void @__omp_offloading_{{[0-9a-f]+}}_{{[0-9a-f]+}}__QQmain_l701
+    !$omp target
+        call some_routine()
+    !$omp end target
+end program missing_inode
\ No newline at end of file

diff  --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index b9893716980fe..0010ca6630050 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -4282,7 +4282,7 @@ LogicalResult convertFlagsAttr(Operation *op, mlir::omp::FlagsAttr attribute,
   return success();
 }
 
-static bool getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
+static void getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
                                      omp::TargetOp targetOp,
                                      llvm::StringRef parentName = "") {
   auto fileLoc = targetOp.getLoc()->findInstanceOf<FileLineColLoc>();
@@ -4291,15 +4291,16 @@ static bool getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
   StringRef fileName = fileLoc.getFilename().getValue();
 
   llvm::sys::fs::UniqueID id;
+  uint64_t line = fileLoc.getLine();
   if (auto ec = llvm::sys::fs::getUniqueID(fileName, id)) {
-    targetOp.emitError("Unable to get unique ID for file");
-    return false;
+    size_t fileHash = llvm::hash_value(fileName.str());
+    size_t deviceId = 0xdeadf17e;
+    targetInfo =
+        llvm::TargetRegionEntryInfo(parentName, deviceId, fileHash, line);
+  } else {
+    targetInfo = llvm::TargetRegionEntryInfo(parentName, id.getDevice(),
+                                             id.getFile(), line);
   }
-
-  uint64_t line = fileLoc.getLine();
-  targetInfo = llvm::TargetRegionEntryInfo(parentName, id.getDevice(),
-                                           id.getFile(), line);
-  return true;
 }
 
 static void
@@ -4899,8 +4900,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
 
   llvm::TargetRegionEntryInfo entryInfo;
 
-  if (!getTargetEntryUniqueInfo(entryInfo, targetOp, parentName))
-    return failure();
+  getTargetEntryUniqueInfo(entryInfo, targetOp, parentName);
 
   MapInfoData mapData;
   collectMapDataFromMapOperands(mapData, mapVars, moduleTranslation, dl,


        


More information about the Mlir-commits mailing list