Add a getLoc() method on mlir::Value that returns the loc of the defining Operations if any, otherwise an unknown location

--

PiperOrigin-RevId: 241354085
This commit is contained in:
Mehdi Amini 2019-04-01 10:42:34 -07:00 committed by Mehdi Amini
parent 005d54329e
commit 51f6c0ea60
2 changed files with 11 additions and 0 deletions

View File

@ -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<OpOperand>;
using use_range = llvm::iterator_range<use_iterator>;

View File

@ -38,6 +38,13 @@ Function *Value::getFunction() {
}
}
Location Value::getLoc() {
if (auto *op = getDefiningOp()) {
return op->getLoc();
}
return UnknownLoc::get(getContext());
}
//===----------------------------------------------------------------------===//
// IRObjectWithUseList implementation.
//===----------------------------------------------------------------------===//