1 LOCAL_PATH := $(call my-dir)
2 SPVTOOLS_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT),$(abspath $(TARGET_OUT)))
3 SPVHEADERS_LOCAL_PATH := $(LOCAL_PATH)/external/spirv-headers
5 SPVTOOLS_SRC_FILES := \
6 source/assembly_grammar.cpp \
8 source/diagnostic.cpp \
9 source/disassemble.cpp \
11 source/enum_string_mapping.cpp \
12 source/extensions.cpp \
13 source/id_descriptor.cpp \
15 source/name_mapper.cpp \
18 source/parsed_operand.cpp \
20 source/software_version.cpp \
21 source/spirv_endian.cpp \
22 source/spirv_target_env.cpp \
23 source/spirv_validator_options.cpp \
26 source/text_handler.cpp \
27 source/util/bit_stream.cpp \
28 source/util/parse_number.cpp \
29 source/util/string_utils.cpp \
30 source/val/basic_block.cpp \
31 source/val/construct.cpp \
32 source/val/function.cpp \
33 source/val/instruction.cpp \
34 source/val/validation_state.cpp \
36 source/validate_arithmetics.cpp \
37 source/validate_bitwise.cpp \
38 source/validate_capability.cpp \
39 source/validate_cfg.cpp \
40 source/validate_conversion.cpp \
41 source/validate_datarules.cpp \
42 source/validate_decorations.cpp \
43 source/validate_id.cpp \
44 source/validate_instruction.cpp \
45 source/validate_layout.cpp \
46 source/validate_logicals.cpp \
47 source/validate_type_unique.cpp
49 SPVTOOLS_OPT_SRC_FILES := \
50 source/opt/aggressive_dead_code_elim_pass.cpp \
51 source/opt/basic_block.cpp \
52 source/opt/block_merge_pass.cpp \
53 source/opt/build_module.cpp \
55 source/opt/cfg_cleanup_pass.cpp \
56 source/opt/compact_ids_pass.cpp \
57 source/opt/common_uniform_elim_pass.cpp \
58 source/opt/dead_branch_elim_pass.cpp \
59 source/opt/dead_variable_elimination.cpp \
60 source/opt/decoration_manager.cpp \
61 source/opt/def_use_manager.cpp \
62 source/opt/eliminate_dead_constant_pass.cpp \
63 source/opt/eliminate_dead_functions_pass.cpp \
64 source/opt/flatten_decoration_pass.cpp \
66 source/opt/fold_spec_constant_op_and_composite_pass.cpp \
67 source/opt/freeze_spec_constant_value_pass.cpp \
68 source/opt/function.cpp \
69 source/opt/inline_pass.cpp \
70 source/opt/inline_exhaustive_pass.cpp \
71 source/opt/inline_opaque_pass.cpp \
72 source/opt/insert_extract_elim.cpp \
73 source/opt/instruction.cpp \
74 source/opt/instruction_list.cpp \
75 source/opt/ir_context.cpp \
76 source/opt/ir_loader.cpp \
77 source/opt/local_access_chain_convert_pass.cpp \
78 source/opt/local_single_block_elim_pass.cpp \
79 source/opt/local_single_store_elim_pass.cpp \
80 source/opt/local_ssa_elim_pass.cpp \
81 source/opt/mem_pass.cpp \
82 source/opt/module.cpp \
83 source/opt/optimizer.cpp \
85 source/opt/pass_manager.cpp \
86 source/opt/remove_duplicates_pass.cpp \
87 source/opt/set_spec_constant_default_value_pass.cpp \
88 source/opt/strength_reduction_pass.cpp \
89 source/opt/strip_debug_info_pass.cpp \
90 source/opt/type_manager.cpp \
91 source/opt/types.cpp \
92 source/opt/unify_const_pass.cpp \
93 source/opt/merge_return_pass.cpp
95 # Locations of grammar files.
96 SPV_CORE10_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/spirv.core.grammar.json
97 SPV_CORE11_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.1/spirv.core.grammar.json
98 SPV_CORE12_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/spirv.core.grammar.json
99 SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/extinst.glsl.std.450.grammar.json
100 SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/extinst.opencl.std.100.grammar.json
102 define gen_spvtools_grammar_tables
103 $(call generate-file-dir,$(1)/core.insts-1.0.inc)
104 $(1)/core.insts-1.0.inc $(1)/operand.kinds-1.0.inc $(1)/glsl.std.450.insts-1.0.inc $(1)/opencl.std.insts-1.0.inc: \
105 $(LOCAL_PATH)/utils/generate_grammar_tables.py \
106 $(SPV_CORE10_GRAMMAR) \
107 $(SPV_GLSL_GRAMMAR) \
108 $(SPV_OPENCL_GRAMMAR)
109 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
110 --spirv-core-grammar=$(SPV_CORE10_GRAMMAR) \
111 --extinst-glsl-grammar=$(SPV_GLSL_GRAMMAR) \
112 --extinst-opencl-grammar=$(SPV_OPENCL_GRAMMAR) \
113 --core-insts-output=$(1)/core.insts-1.0.inc \
114 --glsl-insts-output=$(1)/glsl.std.450.insts-1.0.inc \
115 --opencl-insts-output=$(1)/opencl.std.insts-1.0.inc \
116 --operand-kinds-output=$(1)/operand.kinds-1.0.inc
117 @echo "[$(TARGET_ARCH_ABI)] Grammar v1.0 : instructions & operands <= grammar JSON files"
118 $(1)/core.insts-1.1.inc $(1)/operand.kinds-1.1.inc: \
119 $(LOCAL_PATH)/utils/generate_grammar_tables.py \
120 $(SPV_CORE11_GRAMMAR)
121 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
122 --spirv-core-grammar=$(SPV_CORE11_GRAMMAR) \
123 --core-insts-output=$(1)/core.insts-1.1.inc \
124 --operand-kinds-output=$(1)/operand.kinds-1.1.inc
125 @echo "[$(TARGET_ARCH_ABI)] Grammar v1.1 : instructions & operands <= grammar JSON files"
126 $(1)/core.insts-1.2.inc $(1)/operand.kinds-1.2.inc: \
127 $(LOCAL_PATH)/utils/generate_grammar_tables.py \
128 $(SPV_CORE12_GRAMMAR)
129 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
130 --spirv-core-grammar=$(SPV_CORE12_GRAMMAR) \
131 --core-insts-output=$(1)/core.insts-1.2.inc \
132 --operand-kinds-output=$(1)/operand.kinds-1.2.inc
133 @echo "[$(TARGET_ARCH_ABI)] Grammar v1.2 : instructions & operands <= grammar JSON files"
134 $(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-1.0.inc $(1)/core.insts-1.1.inc $(1)/core.insts-1.2.inc
135 $(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-1.0.inc $(1)/operand.kinds-1.1.inc $(1)/operand.kinds-1.2.inc
136 $(LOCAL_PATH)/source/ext_inst.cpp: $(1)/glsl.std.450.insts-1.0.inc $(1)/opencl.std.insts-1.0.inc
138 $(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH)))
140 define gen_spvtools_vendor_tables
141 $(call generate-file-dir,$(1)/$(2).insts.inc)
142 $(1)/$(2).insts.inc : \
143 $(LOCAL_PATH)/utils/generate_grammar_tables.py \
144 $(LOCAL_PATH)/source/extinst.$(2).grammar.json
145 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
146 --extinst-vendor-grammar=$(LOCAL_PATH)/source/extinst.$(2).grammar.json \
147 --vendor-insts-output=$(1)/$(2).insts.inc
148 @echo "[$(TARGET_ARCH_ABI)] Vendor extended instruction set: $(2) tables <= grammar"
149 $(LOCAL_PATH)/source/ext_inst.cpp: $(1)/$(2).insts.inc
151 # Vendor extended instruction sets, with grammars from SPIRV-Tools source tree.
152 SPV_NONSTANDARD_EXTINST_GRAMMARS=$(foreach F,$(wildcard $(LOCAL_PATH)/source/extinst.*.grammar.json),$(patsubst extinst.%.grammar.json,%,$(notdir $F)))
153 $(foreach E,$(SPV_NONSTANDARD_EXTINST_GRAMMARS),$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),$E)))
155 define gen_spvtools_enum_string_mapping
156 $(call generate-file-dir,$(1)/extension_enum.inc.inc)
157 $(1)/extension_enum.inc $(1)/enum_string_mapping.inc: \
158 $(LOCAL_PATH)/utils/generate_grammar_tables.py \
159 $(SPV_CORE11_GRAMMAR)
160 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
161 --spirv-core-grammar=$(SPV_CORE11_GRAMMAR) \
162 --extension-enum-output=$(1)/extension_enum.inc \
163 --enum-string-mapping-output=$(1)/enum_string_mapping.inc
164 @echo "[$(TARGET_ARCH_ABI)] Generate enum<->string mapping <= grammar JSON files"
165 # Generated header extension_enum.inc is transitively included by table.h, which is
166 # used pervasively. Capture the pervasive dependency.
167 $(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
168 : $(1)/extension_enum.inc
169 $(LOCAL_PATH)/source/enum_string_mapping.cpp: $(1)/enum_string_mapping.inc
171 $(eval $(call gen_spvtools_enum_string_mapping,$(SPVTOOLS_OUT_PATH)))
173 define gen_spvtools_build_version_inc
174 $(call generate-file-dir,$(1)/dummy_filename)
175 $(1)/build-version.inc: \
176 $(LOCAL_PATH)/utils/update_build_version.py \
177 $(LOCAL_PATH)/CHANGES
178 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/update_build_version.py \
179 $(LOCAL_PATH) $(1)/build-version.inc
180 @echo "[$(TARGET_ARCH_ABI)] Generate : build-version.inc <= CHANGES"
181 $(LOCAL_PATH)/source/software_version.cpp: $(1)/build-version.inc
183 $(eval $(call gen_spvtools_build_version_inc,$(SPVTOOLS_OUT_PATH)))
185 define gen_spvtools_generators_inc
186 $(call generate-file-dir,$(1)/dummy_filename)
187 $(1)/generators.inc: \
188 $(LOCAL_PATH)/utils/generate_registry_tables.py \
189 $(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml
190 @$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_registry_tables.py \
191 --xml=$(SPVHEADERS_LOCAL_PATH)/include/spirv/spir-v.xml \
192 --generator-output=$(1)/generators.inc
193 @echo "[$(TARGET_ARCH_ABI)] Generate : generators.inc <= spir-v.xml"
194 $(LOCAL_PATH)/source/opcode.cpp: $(1)/generators.inc
196 $(eval $(call gen_spvtools_generators_inc,$(SPVTOOLS_OUT_PATH)))
198 include $(CLEAR_VARS)
199 LOCAL_MODULE := SPIRV-Tools
200 LOCAL_C_INCLUDES := \
201 $(LOCAL_PATH)/include \
202 $(LOCAL_PATH)/source \
203 $(LOCAL_PATH)/external/spirv-headers/include \
205 LOCAL_EXPORT_C_INCLUDES := \
206 $(LOCAL_PATH)/include
207 LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror
208 LOCAL_SRC_FILES:= $(SPVTOOLS_SRC_FILES)
209 include $(BUILD_STATIC_LIBRARY)
211 include $(CLEAR_VARS)
212 LOCAL_MODULE := SPIRV-Tools-opt
213 LOCAL_C_INCLUDES := \
214 $(LOCAL_PATH)/include \
215 $(LOCAL_PATH)/source \
216 $(LOCAL_PATH)/external/spirv-headers/include \
218 LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror
219 LOCAL_STATIC_LIBRARIES:=SPIRV-Tools
220 LOCAL_SRC_FILES:= $(SPVTOOLS_OPT_SRC_FILES)
221 include $(BUILD_STATIC_LIBRARY)