Skip to content

Commit 28ffa7f

Browse files
authored
[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.
1 parent 237a910 commit 28ffa7f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
! RUN: %flang_fc1 -emit-llvm -fopenmp -fopenmp-version=51 -fopenmp-targets=amdgcn-amd-amdhsa -o - %s | FileCheck %s
2+
program missing_inode
3+
#line "/this_path_should_not_exist_on_any_system_out_there/and_if_it_does_it_will_break_the/tes.f90" 700
4+
! CHECK: define internal void @__omp_offloading_{{[0-9a-f]+}}_{{[0-9a-f]+}}__QQmain_l701
5+
!$omp target
6+
call some_routine()
7+
!$omp end target
8+
end program missing_inode

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,7 @@ LogicalResult convertFlagsAttr(Operation *op, mlir::omp::FlagsAttr attribute,
42824282
return success();
42834283
}
42844284

4285-
static bool getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
4285+
static void getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
42864286
omp::TargetOp targetOp,
42874287
llvm::StringRef parentName = "") {
42884288
auto fileLoc = targetOp.getLoc()->findInstanceOf<FileLineColLoc>();
@@ -4291,15 +4291,16 @@ static bool getTargetEntryUniqueInfo(llvm::TargetRegionEntryInfo &targetInfo,
42914291
StringRef fileName = fileLoc.getFilename().getValue();
42924292

42934293
llvm::sys::fs::UniqueID id;
4294+
uint64_t line = fileLoc.getLine();
42944295
if (auto ec = llvm::sys::fs::getUniqueID(fileName, id)) {
4295-
targetOp.emitError("Unable to get unique ID for file");
4296-
return false;
4296+
size_t fileHash = llvm::hash_value(fileName.str());
4297+
size_t deviceId = 0xdeadf17e;
4298+
targetInfo =
4299+
llvm::TargetRegionEntryInfo(parentName, deviceId, fileHash, line);
4300+
} else {
4301+
targetInfo = llvm::TargetRegionEntryInfo(parentName, id.getDevice(),
4302+
id.getFile(), line);
42974303
}
4298-
4299-
uint64_t line = fileLoc.getLine();
4300-
targetInfo = llvm::TargetRegionEntryInfo(parentName, id.getDevice(),
4301-
id.getFile(), line);
4302-
return true;
43034304
}
43044305

43054306
static void
@@ -4899,8 +4900,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
48994900

49004901
llvm::TargetRegionEntryInfo entryInfo;
49014902

4902-
if (!getTargetEntryUniqueInfo(entryInfo, targetOp, parentName))
4903-
return failure();
4903+
getTargetEntryUniqueInfo(entryInfo, targetOp, parentName);
49044904

49054905
MapInfoData mapData;
49064906
collectMapDataFromMapOperands(mapData, mapVars, moduleTranslation, dl,

0 commit comments

Comments
 (0)