Add support for Operation::moveBefore(Operation *).

PiperOrigin-RevId: 222252521
This commit is contained in:
River Riddle 2018-11-20 08:48:08 -08:00 committed by jpienaar
parent 89d9913a20
commit d63ab4b47a
3 changed files with 13 additions and 0 deletions

View File

@ -120,6 +120,11 @@ public:
/// Return true if there are no users of any results of this operation.
bool use_empty() const;
/// Unlink this operation from its current block and insert it right before
/// `existingOp` which may be in the same or another block of the same
/// function.
void moveBefore(Operation *existingOp);
// Attributes. Operations may optionally carry a list of attributes that
// associate constants to names. Attributes may be dynamically added and
// removed over the lifetime of an operation.

View File

@ -56,6 +56,7 @@ public:
using Statement::emitNote;
using Statement::emitWarning;
using Statement::getLoc;
using Statement::moveBefore;
using Statement::print;
/// Check if this statement is a return statement.

View File

@ -197,6 +197,13 @@ bool Operation::use_empty() const {
return true;
}
void Operation::moveBefore(Operation *existingOp) {
if (auto *inst = llvm::dyn_cast<Instruction>(this))
return inst->moveBefore(llvm::cast<Instruction>(existingOp));
return llvm::cast<OperationStmt>(this)->moveBefore(
llvm::cast<OperationStmt>(existingOp));
}
ArrayRef<NamedAttribute> Operation::getAttrs() const {
if (!attrs)
return {};