Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b35b4c

Browse files
authoredJan 25, 2025
[mlir] Allow fallback from file line col range to loc (llvm#124321)
This was discussed during the original review but I made it stricter than discussed. Making it a pure view but adding a helper for bytecode serialization (I could avoid the helper, but it ends up with more logic and stronger coupling).
1 parent 8e31050 commit 3b35b4c

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed
 

‎mlir/include/mlir/IR/BuiltinDialectBytecode.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ def FileLineColRange : DialectAttribute<(attr
104104
WithPrinter<"writeFileLineColRangeLocs($_writer, $_name)">>>>:$rawLocData
105105
)> {
106106
let cBuilder = "getFileLineColRange(context, filename, rawLocData)";
107-
let printerPredicate = "!::llvm::isa<FileLineColLoc>($_val)";
107+
let printerPredicate = "!isStrictFileLineColLoc($_val)";
108108
}
109109

110110
def FileLineColLoc : DialectAttribute<(attr
111111
StringAttr:$filename,
112112
VarInt:$start_line,
113113
VarInt:$start_column
114114
)> {
115-
let printerPredicate = "::llvm::isa<FileLineColLoc>($_val)";
115+
let printerPredicate = "isStrictFileLineColLoc($_val)";
116116
}
117117
}
118118

‎mlir/include/mlir/IR/Location.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class FusedLocWith : public FusedLoc {
177177
/// column number. This is similar to the type of location that you get from
178178
/// most source languages.
179179
///
180-
/// FileLineColLoc is a FileLineColRange with exactly one line and column.
180+
/// FileLineColLoc is a view to FileLineColRange with one line and column.
181181
class FileLineColLoc : public FileLineColRange {
182182
public:
183183
using FileLineColRange::FileLineColRange;
@@ -190,11 +190,12 @@ class FileLineColLoc : public FileLineColRange {
190190
StringAttr getFilename() const;
191191
unsigned getLine() const;
192192
unsigned getColumn() const;
193-
194-
/// Methods for support type inquiry through isa, cast, and dyn_cast.
195-
static bool classof(Attribute attr);
196193
};
197194

195+
/// Returns true iff the given location is a FileLineColRange with exactly one
196+
/// line and column.
197+
bool isStrictFileLineColLoc(Location loc);
198+
198199
//===----------------------------------------------------------------------===//
199200
// OpaqueLoc
200201
//===----------------------------------------------------------------------===//

‎mlir/lib/IR/Location.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ unsigned FileLineColLoc::getLine() const { return getStartLine(); }
177177

178178
unsigned FileLineColLoc::getColumn() const { return getStartColumn(); }
179179

180-
bool FileLineColLoc::classof(Attribute attr) {
181-
// This could also have been for <= 2. But given this is matching previous
182-
// behavior, it is left as is.
183-
if (auto range = mlir::dyn_cast<FileLineColRange>(attr))
180+
bool mlir::isStrictFileLineColLoc(Location loc) {
181+
if (auto range = mlir::dyn_cast<FileLineColRange>(loc))
184182
return range.getImpl()->size() == 2;
185183
return false;
186184
}

‎mlir/test/Target/LLVMIR/llvmir-debug.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ llvm.func @func_with_debug(%arg: i64) {
115115
// CHECK: call void @func_no_debug(), !dbg ![[FILE_LOC:[0-9]+]]
116116
llvm.call @func_no_debug() : () -> () loc("foo.mlir":1:2)
117117

118+
// CHECK: call void @func_no_debug(), !dbg ![[FILE_LOC:[0-9]+]]
119+
llvm.call @func_no_debug() : () -> () loc("foo.mlir":1:2 to 5:6)
120+
118121
// CHECK: call void @func_no_debug(), !dbg ![[NAMED_LOC:[0-9]+]]
119122
llvm.call @func_no_debug() : () -> () loc("named"("foo.mlir":10:10))
120123

0 commit comments

Comments
 (0)
Please sign in to comment.