-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMinimalDialect.td
99 lines (82 loc) · 3.13 KB
/
MinimalDialect.td
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//===- MinimalDialect.td - Minimal dialect ---- -------*- tablegen -*-===//
//
// This file is licensed 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
//
//===----------------------------------------------------------------------===//
#ifndef MINIMAL_DIALECT
#define MINIMAL_DIALECT
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Pass/PassBase.td"
include "mlir/IR/AttrTypeBase.td"
//===----------------------------------------------------------------------===//
// Minimal dialect definition.
//===----------------------------------------------------------------------===//
def Minimal_Dialect : Dialect {
let name = "minimal";
let summary = "A minimal out-of-tree MLIR dialect.";
let description = [{
This dialect is an example of an out-of-tree MLIR dialect designed to
illustrate the basic setup required to develop MLIR-based tools without
working inside of the LLVM source tree.
}];
let cppNamespace = "::mlir::minimal";
let useDefaultTypePrinterParser = 1;
let extraClassDeclaration = [{
void registerTypes();
}];
}
//===----------------------------------------------------------------------===//
// Base minimal operation definition.
//===----------------------------------------------------------------------===//
class Minimal_Op<string mnemonic, list<Trait> traits = []> :
Op<Minimal_Dialect, mnemonic, traits>;
def Minimal_FooOp : Minimal_Op<"foo", [Pure, SameOperandsAndResultType]> {
let summary = "Illustrates how to define an operation.";
let description = [{
The `minimal.foo` operation illustrates how to define a new
operation in a dialect. It uses an operation trait to declare that it
has no side effects.
This operation takes an integer argument and returns an integer.
Example:
```mlir
%0 = arith.constant 2 : i32
// Apply the foo operation to %0
%1 = minimal.foo %0 : i32
```
}];
let arguments = (ins I32:$input);
let results = (outs I32:$res);
let assemblyFormat = [{
$input attr-dict `:` type($input)
}];
}
def MinimalSwitchBarFoo: Pass<"minimal-switch-bar-foo", "::mlir::ModuleOp"> {
let summary = "Switches the name of a FuncOp named `bar` to `foo` and folds.";
let description = [{
Switches the name of a FuncOp named `bar` to `foo` and folds.
```
func.func @bar() {
return
}
// Gets transformed to:
func.func @foo() {
return
}
```
}];
}
class Minimal_Type<string name, string typeMnemonic, list<Trait> traits = []>
: TypeDef<Minimal_Dialect, name, traits> {
let mnemonic = typeMnemonic;
}
def Minimal_CustomType : Minimal_Type<"Custom", "custom"> {
let summary = "Minimal custom type";
let description = "Custom type in minimal dialect";
let parameters = (ins StringRefParameter<"the custom value">:$value);
let assemblyFormat = "`<` $value `>`";
}
#endif // MINIMAL_DIALECT