MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / swap_remove_block_param

Method swap_remove_block_param

cranelift/codegen/src/ir/dfg.rs:1280–1304  ·  view source on GitHub ↗

Removes `val` from `block`'s parameters by swapping it with the last parameter on `block`. Returns the position of `val` before removal. Important*: to ensure O(1) deletion, this method swaps the removed parameter with the last `block` parameter. This can disrupt all the branch instructions jumping to this `block` for which you have to change the branch argument order if necessary. Panics if `va

(&mut self, val: Value)

Source from the content-addressed store, hash-verified

1278 ///
1279 /// Panics if `val` is not a block parameter.
1280 pub fn swap_remove_block_param(&mut self, val: Value) -> usize {
1281 let (block, num) =
1282 if let ValueData::Param { num, block, .. } = ValueData::from(self.values[val]) {
1283 (block, num)
1284 } else {
1285 panic!("{val} must be a block parameter");
1286 };
1287 self.blocks[block]
1288 .params
1289 .swap_remove(num as usize, &mut self.value_lists);
1290 if let Some(last_arg_val) = self.blocks[block]
1291 .params
1292 .get(num as usize, &self.value_lists)
1293 {
1294 // We update the position of the old last arg.
1295 let mut last_arg_data = ValueData::from(self.values[last_arg_val]);
1296 if let ValueData::Param { num: old_num, .. } = &mut last_arg_data {
1297 *old_num = num;
1298 self.values[last_arg_val] = last_arg_data.into();
1299 } else {
1300 panic!("{last_arg_val} should be a Block parameter");
1301 }
1302 }
1303 num as usize
1304 }
1305
1306 /// Removes `val` from `block`'s parameters by a standard linear time list removal which
1307 /// preserves ordering. Also updates the values' data.

Callers 1

swap_remove_block_paramsFunction · 0.80

Calls 3

fromFunction · 0.85
swap_removeMethod · 0.45
getMethod · 0.45

Tested by 1

swap_remove_block_paramsFunction · 0.64