1//===- TestDialect.h - MLIR Dialect for testing -----------------*- C++ -*-===//
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 file defines a fake 'test' dialect that can be used for testing things
10// that do not have a respective counterpart in the main source directories.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_TESTDIALECT_H
15#define MLIR_TESTDIALECT_H
16
17#include "TestAttributes.h"
18#include "TestInterfaces.h"
19#include "TestTypes.h"
20#include "mlir/Bytecode/BytecodeImplementation.h"
21#include "mlir/Dialect/DLTI/DLTI.h"
22#include "mlir/Dialect/DLTI/Traits.h"
23#include "mlir/Dialect/Func/IR/FuncOps.h"
24#include "mlir/Dialect/Linalg/IR/Linalg.h"
25#include "mlir/Dialect/Traits.h"
26#include "mlir/IR/AsmState.h"
27#include "mlir/IR/BuiltinOps.h"
28#include "mlir/IR/BuiltinTypes.h"
29#include "mlir/IR/Dialect.h"
30#include "mlir/IR/DialectResourceBlobManager.h"
31#include "mlir/IR/ExtensibleDialect.h"
32#include "mlir/IR/OpDefinition.h"
33#include "mlir/IR/OpImplementation.h"
34#include "mlir/IR/RegionKindInterface.h"
35#include "mlir/IR/SymbolTable.h"
36#include "mlir/Interfaces/CallInterfaces.h"
37#include "mlir/Interfaces/ControlFlowInterfaces.h"
38#include "mlir/Interfaces/CopyOpInterface.h"
39#include "mlir/Interfaces/DerivedAttributeOpInterface.h"
40#include "mlir/Interfaces/InferIntRangeInterface.h"
41#include "mlir/Interfaces/InferTypeOpInterface.h"
42#include "mlir/Interfaces/LoopLikeInterface.h"
43#include "mlir/Interfaces/SideEffectInterfaces.h"
44#include "mlir/Interfaces/ValueBoundsOpInterface.h"
45#include "mlir/Interfaces/ViewLikeInterface.h"
46#include "llvm/ADT/SetVector.h"
47
48#include <memory>
49
50namespace mlir {
51class RewritePatternSet;
52} // end namespace mlir
53
54//===----------------------------------------------------------------------===//
55// TestDialect
56//===----------------------------------------------------------------------===//
57
58#include "TestOpsDialect.h.inc"
59
60namespace test {
61
62//===----------------------------------------------------------------------===//
63// TestDialect version utilities
64//===----------------------------------------------------------------------===//
65
66struct TestDialectVersion : public mlir::DialectVersion {
67 TestDialectVersion() = default;
68 TestDialectVersion(uint32_t majorVersion, uint32_t minorVersion)
69 : major_(majorVersion), minor_(minorVersion){};
70 // We cannot use 'major' and 'minor' here because these identifiers may
71 // already be used by <sys/types.h> on many POSIX systems including Linux and
72 // FreeBSD.
73 uint32_t major_ = 2;
74 uint32_t minor_ = 0;
75};
76
77} // namespace test
78
79namespace test {
80
81// Op deliberately defined in C++ code rather than ODS to test that C++
82// Ops can still use the old `fold` method.
83class ManualCppOpWithFold
84 : public mlir::Op<ManualCppOpWithFold, mlir::OpTrait::OneResult> {
85public:
86 using Op::Op;
87
88 static llvm::StringRef getOperationName() {
89 return "test.manual_cpp_op_with_fold";
90 }
91
92 static llvm::ArrayRef<llvm::StringRef> getAttributeNames() { return {}; }
93
94 mlir::OpFoldResult fold(llvm::ArrayRef<mlir::Attribute> attributes);
95};
96
97void registerTestDialect(::mlir::DialectRegistry &registry);
98void populateTestReductionPatterns(::mlir::RewritePatternSet &patterns);
99void testSideEffectOpGetEffect(
100 mlir::Operation *op,
101 llvm::SmallVectorImpl<
102 mlir::SideEffects::EffectInstance<mlir::TestEffects::Effect>> &effects);
103} // namespace test
104
105#endif // MLIR_TESTDIALECT_H
106

source code of mlir/test/lib/Dialect/Test/TestDialect.h