1LOCAL_PATH := $(call my-dir) 2SPVTOOLS_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT),$(abspath $(TARGET_OUT))) 3 4ifeq ($(SPVHEADERS_LOCAL_PATH),) 5 SPVHEADERS_LOCAL_PATH := $(LOCAL_PATH)/external/spirv-headers 6endif 7 8SPVTOOLS_SRC_FILES := \ 9 source/assembly_grammar.cpp \ 10 source/binary.cpp \ 11 source/diagnostic.cpp \ 12 source/disassemble.cpp \ 13 source/ext_inst.cpp \ 14 source/enum_string_mapping.cpp \ 15 source/extensions.cpp \ 16 source/libspirv.cpp \ 17 source/name_mapper.cpp \ 18 source/opcode.cpp \ 19 source/operand.cpp \ 20 source/parsed_operand.cpp \ 21 source/print.cpp \ 22 source/software_version.cpp \ 23 source/spirv_endian.cpp \ 24 source/spirv_optimizer_options.cpp \ 25 source/spirv_target_env.cpp \ 26 source/spirv_validator_options.cpp \ 27 source/table.cpp \ 28 source/text.cpp \ 29 source/text_handler.cpp \ 30 source/util/bit_vector.cpp \ 31 source/util/parse_number.cpp \ 32 source/util/string_utils.cpp \ 33 source/util/timer.cpp \ 34 source/val/basic_block.cpp \ 35 source/val/construct.cpp \ 36 source/val/function.cpp \ 37 source/val/instruction.cpp \ 38 source/val/validation_state.cpp \ 39 source/val/validate.cpp \ 40 source/val/validate_adjacency.cpp \ 41 source/val/validate_annotation.cpp \ 42 source/val/validate_arithmetics.cpp \ 43 source/val/validate_atomics.cpp \ 44 source/val/validate_barriers.cpp \ 45 source/val/validate_bitwise.cpp \ 46 source/val/validate_builtins.cpp \ 47 source/val/validate_capability.cpp \ 48 source/val/validate_cfg.cpp \ 49 source/val/validate_composites.cpp \ 50 source/val/validate_constants.cpp \ 51 source/val/validate_conversion.cpp \ 52 source/val/validate_debug.cpp \ 53 source/val/validate_decorations.cpp \ 54 source/val/validate_derivatives.cpp \ 55 source/val/validate_extensions.cpp \ 56 source/val/validate_execution_limitations.cpp \ 57 source/val/validate_function.cpp \ 58 source/val/validate_id.cpp \ 59 source/val/validate_image.cpp \ 60 source/val/validate_interfaces.cpp \ 61 source/val/validate_instruction.cpp \ 62 source/val/validate_memory.cpp \ 63 source/val/validate_memory_semantics.cpp \ 64 source/val/validate_misc.cpp \ 65 source/val/validate_mode_setting.cpp \ 66 source/val/validate_layout.cpp \ 67 source/val/validate_literals.cpp \ 68 source/val/validate_logicals.cpp \ 69 source/val/validate_non_uniform.cpp \ 70 source/val/validate_primitives.cpp \ 71 source/val/validate_scopes.cpp \ 72 source/val/validate_small_type_uses.cpp \ 73 source/val/validate_type.cpp 74 75SPVTOOLS_OPT_SRC_FILES := \ 76 source/opt/aggressive_dead_code_elim_pass.cpp \ 77 source/opt/amd_ext_to_khr.cpp \ 78 source/opt/basic_block.cpp \ 79 source/opt/block_merge_pass.cpp \ 80 source/opt/block_merge_util.cpp \ 81 source/opt/build_module.cpp \ 82 source/opt/cfg.cpp \ 83 source/opt/cfg_cleanup_pass.cpp \ 84 source/opt/ccp_pass.cpp \ 85 source/opt/code_sink.cpp \ 86 source/opt/combine_access_chains.cpp \ 87 source/opt/compact_ids_pass.cpp \ 88 source/opt/composite.cpp \ 89 source/opt/const_folding_rules.cpp \ 90 source/opt/constants.cpp \ 91 source/opt/convert_to_half_pass.cpp \ 92 source/opt/copy_prop_arrays.cpp \ 93 source/opt/dead_branch_elim_pass.cpp \ 94 source/opt/dead_insert_elim_pass.cpp \ 95 source/opt/dead_variable_elimination.cpp \ 96 source/opt/decompose_initialized_variables_pass.cpp \ 97 source/opt/decoration_manager.cpp \ 98 source/opt/def_use_manager.cpp \ 99 source/opt/desc_sroa.cpp \ 100 source/opt/dominator_analysis.cpp \ 101 source/opt/dominator_tree.cpp \ 102 source/opt/eliminate_dead_constant_pass.cpp \ 103 source/opt/eliminate_dead_functions_pass.cpp \ 104 source/opt/eliminate_dead_functions_util.cpp \ 105 source/opt/eliminate_dead_members_pass.cpp \ 106 source/opt/feature_manager.cpp \ 107 source/opt/fix_storage_class.cpp \ 108 source/opt/flatten_decoration_pass.cpp \ 109 source/opt/fold.cpp \ 110 source/opt/folding_rules.cpp \ 111 source/opt/fold_spec_constant_op_and_composite_pass.cpp \ 112 source/opt/freeze_spec_constant_value_pass.cpp \ 113 source/opt/function.cpp \ 114 source/opt/generate_webgpu_initializers_pass.cpp \ 115 source/opt/graphics_robust_access_pass.cpp \ 116 source/opt/if_conversion.cpp \ 117 source/opt/inline_pass.cpp \ 118 source/opt/inline_exhaustive_pass.cpp \ 119 source/opt/inline_opaque_pass.cpp \ 120 source/opt/inst_bindless_check_pass.cpp \ 121 source/opt/inst_buff_addr_check_pass.cpp \ 122 source/opt/inst_debug_printf_pass.cpp \ 123 source/opt/instruction.cpp \ 124 source/opt/instruction_list.cpp \ 125 source/opt/instrument_pass.cpp \ 126 source/opt/ir_context.cpp \ 127 source/opt/ir_loader.cpp \ 128 source/opt/legalize_vector_shuffle_pass.cpp \ 129 source/opt/licm_pass.cpp \ 130 source/opt/local_access_chain_convert_pass.cpp \ 131 source/opt/local_redundancy_elimination.cpp \ 132 source/opt/local_single_block_elim_pass.cpp \ 133 source/opt/local_single_store_elim_pass.cpp \ 134 source/opt/loop_dependence.cpp \ 135 source/opt/loop_dependence_helpers.cpp \ 136 source/opt/loop_descriptor.cpp \ 137 source/opt/loop_fission.cpp \ 138 source/opt/loop_fusion.cpp \ 139 source/opt/loop_fusion_pass.cpp \ 140 source/opt/loop_peeling.cpp \ 141 source/opt/loop_unroller.cpp \ 142 source/opt/loop_unswitch_pass.cpp \ 143 source/opt/loop_utils.cpp \ 144 source/opt/mem_pass.cpp \ 145 source/opt/merge_return_pass.cpp \ 146 source/opt/module.cpp \ 147 source/opt/optimizer.cpp \ 148 source/opt/pass.cpp \ 149 source/opt/pass_manager.cpp \ 150 source/opt/private_to_local_pass.cpp \ 151 source/opt/process_lines_pass.cpp \ 152 source/opt/propagator.cpp \ 153 source/opt/reduce_load_size.cpp \ 154 source/opt/redundancy_elimination.cpp \ 155 source/opt/register_pressure.cpp \ 156 source/opt/relax_float_ops_pass.cpp \ 157 source/opt/remove_duplicates_pass.cpp \ 158 source/opt/replace_invalid_opc.cpp \ 159 source/opt/scalar_analysis.cpp \ 160 source/opt/scalar_analysis_simplification.cpp \ 161 source/opt/scalar_replacement_pass.cpp \ 162 source/opt/set_spec_constant_default_value_pass.cpp \ 163 source/opt/simplification_pass.cpp \ 164 source/opt/split_invalid_unreachable_pass.cpp \ 165 source/opt/ssa_rewrite_pass.cpp \ 166 source/opt/strength_reduction_pass.cpp \ 167 source/opt/strip_atomic_counter_memory_pass.cpp \ 168 source/opt/strip_debug_info_pass.cpp \ 169 source/opt/strip_reflect_info_pass.cpp \ 170 source/opt/struct_cfg_analysis.cpp \ 171 source/opt/type_manager.cpp \ 172 source/opt/types.cpp \ 173 source/opt/unify_const_pass.cpp \ 174 source/opt/upgrade_memory_model.cpp \ 175 source/opt/value_number_table.cpp \ 176 source/opt/vector_dce.cpp \ 177 source/opt/workaround1209.cpp \ 178 source/opt/wrap_opkill.cpp 179 180# Locations of grammar files. 181# 182SPV_COREUNIFIED1_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/spirv.core.grammar.json 183SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/extinst.glsl.std.450.grammar.json 184SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/extinst.opencl.std.100.grammar.json 185# TODO(dneto): I expect the DebugInfo grammar file to eventually migrate to SPIRV-Headers 186SPV_DEBUGINFO_GRAMMAR=$(LOCAL_PATH)/source/extinst.debuginfo.grammar.json 187SPV_CLDEBUGINFO100_GRAMMAR=$(LOCAL_PATH)/source/extinst.opencl.debuginfo.100.grammar.json 188 189define gen_spvtools_grammar_tables 190$(call generate-file-dir,$(1)/core.insts-unified1.inc) 191$(1)/core.insts-unified1.inc $(1)/operand.kinds-unified1.inc \ 192$(1)/glsl.std.450.insts.inc \ 193$(1)/opencl.std.insts.inc \ 194: \ 195 $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 196 $(SPV_COREUNIFIED1_GRAMMAR) \ 197 $(SPV_GLSL_GRAMMAR) \ 198 $(SPV_OpenCL_GRAMMAR) \ 199 $(SPV_DEBUGINFO_GRAMMAR) \ 200 $(SPV_CLDEBUGINFO100_GRAMMAR) 201 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 202 --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \ 203 --extinst-glsl-grammar=$(SPV_GLSL_GRAMMAR) \ 204 --extinst-opencl-grammar=$(SPV_OPENCL_GRAMMAR) \ 205 --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \ 206 --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \ 207 --core-insts-output=$(1)/core.insts-unified1.inc \ 208 --glsl-insts-output=$(1)/glsl.std.450.insts.inc \ 209 --opencl-insts-output=$(1)/opencl.std.insts.inc \ 210 --operand-kinds-output=$(1)/operand.kinds-unified1.inc 211 @echo "[$(TARGET_ARCH_ABI)] Grammar (from unified1) : instructions & operands <= grammar JSON files" 212$(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-unified1.inc 213$(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-unified1.inc 214$(LOCAL_PATH)/source/ext_inst.cpp: \ 215 $(1)/glsl.std.450.insts.inc \ 216 $(1)/opencl.std.insts.inc \ 217 $(1)/debuginfo.insts.inc \ 218 $(1)/opencl.debuginfo.100.insts.inc \ 219 $(1)/spv-amd-gcn-shader.insts.inc \ 220 $(1)/spv-amd-shader-ballot.insts.inc \ 221 $(1)/spv-amd-shader-explicit-vertex-parameter.insts.inc \ 222 $(1)/spv-amd-shader-trinary-minmax.insts.inc 223$(LOCAL_PATH)/source/opt/amd_ext_to_khr.cpp: \ 224 $(1)/spv-amd-shader-ballot.insts.inc 225endef 226$(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH))) 227 228 229define gen_spvtools_lang_headers 230# Generate language-specific headers. So far we only generate C headers 231# $1 is the output directory. 232# $2 is the base name of the header file, e.g. "DebugInfo". 233# $3 is the grammar file containing token definitions. 234$(call generate-file-dir,$(1)/$(2).h) 235$(1)/$(2).h : \ 236 $(LOCAL_PATH)/utils/generate_language_headers.py \ 237 $(3) 238 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \ 239 --extinst-grammar=$(3) \ 240 --extinst-output-path=$(1)/$(2).h 241 @echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar" 242$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \ 243 : $(1)/$(2).h 244endef 245# We generate language-specific headers for DebugInfo and OpenCL.DebugInfo.100 246$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),DebugInfo,$(SPV_DEBUGINFO_GRAMMAR))) 247$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),OpenCLDebugInfo100,$(SPV_CLDEBUGINFO100_GRAMMAR))) 248 249 250define gen_spvtools_vendor_tables 251$(call generate-file-dir,$(1)/$(2).insts.inc) 252$(1)/$(2).insts.inc : \ 253 $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 254 $(LOCAL_PATH)/source/extinst.$(2).grammar.json 255 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 256 --extinst-vendor-grammar=$(LOCAL_PATH)/source/extinst.$(2).grammar.json \ 257 --vendor-insts-output=$(1)/$(2).insts.inc \ 258 --vendor-operand-kind-prefix=$(3) 259 @echo "[$(TARGET_ARCH_ABI)] Vendor extended instruction set: $(2) tables <= grammar" 260$(LOCAL_PATH)/source/ext_inst.cpp: $(1)/$(2).insts.inc 261endef 262# Vendor and debug extended instruction sets, with grammars from SPIRV-Tools source tree. 263$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),debuginfo,"")) 264$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),opencl.debuginfo.100,"CLDEBUG100_")) 265$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-gcn-shader,"")) 266$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-ballot,"")) 267$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-explicit-vertex-parameter,"")) 268$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-trinary-minmax,"")) 269 270define gen_spvtools_enum_string_mapping 271$(call generate-file-dir,$(1)/extension_enum.inc.inc) 272$(1)/extension_enum.inc $(1)/enum_string_mapping.inc: \ 273 $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 274 $(SPV_COREUNIFIED1_GRAMMAR) 275 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \ 276 --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \ 277 --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \ 278 --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \ 279 --extension-enum-output=$(1)/extension_enum.inc \ 280 --enum-string-mapping-output=$(1)/enum_string_mapping.inc 281 @echo "[$(TARGET_ARCH_ABI)] Generate enum<->string mapping <= grammar JSON files" 282# Generated header extension_enum.inc is transitively included by table.h, which is 283# used pervasively. Capture the pervasive dependency. 284$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \ 285 : $(1)/extension_enum.inc 286$(LOCAL_PATH)/source/enum_string_mapping.cpp: $(1)/enum_string_mapping.inc 287endef 288$(eval $(call gen_spvtools_enum_string_mapping,$(SPVTOOLS_OUT_PATH))) 289 290define gen_spvtools_build_version_inc 291$(call generate-file-dir,$(1)/dummy_filename) 292$(1)/build-version.inc: \ 293 $(LOCAL_PATH)/utils/update_build_version.py \ 294 $(LOCAL_PATH)/CHANGES 295 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \ 296 $(LOCAL_PATH) $(1)/build-version.inc 297 @echo "[$(TARGET_ARCH_ABI)] Generate : build-version.inc <= CHANGES" 298$(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc 299endef 300$(eval $(call gen_spvtools_build_version_inc,$(SPVTOOLS_OUT_PATH))) 301 302define gen_spvtools_generators_inc 303$(call generate-file-dir,$(1)/dummy_filename) 304$(1)/generators.inc: \ 305 $(LOCAL_PATH)/utils/generate_registry_tables.py \ 306 $(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml 307 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_registry_tables.py \ 308 --xml=$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml \ 309 --generator-output=$(1)/generators.inc 310 @echo "[$(TARGET_ARCH_ABI)] Generate : generators.inc <= spir-v.xml" 311$(LOCAL_PATH)/source/opcode.cpp: $(1)/generators.inc 312endef 313$(eval $(call gen_spvtools_generators_inc,$(SPVTOOLS_OUT_PATH))) 314 315include $(CLEAR_VARS) 316LOCAL_MODULE := SPIRV-Tools 317LOCAL_C_INCLUDES := \ 318 $(LOCAL_PATH)/include \ 319 $(SPVHEADERS_LOCAL_PATH)/include \ 320 $(SPVTOOLS_OUT_PATH) 321LOCAL_EXPORT_C_INCLUDES := \ 322 $(LOCAL_PATH)/include 323LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror 324LOCAL_SRC_FILES:= $(SPVTOOLS_SRC_FILES) 325include $(BUILD_STATIC_LIBRARY) 326 327include $(CLEAR_VARS) 328LOCAL_MODULE := SPIRV-Tools-opt 329LOCAL_C_INCLUDES := \ 330 $(LOCAL_PATH)/include \ 331 $(LOCAL_PATH)/source \ 332 $(SPVHEADERS_LOCAL_PATH)/include \ 333 $(SPVTOOLS_OUT_PATH) 334LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror 335LOCAL_STATIC_LIBRARIES:=SPIRV-Tools 336LOCAL_SRC_FILES:= $(SPVTOOLS_OPT_SRC_FILES) 337include $(BUILD_STATIC_LIBRARY) 338