diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -287,6 +287,11 @@ /// Return the location of the original name token. virtual llvm::SMLoc getNameLoc() const = 0; + /// Re-encode the given source location as an MLIR location and return it. + /// Note: This method should only be used when a `Location` is necessary, as + /// the encoding process is not efficient. + virtual Location getEncodedSourceLoc(llvm::SMLoc loc) = 0; + // These methods emit an error and return failure or success. This allows // these to be chained together into a linear sequence of || expressions in // many cases. diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1057,6 +1057,11 @@ llvm::SMLoc getNameLoc() const override { return nameLoc; } + /// Re-encode the given source location as an MLIR location and return it. + Location getEncodedSourceLoc(llvm::SMLoc loc) override { + return parser.getEncodedSourceLocation(loc); + } + //===--------------------------------------------------------------------===// // Token Parsing //===--------------------------------------------------------------------===//