灵符lingfu

ling-mir

↓ 0 downloads

Mid-level IR with real optimization passes

Keywords mir, compiler, optimizer, ir
lingfu install ling-mir
LicenseApache-2.0 OR MIT
AuthorsLing Lin, Sanny Lin
READMECode / FilesVersionsDependency GraphDependentsSecurityBuildsSettings

Code / Files (29)

src/optimizations/redundant_branch.rs
use super::Transform;
use crate::ir::*;

pub struct RedundantBranch;

impl Transform for RedundantBranch {
    fn run(&self, func: &mut MirFunction) -> bool {
        let mut changed = false;
        for bb in &mut func.basic_blocks {
            if let Some(term) = &mut bb.terminator {
                if let TerminatorKind::SwitchInt { targets, otherwise, .. } = &term.kind {
                    if targets.iter().all(|(_, t)| *t == *otherwise) {
                        let target = *otherwise;
                        term.kind = TerminatorKind::Goto { target };
                        changed = true;
                    }
                }
            }
        }
        changed
    }
}

← Back to index