1 | //===- mlir-query.cpp - MLIR Query Driver ---------------------------------===// |
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 | // This is a command line utility that queries a file from/to MLIR using one |
10 | // of the registered queries. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "mlir/IR/Dialect.h" |
15 | #include "mlir/IR/MLIRContext.h" |
16 | #include "mlir/IR/Matchers.h" |
17 | #include "mlir/InitAllDialects.h" |
18 | #include "mlir/Query/Matcher/Registry.h" |
19 | #include "mlir/Tools/mlir-query/MlirQueryMain.h" |
20 | |
21 | using namespace mlir; |
22 | |
23 | // This is needed because these matchers are defined as overloaded functions. |
24 | using HasOpAttrName = detail::AttrOpMatcher(StringRef); |
25 | using HasOpName = detail::NameOpMatcher(StringRef); |
26 | using IsConstantOp = detail::constant_op_matcher(); |
27 | |
28 | namespace test { |
29 | #ifdef MLIR_INCLUDE_TESTS |
30 | void registerTestDialect(DialectRegistry &); |
31 | #endif |
32 | } // namespace test |
33 | |
34 | int main(int argc, char **argv) { |
35 | |
36 | DialectRegistry dialectRegistry; |
37 | registerAllDialects(registry&: dialectRegistry); |
38 | |
39 | query::matcher::Registry matcherRegistry; |
40 | |
41 | // Matchers registered in alphabetical order for consistency: |
42 | matcherRegistry.registerMatcher(name: "hasOpAttrName" , |
43 | matcher: static_cast<HasOpAttrName *>(m_Attr)); |
44 | matcherRegistry.registerMatcher(name: "hasOpName" , matcher: static_cast<HasOpName *>(m_Op)); |
45 | matcherRegistry.registerMatcher(name: "isConstantOp" , |
46 | matcher: static_cast<IsConstantOp *>(m_Constant)); |
47 | matcherRegistry.registerMatcher(name: "isNegInfFloat" , matcher: m_NegInfFloat); |
48 | matcherRegistry.registerMatcher(name: "isNegZeroFloat" , matcher: m_NegZeroFloat); |
49 | matcherRegistry.registerMatcher(name: "isNonZero" , matcher: m_NonZero); |
50 | matcherRegistry.registerMatcher(name: "isOne" , matcher: m_One); |
51 | matcherRegistry.registerMatcher(name: "isOneFloat" , matcher: m_OneFloat); |
52 | matcherRegistry.registerMatcher(name: "isPosInfFloat" , matcher: m_PosInfFloat); |
53 | matcherRegistry.registerMatcher(name: "isPosZeroFloat" , matcher: m_PosZeroFloat); |
54 | matcherRegistry.registerMatcher(name: "isZero" , matcher: m_Zero); |
55 | matcherRegistry.registerMatcher(name: "isZeroFloat" , matcher: m_AnyZeroFloat); |
56 | |
57 | #ifdef MLIR_INCLUDE_TESTS |
58 | test::registerTestDialect(dialectRegistry); |
59 | #endif |
60 | MLIRContext context(dialectRegistry); |
61 | |
62 | return failed(result: mlirQueryMain(argc, argv, context, matcherRegistry)); |
63 | } |
64 | |