NFC: Simplify ModuleTerminatorOp by using the HasParent trait.

PiperOrigin-RevId: 261962104
This commit is contained in:
River Riddle 2019-08-06 11:46:01 -07:00 committed by A. Unique TensorFlower
parent 55f2e24ab3
commit 8920afb0a6
3 changed files with 2 additions and 15 deletions

View File

@ -107,13 +107,11 @@ public:
/// the terminator in their custom syntax for brevity.
class ModuleTerminatorOp
: public Op<ModuleTerminatorOp, OpTrait::ZeroOperands, OpTrait::ZeroResult,
OpTrait::IsTerminator> {
OpTrait::HasParent<ModuleOp>::Impl, OpTrait::IsTerminator> {
public:
using Op::Op;
static StringRef getOperationName() { return "module_terminator"; }
static void build(Builder *, OperationState *) {}
LogicalResult verify();
};
//===----------------------------------------------------------------------===//

View File

@ -86,14 +86,3 @@ LogicalResult ModuleOp::verify() {
/// Return body of this module.
Region &ModuleOp::getBodyRegion() { return getOperation()->getRegion(0); }
Block *ModuleOp::getBody() { return &getBodyRegion().front(); }
//===----------------------------------------------------------------------===//
// Module Terminator Operation.
//===----------------------------------------------------------------------===//
LogicalResult ModuleTerminatorOp::verify() {
if (!isa_and_nonnull<ModuleOp>(getOperation()->getParentOp()))
return emitOpError() << "is expected to terminate a '"
<< ModuleOp::getOperationName() << "' operation";
return success();
}

View File

@ -38,6 +38,6 @@ func @module_op() {
// -----
func @module_op() {
// expected-error@+1 {{is expected to terminate a 'module' operation}}
// expected-error@+1 {{expects parent op 'module'}}
"module_terminator"() : () -> ()
}