Convert Souper optimizations into Peepmatic DSL

Conversion from Souper into Peepmatic is implemented with a straightforward,
top-down recursive traversal of the optimization's left- and right-hand side
expression DAGs. Most Souper instructions have a corresponding Peepmatic
instruction. If we run into an instruction where that isn't the case, we skip
that Souper optimization and move on to the next one.

Note that Souper fully supports DAGs, for example:

```text
%0 = var
%1 = add 1, %0
%2 = add %1, %1       ;; Two edges to `%1` makes this a DAG.
```

On the other hand, Peepmatic only currently supports trees, so shared
subexpressions are duplicated:

```text
(iadd (iadd 1 $x)
      (iadd 1 $x))    ;; The shared subexpression is duplicated.
```

This does not affect correctness.
This commit is contained in:
Nick Fitzgerald
2020-09-10 12:59:38 -07:00
parent 443965b95d
commit 091de9449a
3 changed files with 741 additions and 0 deletions

23
Cargo.lock generated
View File

@@ -971,6 +971,12 @@ dependencies = [
"quick-error",
]
[[package]]
name = "id-arena"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "indexmap"
version = "1.4.0"
@@ -1330,6 +1336,14 @@ dependencies = [
[[package]]
name = "peepmatic-souper"
version = "0.66.0"
dependencies = [
"anyhow",
"log",
"peepmatic",
"peepmatic-test-operator",
"souper-ir",
"wast",
]
[[package]]
name = "peepmatic-test"
@@ -1925,6 +1939,15 @@ version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
[[package]]
name = "souper-ir"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "163cc2bdd8a66cbaccdf06a6b476689a97e928883e09bffbe06fd5945842a83f"
dependencies = [
"id-arena",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"