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/Query/Matcher/SliceMatchers.h"
20#include "mlir/Tools/mlir-query/MlirQueryMain.h"
21
22using namespace mlir;
23
24// This is needed because these matchers are defined as overloaded functions.
25using HasOpAttrName = detail::AttrOpMatcher(StringRef);
26using HasOpName = detail::NameOpMatcher(StringRef);
27using IsConstantOp = detail::constant_op_matcher();
28
29namespace test {
30#ifdef MLIR_INCLUDE_TESTS
31void registerTestDialect(DialectRegistry &);
32#endif
33} // namespace test
34
35int main(int argc, char **argv) {
36
37 DialectRegistry dialectRegistry;
38 registerAllDialects(registry&: dialectRegistry);
39
40 query::matcher::Registry matcherRegistry;
41
42 // Matchers registered in alphabetical order for consistency:
43 matcherRegistry.registerMatcher(
44 name: "getDefinitions",
45 matcher: query::matcher::m_GetDefinitions<query::matcher::DynMatcher>);
46 matcherRegistry.registerMatcher(
47 name: "getAllDefinitions",
48 matcher: query::matcher::m_GetAllDefinitions<query::matcher::DynMatcher>);
49 matcherRegistry.registerMatcher(name: "hasOpAttrName",
50 matcher: static_cast<HasOpAttrName *>(m_Attr));
51 matcherRegistry.registerMatcher(name: "hasOpName", matcher: static_cast<HasOpName *>(m_Op));
52 matcherRegistry.registerMatcher(name: "isConstantOp",
53 matcher: static_cast<IsConstantOp *>(m_Constant));
54 matcherRegistry.registerMatcher(name: "isNegInfFloat", matcher: m_NegInfFloat);
55 matcherRegistry.registerMatcher(name: "isNegZeroFloat", matcher: m_NegZeroFloat);
56 matcherRegistry.registerMatcher(name: "isNonZero", matcher: m_NonZero);
57 matcherRegistry.registerMatcher(name: "isOne", matcher: m_One);
58 matcherRegistry.registerMatcher(name: "isOneFloat", matcher: m_OneFloat);
59 matcherRegistry.registerMatcher(name: "isPosInfFloat", matcher: m_PosInfFloat);
60 matcherRegistry.registerMatcher(name: "isPosZeroFloat", matcher: m_PosZeroFloat);
61 matcherRegistry.registerMatcher(name: "isZero", matcher: m_Zero);
62 matcherRegistry.registerMatcher(name: "isZeroFloat", matcher: m_AnyZeroFloat);
63
64#ifdef MLIR_INCLUDE_TESTS
65 test::registerTestDialect(dialectRegistry);
66#endif
67 MLIRContext context(dialectRegistry);
68
69 return failed(Result: mlirQueryMain(argc, argv, context, matcherRegistry));
70}
71

source code of mlir/tools/mlir-query/mlir-query.cpp