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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use super::Registry;
use crate::mlir_sys::{
mlirDialectHandleGetNamespace, mlirDialectHandleInsertDialect, mlirDialectHandleLoadDialect,
mlirDialectHandleRegisterDialect, mlirGetDialectHandle__async__, mlirGetDialectHandle__cf__,
mlirGetDialectHandle__func__, mlirGetDialectHandle__gpu__, mlirGetDialectHandle__linalg__,
mlirGetDialectHandle__llvm__, mlirGetDialectHandle__pdl__, mlirGetDialectHandle__quant__,
mlirGetDialectHandle__scf__, mlirGetDialectHandle__shape__,
mlirGetDialectHandle__sparse_tensor__, mlirGetDialectHandle__tensor__, MlirDialectHandle,
};
use crate::{context::Context, dialect::Dialect, string_ref::StringRef};
#[derive(Clone, Copy, Debug)]
pub struct Handle {
raw: MlirDialectHandle,
}
impl Handle {
pub fn r#async() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__async__()) }
}
pub fn cf() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__cf__()) }
}
pub fn func() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__func__()) }
}
pub fn gpu() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__gpu__()) }
}
pub fn linalg() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__linalg__()) }
}
pub fn llvm() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__llvm__()) }
}
pub fn pdl() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__pdl__()) }
}
pub fn quant() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__quant__()) }
}
pub fn scf() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__scf__()) }
}
pub fn shape() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__shape__()) }
}
pub fn sparse_tensor() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__sparse_tensor__()) }
}
pub fn tensor() -> Self {
unsafe { Self::from_raw(mlirGetDialectHandle__tensor__()) }
}
pub fn namespace(&self) -> StringRef {
unsafe { StringRef::from_raw(mlirDialectHandleGetNamespace(self.raw)) }
}
pub fn insert_dialect(&self, registry: &Registry) {
unsafe { mlirDialectHandleInsertDialect(self.raw, registry.to_raw()) }
}
pub fn load_dialect<'c>(&self, context: &'c Context) -> Dialect<'c> {
unsafe { Dialect::from_raw(mlirDialectHandleLoadDialect(self.raw, context.to_raw())) }
}
pub fn register_dialect(&self, context: &Context) {
unsafe { mlirDialectHandleRegisterDialect(self.raw, context.to_raw()) }
}
pub(crate) const unsafe fn from_raw(handle: MlirDialectHandle) -> Self {
Self { raw: handle }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn func() {
Handle::func();
}
#[test]
fn llvm() {
Handle::llvm();
}
#[test]
fn namespace() {
Handle::func().namespace();
}
#[test]
fn insert_dialect() {
let registry = Registry::new();
Handle::func().insert_dialect(®istry);
}
#[test]
fn load_dialect() {
let context = Context::new();
Handle::func().load_dialect(&context);
}
#[test]
fn register_dialect() {
let context = Context::new();
Handle::func().register_dialect(&context);
}
}