Skip to content

Commit

Permalink
Add another getter, stream operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Aug 3, 2024
1 parent 788d387 commit c582677
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/heyoka/llvm_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ HEYOKA_DLL_PUBLIC const target_features &get_target_features();
} // namespace detail

HEYOKA_DLL_PUBLIC std::ostream &operator<<(std::ostream &, const llvm_state &);
HEYOKA_DLL_PUBLIC std::ostream &operator<<(std::ostream &, const llvm_multi_state &);

template <typename T>
inline std::uint32_t recommended_simd_size()
Expand Down Expand Up @@ -133,6 +134,7 @@ HEYOKA_BEGIN_NAMESPACE
class HEYOKA_DLL_PUBLIC llvm_state
{
friend HEYOKA_DLL_PUBLIC std::ostream &operator<<(std::ostream &, const llvm_state &);
friend HEYOKA_DLL_PUBLIC std::ostream &operator<<(std::ostream &, const llvm_multi_state &);
friend class HEYOKA_DLL_PUBLIC llvm_multi_state;

struct jit;
Expand Down Expand Up @@ -352,6 +354,8 @@ void llvm_state_mem_cache_try_insert(std::vector<std::string>, unsigned, llvm_mc

class HEYOKA_DLL_PUBLIC llvm_multi_state
{
friend HEYOKA_DLL_PUBLIC std::ostream &operator<<(std::ostream &, const llvm_multi_state &);

struct impl;

std::unique_ptr<impl> m_impl;
Expand Down Expand Up @@ -379,6 +383,8 @@ class HEYOKA_DLL_PUBLIC llvm_multi_state

[[nodiscard]] bool is_compiled() const noexcept;

[[nodiscard]] unsigned get_n_modules() const noexcept;

[[nodiscard]] bool fast_math() const noexcept;
[[nodiscard]] bool force_avx512() const noexcept;
[[nodiscard]] unsigned get_opt_level() const noexcept;
Expand Down
26 changes: 26 additions & 0 deletions src/llvm_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,11 @@ void llvm_multi_state::check_uncompiled(const char *f) const
}
}

unsigned llvm_multi_state::get_n_modules() const noexcept
{
return m_impl->m_jit->m_n_modules;
}

unsigned llvm_multi_state::get_opt_level() const noexcept
{
return m_impl->m_states[0].get_opt_level();
Expand Down Expand Up @@ -2354,4 +2359,25 @@ std::uintptr_t llvm_multi_state::jit_lookup(const std::string &name)
#endif
}

std::ostream &operator<<(std::ostream &os, const llvm_multi_state &s)
{
std::ostringstream oss;
oss << std::boolalpha;

oss << "N of modules : " << s.get_n_modules() << '\n';
oss << "Compiled : " << s.is_compiled() << '\n';
oss << "Fast math : " << s.fast_math() << '\n';
oss << "Force AVX512 : " << s.force_avx512() << '\n';
oss << "SLP vectorization : " << s.get_slp_vectorize() << '\n';
oss << "Code model : " << s.get_code_model() << '\n';
oss << "Optimisation level: " << s.get_opt_level() << '\n';
oss << "Data layout : " << s.m_impl->m_states[0].m_jitter->m_lljit->getDataLayout().getStringRepresentation()
<< '\n';
oss << "Target triple : " << s.m_impl->m_states[0].m_jitter->get_target_triple().str() << '\n';
oss << "Target CPU : " << s.m_impl->m_states[0].m_jitter->get_target_cpu() << '\n';
oss << "Target features : " << s.m_impl->m_states[0].m_jitter->get_target_features() << '\n';

return os << oss.str();
}

HEYOKA_END_NAMESPACE
25 changes: 25 additions & 0 deletions test/llvm_multi_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ TEST_CASE("basic")
REQUIRE(ms.force_avx512());
REQUIRE(ms.get_slp_vectorize());
REQUIRE(ms.get_code_model() == code_model::large);
REQUIRE(ms.get_n_modules() == 5u);

REQUIRE(!ms.is_compiled());

Expand All @@ -89,6 +90,7 @@ TEST_CASE("basic")
REQUIRE(ms.force_avx512());
REQUIRE(ms.get_slp_vectorize());
REQUIRE(ms.get_code_model() == code_model::large);
REQUIRE(ms.get_n_modules() == 5u);
}
}

Expand Down Expand Up @@ -340,3 +342,26 @@ TEST_CASE("cfunc")
REQUIRE(outs[0] == 6);
REQUIRE(outs[1] == 2. / 3.);
}

TEST_CASE("stream op")
{
auto [x, y] = make_vars("x", "y");

llvm_state s1{kw::mname = "module_0"}, s2{kw::mname = "module_1"};

add_cfunc<double>(s1, "f1", {x * y}, {x, y}, kw::compact_mode = true);
add_cfunc<double>(s2, "f2", {x / y}, {x, y}, kw::compact_mode = true);

const auto orig_ir1 = s1.get_ir();
const auto orig_ir2 = s2.get_ir();

const auto orig_bc1 = s1.get_bc();
const auto orig_bc2 = s2.get_bc();

llvm_multi_state ms{{s1, s2}};

std::ostringstream oss;
oss << ms;

REQUIRE(!oss.str().empty());
}

0 comments on commit c582677

Please sign in to comment.