Optimize JIT code
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.
mentioned in merge request !13
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.
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.
To then add -O3, ClangJIT::Implementation::compile() can check options().optimize.
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
--optimizeflags tohilti-configandspicy-configto trigger inclusion of flags related to optimization - break current
*_DEBUGand*_RELEASEflags of spicy and hilti into plain flags like (e.g., aHILTI_CONFIG_RUNTIME_CXX_FLAGSfor-std=c++17 ${add_cxx_flags} ${CXXFLAGS}), flags related to optimization (e.g.,-O3), flags related to debugging (e.g.,-g), and flags related tooptimized && !debuglike-DNDEBUG. We should do this for bothLDFLAGSandCXXFLAGS.
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?
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.