tvm_tirx/ir/prim.rs
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20//! Primitive expressions. Each node, such as [`Add`] or [`Ramp`], is a [`PrimExpr`] whose `new`
21//! only checks its operand types; the functions of [`op`], which operators such as `&x + 1` call,
22//! also match the operand types and fold constants.
23
24// An object registered under `prim` that no file has a block for yet is generated here, to be moved
25// to the file of the Python module that defines it.
26// tvm-ffi-stubgen(file): mod(missing_docs = allow, prefix = prim)
27// Names the hand-written wrappers use: the import section keeps them even when no generated block
28// does.
29// tvm-ffi-stubgen(import): tvm_ffi::Result
30// tvm-ffi-stubgen(import): crate::ir::expr::PrimExpr
31// tvm-ffi-stubgen(import): crate::ir::expr::IntoExpr
32
33mod const_fold;
34pub mod expr;
35pub mod op;
36pub mod vector_expr;
37
38pub use expr::*;
39pub use op::*;
40pub use vector_expr::*;
41
42// tvm-ffi-stubgen(import): std::borrow::Borrow
43
44// tvm-ffi-stubgen(begin): import-section
45use crate::ir::expr::IntoExpr;
46use crate::ir::expr::PrimExpr;
47use std::borrow::Borrow;
48use tvm_ffi::Result;
49// tvm-ffi-stubgen(end)
50
51/// Return whether `lhs` and `rhs` are the same expression tree, comparing variables by identity;
52/// structural equality also matches distinct variables bound at the same place.
53pub fn expr_deep_equal(lhs: impl IntoExpr<PrimExpr>, rhs: impl IntoExpr<PrimExpr>) -> Result<bool> {
54 tvm_ffi::cached_global_func!("prim.expr_deep_equal")
55 .call_tuple((lhs.into_expr()?.borrow(), rhs.into_expr()?.borrow()))?
56 .try_into()
57}