[MLIR] NFC use Operation::getParentWithTrait in alloca verifier
authorUday Bondhugula <uday@polymagelabs.com>
Thu, 16 Apr 2020 13:27:32 +0000 (18:57 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Thu, 16 Apr 2020 16:04:02 +0000 (21:34 +0530)
Use recently added accessor Operation::getParentWithTrait in alloca
verifier.

Differential Revision: https://reviews.llvm.org/D78296

mlir/lib/Dialect/StandardOps/IR/Ops.cpp

index 53870e4..452dade 100644 (file)
@@ -324,14 +324,11 @@ static LogicalResult verify(AllocLikeOp op) {
     return success();
 
   // An alloca op needs to have an ancestor with an allocation scope trait.
-  auto *parentOp = op.getParentOp();
-  while (parentOp) {
-    if (parentOp->template hasTrait<OpTrait::AutomaticAllocationScope>())
-      return success();
-    parentOp = parentOp->getParentOp();
-  }
-  return op.emitOpError(
-      "requires an ancestor op with AutomaticAllocationScope trait");
+  if (!op.template getParentWithTrait<OpTrait::AutomaticAllocationScope>())
+    return op.emitOpError(
+        "requires an ancestor op with AutomaticAllocationScope trait");
+
+  return success();
 }
 
 namespace {