Skip to content

[mlir] Allow fallback from file line col range to loc #124321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/include/mlir/IR/BuiltinDialectBytecode.td
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def FileLineColRange : DialectAttribute<(attr
WithPrinter<"writeFileLineColRangeLocs($_writer, $_name)">>>>:$rawLocData
)> {
let cBuilder = "getFileLineColRange(context, filename, rawLocData)";
let printerPredicate = "!::llvm::isa<FileLineColLoc>($_val)";
let printerPredicate = "!isStrictFileLineColLoc($_val)";
}

def FileLineColLoc : DialectAttribute<(attr
StringAttr:$filename,
VarInt:$start_line,
VarInt:$start_column
)> {
let printerPredicate = "::llvm::isa<FileLineColLoc>($_val)";
let printerPredicate = "isStrictFileLineColLoc($_val)";
}
}

Expand Down
9 changes: 5 additions & 4 deletions mlir/include/mlir/IR/Location.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class FusedLocWith : public FusedLoc {
/// column number. This is similar to the type of location that you get from
/// most source languages.
///
/// FileLineColLoc is a FileLineColRange with exactly one line and column.
/// FileLineColLoc is a view to FileLineColRange with one line and column.
class FileLineColLoc : public FileLineColRange {
public:
using FileLineColRange::FileLineColRange;
Expand All @@ -190,11 +190,12 @@ class FileLineColLoc : public FileLineColRange {
StringAttr getFilename() const;
unsigned getLine() const;
unsigned getColumn() const;

/// Methods for support type inquiry through isa, cast, and dyn_cast.
static bool classof(Attribute attr);
};

/// Returns true iff the given location is a FileLineColRange with exactly one
/// line and column.
bool isStrictFileLineColLoc(Location loc);

//===----------------------------------------------------------------------===//
// OpaqueLoc
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 2 additions & 4 deletions mlir/lib/IR/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,8 @@ unsigned FileLineColLoc::getLine() const { return getStartLine(); }

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

bool FileLineColLoc::classof(Attribute attr) {
// This could also have been for <= 2. But given this is matching previous
// behavior, it is left as is.
if (auto range = mlir::dyn_cast<FileLineColRange>(attr))
bool mlir::isStrictFileLineColLoc(Location loc) {
if (auto range = mlir::dyn_cast<FileLineColRange>(loc))
return range.getImpl()->size() == 2;
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir-debug.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ llvm.func @func_with_debug(%arg: i64) {
// CHECK: call void @func_no_debug(), !dbg ![[FILE_LOC:[0-9]+]]
llvm.call @func_no_debug() : () -> () loc("foo.mlir":1:2)

// CHECK: call void @func_no_debug(), !dbg ![[FILE_LOC:[0-9]+]]
llvm.call @func_no_debug() : () -> () loc("foo.mlir":1:2 to 5:6)

// CHECK: call void @func_no_debug(), !dbg ![[NAMED_LOC:[0-9]+]]
llvm.call @func_no_debug() : () -> () loc("named"("foo.mlir":10:10))

Expand Down
Loading