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() {} 19 20 //===----------------------------------------------------------------------===// 21 // AttributePosition 22 23 AttributePosition::AttributePosition(const KeyTy &key) : Base(key) { 24 parent = key.first; 25 } 26 27 //===----------------------------------------------------------------------===// 28 // OperandPosition 29 30 OperandPosition::OperandPosition(const KeyTy &key) : Base(key) { 31 parent = key.first; 32 } 33 34 //===----------------------------------------------------------------------===// 35 // OperationPosition 36 37 OperationPosition *OperationPosition::get(StorageUniquer &uniquer, 38 ArrayRef<unsigned> index) { 39 assert(!index.empty() && "expected at least two indices"); 40 41 // Set the parent position if this isn't the root. 42 Position *parent = nullptr; 43 if (index.size() > 1) { 44 auto *node = OperationPosition::get(uniquer, index.drop_back()); 45 parent = OperandPosition::get(uniquer, std::make_pair(node, index.back())); 46 } 47 return uniquer.get<OperationPosition>( 48 [parent](OperationPosition *node) { node->parent = parent; }, index); 49 } 50