[Mlir-commits] [mlir] 27b2bd7 - [MLIR] Enable conversion from llvm::SMLoc to mlir::Location with OpAsmParser.
Alex Zinenko
llvmlistbot at llvm.org
Wed May 12 00:08:38 PDT 2021
Author: Ulysse Beaugnon
Date: 2021-05-12T09:08:32+02:00
New Revision: 27b2bd76017f5b486b96ad782bfb28e1b28b5088
URL: https://github.com/llvm/llvm-project/commit/27b2bd76017f5b486b96ad782bfb28e1b28b5088
DIFF: https://github.com/llvm/llvm-project/commit/27b2bd76017f5b486b96ad782bfb28e1b28b5088.diff
LOG: [MLIR] Enable conversion from llvm::SMLoc to mlir::Location with OpAsmParser.
DialectAsmParser already allows converting an llvm::SMLoc location to a
mlir::Location location. This commit adds the same functionality to OpAsmParser.
Implementation is copied from DialectAsmParser.
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D102165
Added:
Modified:
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/Parser/Parser.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index fb4f1a85077c0..db1e98d95b966 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -287,6 +287,11 @@ class OpAsmParser {
/// 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
index b3c66b2fa1916..fea26bcb2e32d 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -1066,6 +1066,11 @@ class CustomOpAsmParser : public OpAsmParser {
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
//===--------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list