• 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_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/decoration_manager.cpp \
97		source/opt/debug_info_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/graphics_robust_access_pass.cpp \
115		source/opt/if_conversion.cpp \
116		source/opt/inline_pass.cpp \
117		source/opt/inline_exhaustive_pass.cpp \
118		source/opt/inline_opaque_pass.cpp \
119		source/opt/inst_bindless_check_pass.cpp \
120		source/opt/inst_buff_addr_check_pass.cpp \
121		source/opt/inst_debug_printf_pass.cpp \
122		source/opt/instruction.cpp \
123		source/opt/instruction_list.cpp \
124		source/opt/instrument_pass.cpp \
125		source/opt/interp_fixup_pass.cpp \
126		source/opt/ir_context.cpp \
127		source/opt/ir_loader.cpp \
128		source/opt/licm_pass.cpp \
129		source/opt/local_access_chain_convert_pass.cpp \
130		source/opt/local_redundancy_elimination.cpp \
131		source/opt/local_single_block_elim_pass.cpp \
132		source/opt/local_single_store_elim_pass.cpp \
133		source/opt/loop_dependence.cpp \
134		source/opt/loop_dependence_helpers.cpp \
135		source/opt/loop_descriptor.cpp \
136		source/opt/loop_fission.cpp \
137		source/opt/loop_fusion.cpp \
138		source/opt/loop_fusion_pass.cpp \
139		source/opt/loop_peeling.cpp \
140		source/opt/loop_unroller.cpp \
141		source/opt/loop_unswitch_pass.cpp \
142		source/opt/loop_utils.cpp \
143		source/opt/mem_pass.cpp \
144		source/opt/merge_return_pass.cpp \
145		source/opt/module.cpp \
146		source/opt/optimizer.cpp \
147		source/opt/pass.cpp \
148		source/opt/pass_manager.cpp \
149		source/opt/private_to_local_pass.cpp \
150		source/opt/propagator.cpp \
151		source/opt/reduce_load_size.cpp \
152		source/opt/redundancy_elimination.cpp \
153		source/opt/register_pressure.cpp \
154		source/opt/relax_float_ops_pass.cpp \
155		source/opt/remove_duplicates_pass.cpp \
156		source/opt/replace_invalid_opc.cpp \
157		source/opt/scalar_analysis.cpp \
158		source/opt/scalar_analysis_simplification.cpp \
159		source/opt/scalar_replacement_pass.cpp \
160		source/opt/set_spec_constant_default_value_pass.cpp \
161		source/opt/simplification_pass.cpp \
162		source/opt/ssa_rewrite_pass.cpp \
163		source/opt/strength_reduction_pass.cpp \
164		source/opt/strip_debug_info_pass.cpp \
165		source/opt/strip_reflect_info_pass.cpp \
166		source/opt/struct_cfg_analysis.cpp \
167		source/opt/type_manager.cpp \
168		source/opt/types.cpp \
169		source/opt/unify_const_pass.cpp \
170		source/opt/upgrade_memory_model.cpp \
171		source/opt/value_number_table.cpp \
172		source/opt/vector_dce.cpp \
173		source/opt/workaround1209.cpp \
174		source/opt/wrap_opkill.cpp
175
176# Locations of grammar files.
177#
178SPV_COREUNIFIED1_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/spirv.core.grammar.json
179SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.glsl.std.450.grammar.json
180SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.opencl.std.100.grammar.json
181SPV_DEBUGINFO_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.debuginfo.grammar.json
182SPV_CLDEBUGINFO100_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json
183
184define gen_spvtools_grammar_tables
185$(call generate-file-dir,$(1)/core.insts-unified1.inc)
186$(1)/core.insts-unified1.inc $(1)/operand.kinds-unified1.inc \
187$(1)/glsl.std.450.insts.inc \
188$(1)/opencl.std.insts.inc \
189: \
190        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
191        $(SPV_COREUNIFIED1_GRAMMAR) \
192        $(SPV_GLSL_GRAMMAR) \
193        $(SPV_OpenCL_GRAMMAR) \
194        $(SPV_DEBUGINFO_GRAMMAR) \
195        $(SPV_CLDEBUGINFO100_GRAMMAR)
196		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
197		                --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
198		                --extinst-glsl-grammar=$(SPV_GLSL_GRAMMAR) \
199		                --extinst-opencl-grammar=$(SPV_OPENCL_GRAMMAR) \
200		                --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
201		                --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \
202		                --core-insts-output=$(1)/core.insts-unified1.inc \
203		                --glsl-insts-output=$(1)/glsl.std.450.insts.inc \
204		                --opencl-insts-output=$(1)/opencl.std.insts.inc \
205		                --operand-kinds-output=$(1)/operand.kinds-unified1.inc
206		@echo "[$(TARGET_ARCH_ABI)] Grammar (from unified1)  : instructions & operands <= grammar JSON files"
207$(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-unified1.inc
208$(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-unified1.inc
209$(LOCAL_PATH)/source/ext_inst.cpp: \
210	$(1)/glsl.std.450.insts.inc \
211	$(1)/opencl.std.insts.inc \
212	$(1)/debuginfo.insts.inc \
213	$(1)/opencl.debuginfo.100.insts.inc \
214	$(1)/spv-amd-gcn-shader.insts.inc \
215	$(1)/spv-amd-shader-ballot.insts.inc \
216	$(1)/spv-amd-shader-explicit-vertex-parameter.insts.inc \
217	$(1)/spv-amd-shader-trinary-minmax.insts.inc
218$(LOCAL_PATH)/source/opt/amd_ext_to_khr.cpp: \
219	$(1)/spv-amd-shader-ballot.insts.inc
220endef
221$(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH)))
222
223
224define gen_spvtools_lang_headers
225# Generate language-specific headers.  So far we only generate C headers
226# $1 is the output directory.
227# $2 is the base name of the header file, e.g. "DebugInfo".
228# $3 is the grammar file containing token definitions.
229$(call generate-file-dir,$(1)/$(2).h)
230$(1)/$(2).h : \
231        $(LOCAL_PATH)/utils/generate_language_headers.py \
232        $(3)
233		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \
234		    --extinst-grammar=$(3) \
235		    --extinst-output-path=$(1)/$(2).h
236		@echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar"
237$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
238	: $(1)/$(2).h
239endef
240# We generate language-specific headers for DebugInfo and OpenCL.DebugInfo.100
241$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),DebugInfo,$(SPV_DEBUGINFO_GRAMMAR)))
242$(eval $(call gen_spvtools_lang_headers,$(SPVTOOLS_OUT_PATH),OpenCLDebugInfo100,$(SPV_CLDEBUGINFO100_GRAMMAR)))
243
244
245define gen_spvtools_vendor_tables
246$(call generate-file-dir,$(1)/$(2).insts.inc)
247$(1)/$(2).insts.inc : \
248        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
249        $(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.$(2).grammar.json
250		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
251		    --extinst-vendor-grammar=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.$(2).grammar.json \
252		    --vendor-insts-output=$(1)/$(2).insts.inc \
253		    --vendor-operand-kind-prefix=$(3)
254		@echo "[$(TARGET_ARCH_ABI)] Vendor extended instruction set: $(2) tables <= grammar"
255$(LOCAL_PATH)/source/ext_inst.cpp: $(1)/$(2).insts.inc
256endef
257# Vendor and debug extended instruction sets, with grammars from SPIRV-Tools source tree.
258$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),debuginfo,""))
259$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),opencl.debuginfo.100,"CLDEBUG100_"))
260$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-gcn-shader,""))
261$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-ballot,""))
262$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-explicit-vertex-parameter,""))
263$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-trinary-minmax,""))
264$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),nonsemantic.clspvreflection,""))
265
266define gen_spvtools_enum_string_mapping
267$(call generate-file-dir,$(1)/extension_enum.inc.inc)
268$(1)/extension_enum.inc $(1)/enum_string_mapping.inc: \
269        $(LOCAL_PATH)/utils/generate_grammar_tables.py \
270        $(SPV_COREUNIFIED1_GRAMMAR)
271		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
272		                --spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
273		                --extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
274		                --extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \
275		                --extension-enum-output=$(1)/extension_enum.inc \
276		                --enum-string-mapping-output=$(1)/enum_string_mapping.inc
277		@echo "[$(TARGET_ARCH_ABI)] Generate enum<->string mapping <= grammar JSON files"
278# Generated header extension_enum.inc is transitively included by table.h, which is
279# used pervasively.  Capture the pervasive dependency.
280$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
281  : $(1)/extension_enum.inc
282$(LOCAL_PATH)/source/enum_string_mapping.cpp: $(1)/enum_string_mapping.inc
283endef
284$(eval $(call gen_spvtools_enum_string_mapping,$(SPVTOOLS_OUT_PATH)))
285
286define gen_spvtools_build_version_inc
287$(call generate-file-dir,$(1)/dummy_filename)
288$(1)/build-version.inc: \
289        $(LOCAL_PATH)/utils/update_build_version.py \
290        $(LOCAL_PATH)/CHANGES
291		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \
292		                $(LOCAL_PATH) $(1)/build-version.inc
293		@echo "[$(TARGET_ARCH_ABI)] Generate       : build-version.inc <= CHANGES"
294$(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc
295endef
296$(eval $(call gen_spvtools_build_version_inc,$(SPVTOOLS_OUT_PATH)))
297
298define gen_spvtools_generators_inc
299$(call generate-file-dir,$(1)/dummy_filename)
300$(1)/generators.inc: \
301        $(LOCAL_PATH)/utils/generate_registry_tables.py \
302        $(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml
303		@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_registry_tables.py \
304		                --xml=$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml \
305				--generator-output=$(1)/generators.inc
306		@echo "[$(TARGET_ARCH_ABI)] Generate       : generators.inc <= spir-v.xml"
307$(LOCAL_PATH)/source/opcode.cpp: $(1)/generators.inc
308endef
309$(eval $(call gen_spvtools_generators_inc,$(SPVTOOLS_OUT_PATH)))
310
311include $(CLEAR_VARS)
312LOCAL_MODULE := SPIRV-Tools
313LOCAL_C_INCLUDES := \
314		$(LOCAL_PATH)/include \
315		$(SPVHEADERS_LOCAL_PATH)/include \
316		$(SPVTOOLS_OUT_PATH)
317LOCAL_EXPORT_C_INCLUDES := \
318		$(LOCAL_PATH)/include
319LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror
320LOCAL_SRC_FILES:= $(SPVTOOLS_SRC_FILES)
321include $(BUILD_STATIC_LIBRARY)
322
323include $(CLEAR_VARS)
324LOCAL_MODULE := SPIRV-Tools-opt
325LOCAL_C_INCLUDES := \
326		$(LOCAL_PATH)/include \
327		$(LOCAL_PATH)/source \
328		$(SPVHEADERS_LOCAL_PATH)/include \
329		$(SPVTOOLS_OUT_PATH)
330LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror
331LOCAL_STATIC_LIBRARIES:=SPIRV-Tools
332LOCAL_SRC_FILES:= $(SPVTOOLS_OPT_SRC_FILES)
333include $(BUILD_STATIC_LIBRARY)
334