Commit 4ec19433 authored by Paul's avatar Paul
Browse files

Add mlir dump function

parent 71f9ab23
#ifndef MIGRAPHX_GUARD_RTGLIB_MLIR_HPP
#define MIGRAPHX_GUARD_RTGLIB_MLIR_HPP
#include <string>
#include <migraphx/config.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
struct module;
std::string dump_mlir(const module& m);
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
#include <migraphx/mlir.hpp>
#include <mlir-c/IR.h> #include <mlir-c/IR.h>
#include <mlir-c/BuiltinAttributes.h> #include <mlir-c/BuiltinAttributes.h>
...@@ -99,6 +100,14 @@ void mlir_print(F f, T x, std::ostream& os) ...@@ -99,6 +100,14 @@ void mlir_print(F f, T x, std::ostream& os)
mlir_print(f, x, [&](auto s) { os << s; }); mlir_print(f, x, [&](auto s) { os << s; });
} }
template <class F, class T>
std::string mlir_print(F f, T x)
{
std::stringstream ss;
mlir_print(f, x, [&](auto s) { ss << s; });
return ss.str();
}
struct mlir_program struct mlir_program
{ {
mlir_program() mlir_program()
...@@ -411,5 +420,13 @@ struct mlir_program ...@@ -411,5 +420,13 @@ struct mlir_program
std::deque<std::string> strings{}; std::deque<std::string> strings{};
}; };
std::string dump_mlir(const module& m)
{
mlir_program mp;
mp.parse(m);
auto mod_op = mlirModuleGetOperation(mp.mmodule.get());
return mlir_print(&mlirOperationPrint, mod_op);
}
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx } // namespace migraphx
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment