Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roll optimise() into compile() #339

Merged
merged 13 commits into from
Aug 17, 2023
Merged
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka VERSION 1.0.0 LANGUAGES CXX C)
project(heyoka VERSION 1.1.0 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -293,7 +293,7 @@ if(HEYOKA_WITH_SLEEF)
endif()

# Setup the heyoka ABI version number.
set(HEYOKA_ABI_VERSION 22)
set(HEYOKA_ABI_VERSION 23)

if(HEYOKA_BUILD_STATIC_LIBRARY)
# Setup of the heyoka static library.
Expand Down
1 change: 0 additions & 1 deletion benchmark/large_cfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int main()

add_cfunc<double>(s, "en", {en}, kw::vars = {x, y, z, vx, vy, vz}, kw::compact_mode = true);

s.optimise();
s.compile();

[[maybe_unused]] auto fn = s.jit_lookup("en");
Expand Down
3 changes: 0 additions & 3 deletions benchmark/penc_comparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ void run_benchmark(unsigned order)
// Verify.
s.verify_function(f);

// Run the optimisation pass.
s.optimise();

// Compile.
s.compile();

Expand Down
32 changes: 32 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
Changelog
=========

1.1.0 (unreleased)
------------------

New
~~~

- It is now possible to get the LLVM bitcode of
an ``llvm_state``
(`#339 <https://github.com/bluescarni/heyoka/pull/339>`__).

Changes
~~~~~~~

- The LLVM bitcode is now used internally (instead of the textual
representation of the IR) when copying and serialising
an ``llvm_state``
(`#339 <https://github.com/bluescarni/heyoka/pull/339>`__).
- The optimisation pass in an ``llvm_state`` is now automatically
called during compilation
(`#339 <https://github.com/bluescarni/heyoka/pull/339>`__).

Fix
~~~

- Fix the object file of an ``llvm_state`` not being
preserved during copy and deserialisation
(`#339 <https://github.com/bluescarni/heyoka/pull/339>`__).
- Fix LLVM module name not being preserved during
copy and deserialisation of ``llvm_state``
(`#339 <https://github.com/bluescarni/heyoka/pull/339>`__).
- Fix broken link in the docs.

1.0.0 (2023-08-10)
------------------

Expand Down
31 changes: 18 additions & 13 deletions include/heyoka/llvm_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class HEYOKA_DLL_PUBLIC llvm_state
std::unique_ptr<ir_builder> m_builder;
unsigned m_opt_level;
std::string m_ir_snapshot;
std::string m_bc_snapshot;
bool m_fast_math;
bool m_force_avx512;
std::string m_module_name;
Expand Down Expand Up @@ -210,19 +211,20 @@ class HEYOKA_DLL_PUBLIC llvm_state
// end of a constructor.
HEYOKA_DLL_LOCAL void ctor_setup_math_flags();

public:
llvm_state();
// NOTE: enable the kwargs ctor only if:
// Meta-programming for the kwargs ctor. Enabled if:
// - there is at least 1 argument (i.e., cannot act as a def ctor),
// - if there is only 1 argument, it cannot be of type llvm_state
// (so that it does not interfere with copy/move ctors).
template <typename... KwArgs,
std::enable_if_t<
(sizeof...(KwArgs) > 0u)
&& (sizeof...(KwArgs) > 1u
|| std::conjunction_v<std::negation<std::is_same<detail::uncvref_t<KwArgs>, llvm_state>>...>),
int>
= 0>
template <typename... KwArgs>
using kwargs_ctor_enabler = std::enable_if_t<
(sizeof...(KwArgs) > 0u)
&& (sizeof...(KwArgs) > 1u
|| std::conjunction_v<std::negation<std::is_same<detail::uncvref_t<KwArgs>, llvm_state>>...>),
int>;

public:
llvm_state();
template <typename... KwArgs, kwargs_ctor_enabler<KwArgs...> = 0>
explicit llvm_state(KwArgs &&...kw_args) : llvm_state(kw_args_ctor_impl(std::forward<KwArgs>(kw_args)...))
{
}
Expand All @@ -246,6 +248,7 @@ class HEYOKA_DLL_PUBLIC llvm_state
[[nodiscard]] bool force_avx512() const;

[[nodiscard]] std::string get_ir() const;
[[nodiscard]] std::string get_bc() const;
void dump_object_code(const std::string &) const;
[[nodiscard]] const std::string &get_object_code() const;

Expand All @@ -255,6 +258,7 @@ class HEYOKA_DLL_PUBLIC llvm_state
void optimise();

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

void compile();

Expand All @@ -265,9 +269,10 @@ class HEYOKA_DLL_PUBLIC llvm_state

HEYOKA_END_NAMESPACE

// Current archive version is 2. Changelog:
// Archive version changelog:
// - version 1: got rid of the inline_functions setting;
// - version 2: added the force_avx512 setting.
BOOST_CLASS_VERSION(heyoka::llvm_state, 2)
// - version 2: added the force_avx512 setting;
// - version 3: added the bitcode snapshot.
BOOST_CLASS_VERSION(heyoka::llvm_state, 3)

#endif
2 changes: 1 addition & 1 deletion include/heyoka/taylor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ taylor_c_diff_func_name_args(llvm::LLVMContext &, llvm::Type *, const std::strin
// Add a function for computing the dense output
// via polynomial evaluation.
void taylor_add_d_out_function(llvm_state &, llvm::Type *, std::uint32_t, std::uint32_t, std::uint32_t, bool,
bool = true, bool = true);
bool = true);

} // namespace detail

Expand Down
6 changes: 0 additions & 6 deletions src/detail/event_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,6 @@ taylor_adaptive<T>::ed_data::ed_data(llvm_state s, std::vector<t_event_t> tes, s
// Add the function for the fast exclusion check.
detail::llvm_add_fex_check(m_state, fp_t, order, 1);

// Run the optimisation pass.
m_state.optimise();

// Compile.
m_state.compile();

Expand Down Expand Up @@ -1548,9 +1545,6 @@ taylor_adaptive_batch<T>::ed_data::ed_data(llvm_state s, std::vector<t_event_t>
// NOTE: the fast exclusion check is vectorised.
detail::llvm_add_fex_check(m_state, fp_t, order, batch_size);

// Run the optimisation pass.
m_state.optimise();

// Compile.
m_state.compile();

Expand Down
2 changes: 1 addition & 1 deletion src/detail/llvm_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ std::string llvm_type_name(llvm::Type *t)

t->print(ostr, false, true);

return ostr.str();
return std::move(ostr.str());
}

// This function will return true if:
Expand Down
3 changes: 0 additions & 3 deletions src/expression_cfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1722,9 +1722,6 @@ auto add_cfunc_impl(llvm_state &s, const std::string &name, const F &fn, std::ui
// Restore the original insertion block.
builder.SetInsertPoint(orig_bb);

// Run the optimisation pass.
s.optimise();

return dc;
}

Expand Down
Loading
Loading