Support `IREE_SIZE_OPTIMIZED` cmake flag on clang/gcc.
The flag currently only controls the compiler options for MSVC/clang-cl: https://github.com/iree-org/iree/blob/7df397317736788046e02e5d8e821c498d7266da/build_tools/cmake/iree_copts.cmake#L371
If anyone wants to use this flag to get smaller sample binaries directly out of the IREE repo we'd want to have clang/gcc/ld flags that do the stuff the MSVC ones are (optimize for size, enable LTO, aggressive dead code stripping, etc).
The remaining flags set in there are controlling runtime C code and apply universally.
I had a quick lock at the compiler options passed to MSVC/clang-cl which raised a question:
Should we really set /Os explicitly here or should this rather be controlled by the CMAKE_BUILD_TYPE? Or should we even set the (default) build type to MinSizeRel if IREE_SIZE_OPTIMIZED?
https://github.com/iree-org/iree/blob/2dbe84183ac5c9b9de96faf46453bc20cb07914b/CMakeLists.txt#L30
The IREE_SIZE_OPTIMIZED is saying "build IREE in a size-optimized configuration" - since IREE is a library we want to be able to control this independently of global build configuration - that way a user can build their application in whatever mode they want but IREE in a different one.
IMO we should never be changing the build type ourselves and don't want to make what we have more complex. I wish we didn't have that line :)
(sorry, incomplete thought) enabling IREE_SIZE_OPTIMIZED if in MinSizeRel would make sense if it didn't also aggressively disable things like status messages and such - IREE_SIZE_OPTIMIZED is like an extreme MinSizeRel that has a lot of tradeoffs we don't always want to make.
I started to look for equivalent options, resulting in a need for discussion:
Regarding the equivalent to /GL, we could pass -fwhole-program to GCC, see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html. However, -fwhole-program should not be used in combination with -flto. The latter only makes sense when used togesther with -fuse-linker-plugin.
Furthermore, with view to clang, is there a preference for a specific LTO type? E.g. ThinLTO requires to use an appropriate linker: https://clang.llvm.org/docs/ThinLTO.html#linkers