小编Ahm*_*mud的帖子

更好的方式来模式匹配带有 Rust 的窥视孔装配说明窗口?

所以我试图实现窥视孔优化,我从 a 开始Vec<LLStackInstruction> -> Vec<LLStackInstruction>,返回的列表被优化。(LL对于低级)我们的编译器被建模为抽象堆栈机,对于 init/assign,我们将 RHS 压入堆栈,将 LHS 的 addr 压入堆栈,然后弹出和 STR,但尝试将其减少为压入 RHS,然后存储到直接通过地址说明符来寻址,但我得到了一个非常丑陋的匹配,如下所示:(并且具有可变性)

pub fn peephole_optimiser(instrs: Vec<LLStackInstruction>) -> Vec<LLStackInstruction> {
    let mut optimized_instructions: Vec<LLStackInstruction> = Vec::new();

    let mut iter = instrs.iter().peekable();

    while let Some(instruction) = iter.next() {
        let window_iter = iter.clone();
        let window: Vec<_> = [vec![instruction], window_iter.take(10).collect()].concat();
        
        if let Some(LLStackInstruction::Push(Register::FP)) = window.get(0) {
            if let Some(LLStackInstruction::Mov(Condition::None, r1, ArgType::Imm(n))) = window.get(1) {
                if let Some(LLStackInstruction::Push(r2)) = window.get(2) {
                    if let Some(LLStackInstruction::Pop(_)) = window.get(3) {
                        if let …
Run Code Online (Sandbox Code Playgroud)

compiler-construction assembly compiler-optimization rust peephole-optimization

2
推荐指数
1
解决办法
93
查看次数