-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SSA] Fix up to_ssa.py and add test cases #119
base: main
Are you sure you want to change the base?
Conversation
to_ssa.py
and add test cases
I think the allowance of undefined variables in I think that there are two logical choices, and anything in the middle will cause headaches:
|
Cool! This is probably much cleaner than my approach. The end result is the same, having to define an |
examples/to_ssa.py
Outdated
|
||
def insert_undefined_vars(blocks, types): | ||
entry = list(blocks.keys())[0] | ||
types = sorted(set(types.values())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will crash when using memory. For example,
bril/benchmarks/eight-queens.bril
Line 6 in dbbd8e8
site: ptr<int> = alloc n; |
bril2json < benchmarks/eight-queens.bril | python3 examples/to_ssa.py
The pointer type is stored in a
dict
, and thus unhashable.
Reference: https://capra.cs.cornell.edu/bril/lang/memory.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, is this something that to_ssa.py
should support? If so I can add it. There currently isn't a null
value for pointers, but I suppose alloc 0;
would work, and just never free
.
65fc822
to
c89a009
Compare
I've added support for the memory extension to I've decided to use |
* Null pointers are created by `alloc 0`. * All null pointers share the same key `Key(0, 0)`. * Freeing a null pointer is a no-op. * Null pointers do not need to be freed. * Reading/writing a null pointer is an error. * Pointer addition is allowed on null pointers.
The use of `defaultdict()` and `stack.update(old_stack)` meant that any stacks that were empty at the top of `_rename()` weren't cleared at the bottom. This caused use of undefined variables inserted into `phi` instead of `__undefined`. The fix is to copy the stack at the top of _rename(). This is just as efficient as before (not very efficient).
Break undefined variables up by type, to meet the bril spec that each variable has only one type. Then, define the undefined variable for each type in the entry block. This ensures that no phi node uses undefined variables, or produces undefined variables, in any case. Add an interesting test case `loop-branch.bril` which produces phi nodes that form a dependency loop.
Add `brili` test cases, since I want to test that no undefined varaibles are used during execution after `from_ssa`.
This is similar to the functional stack passing fix in #119 but has a smaller fix (just clobber the stacks altogether before restoring the old values; previously we just overwrote the new variables).
More tests and a fix for SSA conversion (from #119)
This PR contains 4 commits detailed below. In summary the goal is to remove all uses of undefined variables. It fixes all the problems of Issue #108. It is done in 3 steps:
null
pointers tobrili
andbrilirs
, created withalloc 0
.rename()
that caused references to undefined variables (not__undefined
) to be emitted.__undefined.${type}
for each type at the top of the entry block, and use__undefined.${type}
instead of__undefined
.After these steps
phi
nodes no longer have undefined arguments, and no longer produce undefined results. The ability to executephi
nodes with undefined or missing arguments could be removed frombrili
, or hidden behind a flag (but I haven't done that).I added one test case
to_ssa/
calledloop-branch.bril
which has an interesting feature where two phis form a dependency loop:v.0
depends onv.1
and visa-versa.Then I add test cases for
from_ssa.py
that executes the round-tripped code for every test into_ssa/
. I also tested on all the programs in thebenchmarks
directory, and it works on everything in that directory. I haven't added them to thefrom_ssa
tests to avoid adding overly complex tests.This newly generated code inserts potentially unnecessary
__undefined.${type}
definitions. A DCE pass can trivially remove the unnecessary ones.[brili][memory] Support null pointers
alloc 0
.Key(0, 0)
.[to_ssa] Fix bug in rename()
The use of
defaultdict()
andstack.update(old_stack)
meant that anystacks that were empty at the top of
_rename()
weren't cleared at thebottom. This caused use of undefined variables inserted into
phi
instead of
__undefined
.[to_ssa] Define undefined variables
Break undefined variables up by type, to meet the bril spec that each
variable has only one type. Then, define the undefined variable for each
type in the entry block. This ensures that no phi node uses undefined
variables, or produces undefined variables, in any case.
Add an interesting test case
loop-branch.bril
which produces phi nodesthat form a dependency loop.
[from_ssa] Add test cases
Add
brili
test cases, since I want to test that no undefined varaiblesare used during execution after
from_ssa
.