1/*******************************************************************************
2* Copyright 2022 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef GPU_JIT_PASS_SIMPLIFY_HPP
18#define GPU_JIT_PASS_SIMPLIFY_HPP
19
20#include "gpu/jit/ir/ir.hpp"
21
22namespace dnnl {
23namespace impl {
24namespace gpu {
25namespace jit {
26
27// Determine the maximum constant factor of an expression, returns 0 in the
28// special case that the expression evaluates to 0.
29int64_t get_max_const_factor(const expr_t &e, const constraint_set_t &cset);
30
31// Simplifies expression using rewriting rules.
32expr_t simplify_rewrite(const expr_t &e);
33
34// Simplifies expression or statement. An optional constraint set is used to
35// pass known equalities and inequalities which may be used for simplification.
36object_t simplify(const object_t &obj, const constraint_set_t &cset = {});
37
38// Searches for expression patterns to reduce them to the equivalent ternary
39// operations.
40expr_t simplify_rewrite_with_ternary(const expr_t &e, bool recursive = true);
41
42// Moves constants to the right hand side of an expression.
43// Example: (c0 + x) op c1 -> x op (c1 - c0)
44expr_t simplify_cmp_move_const_to_rhs(const expr_t &e);
45
46// Reduces left and right hand sides of an expression.
47// Example: A * x < A * B -> x < B (if A > 0).
48expr_t simplify_cmp_reduce_lhs_rhs(const expr_t &e);
49
50// Propagates shuffle down the expression tree for more effective vectorization.
51expr_t simplify_propagate_shuffle(const expr_t &e);
52
53stmt_t simplify(const stmt_t &s, ir_context_t &ir_ctx);
54
55} // namespace jit
56} // namespace gpu
57} // namespace impl
58} // namespace dnnl
59
60#endif
61