spicy icon indicating copy to clipboard operation
spicy copied to clipboard

Optimize JIT code

Open bbannier opened this issue 4 years ago • 6 comments

Currently we compile individual C++ units with -O3 when JITing in non-debug mode, we don't however apply any cross-module optimizations after linking them all together. We should add that when the optimize flag is set.

We should probably also make the -O3 dependent on the optimize flag as well and/or join the debug/optimize flag into one.

bbannier avatar Apr 06 '20 12:04 bbannier

mentioned in merge request !13

bbannier avatar Apr 06 '20 12:04 bbannier

The first part of this is done: after linking all the modules together, we run a set of standard optimization passed on the joined module. Not sure if it's the right choice of passes, but should be good for now.

Still need to make the -O3 dependent on the optimize flag.

bbannier avatar Apr 06 '20 12:04 bbannier

The -O3 gets into runtime_cxx_flags_release in build/hilti/src/autogen/config.cc, which is auto-generated by cmake. Need to get it out of there, and then re-add during JIT if optimization is requested.

bbannier avatar Apr 06 '20 12:04 bbannier

To then add -O3, ClangJIT::Implementation::compile() can check options().optimize.

bbannier avatar Apr 06 '20 12:04 bbannier

We currently allow both --optimize and --debug and it seems to make sense to support debugging optimized code as well. If we should want to support that we would need to

  • add --optimize flags to hilti-config and spicy-config to trigger inclusion of flags related to optimization
  • break current *_DEBUG and *_RELEASE flags of spicy and hilti into plain flags like (e.g., a HILTI_CONFIG_RUNTIME_CXX_FLAGS for -std=c++17 ${add_cxx_flags} ${CXXFLAGS}), flags related to optimization (e.g., -O3), flags related to debugging (e.g., -g), and flags related to optimized && !debug like -DNDEBUG. We should do this for both LDFLAGS and CXXFLAGS.

Alternatively, we could make it illegal to combine --optimize with --debug and largely reuse the existing infrastructure until further notice.

What would be the preferred approach here?

bbannier avatar Apr 06 '20 12:04 bbannier

Let's just split the -O3 out for now, and have --optimize put it back in. It's primarily to control that independently. We'll see if need to do more / something different later, I'm not quite sure yet what's the right approach here (--optimize will eventually perform HILTI-level optimizations, too; and maybe that's really it's main task).

Right now the main alternative would be just removing the --optimize flag altogether, but I figured making it trigger -O3 shouldn't be too difficult to give it some meaning.

bbannier avatar Apr 06 '20 12:04 bbannier