Skip to content

Commit 6db659d

Browse files
authored
Add instruction printingClass value to InstructionDesc (KhronosGroup#6118)
The compressed tables content now goes to: core_tables_headers.h, included by table2.h core_tables_body.h, included by table2.cpp Fixes: KhronosGroup#6067
1 parent c0fa1ef commit 6db659d

File tree

8 files changed

+159
-58
lines changed

8 files changed

+159
-58
lines changed

Android.mk

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ SPV_CLDEBUGINFO100_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extin
207207
SPV_VKDEBUGINFO100_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/extinst.nonsemantic.shader.debuginfo.100.grammar.json
208208

209209
define gen_spvtools_grammar_tables
210-
$(call generate-file-dir,$(1)/core_tables.inc)
211-
$(1)/core_tables.inc \
210+
$(call generate-file-dir,$(1)/core_tables_body.inc)
211+
$(1)/core_tables_body.inc \
212+
$(1)/core_tables_header.inc \
212213
: \
213214
$(LOCAL_PATH)/utils/generate_grammar_tables.py \
214215
$(SPV_COREUNIFIED1_GRAMMAR) \
@@ -218,9 +219,13 @@ $(1)/core_tables.inc \
218219
--spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
219220
--extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
220221
--extinst-cldebuginfo100-grammar=$(SPV_CLDEBUGINFO100_GRAMMAR) \
221-
--core-tables-output=$(1)/core_tables.inc
222-
@echo "[$(TARGET_ARCH_ABI)] Grammar (from unified1) : instructions & operands <= grammar JSON files"
223-
$(LOCAL_PATH)/source/table2.cpp: $(1)/core_tables.inc
222+
--core-tables-body-output=$(1)/core_tables_body.inc \
223+
--core-tables-header-output=$(1)/core_tables_header.inc
224+
@echo "[$(TARGET_ARCH_ABI)] Grammar from unified1) : instructions & operands <= grammar JSON files"
225+
# Make all source files depend on the generated core tables
226+
$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
227+
: $(1)/core_tables_body.inc \
228+
$(1)/core_tables_header.inc
224229
$(LOCAL_PATH)/source/ext_inst.cpp: \
225230
$(1)/glsl.std.450.insts.inc \
226231
$(1)/opencl.std.100.insts.inc \

BUILD.gn

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ action("spvtools_core_tables") {
4242
"${spirv_headers}/include/spirv/unified1/extinst.debuginfo.grammar.json"
4343
cldebuginfo100_insts_file = "${spirv_headers}/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"
4444

45-
core_tables_file = "${target_gen_dir}/core_tables.inc"
45+
core_tables_body_file = "${target_gen_dir}/core_tables_body.inc"
46+
core_tables_header_file = "${target_gen_dir}/core_tables_header.inc"
4647

4748
sources = [
4849
cldebuginfo100_insts_file,
4950
core_json_file,
5051
debuginfo_insts_file,
5152
]
5253
outputs = [
53-
core_tables_file,
54+
core_tables_body_file,
55+
core_tables_header_file,
5456
]
5557
args = [
5658
"--spirv-core-grammar",
@@ -59,8 +61,10 @@ action("spvtools_core_tables") {
5961
rebase_path(debuginfo_insts_file, root_build_dir),
6062
"--extinst-cldebuginfo100-grammar",
6163
rebase_path(cldebuginfo100_insts_file, root_build_dir),
62-
"--core-tables-output",
63-
rebase_path(core_tables_file, root_build_dir)
64+
"--core-tables-body-output",
65+
rebase_path(core_tables_body_file, root_build_dir),
66+
"--core-tables-header-output",
67+
rebase_path(core_tables_header_file, root_build_dir)
6468
]
6569
}
6670

build_defs.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ def generate_compressed_tables():
101101
)
102102

103103
outs = dict(
104-
core_tables_output = "core_tables.inc",
104+
core_tables_header_output = "core_tables_header.inc",
105+
core_tables_body_output = "core_tables_body.inc",
105106
)
106107

107108
cmd = (
108109
"$(location :ggt)" +
109110
" --spirv-core-grammar=$(location {core_grammar})" +
110111
" --extinst-debuginfo-grammar=$(location {debuginfo_grammar})" +
111112
" --extinst-cldebuginfo100-grammar=$(location {cldebuginfo_grammar})" +
112-
" --core-tables-output=$(location {core_tables_output})"
113+
" --core-tables-body-output=$(location {core_tables_body_output})" +
114+
" --core-tables-header-output=$(location {core_tables_header_output})"
113115
).format(**_merge_dicts([grammars, outs]))
114116

115117
native.genrule(

source/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ set(DEBUGINFO_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/exti
2424
set(CLDEBUGINFO100_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json")
2525
set(VKDEBUGINFO100_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.nonsemantic.shader.debuginfo.100.grammar.json")
2626

27-
set(CORE_TABLES_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables.inc)
28-
add_custom_command(OUTPUT ${CORE_TABLES_INC_FILE}
27+
set(CORE_TABLES_BODY_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_body.inc)
28+
set(CORE_TABLES_HEADER_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_header.inc)
29+
add_custom_command(OUTPUT ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_FILE}
2930
COMMAND Python3::Interpreter ${GGT_SCRIPT}
3031
--spirv-core-grammar=${SPIRV_CORE_GRAMMAR_JSON_FILE}
3132
--extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
3233
--extinst-cldebuginfo100-grammar=${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
33-
--core-tables-output=${CORE_TABLES_INC_FILE}
34+
--core-tables-body-output=${CORE_TABLES_BODY_INC_FILE}
35+
--core-tables-header-output=${CORE_TABLES_HEADER_INC_FILE}
3436
DEPENDS ${GGT_SCRIPT}
3537
${SPIRV_CORE_GRAMMAR_JSON_FILE}
3638
${DEBUGINFO_GRAMMAR_JSON_FILE}
3739
${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
3840
COMMENT "Generate core tables")
39-
add_custom_target(spirv-tools-tables DEPENDS ${CORE_TABLES_INC_FILE})
41+
add_custom_target(spirv-tools-tables DEPENDS ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_FILE})
4042

4143
macro(spvtools_enum_string_mapping CONFIG_VERSION)
4244
set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
@@ -144,7 +146,10 @@ list(APPEND OPCODE_CPP_DEPENDS ${GENERATOR_INC_FILE})
144146
# We need to wrap the .inc files with a custom target to avoid problems when
145147
# multiple targets depend on the same custom command.
146148
add_custom_target(core_tables
147-
DEPENDS ${OPCODE_CPP_DEPENDS} ${OPERAND_CPP_DEPENDS} ${CORE_TABLES_INC_FILE})
149+
DEPENDS ${OPCODE_CPP_DEPENDS}
150+
${OPERAND_CPP_DEPENDS}
151+
${CORE_TABLES_BODY_INC_FILE}
152+
${CORE_TABLES_HEADER_INC_FILE})
148153
add_custom_target(enum_string_mapping
149154
DEPENDS ${EXTENSION_H_DEPENDS} ${ENUM_STRING_MAPPING_CPP_DEPENDS})
150155
add_custom_target(extinst_tables

source/table2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ IndexRange OperandByValueRangeForKind(spv_operand_type_t type);
9494
// Returns the name of an extension, as an index into kStrings
9595
IndexRange ExtensionToIndexRange(Extension extension);
9696

97-
#include "core_tables.inc"
97+
#include "core_tables_body.inc"
9898

9999
// Returns a pointer to the null-terminated C-style string in the global
100100
// strings table, as referenced by 'ir'. Assumes the given range is valid.

source/table2.h

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
// - a spv::Op opcode
5959
// - a bool hasResult
6060
// - a bool hasType
61+
// - a printing class
6162
//
6263
// The arrays are represented by spans into a global static array, with one
6364
// array for each of:
@@ -82,6 +83,8 @@
8283

8384
namespace spvtools {
8485

86+
#include "core_tables_header.inc"
87+
8588
using IndexRange = utils::IndexRange<uint32_t, uint32_t>;
8689

8790
// Describes a SPIR-V operand.
@@ -100,8 +103,8 @@ struct OperandDesc {
100103
// Minimal core SPIR-V version required for this feature, if without
101104
// extensions. ~0u means reserved for future use. ~0u and non-empty
102105
// extension lists means only available in extensions.
103-
const uint32_t minVersion;
104-
const uint32_t lastVersion;
106+
const uint32_t minVersion = 0xFFFFFFFFu;
107+
const uint32_t lastVersion = 0xFFFFFFFFu;
105108
utils::Span<const spv_operand_type_t> operands() const;
106109
utils::Span<const char> name() const;
107110
utils::Span<const IndexRange> aliases() const;
@@ -119,15 +122,7 @@ struct OperandDesc {
119122
minVersion(mv),
120123
lastVersion(lv) {}
121124

122-
OperandDesc(uint32_t v)
123-
: value(v),
124-
operands_range(),
125-
name_range(),
126-
aliases_range(),
127-
capabilities_range(),
128-
extensions_range(),
129-
minVersion(0u),
130-
lastVersion(0u) {}
125+
OperandDesc(uint32_t v) : value(v) {}
131126

132127
OperandDesc(const OperandDesc&) = delete;
133128
OperandDesc(OperandDesc&&) = delete;
@@ -136,8 +131,8 @@ struct OperandDesc {
136131
// Describes an Instruction
137132
struct InstructionDesc {
138133
const spv::Op opcode;
139-
const bool hasResult;
140-
const bool hasType;
134+
const bool hasResult = false;
135+
const bool hasType = false;
141136

142137
const IndexRange operands_range; // Indexes kOperandSpans
143138
const IndexRange name_range; // Indexes kStrings
@@ -151,8 +146,11 @@ struct InstructionDesc {
151146
// Minimal core SPIR-V version required for this feature, if without
152147
// extensions. ~0u means reserved for future use. ~0u and non-empty
153148
// extension lists means only available in extensions.
154-
const uint32_t minVersion;
155-
const uint32_t lastVersion;
149+
const uint32_t minVersion = 0xFFFFFFFFu;
150+
const uint32_t lastVersion = 0xFFFFFFFFu;
151+
// The printing class specifies what kind of instruction it is, e.g. what
152+
// section of the SPIR-V spec. E.g. kImage, kComposite
153+
const PrintingClass printingClass = PrintingClass::kReserved;
156154
// Returns the span of elements in the global grammar tables corresponding
157155
// to the privately-stored index ranges
158156
utils::Span<const spv_operand_type_t> operands() const;
@@ -163,7 +161,7 @@ struct InstructionDesc {
163161

164162
InstructionDesc(spv::Op oc, bool hr, bool ht, IndexRange o, IndexRange n,
165163
IndexRange a, IndexRange c, IndexRange e, uint32_t mv,
166-
uint32_t lv)
164+
uint32_t lv, PrintingClass pc)
167165
: opcode(oc),
168166
hasResult(hr),
169167
hasType(ht),
@@ -173,19 +171,10 @@ struct InstructionDesc {
173171
capabilities_range(c),
174172
extensions_range(e),
175173
minVersion(mv),
176-
lastVersion(lv) {}
174+
lastVersion(lv),
175+
printingClass(pc) {}
177176

178-
InstructionDesc(spv::Op oc)
179-
: opcode(oc),
180-
hasResult(false),
181-
hasType(false),
182-
operands_range(),
183-
name_range(),
184-
aliases_range(),
185-
capabilities_range(),
186-
extensions_range(),
187-
minVersion(0u),
188-
lastVersion(0u) {}
177+
InstructionDesc(spv::Op oc) : opcode(oc) {}
189178

190179
InstructionDesc(const InstructionDesc&) = delete;
191180
InstructionDesc(InstructionDesc&&) = delete;

test/opcode_lookup_test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,59 @@ TEST(OpcodeLookupExtInstTest, Operands) {
174174
SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER}));
175175
}
176176

177+
// Test printingClass
178+
179+
struct OpcodePrintingClassCase {
180+
std::string name;
181+
PrintingClass expected;
182+
};
183+
184+
std::ostream& operator<<(std::ostream& os,
185+
const OpcodePrintingClassCase& opcc) {
186+
os << "OPCC('" << opcc.name << "', " << static_cast<int>(opcc.expected)
187+
<< ")";
188+
return os;
189+
}
190+
191+
using OpcodePrintingClassTest =
192+
::testing::TestWithParam<OpcodePrintingClassCase>;
193+
194+
TEST_P(OpcodePrintingClassTest, OpcodeLookup_ByName) {
195+
InstructionDesc* desc = nullptr;
196+
auto status = LookupOpcode(GetParam().name.data(), &desc);
197+
EXPECT_EQ(status, SPV_SUCCESS);
198+
ASSERT_NE(desc, nullptr);
199+
EXPECT_EQ(desc->printingClass, GetParam().expected);
200+
}
201+
202+
INSTANTIATE_TEST_SUITE_P(
203+
Samples, OpcodePrintingClassTest,
204+
ValuesIn(std::vector<OpcodePrintingClassCase>{
205+
{"ConstantFunctionPointerINTEL", PrintingClass::k_exclude},
206+
{"Nop", PrintingClass::kMiscellaneous},
207+
{"SourceContinued", PrintingClass::kDebug},
208+
{"Decorate", PrintingClass::kAnnotation},
209+
{"Extension", PrintingClass::kExtension},
210+
{"MemoryModel", PrintingClass::kMode_Setting},
211+
{"Variable", PrintingClass::kMemory},
212+
{"CooperativeMatrixPerElementOpNV", PrintingClass::kFunction},
213+
{"SampledImage", PrintingClass::kImage},
214+
{"ConvertFToU", PrintingClass::kConversion},
215+
{"VectorExtractDynamic", PrintingClass::kComposite},
216+
{"IAdd", PrintingClass::kArithmetic},
217+
{"ShiftRightLogical", PrintingClass::kBit},
218+
{"Any", PrintingClass::kRelational_and_Logical},
219+
{"DPdx", PrintingClass::kDerivative},
220+
{"Branch", PrintingClass::kControl_Flow},
221+
{"AtomicLoad", PrintingClass::kAtomic},
222+
{"ControlBarrier", PrintingClass::kBarrier},
223+
{"GroupAll", PrintingClass::kGroup},
224+
{"EnqueueMarker", PrintingClass::kDevice_Side_Enqueue},
225+
{"ReadPipe", PrintingClass::kPipe},
226+
{"GroupNonUniformElect", PrintingClass::kNon_Uniform},
227+
// Skipping "Reserved" because it's probably an
228+
// unstable class.
229+
}));
230+
177231
} // namespace
178232
} // namespace spvtools

0 commit comments

Comments
 (0)