0xMiden / 0xMiden/compiler

Implement peephole optimizer

未关闭
#31 0 条评论 0 个 reaction 已指派 1 人 已被 @bitwalker 认领 在 GitHub 查看
codegen good first issue optimization
主要语言
Rust
星标
115
派生
84
平均合并
1 天 8 小时
30 天内合并 PR
15

描述

This is the first optimization pass I think we'll want to implement as we start to observe less-than-ideal instruction sequences in the generated MASM. Such sequences are likely to occur as an artifact of the stackification algorithm. Rather than add more complexity to that pass, it is more beneficial to post-process the output of the pass and collapse inefficient instruction sequences into more efficient forms using peephole optimization. We can then use this to inform changes to the stackification pass, by focusing on things which are not easily resolved by the peephole optimizer.

In particular, I'm expecting the following to be good candidates for this:

```[tasklist]
### Possible Optimizations
- [ ] Inefficient/noisy stack manipulation, e.g. `movup.4, drop, movup.3, drop, movup.2 drop, swap.1, drop` could become `swapw.1, dropw`
- [ ] Redundant/useless stack manipulation, e.g. `swap.1, swap.1` could be elided completely as such a sequence has no effect
- [ ] Inefficient arithmetic, e.g. `add.1, add.1` could become simply `add.2`
- [ ] Redundant arithmetic, e.g. `add.1, sub.1` could be elided completely
- [ ] Dead stores, e.g. `push.1, store.addr, push.2 store.addr` could be reduced to `push.2, store.addr` as the first store is never read
```

Some of these we could implement at a higher-level on the IR prior to stackification, but we'll want at least some degree of peephole optimization to clean up the output of stackification.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。