pass_manager.cpp 1.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <migraphx/program.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/target.hpp>
#include <migraphx/env.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/time.hpp>
#include <migraphx/iterator_for.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <utility>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

18
void run_passes(module& modl, const std::vector<pass>& passes, tracer trace)
19
{
20
    for(const auto& p : passes)
21
22
    {
        trace("Pass: ", p.name());
23
24
        p.apply(modl);
        trace(modl);
25
26
27

#ifndef NDEBUG
        trace("Validate ...");
28
29
        auto invalid = modl.validate();
        if(invalid != modl.end())
30
        {
31
            auto index = std::distance(modl.begin(), invalid);
32
33
34
35
36
37
38
39
40
41
            MIGRAPHX_THROW(p.name() + " pass produces invalid program at instruction " +
                           std::to_string(index) + ": " + invalid->name());
        }
        trace();
#endif
    }
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx