forked from xdslproject/xdsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_use.py
61 lines (46 loc) · 1.33 KB
/
test_use.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from xdsl.context import MLContext
from xdsl.dialects.builtin import Builtin, ModuleOp
from xdsl.dialects.test import Test, TestOp
from xdsl.ir import Use
from xdsl.parser import Parser
test_prog = """
"builtin.module"() ({
%0 = "test.op"() : () -> i32
%1 = "test.op"(%0, %0) : (i32, i32) -> i32
}) : () -> ()
"""
def test_main():
ctx = MLContext()
ctx.load_dialect(Builtin)
ctx.load_dialect(Test)
parser = Parser(ctx, test_prog)
module = parser.parse_op()
module.verify()
assert isinstance(module, ModuleOp)
op1, op2 = list(module.ops)
assert op1.results[0].uses == {Use(op2, 0), Use(op2, 1)}
assert op2.results[0].uses == set()
print("Done")
test_prog_blocks = """
"test.op"() ({
"test.termop"() [^0, ^1] : () -> ()
^0:
"test.termop"()[^2] : () -> ()
^1:
"test.termop"()[^2] : () -> ()
^2:
"test.termop"() : () -> ()
}) : () -> ()
"""
def test_predecessor():
ctx = MLContext()
ctx.load_dialect(Builtin)
ctx.load_dialect(Test)
parser = Parser(ctx, test_prog_blocks)
op = parser.parse_op()
assert isinstance(op, TestOp)
block1, block2, block3, block4 = op.regions[0].blocks
assert block1.predecessors() == ()
assert block2.predecessors() == (block1,)
assert block3.predecessors() == (block1,)
assert set(block4.predecessors()) == {block2, block3}