Skip to content

Commit 3306d0c

Browse files
committed
dedup builtins: don't dedup debug names twice
1 parent 00a1609 commit 3306d0c

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

crates/rustc_codegen_spirv/src/linker/duplicates.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,17 @@ fn make_dedupe_key(
174174
}
175175

176176
fn rewrite_inst_with_rules(inst: &mut Instruction, rules: &FxHashMap<u32, u32>) {
177-
if let Some(ref mut id) = inst.result_id {
177+
if let Some(ref mut id) = inst.result_type {
178178
// If the rewrite rules contain this ID, replace with the mapped value, otherwise don't touch it.
179179
*id = rules.get(id).copied().unwrap_or(*id);
180180
}
181-
if let Some(ref mut type_id) = inst.result_type {
182-
*type_id = rules.get(type_id).copied().unwrap_or(*type_id);
183-
}
184181
for op in &mut inst.operands {
185182
if let Some(id) = op.id_ref_any_mut() {
186183
*id = rules.get(id).copied().unwrap_or(*id);
187184
}
188185
}
189186
}
190187

191-
/// Remove duplicate `OpName` and `OpMemberName` instructions from module debug names section.
192-
fn remove_duplicate_debug_names(debug_names: &mut Vec<Instruction>) {
193-
let mut name_ids = FxHashSet::default();
194-
let mut member_name_ids = FxHashSet::default();
195-
debug_names.retain(|inst| {
196-
(inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref()))
197-
&& (inst.class.opcode != Op::MemberName
198-
|| member_name_ids.insert((
199-
inst.operands[0].unwrap_id_ref(),
200-
inst.operands[1].unwrap_literal_bit32(),
201-
)))
202-
});
203-
}
204-
205188
pub fn remove_duplicate_types(module: &mut Module) {
206189
// Keep in mind, this algorithm requires forward type references to not exist - i.e. it's a valid spir-v module.
207190

@@ -277,9 +260,17 @@ pub fn remove_duplicate_types(module: &mut Module) {
277260
module
278261
.annotations
279262
.retain(|inst| anno_set.insert(inst.assemble()));
280-
281-
// Same thing with debug names section
282-
remove_duplicate_debug_names(&mut module.debug_names);
263+
// Same thing with OpName
264+
let mut name_ids = FxHashSet::default();
265+
let mut member_name_ids = FxHashSet::default();
266+
module.debug_names.retain(|inst| {
267+
(inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref()))
268+
&& (inst.class.opcode != Op::MemberName
269+
|| member_name_ids.insert((
270+
inst.operands[0].unwrap_id_ref(),
271+
inst.operands[1].unwrap_literal_bit32(),
272+
)))
273+
});
283274
}
284275

285276
pub fn remove_duplicate_debuginfo(module: &mut Module) {
@@ -573,7 +564,6 @@ pub fn remove_duplicate_builtin_input_variables(module: &mut Module) {
573564
let _prev = var_id_to_builtin_mut.insert(var_id, builtin);
574565
}
575566
}
576-
// Rebind as immutable.
577567
var_id_to_builtin = var_id_to_builtin_mut;
578568
};
579569

@@ -606,7 +596,6 @@ pub fn remove_duplicate_builtin_input_variables(module: &mut Module) {
606596
};
607597
}
608598
}
609-
// Rebind as immutable.
610599
duplicate_vars = duplicate_in_vars_mut;
611600
};
612601

@@ -621,9 +610,6 @@ pub fn remove_duplicate_builtin_input_variables(module: &mut Module) {
621610
.retain(|op| !matches!(op, Operand::IdRef(id) if duplicate_vars.contains_key(id)));
622611
}
623612

624-
// Remove duplicate debug names after merging variables.
625-
remove_duplicate_debug_names(&mut module.debug_names);
626-
627613
// Rewrite annotations for duplicates to point at de-duplicated variables;
628614
// this will merge the annotations sets but produce duplicate annotations
629615
// (which we will remove next).

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ pub fn link(
289289
duplicates::remove_duplicate_extensions(&mut output);
290290
duplicates::remove_duplicate_capabilities(&mut output);
291291
duplicates::remove_duplicate_ext_inst_imports(&mut output);
292-
duplicates::remove_duplicate_types(&mut output);
293292
duplicates::remove_duplicate_builtin_input_variables(&mut output);
293+
duplicates::remove_duplicate_types(&mut output);
294294
// jb-todo: strip identical OpDecoration / OpDecorationGroups
295295
}
296296

0 commit comments

Comments
 (0)