KhronosGroup / SPIRV-Tools

Apache License 2.0
1.09k stars 555 forks source link

Reducing build size #4351

Closed mgood7123 closed 1 year ago

mgood7123 commented 3 years ago

how can i reduce my build size?

as i currently require ~850 to ~930 MB to cross-compile SPIRV-Tools for each architecture leading to me quickly running out of build space as the total build directory is ~1GB per full build with ~400 MB without SPIRV-Tools

any ideas on how i can reduce the total space needed to build?

i am building via CMake as a sub project in originating from https://github.com/DiligentGraphics/DiligentCore/blob/20d5d7d2866e831a73437db2dec16bdc61413eb0/ThirdParty/CMakeLists.txt#L33

https://github.com/DiligentGraphics/DiligentCore IS NOT owned by me however i would like to support Vulkan shader compilation for Android

dneto0 commented 3 years ago

I looked at that CMakeLists.txt and it's already doing the obvious things: turning off building of tests and executables.

Right now a build of SPIRV-Tools builds core things, plus

You may not need any of the last four things. I don't think there are CMake options to disable building them. But in the meantime, you could delete those outputs as soon as they are built.

The "core" functionality includes the assembler, disassembler, and binary parsing.

mgood7123 commented 3 years ago

the main build size is from the optimizer which on my machine builds at

1.4G    total
720M    SPIRV-Tools/source/opt/libSPIRV-Tools-opt.a
702M    SPIRV-Tools/source/opt/CMakeFiles
4.0K    SPIRV-Tools/source/opt/cmake_install.cmake
4.0K    SPIRV-Tools/source/opt/CTestTestfile.cmake
702M    total
 14M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/folding_rules.cpp.o
 13M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/const_folding_rules.cpp.o
 11M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/optimizer.cpp.o
 11M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_utils.cpp.o
 11M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_unswitch_pass.cpp.o
 11M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_peeling.cpp.o
 11M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/aggressive_dead_code_elim_pass.cpp.o
 10M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/merge_return_pass.cpp.o
 10M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/ir_context.cpp.o
9.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_fusion.cpp.o
9.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/cfg.cpp.o
9.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/upgrade_memory_model.cpp.o
9.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/instrument_pass.cpp.o
9.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_descriptor.cpp.o
9.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inline_pass.cpp.o
9.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/dominator_tree.cpp.o
9.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/mem_pass.cpp.o
9.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_fission.cpp.o
8.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/register_pressure.cpp.o
8.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/dead_branch_elim_pass.cpp.o
8.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/scalar_replacement_pass.cpp.o
8.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_unroller.cpp.o
8.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/convert_to_half_pass.cpp.o
8.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/propagator.cpp.o
8.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/ssa_rewrite_pass.cpp.o
8.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inst_bindless_check_pass.cpp.o
8.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/basic_block.cpp.o
8.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/instruction.cpp.o
7.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/desc_sroa.cpp.o
7.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/amd_ext_to_khr.cpp.o
7.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/if_conversion.cpp.o
7.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/eliminate_dead_members_pass.cpp.o
7.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/scalar_analysis.cpp.o
7.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/copy_prop_arrays.cpp.o
7.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/type_manager.cpp.o
7.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/ccp_pass.cpp.o
7.4M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/code_sink.cpp.o
7.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/vector_dce.cpp.o
7.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/local_access_chain_convert_pass.cpp.o
7.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/debug_info_manager.cpp.o
7.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/simplification_pass.cpp.o
7.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/private_to_local_pass.cpp.o
7.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/combine_access_chains.cpp.o
7.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/wrap_opkill.cpp.o
7.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inst_debug_printf_pass.cpp.o
7.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inst_buff_addr_check_pass.cpp.o
7.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/reduce_load_size.cpp.o
7.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/local_single_store_elim_pass.cpp.o
7.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/block_merge_util.cpp.o
6.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_dependence.cpp.o
6.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/graphics_robust_access_pass.cpp.o
6.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/constants.cpp.o
6.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/struct_cfg_analysis.cpp.o
6.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/function.cpp.o
6.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/fix_storage_class.cpp.o
6.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/decoration_manager.cpp.o
6.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/build_module.cpp.o
6.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/dead_insert_elim_pass.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/set_spec_constant_default_value_pass.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/pass.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/module.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/local_single_block_elim_pass.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/fold_spec_constant_op_and_composite_pass.cpp.o
6.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/fold.cpp.o
6.4M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/interp_fixup_pass.cpp.o
6.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/value_number_table.cpp.o
6.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/remove_duplicates_pass.cpp.o
6.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_dependence_helpers.cpp.o
6.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/relax_float_ops_pass.cpp.o
6.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inline_opaque_pass.cpp.o
6.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/replace_invalid_opc.cpp.o
6.0M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/dead_variable_elimination.cpp.o
5.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/workaround1209.cpp.o
5.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/local_redundancy_elimination.cpp.o
5.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/licm_pass.cpp.o
5.9M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/eliminate_dead_constant_pass.cpp.o
5.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/strip_debug_info_pass.cpp.o
5.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/strength_reduction_pass.cpp.o
5.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/eliminate_dead_functions_util.cpp.o
5.8M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/dominator_analysis.cpp.o
5.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/unify_const_pass.cpp.o
5.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/flatten_decoration_pass.cpp.o
5.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/strip_reflect_info_pass.cpp.o
5.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/inline_exhaustive_pass.cpp.o
5.6M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/eliminate_dead_functions_pass.cpp.o
5.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/redundancy_elimination.cpp.o
5.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/loop_fusion_pass.cpp.o
5.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/compact_ids_pass.cpp.o
5.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/pass_manager.cpp.o
5.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/freeze_spec_constant_value_pass.cpp.o
5.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/cfg_cleanup_pass.cpp.o
5.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/block_merge_pass.cpp.o
5.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/composite.cpp.o
2.5M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/def_use_manager.cpp.o
2.3M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/types.cpp.o
1.7M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/scalar_analysis_simplification.cpp.o
1.2M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/ir_loader.cpp.o
1.1M    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/feature_manager.cpp.o
360K    SPIRV-Tools/source/opt/CMakeFiles/SPIRV-Tools-opt.dir/instruction_list.cpp.o
s-perron commented 1 year ago

I don't know how this changed over time, but I currently see libSPIRV-Tools-opt.a at 8.3M using the latest source and building the release version on linux. The size goes up to 205M for a debug build.

If this is still a problem please provide the platform and compiler you are using.