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