pass.hpp 2.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
Paul's avatar
Paul committed
24
25
#ifndef MIGRAPHX_GUARD_PASS_HPP
#define MIGRAPHX_GUARD_PASS_HPP
Paul's avatar
Paul committed
26

Paul's avatar
Paul committed
27
#include <cassert>
Paul's avatar
Paul committed
28
29
30
31
#include <string>
#include <memory>
#include <type_traits>
#include <utility>
32
#include <migraphx/functional.hpp>
Paul's avatar
Paul committed
33
#include <migraphx/config.hpp>
34
#include <migraphx/rank.hpp>
Paul's avatar
Paul committed
35

Paul's avatar
Paul committed
36
namespace migraphx {
Paul's avatar
Paul committed
37
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
38
39

struct program;
Shucai Xiao's avatar
Shucai Xiao committed
40
struct module;
41
struct module_pass_manager;
Paul's avatar
Paul committed
42

Paul's avatar
Paul committed
43
44
#ifdef DOXYGEN

Paul's avatar
Paul committed
45
46
/// An interface for applying a transformation to the instructions in a
/// `program`
Paul's avatar
Paul committed
47
48
49
50
struct pass
{
    /// A unique name used to identify the pass
    std::string name() const;
51
    /// Run the pass on the module
52
    void apply(module_pass_manager& mpm) const;
53
    void apply(module& m) const;
Paul's avatar
Paul committed
54
    /// Run the pass on the program
55
    void apply(program& p) const;
Paul's avatar
Paul committed
56
57
58
59
};

#else

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module& get_module(module_pass_manager& mpm);

namespace detail {

template <class T>
auto module_pass_manager_apply(rank<1>, const T& x, module_pass_manager& mpm)
    -> decltype(x.apply(get_module(mpm)))
{
    return x.apply(get_module(mpm));
}

template <class T>
void module_pass_manager_apply(rank<0>, const T&, module_pass_manager&)
{
}

template <class T>
void module_pass_manager_apply(const T& x, module_pass_manager& mpm)
{
    module_pass_manager_apply(rank<1>{}, x, mpm);
}

} // namespace detail

Paul's avatar
Paul committed
84
85
86
<%
interface('pass',
    virtual('name', returns='std::string', const=True),
87
    virtual('apply', returns='void', mpm='module_pass_manager &', const=True, default='migraphx::detail::module_pass_manager_apply'),
88
    virtual('apply', returns='void', p='program &', const=True, default='migraphx::nop')
Paul's avatar
Paul committed
89
90
91
)
%>

Paul's avatar
Paul committed
92
93
#endif

Paul's avatar
Paul committed
94
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
95
} // namespace migraphx
Paul's avatar
Paul committed
96
97

#endif