• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_mesh_shading.cpp \
65		source/val/validate_misc.cpp \
66		source/val/validate_mode_setting.cpp \
67		source/val/validate_layout.cpp \
68		source/val/validate_literals.cpp \
69		source/val/validate_logicals.cpp \
70		source/val/validate_non_uniform.cpp \
71		source/val/validate_primitives.cpp \
72		source/val/validate_ray_query.cpp \
73		source/val/validate_ray_tracing.cpp \
74		source/val/validate_ray_tracing_reorder.cpp \
75		source/val/validate_scopes.cpp \
76		source/val/validate_small_type_uses.cpp \
77		source/val/validate_type.cpp
78
79SPVTOOLS_OPT_SRC_FILES := \
80		source/opt/aggressive_dead_code_elim_pass.cpp \
81		source/opt/amd_ext_to_khr.cpp \
82		source/opt/analyze_live_input_pass.cpp \
83		source/opt/basic_block.cpp \
84		source/opt/block_merge_pass.cpp \
85		source/opt/block_merge_util.cpp \
86		source/opt/build_module.cpp \
87		source/opt/cfg.cpp \
88		source/opt/cfg_cleanup_pass.cpp \
89		source/opt/ccp_pass.cpp \
90		source/opt/code_sink.cpp \
91		source/opt/combine_access_chains.cpp \
92		source/opt/compact_ids_pass.cpp \
93		source/opt/composite.cpp \
94		source/opt/const_folding_rules.cpp \
95		source/opt/constants.cpp \
96		source/opt/control_dependence.cpp \
97		source/opt/convert_to_sampled_image_pass.cpp \
98		source/opt/convert_to_half_pass.cpp \
99		source/opt/copy_prop_arrays.cpp \
100		source/opt/dataflow.cpp \
101		source/opt/dead_branch_elim_pass.cpp \
102		source/opt/dead_insert_elim_pass.cpp \
103		source/opt/dead_variable_elimination.cpp \
104		source/opt/decoration_manager.cpp \
105		source/opt/debug_info_manager.cpp \
106		source/opt/def_use_manager.cpp \
107		source/opt/desc_sroa.cpp \
108		source/opt/desc_sroa_util.cpp \
109		source/opt/dominator_analysis.cpp \
110		source/opt/dominator_tree.cpp \
111		source/opt/eliminate_dead_constant_pass.cpp \
112		source/opt/eliminate_dead_functions_pass.cpp \
113		source/opt/eliminate_dead_functions_util.cpp \
114		source/opt/eliminate_dead_io_components_pass.cpp \
115		source/opt/eliminate_dead_members_pass.cpp \
116		source/opt/eliminate_dead_output_stores_pass.cpp \
117		source/opt/feature_manager.cpp \
118		source/opt/fix_func_call_arguments.cpp \
119		source/opt/fix_storage_class.cpp \
120		source/opt/flatten_decoration_pass.cpp \
121		source/opt/fold.cpp \
122		source/opt/folding_rules.cpp \
123		source/opt/fold_spec_constant_op_and_composite_pass.cpp \
124		source/opt/freeze_spec_constant_value_pass.cpp \
125		source/opt/function.cpp \
126		source/opt/graphics_robust_access_pass.cpp \
127		source/opt/if_conversion.cpp \
128		source/opt/inline_pass.cpp \
129		source/opt/inline_exhaustive_pass.cpp \
130		source/opt/inline_opaque_pass.cpp \
131		source/opt/inst_bindless_check_pass.cpp \
132		source/opt/inst_buff_addr_check_pass.cpp \
133		source/opt/inst_debug_printf_pass.cpp \
134		source/opt/instruction.cpp \
135		source/opt/instruction_list.cpp \
136		source/opt/instrument_pass.cpp \
137		source/opt/interface_var_sroa.cpp \
138		source/opt/interp_fixup_pass.cpp \
139		source/opt/invocation_interlock_placement_pass.cpp \
140		source/opt/ir_context.cpp \
141		source/opt/ir_loader.cpp \
142		source/opt/licm_pass.cpp \
143		source/opt/liveness.cpp \
144		source/opt/local_access_chain_convert_pass.cpp \
145		source/opt/local_redundancy_elimination.cpp \
146		source/opt/local_single_block_elim_pass.cpp \
147		source/opt/local_single_store_elim_pass.cpp \
148		source/opt/loop_dependence.cpp \
149		source/opt/loop_dependence_helpers.cpp \
150		source/opt/loop_descriptor.cpp \
151		source/opt/loop_fission.cpp \
152		source/opt/loop_fusion.cpp \
153		source/opt/loop_fusion_pass.cpp \
154		source/opt/loop_peeling.cpp \
155		source/opt/loop_unroller.cpp \
156		source/opt/loop_unswitch_pass.cpp \
157		source/opt/loop_utils.cpp \
158		source/opt/mem_pass.cpp \
159		source/opt/merge_return_pass.cpp \
160		source/opt/module.cpp \
161		source/opt/optimizer.cpp \
162		source/opt/pass.cpp \
163		source/opt/pass_manager.cpp \
164		source/opt/private_to_local_pass.cpp \
165		source/opt/propagator.cpp \
166		source/opt/reduce_load_size.cpp \
167		source/opt/redundancy_elimination.cpp \
168		source/opt/register_pressure.cpp \
169		source/opt/relax_float_ops_pass.cpp \
170		source/opt/remove_dontinline_pass.cpp \
171		source/opt/remove_duplicates_pass.cpp \
172		source/opt/remove_unused_interface_variables_pass.cpp \
173		source/opt/replace_desc_array_access_using_var_index.cpp \
174		source/opt/replace_invalid_opc.cpp \
175		source/opt/scalar_analysis.cpp \
176		source/opt/scalar_analysis_simplification.cpp \
177		source/opt/scalar_replacement_pass.cpp \
178		source/opt/set_spec_constant_default_value_pass.cpp \
179		source/opt/simplification_pass.cpp \
180		source/opt/spread_volatile_semantics.cpp \
181		source/opt/ssa_rewrite_pass.cpp \
182		source/opt/strength_reduction_pass.cpp \
183		source/opt/strip_debug_info_pass.cpp \
184		source/opt/strip_nonsemantic_info_pass.cpp \
185		source/opt/struct_cfg_analysis.cpp \
186		source/opt/switch_descriptorset_pass.cpp \
187		source/opt/trim_capabilities_pass.cpp \
188		source/opt/type_manager.cpp \
189		source/opt/types.cpp \
190		source/opt/unify_const_pass.cpp \
191		source/opt/upgrade_memory_model.cpp \
192		source/opt/value_number_table.cpp \
193		source/opt/vector_dce.cpp \
194		source/opt/workaround1209.cpp \
195		source/opt/wrap_opkill.cpp
196
197# Locations of grammar files.
198#
199SPV_COREUNIFIED1_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/spirv.core.grammar.json
200SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.glsl.std.450.grammar.json
201SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.opencl.std.100.grammar.json
202SPV_DEBUGINFO_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.debuginfo.grammar.json
203SPV_CLDEBUGINFO100_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json
204SPV_VKDEBUGINFO100_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.nonsemantic.shader.debuginfo.100.grammar.json
205
206define gen_spvtools_grammar_tables
207$(call generate-file-dir,$(1)/core.insts-unified1.inc)
208$(1)/core.insts-unified1.inc $(1)/operand.kinds-unified1.inc \
209$(1)/glsl.std.450.insts.inc \
210$(1)/opencl.std.insts.inc \
211: \
212        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
213        $(SPV_COREUNIFIED1_GRAMMAR) \
214        $(SPV_GLSL_GRAMMAR) \
215        $(SPV_OpenCL_GRAMMAR) \
216        $(SPV_DEBUGINFO_GRAMMAR) \
217        $(SPV_CLDEBUGINFO100_GRAMMAR)
218		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
219		                --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
220		                --extinst-glsl-grammar=$(SPV_GLSL_GRAMMAR) \
221		                --extinst-opencl-grammar=$(SPV_OPENCL_GRAMMAR) \
222		                --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
223		                --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \
224		                --core-insts-output=$(1)/core.insts-unified1.inc \
225		                --glsl-insts-output=$(1)/glsl.std.450.insts.inc \
226		                --opencl-insts-output=$(1)/opencl.std.insts.inc \
227		                --operand-kinds-output=$(1)/operand.kinds-unified1.inc \
228										--output-language=c++
229		@echo "[$(TARGET_ARCH_ABI)] Grammar (from unified1)  : instructions & operands <= grammar JSON files"
230$(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-unified1.inc
231$(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-unified1.inc
232$(LOCAL_PATH)/source/ext_inst.cpp: \
233	$(1)/glsl.std.450.insts.inc \
234	$(1)/opencl.std.insts.inc \
235	$(1)/debuginfo.insts.inc \
236	$(1)/opencl.debuginfo.100.insts.inc \
237	$(1)/nonsemantic.shader.debuginfo.100.insts.inc \
238	$(1)/spv-amd-gcn-shader.insts.inc \
239	$(1)/spv-amd-shader-ballot.insts.inc \
240	$(1)/spv-amd-shader-explicit-vertex-parameter.insts.inc \
241	$(1)/spv-amd-shader-trinary-minmax.insts.inc
242$(LOCAL_PATH)/source/opt/amd_ext_to_khr.cpp: \
243	$(1)/spv-amd-shader-ballot.insts.inc
244endef
245$(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH)))
246
247
248define gen_spvtools_lang_headers
249# Generate language-specific headers.  So far we only generate C headers
250# $1 is the output directory.
251# $2 is the base name of the header file, e.g. "DebugInfo".
252# $3 is the grammar file containing token definitions.
253$(call generate-file-dir,$(1)/$(2).h)
254$(1)/$(2).h : \
255        $(LOCAL_PATH)/utils/generate_language_headers.py \
256        $(3)
257		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \
258		    --extinst-grammar=$(3) \
259		    --extinst-output-path=$(1)/$(2).h
260		@echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar"
261$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
262	: $(1)/$(2).h
263endef
264# We generate language-specific headers for DebugInfo and OpenCL.DebugInfo.100
265$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),DebugInfo,$(SPV_DEBUGINFO_GRAMMAR)))
266$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),OpenCLDebugInfo100,$(SPV_CLDEBUGINFO100_GRAMMAR)))
267$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),NonSemanticShaderDebugInfo100,$(SPV_VKDEBUGINFO100_GRAMMAR)))
268
269
270define gen_spvtools_vendor_tables
271$(call generate-file-dir,$(1)/$(2).insts.inc)
272$(1)/$(2).insts.inc : \
273        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
274        $(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.$(2).grammar.json
275		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
276		    --extinst-vendor-grammar=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.$(2).grammar.json \
277		    --vendor-insts-output=$(1)/$(2).insts.inc \
278		    --vendor-operand-kind-prefix=$(3)
279		@echo "[$(TARGET_ARCH_ABI)] Vendor extended instruction set: $(2) tables <= grammar"
280$(LOCAL_PATH)/source/ext_inst.cpp: $(1)/$(2).insts.inc
281endef
282# Vendor and debug extended instruction sets, with grammars from SPIRV-Tools source tree.
283$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),debuginfo,""))
284$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),opencl.debuginfo.100,"CLDEBUG100_"))
285$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),nonsemantic.shader.debuginfo.100,"SHDEBUG100_"))
286$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-gcn-shader,""))
287$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-ballot,""))
288$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-explicit-vertex-parameter,""))
289$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-trinary-minmax,""))
290$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),nonsemantic.clspvreflection,""))
291
292define gen_spvtools_enum_string_mapping
293$(call generate-file-dir,$(1)/extension_enum.inc.inc)
294$(1)/extension_enum.inc $(1)/enum_string_mapping.inc: \
295        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
296        $(SPV_COREUNIFIED1_GRAMMAR)
297		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
298		                --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
299		                --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
300		                --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \
301		                --extension-enum-output=$(1)/extension_enum.inc \
302		                --enum-string-mapping-output=$(1)/enum_string_mapping.inc \
303										--output-language=c++
304		@echo "[$(TARGET_ARCH_ABI)] Generate enum<->string mapping <= grammar JSON files"
305# Generated header extension_enum.inc is transitively included by table.h, which is
306# used pervasively.  Capture the pervasive dependency.
307$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
308  : $(1)/extension_enum.inc
309$(LOCAL_PATH)/source/enum_string_mapping.cpp: $(1)/enum_string_mapping.inc
310endef
311$(eval $(call gen_spvtools_enum_string_mapping,$(SPVTOOLS_OUT_PATH)))
312
313define gen_spvtools_build_version_inc
314$(call generate-file-dir,$(1)/dummy_filename)
315$(1)/build-version.inc: \
316        $(LOCAL_PATH)/utils/update_build_version.py \
317        $(LOCAL_PATH)/CHANGES
318		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \
319		                $(LOCAL_PATH)/CHANGES $(1)/build-version.inc
320		@echo "[$(TARGET_ARCH_ABI)] Generate       : build-version.inc <= CHANGES"
321$(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc
322endef
323$(eval $(call gen_spvtools_build_version_inc,$(SPVTOOLS_OUT_PATH)))
324
325define gen_spvtools_generators_inc
326$(call generate-file-dir,$(1)/dummy_filename)
327$(1)/generators.inc: \
328        $(LOCAL_PATH)/utils/generate_registry_tables.py \
329        $(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml
330		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_registry_tables.py \
331		                --xml=$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml \
332				--generator-output=$(1)/generators.inc
333		@echo "[$(TARGET_ARCH_ABI)] Generate       : generators.inc <= spir-v.xml"
334$(LOCAL_PATH)/source/opcode.cpp: $(1)/generators.inc
335endef
336$(eval $(call gen_spvtools_generators_inc,$(SPVTOOLS_OUT_PATH)))
337
338include $(CLEAR_VARS)
339LOCAL_MODULE := SPIRV-Tools
340LOCAL_C_INCLUDES := \
341		$(LOCAL_PATH)/include \
342		$(SPVHEADERS_LOCAL_PATH)/include \
343		$(SPVTOOLS_OUT_PATH)
344LOCAL_EXPORT_C_INCLUDES := \
345		$(LOCAL_PATH)/include
346LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
347LOCAL_SRC_FILES:= $(SPVTOOLS_SRC_FILES)
348include $(BUILD_STATIC_LIBRARY)
349
350include $(CLEAR_VARS)
351LOCAL_MODULE := SPIRV-Tools-opt
352LOCAL_C_INCLUDES := \
353		$(LOCAL_PATH)/include \
354		$(LOCAL_PATH)/source \
355		$(SPVHEADERS_LOCAL_PATH)/include \
356		$(SPVTOOLS_OUT_PATH)
357LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
358LOCAL_STATIC_LIBRARIES:=SPIRV-Tools
359LOCAL_SRC_FILES:= $(SPVTOOLS_OPT_SRC_FILES)
360include $(BUILD_STATIC_LIBRARY)
361