MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / lower_cast

Method lower_cast

crates/ir-to-asm/src/compiler/compiler_rv64.rs:1674–1722  ·  view source on GitHub ↗
(&mut self, rd: Reg, rs: Reg, mode: IrCastMode, src_ty: &IrType, ty: &IrType)

Source from the content-addressed store, hash-verified

1672 then_label,
1673 else_label,
1674 } => {
1675 let cond_tmp = self.load_value_to_temp(cond, ctx);
1676 let then_lbl = ctx.get_label(then_label).unwrap().to_owned();
1677 let else_lbl = ctx.get_label(else_label).unwrap().to_owned();
1678 let then_has_phis = edges.phis.contains_key(then_label.0.as_str());
1679 let else_has_phis = edges.phis.contains_key(else_label.0.as_str());
1680 if !then_has_phis && !else_has_phis {
1681 self.emitter.emit_bne(cond_tmp, ZERO, &then_lbl);
1682 self.emitter.emit_jal(ZERO, &else_lbl);
1683 return;
1684 }
1685 // Copies belong to one edge only, so each phi-carrying target
1686 // gets a trampoline that stages the copies before jumping on.
1687 let then_edge = if then_has_phis {
1688 format!("{}__{}__phi__{}", edges.function, edges.pred, then_label)
1689 } else {
1690 then_lbl.clone()
1691 };
1692 let else_edge = if else_has_phis {
1693 format!("{}__{}__phi__{}", edges.function, edges.pred, else_label)
1694 } else {
1695 else_lbl.clone()
1696 };
1697 self.emitter.emit_bne(cond_tmp, ZERO, &then_edge);
1698 self.emitter.emit_jal(ZERO, &else_edge);
1699 if then_has_phis {
1700 self.emitter.emit_label(&then_edge);
1701 self.emit_phi_edge_copies(edges, then_label, ctx);
1702 self.emitter.emit_jal(ZERO, &then_lbl);
1703 }
1704 if else_has_phis {
1705 self.emitter.emit_label(&else_edge);
1706 self.emit_phi_edge_copies(edges, else_label, ctx);
1707 self.emitter.emit_jal(ZERO, &else_lbl);
1708 }
1709 }
1710 IrTerminator::Trap { code } => {
1711 // Exit with the diagnostic code in a0 (syscall 93). The firmware
1712 // turns this into a clean halt, so a failed check shows as that code.
1713 self.emitter.emit_raw(&format!("\tli a0, {code}"));
1714 self.emitter.emit_raw("\tli a7, 93");
1715 self.emitter.emit_raw("\tecall");
1716 }
1717 }
1718 }
1719
1720 fn lower_return(&mut self, val: Option<&IrValue>, needs_sret: bool, ctx: &mut FunctionContext) {
1721 if let Some(val) = val {
1722 let raw_val_type = self.resolve_value_type(val, ctx);
1723 // The declared return type decides the aggregate paths; the value
1724 // register may hold the bytes or only a pointer to them.
1725 let is_agg_return = matches!(

Callers 1

lower_cast_instMethod · 0.45

Calls 6

emit_mvMethod · 0.80
resolve_ir_typeMethod · 0.80
emit_slliMethod · 0.80
emit_srliMethod · 0.80
emit_addiwMethod · 0.80
emit_sraiMethod · 0.80

Tested by

no test coverage detected