Normalize passes keep spans and clean warnings
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
use crate::mir::{BasicBlockId, CompareOp, MirFunction, MirInstruction, ValueId};
|
||||
use crate::mir::{
|
||||
BasicBlockId, CompareOp, MirFunction, MirInstruction, SpannedInstruction, ValueId,
|
||||
};
|
||||
use crate::ast::Span;
|
||||
|
||||
/// Emit a MIR Compare instruction into the current block (function-level SSOT helper)
|
||||
pub fn emit_compare_func(
|
||||
@ -49,16 +52,28 @@ pub fn set_jump(f: &mut MirFunction, cur_bb: BasicBlockId, target: BasicBlockId)
|
||||
|
||||
/// Insert a PHI instruction at block head (after existing PHIs) with normalized inputs order.
|
||||
pub fn insert_phi_at_head(
|
||||
f: &mut MirFunction,
|
||||
bb_id: BasicBlockId,
|
||||
dst: ValueId,
|
||||
inputs: Vec<(BasicBlockId, ValueId)>,
|
||||
) {
|
||||
insert_phi_at_head_spanned(f, bb_id, dst, inputs, Span::unknown());
|
||||
}
|
||||
|
||||
/// Insert a PHI instruction at block head (after existing PHIs) with normalized inputs order.
|
||||
/// Allows passing a span to retain source mapping when available.
|
||||
pub fn insert_phi_at_head_spanned(
|
||||
f: &mut MirFunction,
|
||||
bb_id: BasicBlockId,
|
||||
dst: ValueId,
|
||||
mut inputs: Vec<(BasicBlockId, ValueId)>,
|
||||
span: Span,
|
||||
) {
|
||||
inputs.sort_by_key(|(bb, _)| bb.0);
|
||||
if let Some(bb) = f.get_block_mut(bb_id) {
|
||||
bb.insert_spanned_after_phis(crate::mir::SpannedInstruction {
|
||||
bb.insert_spanned_after_phis(SpannedInstruction {
|
||||
inst: MirInstruction::Phi { dst, inputs },
|
||||
span: crate::ast::Span::unknown(),
|
||||
span,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user