-
-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
167 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from vyper.venom.analysis.analysis import IRAnalysesCache | ||
from vyper.venom.basicblock import IRBasicBlock, IRLabel, IRLiteral | ||
from vyper.venom.context import IRContext | ||
from vyper.venom.passes.sccp import SCCP | ||
from vyper.venom.passes.simplify_cfg import SimplifyCFGPass | ||
|
||
|
||
def test_phi_reduction_after_block_pruning(): | ||
ctx = IRContext() | ||
fn = ctx.create_function("_global") | ||
|
||
bb = fn.get_basic_block() | ||
|
||
br1 = IRBasicBlock(IRLabel("then"), fn) | ||
fn.append_basic_block(br1) | ||
br2 = IRBasicBlock(IRLabel("else"), fn) | ||
fn.append_basic_block(br2) | ||
|
||
join = IRBasicBlock(IRLabel("join"), fn) | ||
fn.append_basic_block(join) | ||
|
||
true = IRLiteral(1) | ||
bb.append_instruction("jnz", true, br1.label, br2.label) | ||
|
||
op1 = br1.append_instruction("store", 1) | ||
op2 = br2.append_instruction("store", 2) | ||
|
||
br1.append_instruction("jmp", join.label) | ||
br2.append_instruction("jmp", join.label) | ||
|
||
join.append_instruction("phi", br1.label, op1, br2.label, op2) | ||
join.append_instruction("stop") | ||
|
||
ac = IRAnalysesCache(fn) | ||
SCCP(ac, fn).run_pass() | ||
SimplifyCFGPass(ac, fn).run_pass() | ||
|
||
bbs = list(fn.get_basic_blocks()) | ||
|
||
assert len(bbs) == 1 | ||
final_bb = bbs[0] | ||
|
||
inst0, inst1, inst2 = final_bb.instructions | ||
|
||
assert inst0.opcode == "store" | ||
assert inst0.operands == [IRLiteral(1)] | ||
assert inst1.opcode == "store" | ||
assert inst1.operands == [inst0.output] | ||
assert inst2.opcode == "stop" |
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 was deleted.
Oops, something went wrong.
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