1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use super::{ast::*, cfg::BlockCFG};

/// Returns true if anything changed
pub fn optimize(cfg: &mut BlockCFG) -> bool {
    let mut changed = false;
    for block in cfg.blocks_mut().values_mut() {
        let old_block = std::mem::take(block);
        let old_len = old_block.len();
        *block = old_block
            .into_iter()
            .filter(|c| !c.value.is_unit())
            .collect::<BasicBlock>();
        changed = changed || old_len != block.len();
    }
    changed
}