tvm_tirx/
sym.rs

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
#![allow(dead_code, unused_imports)]

//! Symbolic analysis of integer expressions.
//!
//! Laid out like `python/tvm_tirx/sym/`: [`analyzer`] holds the analyzer and its results,
//! [`int_set`] the integer sets, and [`iter_affine_map`] the iterator maps. The analyses run
//! through the native `sym.*` functions.

// An object registered under `sym` that no file has a block for yet is generated here, to be moved
// to the file of the Python module that defines it.
// tvm-ffi-stubgen(prefix): sym

pub mod analyzer;
pub mod int_set;
pub mod iter_affine_map;

pub use analyzer::*;
pub use int_set::*;
pub use iter_affine_map::*;

// tvm-ffi-stubgen(begin): import-section
use crate::ir::expr::Expr;
use crate::ir::expr::Range;
use crate::ir::expr::Var;
use std::ops::Deref;
use std::ptr::addr_of_mut;
use tvm_ffi::Object;
use tvm_ffi::ObjectArc;
use tvm_ffi::ShallowCopy;
use tvm_ffi::UnsafeInit;
// tvm-ffi-stubgen(end)

// tvm-ffi-stubgen(begin): object/sym.Constraint
/// Complete: reflected fields fill [24, 24) exactly.
#[repr(C)]
#[derive(tvm_ffi::derive::Object)]
#[type_key = "sym.Constraint"]
pub struct ConstraintObj {
    base: Object,
}

const _: () = {
    assert!(::core::mem::size_of::<ConstraintObj>() == 24);
    assert!(::core::mem::align_of::<ConstraintObj>() == 8);
};

#[repr(C)]
#[derive(tvm_ffi::derive::ObjectRef, Clone)]
pub struct Constraint {
    base: ObjectArc<ConstraintObj>,
}

impl Deref for Constraint {
    type Target = ConstraintObj;
    fn deref(&self) -> &ConstraintObj {
        &self.base
    }
}

impl ConstraintObj {
    pub fn new() -> Self {
        let base = Object::new();
        Self { base }
    }
}

impl Constraint {
    /// Lossless complete-field allocation.
    pub fn new() -> Self {
        let obj = ConstraintObj::new();
        Self { base: ObjectArc::new(obj) }
    }
}

impl ShallowCopy for ConstraintObj {
    fn shallow_copy(&self) -> Self {
        Self { base: ShallowCopy::shallow_copy(&self.base) }
    }
}

unsafe impl UnsafeInit for ConstraintObj {
    unsafe fn drop_defined_fields(this: *mut Self) {
        unsafe {
            UnsafeInit::drop_defined_fields(addr_of_mut!((*this).base));
        }
    }
}
// tvm-ffi-stubgen(end)

// tvm-ffi-stubgen(begin): object/sym.BindingConstraint
/// Complete: reflected fields fill [24, 40) exactly.
#[repr(C)]
#[derive(tvm_ffi::derive::Object)]
#[type_key = "sym.BindingConstraint"]
#[type_final]
pub struct BindingConstraintObj {
    base: ConstraintObj,
    pub var: Var,
    pub value: Expr,
}

const _: () = {
    assert!(::core::mem::size_of::<BindingConstraintObj>() == 40);
    assert!(::core::mem::align_of::<BindingConstraintObj>() == 8);
};

#[repr(C)]
#[derive(tvm_ffi::derive::ObjectRef, Clone)]
pub struct BindingConstraint {
    base: ObjectArc<BindingConstraintObj>,
}

impl Deref for BindingConstraint {
    type Target = BindingConstraintObj;
    fn deref(&self) -> &BindingConstraintObj {
        &self.base
    }
}

impl Deref for BindingConstraintObj {
    type Target = ConstraintObj;
    fn deref(&self) -> &ConstraintObj {
        &self.base
    }
}

impl BindingConstraintObj {
    pub(crate) fn new(var: Var, value: Expr) -> Self {
        let base = ConstraintObj::new();
        Self { base, var, value }
    }
}

impl BindingConstraint {
    /// Lossless complete-field allocation.
    pub fn new(var: impl Into<Var>, value: impl Into<Expr>) -> Self {
        let obj = BindingConstraintObj::new(var.into(), value.into());
        Self { base: ObjectArc::new(obj) }
    }
}

tvm_ffi::impl_object_upcast!(BindingConstraint => Constraint);
// tvm-ffi-stubgen(end)

// tvm-ffi-stubgen(begin): object/sym.ConstraintContext
/// Opaque: bytes [24, 48) of [24, 48) are not accounted for by reflected fields. Fields are read through the C ABI getters.
#[repr(C)]
#[derive(tvm_ffi::derive::Object)]
#[type_key = "sym.ConstraintContext"]
#[type_final]
pub struct ConstraintContextObj {
    base: Object,
}

#[repr(C)]
#[derive(tvm_ffi::derive::ObjectRef, Clone)]
pub struct ConstraintContext {
    base: ObjectArc<ConstraintContextObj>,
}

impl Deref for ConstraintContext {
    type Target = ConstraintContextObj;
    fn deref(&self) -> &ConstraintContextObj {
        &self.base
    }
}
// tvm-ffi-stubgen(end)

// tvm-ffi-stubgen(begin): object/sym.PredicateConstraint
/// Complete: reflected fields fill [24, 40) exactly (alignment padding [33, 40)).
#[repr(C)]
#[derive(tvm_ffi::derive::Object)]
#[type_key = "sym.PredicateConstraint"]
#[type_final]
pub struct PredicateConstraintObj {
    base: ConstraintObj,
    pub condition: Expr,
    pub assume_always: bool,
}

const _: () = {
    assert!(::core::mem::size_of::<PredicateConstraintObj>() == 40);
    assert!(::core::mem::align_of::<PredicateConstraintObj>() == 8);
};

#[repr(C)]
#[derive(tvm_ffi::derive::ObjectRef, Clone)]
pub struct PredicateConstraint {
    base: ObjectArc<PredicateConstraintObj>,
}

impl Deref for PredicateConstraint {
    type Target = PredicateConstraintObj;
    fn deref(&self) -> &PredicateConstraintObj {
        &self.base
    }
}

impl Deref for PredicateConstraintObj {
    type Target = ConstraintObj;
    fn deref(&self) -> &ConstraintObj {
        &self.base
    }
}

impl PredicateConstraintObj {
    pub(crate) fn new(condition: Expr, assume_always: bool) -> Self {
        let base = ConstraintObj::new();
        Self { base, condition, assume_always }
    }
}

impl PredicateConstraint {
    /// Lossless complete-field allocation.
    pub fn new(condition: impl Into<Expr>, assume_always: bool) -> Self {
        let obj = PredicateConstraintObj::new(condition.into(), assume_always);
        Self { base: ObjectArc::new(obj) }
    }
}

tvm_ffi::impl_object_upcast!(PredicateConstraint => Constraint);
// tvm-ffi-stubgen(end)

// tvm-ffi-stubgen(begin): object/sym.RangeConstraint
/// Complete: reflected fields fill [24, 40) exactly.
#[repr(C)]
#[derive(tvm_ffi::derive::Object)]
#[type_key = "sym.RangeConstraint"]
#[type_final]
pub struct RangeConstraintObj {
    base: ConstraintObj,
    pub var: Var,
    pub range: Range,
}

const _: () = {
    assert!(::core::mem::size_of::<RangeConstraintObj>() == 40);
    assert!(::core::mem::align_of::<RangeConstraintObj>() == 8);
};

#[repr(C)]
#[derive(tvm_ffi::derive::ObjectRef, Clone)]
pub struct RangeConstraint {
    base: ObjectArc<RangeConstraintObj>,
}

impl Deref for RangeConstraint {
    type Target = RangeConstraintObj;
    fn deref(&self) -> &RangeConstraintObj {
        &self.base
    }
}

impl Deref for RangeConstraintObj {
    type Target = ConstraintObj;
    fn deref(&self) -> &ConstraintObj {
        &self.base
    }
}

impl RangeConstraintObj {
    pub(crate) fn new(var: Var, range: Range) -> Self {
        let base = ConstraintObj::new();
        Self { base, var, range }
    }
}

impl RangeConstraint {
    /// Lossless complete-field allocation.
    pub fn new(var: impl Into<Var>, range: impl Into<Range>) -> Self {
        let obj = RangeConstraintObj::new(var.into(), range.into());
        Self { base: ObjectArc::new(obj) }
    }
}

tvm_ffi::impl_object_upcast!(RangeConstraint => Constraint);
// tvm-ffi-stubgen(end)