From 51f6c0ea600b665be8436c9bd732008df7137f38 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 1 Apr 2019 10:42:34 -0700 Subject: [PATCH] Add a getLoc() method on mlir::Value that returns the loc of the defining Operations if any, otherwise an unknown location -- PiperOrigin-RevId: 241354085 --- mlir/include/mlir/IR/Value.h | 4 ++++ mlir/lib/IR/Value.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h index 30f352b0e9e0..aa52c6be7740 100644 --- a/mlir/include/mlir/IR/Value.h +++ b/mlir/include/mlir/IR/Value.h @@ -77,6 +77,10 @@ public: /// defines it. Operation *getDefiningOp(); + /// If this value is the result of an operation, use it as a location, + /// otherwise return an unknown location. + Location getLoc(); + using use_iterator = ValueUseIterator; using use_range = llvm::iterator_range; diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp index bd81784c512a..e3ce7a5656c1 100644 --- a/mlir/lib/IR/Value.cpp +++ b/mlir/lib/IR/Value.cpp @@ -38,6 +38,13 @@ Function *Value::getFunction() { } } +Location Value::getLoc() { + if (auto *op = getDefiningOp()) { + return op->getLoc(); + } + return UnknownLoc::get(getContext()); +} + //===----------------------------------------------------------------------===// // IRObjectWithUseList implementation. //===----------------------------------------------------------------------===//