FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
binaryen/test/example/domtree.cpp at waitqueue-api · WebAssembly/binaryen · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebAssembly
/
binaryen
Public
Notifications
You must be signed in to change notification settings
Fork
881
Star
8.6k
Code
Issues
339
Pull requests
221
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
binaryen
/
test
/
example
/
domtree.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (140 loc) · 3.81 KB
Breadcrumbs
binaryen
/
test
/
example
/
domtree.cpp
Copy path
File metadata and controls
163 lines (140 loc) · 3.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
include
<
cassert
>
#
include
<
iostream
>
#
include
<
cfg/domtree.h
>
#
include
<
wasm.h
>
using
namespace
wasm
;
struct
BasicBlock
{
std::vector<BasicBlock*> in;
void
addPred
(BasicBlock* pred) { in.
push_back
(pred); }
};
struct
CFG
:
public
std
::vector<std::unique_ptr<BasicBlock>> {
BasicBlock*
add
() {
emplace_back
(std::make_unique<BasicBlock>());
return
back
().
get
();
}
void
connect
(BasicBlock* pred, BasicBlock* succ) { succ->
addPred
(pred); }
};
int
main
() {
//
An empty CFG.
{
CFG
cfg;
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
empty
());
}
//
An CFG with just an entry.
{
CFG
cfg;
cfg.
add
();
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
1
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
//
the entry has no parent.
}
//
entry -> a.
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
cfg.
connect
(entry, a);
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
2
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
0
);
//
a is dominated by the entry.
}
//
entry and a non-connected (unreachable) block.
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
2
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
Index
(-
1
));
//
unreachables have no parent.
}
//
entry -> a -> b -> c.
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
auto
* b = cfg.
add
();
auto
* c = cfg.
add
();
cfg.
connect
(entry, a);
cfg.
connect
(a, b);
cfg.
connect
(b, c);
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
4
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
0
);
assert
(domTree.
iDoms
[
2
] ==
1
);
assert
(domTree.
iDoms
[
3
] ==
2
);
}
//
An if:
//
b
//
/ \
// entry -> a d
//
\ /
//
c
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
auto
* b = cfg.
add
();
auto
* c = cfg.
add
();
auto
* d = cfg.
add
();
cfg.
connect
(entry, a);
cfg.
connect
(a, b);
cfg.
connect
(a, c);
cfg.
connect
(b, d);
cfg.
connect
(c, d);
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
5
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
0
);
//
a
assert
(domTree.
iDoms
[
2
] ==
1
);
//
b
assert
(domTree.
iDoms
[
3
] ==
1
);
//
c
assert
(domTree.
iDoms
[
4
] ==
1
);
//
d is also dominated by a.
}
//
A loop:
//
//
entry -> a -> b -> c -> d
//
^ |
//
| |
//
\---------/
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
auto
* b = cfg.
add
();
auto
* c = cfg.
add
();
auto
* d = cfg.
add
();
cfg.
connect
(entry, a);
cfg.
connect
(a, b);
cfg.
connect
(b, c);
cfg.
connect
(c, d);
cfg.
connect
(d, b);
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
5
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
0
);
//
a
assert
(domTree.
iDoms
[
2
] ==
1
);
//
b, the loop entry, is dominated by a
assert
(domTree.
iDoms
[
3
] ==
2
);
//
c, the loop "middle", is dominated by b
assert
(domTree.
iDoms
[
4
] ==
3
);
//
d, the loop "end", is dominated by c
}
//
Subsequent blocks after an unreachable one.
//
//
entry a -> b
//
//
(a is unreachable, and b is reached by a, but in unreachable code)
{
CFG
cfg;
auto
* entry = cfg.
add
();
auto
* a = cfg.
add
();
auto
* b = cfg.
add
();
cfg.
connect
(a, b);
DomTree<BasicBlock>
domTree
(cfg);
assert
(domTree.
iDoms
.
size
() ==
3
);
assert
(domTree.
iDoms
[
0
] ==
Index
(-
1
));
assert
(domTree.
iDoms
[
1
] ==
Index
(-
1
));
//
a
assert
(domTree.
iDoms
[
2
] ==
Index
(-
1
));
//
b
}
std::cout <<
"
success.
\n
"
;
}
Back
|
FazBrowse Home
|
New Git URL