aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/TestDyn/TestDynDialect.cpp
blob: 1757f1dbb873df1a08a588d85190ddbe95f726bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//===- TestDynDialect.cpp -------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines a fake 'test_dyn' dynamic dialect that is used to test the
// registration of dynamic dialects.
//
//===----------------------------------------------------------------------===//

#include "mlir/IR/ExtensibleDialect.h"

using namespace mlir;

namespace test {
void registerTestDynDialect(DialectRegistry &registry) {
  registry.insertDynamic(
      "test_dyn", [](MLIRContext *ctx, DynamicDialect *testDyn) {
        auto opVerifier = [](Operation *op) -> LogicalResult {
          if (op->getNumOperands() == 0 && op->getNumResults() == 1 &&
              op->getNumRegions() == 0)
            return success();
          return op->emitError(
              "expected a single result, no operands and no regions");
        };

        auto opRegionVerifier = [](Operation *op) { return success(); };

        testDyn->registerDynamicOp(DynamicOpDefinition::get(
            "one_result", testDyn, opVerifier, opRegionVerifier));
      });
}
} // namespace test