Files
clang-p2996/mlir/unittests/Dialect/Transform/BuildOnlyExtensionTest.cpp
Alex Zinenko 333ee218ce [mlir] Transform dialect: separate dependent and generated dialects
In the Transform dialect extensions, provide the separate mechanism to
declare dependent dialects (the dialects the transform IR depends on)
and the generated dialects (the dialects the payload IR may be
transformed into). This allows the Transform dialect clients that are
only constructing the transform IR to avoid loading the dialects
relevant for the payload IR along with the Transform dialect itself,
thus decreasing the build/link time.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D130289
2022-07-25 09:59:53 +00:00

46 lines
1.6 KiB
C++

//===- 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:
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>());
}