Add support for setting the location of an IROperandOwner.

PiperOrigin-RevId: 222995814
This commit is contained in:
River Riddle 2018-11-27 08:33:49 -08:00 committed by jpienaar
parent 721a30d6a0
commit 759fd1c6a3
5 changed files with 16 additions and 0 deletions

View File

@ -77,6 +77,7 @@ class Instruction final
public:
using IROperandOwner::getContext;
using IROperandOwner::getLoc;
using IROperandOwner::setLoc;
//===--------------------------------------------------------------------===//
// Operands

View File

@ -46,6 +46,9 @@ public:
/// The source location the operation was defined or derived from.
Location getLoc() const;
/// Set the source location the operation was defined or derived from.
void setLoc(Location loc);
/// Return the function this operation is defined in. This has a verbose
/// name to avoid name lookup ambiguities.
Function *getOperationFunction();

View File

@ -58,6 +58,7 @@ public:
using Statement::getLoc;
using Statement::moveBefore;
using Statement::print;
using Statement::setLoc;
/// Check if this statement is a return statement.
bool isReturn() const;

View File

@ -90,6 +90,9 @@ public:
/// The source location the operation was defined or derived from.
Location getLoc() const { return locationAndKind.getPointer(); }
/// Set the source location the operation was defined or derived from.
void setLoc(Location loc) { locationAndKind.setPointer(loc); }
/// Return the context this operation is associated with.
MLIRContext *getContext() const;

View File

@ -87,6 +87,14 @@ Location Operation::getLoc() const {
return llvm::cast<OperationStmt>(this)->getLoc();
}
/// Set the source location the operation was defined or derived from.
void Operation::setLoc(Location loc) {
if (auto *inst = llvm::dyn_cast<Instruction>(this))
inst->setLoc(loc);
else
llvm::cast<OperationStmt>(this)->setLoc(loc);
}
/// Return the function this operation is defined in.
Function *Operation::getOperationFunction() {
if (auto *inst = llvm::dyn_cast<Instruction>(this))