1 | //===- IRDLSymbols.cpp - IRDL-related symbol logic --------------*- C++ -*-===// |
---|---|
2 | // |
3 | // This file is licensed 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 "mlir/Dialect/IRDL/IRDLSymbols.h" |
10 | #include "mlir/Dialect/IRDL/IR/IRDL.h" |
11 | |
12 | using namespace mlir; |
13 | using namespace mlir::irdl; |
14 | |
15 | static Operation *lookupDialectOp(Operation *source) { |
16 | Operation *dialectOp = source; |
17 | while (dialectOp && !isa<DialectOp>(dialectOp)) |
18 | dialectOp = dialectOp->getParentOp(); |
19 | |
20 | if (!dialectOp) |
21 | llvm_unreachable("symbol lookup near dialect must originate from " |
22 | "within a dialect definition"); |
23 | |
24 | return dialectOp; |
25 | } |
26 | |
27 | Operation * |
28 | mlir::irdl::lookupSymbolNearDialect(SymbolTableCollection &symbolTable, |
29 | Operation *source, SymbolRefAttr symbol) { |
30 | return symbolTable.lookupNearestSymbolFrom( |
31 | lookupDialectOp(source)->getParentOp(), symbol); |
32 | } |
33 | |
34 | Operation *mlir::irdl::lookupSymbolNearDialect(Operation *source, |
35 | SymbolRefAttr symbol) { |
36 | return SymbolTable::lookupNearestSymbolFrom( |
37 | lookupDialectOp(source)->getParentOp(), symbol); |
38 | } |
39 |