aboutsummaryrefslogtreecommitdiff
path: root/mlir/unittests/Dialect/Transform/BuildOnlyExtensionTest.cpp
blob: d2a4999594a9e991b2053941af08cb015dd46b0b (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
37
38
39
40
41
42
43
44
45
46
47
//===- BuildOnlyExtensionTest.cpp - unit test for transform extensions ----===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
#include "mlir/IR/DialectRegistry.h"
#include "mlir/IR/MLIRContext.h"
#include "gtest/gtest.h"

using namespace mlir;
using namespace mlir::transform;

namespace {
class Extension : public TransformDialectExtension<Extension> {
public:
  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(Extension)

  using Base::Base;
  void init() { declareGeneratedDialect<func::FuncDialect>(); }
};
} // end namespace

TEST(BuildOnlyExtensionTest, buildOnlyExtension) {
  // Register the build-only version of the transform dialect extension. The
  // func dialect is declared as generated so it should not be loaded along with
  // the transform dialect.
  DialectRegistry registry;
  registry.addExtensions<BuildOnly<Extension>>();
  MLIRContext ctx(registry);
  ctx.getOrLoadDialect<TransformDialect>();
  ASSERT_FALSE(ctx.getLoadedDialect<func::FuncDialect>());
}

TEST(BuildOnlyExtensionTest, buildAndApplyExtension) {
  // Register the full version of the transform dialect extension. The func
  // dialect should be loaded along with the transform dialect.
  DialectRegistry registry;
  registry.addExtensions<Extension>();
  MLIRContext ctx(registry);
  ctx.getOrLoadDialect<TransformDialect>();
  ASSERT_TRUE(ctx.getLoadedDialect<func::FuncDialect>());
}