From 7c849845e09a90fa9948afb207e755bbecb80484 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Mon, 7 Nov 2022 19:01:14 -0800 Subject: [PATCH] [mlir][LLVMDebugTranslation] Add inlinedAt to the key when caching locations This avoids accidentally using the wrong inlined at scope when translating locations. --- mlir/lib/Target/LLVMIR/DebugTranslation.cpp | 4 ++-- mlir/lib/Target/LLVMIR/DebugTranslation.h | 3 ++- mlir/test/Target/LLVMIR/llvmir-debug.mlir | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp index 3dbb3f7..fc3f9fa 100644 --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -247,7 +247,7 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope, return nullptr; // Check for a cached instance. - auto existingIt = locationToLoc.find(std::make_pair(loc, scope)); + auto existingIt = locationToLoc.find(std::make_tuple(loc, scope, inlinedAt)); if (existingIt != locationToLoc.end()) return existingIt->second; @@ -285,7 +285,7 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope, llvm_unreachable("unknown location kind"); } - locationToLoc.try_emplace(std::make_pair(loc, scope), llvmLoc); + locationToLoc.try_emplace(std::make_tuple(loc, scope, inlinedAt), llvmLoc); return llvmLoc; } diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h index 14bd3b5..79f1326 100644 --- a/mlir/lib/Target/LLVMIR/DebugTranslation.h +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h @@ -77,7 +77,8 @@ private: /// A mapping between mlir location+scope and the corresponding llvm debug /// metadata. - DenseMap, const llvm::DILocation *> + DenseMap, + const llvm::DILocation *> locationToLoc; /// A mapping between debug attribute and the corresponding llvm debug diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir index 72f8f74..be5142a 100644 --- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir @@ -64,7 +64,7 @@ llvm.func @func_with_debug(%arg: i64) { llvm.call @func_no_debug() : () -> () loc("named"("foo.mlir":10:10)) // CHECK: call void @func_no_debug(), !dbg ![[FUSED_LOC:[0-9]+]] - llvm.call @func_no_debug() : () -> () loc(fused[callsite("mysource.cc":1:1 at "mysource.cc":5:6), "mysource.cc":1:1]) + llvm.call @func_no_debug() : () -> () loc(fused[callsite("mysource.cc":5:6 at "mysource.cc":1:1), "mysource.cc":1:1]) llvm.return } loc(fused<#sp>["foo.mlir":1:1]) -- 2.7.4