#include "dsl/ir/pass/trace.hpp"
#include "dsl/ir/ir.hpp"
#include "dsl/utils/logging.hpp"
#include "dsl/utils/profiler.hpp"
GEMMSTONE_NAMESPACE_START
namespace dsl {
namespace ir {
#if GEMMSTONE_ASSERTIONS
profiler_t *get_trace_profiler() {
static thread_local auto profiler = getVerbose(GEMMVerbose::DebugInfo)
>= static_cast<int>(log_level_t::perf)
? std::unique_ptr<profiler_t>(new profiler_t("Trace Profile"))
: std::unique_ptr<profiler_t>(nullptr);
return profiler.get();
}
void trace_start() {
if (get_trace_profiler()) get_trace_profiler()->start();
}
void trace_reset() {
if (get_trace_profiler()) get_trace_profiler()->reset();
}
void trace_stamp(const char *pass_name) {
if (get_trace_profiler()) get_trace_profiler()->stamp(pass_name);
}
void trace_stop(const char *pass_name) {
if (get_trace_profiler()) get_trace_profiler()->stop(pass_name);
}
void trace_perf() {
dsl_perf() << get_trace_profiler();
}
void trace_pass(
const char *pass_name, const stmt_t &stmt, const ir_context_t &ir_ctx) {
trace_stop(pass_name);
dsl_trace() << "=== After " << pass_name << "\n" << stmt;
dsl_trace() << ir_ctx.cset();
}
#endif
} } GEMMSTONE_NAMESPACE_END