MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / compact_ids

Function compact_ids

crates/rustc_codegen_spirv/src/linker/simple_passes.rs:103–128  ·  view source on GitHub ↗
(module: &mut Module)

Source from the content-addressed store, hash-verified

101}
102
103pub fn compact_ids(module: &mut Module) -> u32 {
104 let mut remap = FxHashMap::default();
105
106 let mut insert = |current_id: u32| -> u32 {
107 let len = remap.len();
108 *remap.entry(current_id).or_insert_with(|| len as u32 + 1)
109 };
110
111 module.all_inst_iter_mut().for_each(|inst| {
112 if let Some(ref mut result_id) = &mut inst.result_id {
113 *result_id = insert(*result_id);
114 }
115
116 if let Some(ref mut result_type) = &mut inst.result_type {
117 *result_type = insert(*result_type);
118 }
119
120 inst.operands.iter_mut().for_each(|op| {
121 if let Some(w) = op.id_ref_any_mut() {
122 *w = insert(*w);
123 }
124 });
125 });
126
127 remap.len() as u32 + 1
128}
129
130pub fn sort_globals(module: &mut Module) {
131 // Function declarations come before definitions. TODO: Figure out if it's even possible to

Callers 2

linkFunction · 0.85
do_disassembleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected