@@ -127,44 +127,6 @@ def split_list_into_sublists(items):
127
127
return chuncks
128
128
129
129
130
- def uniquify_enum_cases (lst ):
131
- """Prunes duplicate enum cases from the list.
132
-
133
- Arguments:
134
- - lst: List whose elements are to be uniqued. Assumes each element is a
135
- (symbol, value) pair and elements already sorted according to value.
136
-
137
- Returns:
138
- - A list with all duplicates removed. The elements are sorted according to
139
- value and, for each value, uniqued according to symbol.
140
- original list,
141
- - A map from deduplicated cases to the uniqued case.
142
- """
143
- cases = lst
144
- uniqued_cases = []
145
- duplicated_cases = {}
146
-
147
- # First sort according to the value
148
- cases .sort (key = lambda x : x [1 ])
149
-
150
- # Then group them according to the value
151
- for _ , groups in itertools .groupby (cases , key = lambda x : x [1 ]):
152
- # For each value, sort according to the enumerant symbol.
153
- sorted_group = sorted (groups , key = lambda x : x [0 ])
154
- # Keep the "smallest" case, which is typically the symbol without extension
155
- # suffix. But we have special cases that we want to fix.
156
- case = sorted_group [0 ]
157
- for i in range (1 , len (sorted_group )):
158
- duplicated_cases [sorted_group [i ][0 ]] = case [0 ]
159
- if case [0 ] == "HlslSemanticGOOGLE" :
160
- assert len (sorted_group ) == 2 , "unexpected new variant for HlslSemantic"
161
- case = sorted_group [1 ]
162
- duplicated_cases [sorted_group [0 ][0 ]] = case [0 ]
163
- uniqued_cases .append (case )
164
-
165
- return uniqued_cases , duplicated_cases
166
-
167
-
168
130
def toposort (dag , sort_fn ):
169
131
"""Topologically sorts the given dag.
170
132
@@ -197,14 +159,12 @@ def get_next_batch(dag):
197
159
return sorted_nodes
198
160
199
161
200
- def toposort_capabilities (all_cases , capability_mapping ):
162
+ def toposort_capabilities (all_cases ):
201
163
"""Returns topologically sorted capability (symbol, value) pairs.
202
164
203
165
Arguments:
204
166
- all_cases: all capability cases (containing symbol, value, and implied
205
167
capabilities).
206
- - capability_mapping: mapping from duplicated capability symbols to the
207
- canonicalized symbol chosen for SPIRVBase.td.
208
168
209
169
Returns:
210
170
A list containing topologically sorted capability (symbol, value) pairs.
@@ -215,50 +175,23 @@ def toposort_capabilities(all_cases, capability_mapping):
215
175
# Get the current capability.
216
176
cur = case ["enumerant" ]
217
177
name_to_value [cur ] = case ["value" ]
218
- # Ignore duplicated symbols.
219
- if cur in capability_mapping :
220
- continue
221
178
222
179
# Get capabilities implied by the current capability.
223
180
prev = case .get ("capabilities" , [])
224
- uniqued_prev = set ([ capability_mapping . get ( c , c ) for c in prev ] )
181
+ uniqued_prev = set (prev )
225
182
dag [cur ] = uniqued_prev
226
183
227
184
sorted_caps = toposort (dag , lambda x : name_to_value [x ])
228
185
# Attach the capability's value as the second component of the pair.
229
186
return [(c , name_to_value [c ]) for c in sorted_caps ]
230
187
231
188
232
- def get_capability_mapping (operand_kinds ):
233
- """Returns the capability mapping from duplicated cases to canonicalized ones.
234
-
235
- Arguments:
236
- - operand_kinds: all operand kinds' grammar spec
237
-
238
- Returns:
239
- - A map mapping from duplicated capability symbols to the canonicalized
240
- symbol chosen for SPIRVBase.td.
241
- """
242
- # Find the operand kind for capability
243
- cap_kind = {}
244
- for kind in operand_kinds :
245
- if kind ["kind" ] == "Capability" :
246
- cap_kind = kind
247
-
248
- kind_cases = [(case ["enumerant" ], case ["value" ]) for case in cap_kind ["enumerants" ]]
249
- _ , capability_mapping = uniquify_enum_cases (kind_cases )
250
-
251
- return capability_mapping
252
-
253
-
254
- def get_availability_spec (enum_case , capability_mapping , for_op , for_cap ):
189
+ def get_availability_spec (enum_case , for_op , for_cap ):
255
190
"""Returns the availability specification string for the given enum case.
256
191
257
192
Arguments:
258
193
- enum_case: the enum case to generate availability spec for. It may contain
259
194
'version', 'lastVersion', 'extensions', or 'capabilities'.
260
- - capability_mapping: mapping from duplicated capability symbols to the
261
- canonicalized symbol chosen for SPIRVBase.td.
262
195
- for_op: bool value indicating whether this is the availability spec for an
263
196
op itself.
264
197
- for_cap: bool value indicating whether this is the availability spec for
@@ -313,10 +246,7 @@ def get_availability_spec(enum_case, capability_mapping, for_op, for_cap):
313
246
if caps :
314
247
canonicalized_caps = []
315
248
for c in caps :
316
- if c in capability_mapping :
317
- canonicalized_caps .append (capability_mapping [c ])
318
- else :
319
- canonicalized_caps .append (c )
249
+ canonicalized_caps .append (c )
320
250
prefixed_caps = [
321
251
"SPIRV_C_{}" .format (c ) for c in sorted (set (canonicalized_caps ))
322
252
]
@@ -357,7 +287,7 @@ def get_availability_spec(enum_case, capability_mapping, for_op, for_cap):
357
287
return "{}{}{}" .format (implies , "\n " if implies and avail else "" , avail )
358
288
359
289
360
- def gen_operand_kind_enum_attr (operand_kind , capability_mapping ):
290
+ def gen_operand_kind_enum_attr (operand_kind ):
361
291
"""Generates the TableGen EnumAttr definition for the given operand kind.
362
292
363
293
Returns:
@@ -388,13 +318,12 @@ def get_case_symbol(kind_name, case_name):
388
318
# Special treatment for capability cases: we need to sort them topologically
389
319
# because a capability can refer to another via the 'implies' field.
390
320
kind_cases = toposort_capabilities (
391
- operand_kind ["enumerants" ], capability_mapping
321
+ operand_kind ["enumerants" ]
392
322
)
393
323
else :
394
324
kind_cases = [
395
325
(case ["enumerant" ], case ["value" ]) for case in operand_kind ["enumerants" ]
396
326
]
397
- kind_cases , _ = uniquify_enum_cases (kind_cases )
398
327
max_len = max ([len (symbol ) for (symbol , _ ) in kind_cases ])
399
328
400
329
# Generate the definition for each enum case
@@ -412,7 +341,6 @@ def get_case_symbol(kind_name, case_name):
412
341
value = int (case_pair [1 ])
413
342
avail = get_availability_spec (
414
343
name_to_case_dict [name ],
415
- capability_mapping ,
416
344
False ,
417
345
kind_name == "Capability" ,
418
346
)
@@ -648,11 +576,9 @@ def update_td_enum_attrs(path, operand_kinds, filter_list):
648
576
]
649
577
filter_list .extend (existing_kinds )
650
578
651
- capability_mapping = get_capability_mapping (operand_kinds )
652
-
653
579
# Generate definitions for all enums in filter list
654
580
defs = [
655
- gen_operand_kind_enum_attr (kind , capability_mapping )
581
+ gen_operand_kind_enum_attr (kind )
656
582
for kind in operand_kinds
657
583
if kind ["kind" ] in filter_list
658
584
]
@@ -762,7 +688,7 @@ def get_description(text, appendix):
762
688
763
689
764
690
def get_op_definition (
765
- instruction , opname , doc , existing_info , capability_mapping , settings
691
+ instruction , opname , doc , existing_info , settings
766
692
):
767
693
"""Generates the TableGen op definition for the given SPIR-V instruction.
768
694
@@ -771,8 +697,6 @@ def get_op_definition(
771
697
- doc: the instruction's SPIR-V HTML doc
772
698
- existing_info: a dict containing potential manually specified sections for
773
699
this instruction
774
- - capability_mapping: mapping from duplicated capability symbols to the
775
- canonicalized symbol chosen for SPIRVBase.td
776
700
777
701
Returns:
778
702
- A string containing the TableGen op definition
@@ -840,7 +764,7 @@ def get_op_definition(
840
764
operands = instruction .get ("operands" , [])
841
765
842
766
# Op availability
843
- avail = get_availability_spec (instruction , capability_mapping , True , False )
767
+ avail = get_availability_spec (instruction , True , False )
844
768
if avail :
845
769
avail = "\n \n {0}" .format (avail )
846
770
@@ -1021,7 +945,7 @@ def extract_td_op_info(op_def):
1021
945
1022
946
1023
947
def update_td_op_definitions (
1024
- path , instructions , docs , filter_list , inst_category , capability_mapping , settings
948
+ path , instructions , docs , filter_list , inst_category , settings
1025
949
):
1026
950
"""Updates SPIRVOps.td with newly generated op definition.
1027
951
@@ -1030,8 +954,6 @@ def update_td_op_definitions(
1030
954
- instructions: SPIR-V JSON grammar for all instructions
1031
955
- docs: SPIR-V HTML doc for all instructions
1032
956
- filter_list: a list containing new opnames to include
1033
- - capability_mapping: mapping from duplicated capability symbols to the
1034
- canonicalized symbol chosen for SPIRVBase.td.
1035
957
1036
958
Returns:
1037
959
- A string containing all the TableGen op definitions
@@ -1079,7 +1001,6 @@ def update_td_op_definitions(
1079
1001
opname ,
1080
1002
docs [fixed_opname ],
1081
1003
op_info_dict .get (opname , {"inst_category" : inst_category }),
1082
- capability_mapping ,
1083
1004
settings ,
1084
1005
)
1085
1006
)
@@ -1186,14 +1107,12 @@ def update_td_op_definitions(
1186
1107
if args .new_inst is not None :
1187
1108
assert args .op_td_path is not None
1188
1109
docs = get_spirv_doc_from_html_spec (ext_html_url , args )
1189
- capability_mapping = get_capability_mapping (operand_kinds )
1190
1110
update_td_op_definitions (
1191
1111
args .op_td_path ,
1192
1112
instructions ,
1193
1113
docs ,
1194
1114
args .new_inst ,
1195
1115
args .inst_category ,
1196
- capability_mapping ,
1197
1116
args ,
1198
1117
)
1199
1118
print ("Done. Note that this script just generates a template; " , end = "" )
0 commit comments