Skip to content

Commit

Permalink
Fix errors in IL documentation
Browse files Browse the repository at this point in the history
* fix the expression being used in the IL example
* provide a clearer ASCII diagram for IL example
* fix minor typos

Signed-off-by: Daryl Maier <maier@ca.ibm.com>
  • Loading branch information
0xdaryl committed Jan 29, 2021
1 parent 5ad8273 commit 097669b
Showing 1 changed file with 53 additions and 24 deletions.
77 changes: 53 additions & 24 deletions doc/compiler/il/IntroToTrees.md
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2016, 2017 IBM Corp. and others
Copyright (c) 2016, 2021 IBM Corp. and others
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -116,33 +116,62 @@ pattern-matching on the DAGs.



### Representation of `(a+b)*(a-b)`

The following two figures show matching representations of the same expression,
after some common sub-expression elimination has ocurred.

treetop----> istore a
|
imul--- isub---------+
| |
iadd |
| |
+-----> iload b <--+
| |
+-----> iload a <--+

This can be re-represented as textual representation. Note the node identifiers
in the leftmost column, which show how `n4` and `n5` have been reused.

### Example IL Representation

The following two figures show matching representations of the same expression
`a = (a+b) * (a-b)` after some common sub-expression elimination has occurred.

```
+---------+
| treetop |
+----+----+
|
| +----------+
+----->+ istore a | n1
+----+-----+
|
| +------+
+---->+ imul | n2
+---+--+
|
| +------+
+--->+ iadd | n3
| +---+--+
| |
| | +---------+
| +--------+--------->+ iload a | n4
| | ^ +---------+
| | |
| | | +---------+
| +--------------+--->+ iload b | n5
| | ^ +---------+
| | |
| +------+ | |
+--->+ isub | n6 | |
+---+--+ | |
| | |
| | |
+--------+ |
| |
| |
| |
+--------------+
```

This can be represented textually as well. Note the node identifiers
in the leftmost column which show how `n4` and `n5` have been reused.

```
n1 istore <a>
n2 imul
n3 iadd
n4 iload <b>
n5 iload <c>
n4 iload <a>
n5 iload <b>
n6 isub
n4 ==>iload <b>
n5 ==>iload <c>

n4 ==>iload <a>
n5 ==>iload <b>
```

## Basic Blocks

Expand Down

0 comments on commit 097669b

Please sign in to comment.