Skip to content

Commit 507c6f8

Browse files
authored
Merge pull request #5138 from smowton/smowton/feature/lexical-loops
Add lexical loop analysis
2 parents b68457c + 7787803 commit 507c6f8

File tree

25 files changed

+592
-175
lines changed

25 files changed

+592
-175
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
for(int i = 0; i < 10; ++i)
5+
{
6+
++argc;
7+
}
8+
9+
return argc;
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
2 is head of \{ 2, 3, 4, 5 \(backedge\) \}
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
while(i < 10)
7+
{
8+
++i;
9+
argc--;
10+
}
11+
12+
return argc;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
2 is head of \{ 2, 3, 4, 5 \(backedge\) \}
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
do
7+
{
8+
++i;
9+
argc--;
10+
} while(i < 10);
11+
12+
return argc;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
2 is head of \{ 2, 3, 4 \(backedge\) \}
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
head:
7+
++i;
8+
argc--;
9+
if(i < 10)
10+
goto head;
11+
12+
return argc;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
2 is head of \{ 2, 3, 4 \(backedge\) \}
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
for(int i = 0; i < 5; ++i)
5+
{
6+
for(int j = 0; j < 5; ++j)
7+
{
8+
argc++;
9+
}
10+
}
11+
12+
return argc;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
2 is head of \{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 \(backedge\) \}
5+
5 is head of \{ 5, 6, 7, 8 \(backedge\) \}
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
if(argc % 2)
7+
goto head2;
8+
9+
head:
10+
argc--;
11+
head2:
12+
++i;
13+
if(i < 10)
14+
goto head;
15+
16+
return argc;
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
^Note not all loops were in lexical loop form$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
is head of
9+
^warning: ignoring
10+
--
11+
This checks that a loop with multiple entry edges is correctly identified as
12+
having an unusual form
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
head:
7+
argc--;
8+
++i;
9+
if(i < 10 && i % 2)
10+
goto head;
11+
else if(i < 10)
12+
goto head;
13+
14+
return argc;
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
^Note not all loops were in lexical loop form$
5+
^2 is head of \{ 2, 3, 4, 5 \(backedge\) \}
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
--
11+
This checks that a loop with multiple back-edges results in a
12+
warning that not all back-edges are in simple lexical loop form
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
while(i < 10)
7+
{
8+
if(argc == 5)
9+
break;
10+
++i;
11+
if(argc % 7)
12+
continue;
13+
argc--;
14+
}
15+
16+
return argc;
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
^2 is head of \{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 \(backedge\) \}$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This checks that a loop with a break edge and a continue edge nontheless
11+
gets classified as a lexical loop
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
int main(int argc, char **argv)
3+
{
4+
int i = 0;
5+
6+
while(i < 10)
7+
{
8+
++i;
9+
if(argc == 5)
10+
{
11+
++i;
12+
break;
13+
}
14+
argc--;
15+
}
16+
17+
return argc;
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
--show-lexical-loops
4+
^2 is head of \{ 2, 3, 4, 7, 8, 9 \(backedge\) \}$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This checks that we identify a loop with a "hole" as a lexical loop. The hole is made from
11+
instructions that cannot reach the back-edge (they are postdominated by a 'break' instruction)
12+
but which are lexically included in the loop.

src/analyses/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ SRC = ai.cpp \
2525
local_may_alias.cpp \
2626
local_safe_pointers.cpp \
2727
locals.cpp \
28-
natural_loops.cpp \
2928
reaching_definitions.cpp \
3029
sese_regions.cpp \
3130
static_analysis.cpp \

0 commit comments

Comments
 (0)