1 //===- Predicate.cpp - Pattern predicates ---------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "Predicate.h" 10 11 using namespace mlir; 12 using namespace mlir::pdl_to_pdl_interp; 13 14 //===----------------------------------------------------------------------===// 15 // Positions 16 //===----------------------------------------------------------------------===// 17 18 Position::~Position() = default; 19 20 /// Returns the depth of the first ancestor operation position. getOperationDepth() const21unsigned Position::getOperationDepth() const { 22 if (const auto *operationPos = dyn_cast<OperationPosition>(this)) 23 return operationPos->getDepth(); 24 return parent ? parent->getOperationDepth() : 0; 25 } 26 27 //===----------------------------------------------------------------------===// 28 // AttributePosition 29 AttributePosition(const KeyTy & key)30AttributePosition::AttributePosition(const KeyTy &key) : Base(key) { 31 parent = key.first; 32 } 33 34 //===----------------------------------------------------------------------===// 35 // OperandPosition 36 OperandPosition(const KeyTy & key)37OperandPosition::OperandPosition(const KeyTy &key) : Base(key) { 38 parent = key.first; 39 } 40 41 //===----------------------------------------------------------------------===// 42 // OperandGroupPosition 43 OperandGroupPosition(const KeyTy & key)44OperandGroupPosition::OperandGroupPosition(const KeyTy &key) : Base(key) { 45 parent = std::get<0>(key); 46 } 47 48 //===----------------------------------------------------------------------===// 49 // OperationPosition 50 isOperandDefiningOp() const51bool OperationPosition::isOperandDefiningOp() const { 52 return isa_and_nonnull<OperandPosition, OperandGroupPosition>(parent); 53 } 54