Insert `inst` before the instruction `before` in the same block.
(&mut self, inst: Inst, before: Inst)
| 472 | |
| 473 | /// Insert `inst` before the instruction `before` in the same block. |
| 474 | pub fn insert_inst(&mut self, inst: Inst, before: Inst) { |
| 475 | debug_assert_eq!(self.inst_block(inst), None); |
| 476 | let block = self |
| 477 | .inst_block(before) |
| 478 | .expect("Instruction before insertion point not in the layout"); |
| 479 | let after = self.insts[before].prev; |
| 480 | { |
| 481 | let inst_node = &mut self.insts[inst]; |
| 482 | inst_node.block = block.into(); |
| 483 | inst_node.next = before.into(); |
| 484 | inst_node.prev = after; |
| 485 | } |
| 486 | self.insts[before].prev = inst.into(); |
| 487 | match after.expand() { |
| 488 | None => self.blocks[block].first_inst = inst.into(), |
| 489 | Some(a) => self.insts[a].next = inst.into(), |
| 490 | } |
| 491 | self.assign_inst_seq(inst); |
| 492 | } |
| 493 | |
| 494 | /// Remove `inst` from the layout. |
| 495 | pub fn remove_inst(&mut self, inst: Inst) { |