pass.hpp 1.62 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPHX_GUARD_PASS_HPP
#define MIGRAPHX_GUARD_PASS_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <cassert>
Paul's avatar
Paul committed
5
6
7
8
#include <string>
#include <memory>
#include <type_traits>
#include <utility>
9
#include <migraphx/functional.hpp>
Paul's avatar
Paul committed
10
#include <migraphx/config.hpp>
11
#include <migraphx/rank.hpp>
Paul's avatar
Paul committed
12

Paul's avatar
Paul committed
13
namespace migraphx {
Paul's avatar
Paul committed
14
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
15
16

struct program;
Shucai Xiao's avatar
Shucai Xiao committed
17
struct module;
18
struct module_pass_manager;
Paul's avatar
Paul committed
19

Paul's avatar
Paul committed
20
21
#ifdef DOXYGEN

Paul's avatar
Paul committed
22
23
/// An interface for applying a transformation to the instructions in a
/// `program`
Paul's avatar
Paul committed
24
25
26
27
struct pass
{
    /// A unique name used to identify the pass
    std::string name() const;
28
    /// Run the pass on the module
29
    void apply(module_pass_manager& mpm) const;
30
    void apply(module& m) const;
Paul's avatar
Paul committed
31
    /// Run the pass on the program
32
    void apply(program& p) const;
Paul's avatar
Paul committed
33
34
35
36
};

#else

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
61
62
63
<%
interface('pass',
    virtual('name', returns='std::string', const=True),
64
    virtual('apply', returns='void', mpm='module_pass_manager &', const=True, default='migraphx::detail::module_pass_manager_apply'),
65
    virtual('apply', returns='void', p='program &', const=True, default='migraphx::nop')
Paul's avatar
Paul committed
66
67
68
)
%>

Paul's avatar
Paul committed
69
70
#endif

Paul's avatar
Paul committed
71
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
72
} // namespace migraphx
Paul's avatar
Paul committed
73
74

#endif