-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicate name when lowering
scf.if
(#30)
Fixes a bug where variables are not automatically renamed when lowered from inside the region. This, for example, comes up when lowering ```mlir func.func @main() -> i64 { %x = arith.constant false scf.if %x { %0 = arith.constant 2 : i64 } else { %0 = arith.constant 3 : i64 } %1 = arith.constant 0 : i64 return %1 : i64 } ``` to ```mlir func.func @main() -> i64 { %0 = arith.constant false cf.cond_br %0, ^bb1, ^bb2 ^bb1: %1 = arith.constant 2 : i64 cf.br ^bb3 ^bb2: %2 = arith.constant 3 : i64 cf.br ^bb3 ^bb3: %3 = arith.constant 0 : i64 return %3 : i64 } ``` Notice that the second definition of `%0` has to be renamed. Now it makes sense why MLIR always renames variables. If you don't, any variable that is inlined and has a name that is the same as another variable needs to have a new name. But say you have `%0`, `%1` and now you inline another `%0`. What name would you give it? `%0_0`? You cannot just call it `%2` because, if I'm not mistaken, LLVM will then start to complain (fair enough) because `%2` occurs before `%1`. Just ignoring names and giving everything a new ("fresh") name leads to much cleaner generated code.
- Loading branch information
1 parent
3baeddf
commit d87c4c0
Showing
21 changed files
with
510 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# xrcf | ||
|
||
<!-- This README shows up at https://crates.io/crates/xrcf --> | ||
<!-- When updating this README also update the README in the root --> | ||
|
||
The eXtensible and Reusable Compiler Framework (xrcf) is a framework for building compilers. | ||
|
||
You may be looking for: | ||
|
||
- [An high-level overview of xrcf](https://docs.rs/xrcf/latest/xrcf/) | ||
- [An example compiler built with xrcf](https://xrcf.org/blog/basic-arnoldc/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.