Coverage Report

Created: 2024-10-16 07:58

/rust/registry/src/index.crates.io-6f17d22bba15001f/regalloc2-0.5.1/src/postorder.rs
Line
Count
Source
1
/*
2
 * Released under the terms of the Apache 2.0 license with LLVM
3
 * exception. See `LICENSE` for details.
4
 */
5
6
//! Fast postorder computation.
7
8
use crate::Block;
9
use smallvec::{smallvec, SmallVec};
10
11
139k
pub fn calculate<'a, SuccFn: Fn(Block) -> &'a [Block]>(
12
139k
    num_blocks: usize,
13
139k
    entry: Block,
14
139k
    succ_blocks: SuccFn,
15
139k
) -> Vec<Block> {
16
139k
    let mut ret = vec![];
17
139k
18
139k
    // State: visited-block map, and explicit DFS stack.
19
139k
    let mut visited = vec![];
20
139k
    visited.resize(num_blocks, false);
21
22
    struct State<'a> {
23
        block: Block,
24
        succs: &'a [Block],
25
        next_succ: usize,
26
    }
27
139k
    let mut stack: SmallVec<[State; 64]> = smallvec![];
28
29
139k
    visited[entry.index()] = true;
30
139k
    stack.push(State {
31
139k
        block: entry,
32
139k
        succs: succ_blocks(entry),
33
139k
        next_succ: 0,
34
139k
    });
35
36
680k
    while let Some(ref mut state) = stack.last_mut() {
37
        // Perform one action: push to new succ, skip an already-visited succ, or pop.
38
541k
        if state.next_succ < state.succs.len() {
39
204k
            let succ = state.succs[state.next_succ];
40
204k
            state.next_succ += 1;
41
204k
            if !visited[succ.index()] {
42
197k
                visited[succ.index()] = true;
43
197k
                stack.push(State {
44
197k
                    block: succ,
45
197k
                    succs: succ_blocks(succ),
46
197k
                    next_succ: 0,
47
197k
                });
48
197k
            }
49
336k
        } else {
50
336k
            ret.push(state.block);
51
336k
            stack.pop();
52
336k
        }
53
    }
54
55
139k
    ret
56
139k
}
regalloc2::postorder::calculate::<<regalloc2::cfg::CFGInfo>::new<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::x64::lower::isle::generated_code::MInst>>::{closure#0}>
Line
Count
Source
11
139k
pub fn calculate<'a, SuccFn: Fn(Block) -> &'a [Block]>(
12
139k
    num_blocks: usize,
13
139k
    entry: Block,
14
139k
    succ_blocks: SuccFn,
15
139k
) -> Vec<Block> {
16
139k
    let mut ret = vec![];
17
139k
18
139k
    // State: visited-block map, and explicit DFS stack.
19
139k
    let mut visited = vec![];
20
139k
    visited.resize(num_blocks, false);
21
22
    struct State<'a> {
23
        block: Block,
24
        succs: &'a [Block],
25
        next_succ: usize,
26
    }
27
139k
    let mut stack: SmallVec<[State; 64]> = smallvec![];
28
29
139k
    visited[entry.index()] = true;
30
139k
    stack.push(State {
31
139k
        block: entry,
32
139k
        succs: succ_blocks(entry),
33
139k
        next_succ: 0,
34
139k
    });
35
36
680k
    while let Some(ref mut state) = stack.last_mut() {
37
        // Perform one action: push to new succ, skip an already-visited succ, or pop.
38
541k
        if state.next_succ < state.succs.len() {
39
204k
            let succ = state.succs[state.next_succ];
40
204k
            state.next_succ += 1;
41
204k
            if !visited[succ.index()] {
42
197k
                visited[succ.index()] = true;
43
197k
                stack.push(State {
44
197k
                    block: succ,
45
197k
                    succs: succ_blocks(succ),
46
197k
                    next_succ: 0,
47
197k
                });
48
197k
            }
49
336k
        } else {
50
336k
            ret.push(state.block);
51
336k
            stack.pop();
52
336k
        }
53
    }
54
55
139k
    ret
56
139k
}
Unexecuted instantiation: regalloc2::postorder::calculate::<<regalloc2::cfg::CFGInfo>::new<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::aarch64::lower::isle::generated_code::MInst>>::{closure#0}>
Unexecuted instantiation: regalloc2::postorder::calculate::<<regalloc2::cfg::CFGInfo>::new<cranelift_codegen::machinst::vcode::VCode<cranelift_codegen::isa::riscv64::lower::isle::generated_code::MInst>>::{closure#0}>
Unexecuted instantiation: regalloc2::postorder::calculate::<_>