-
Notifications
You must be signed in to change notification settings - Fork 273
Control dependency computation fix #1858
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
int a; | ||
|
||
void main(void) | ||
{ | ||
int i = 0; | ||
|
||
if(i < 10) | ||
{ | ||
a = 1; | ||
} | ||
else | ||
{ | ||
a = 2; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// First assignment has a control dependency on the if | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 1 | ||
// Second assignment has a control dependency on the if | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 2 | ||
-- | ||
^warning: ignoring | ||
-- | ||
The first regex above matches output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the goto statement. | ||
|
||
// <N> file main.c line 7 function main | ||
IF !(i < 10) THEN GOTO 1 | ||
|
||
**** 3 file main.c line 9 function main | ||
Control dependencies: <N> | ||
|
||
// 3 file main.c line 9 function main | ||
a = 1; | ||
|
||
The second regex above matches output portions like shown below (with <N> being | ||
a location number). The intention is to check whether the assignment has a | ||
control dependency on the goto statement. | ||
|
||
// <N> file main.c line 7 function main | ||
IF !(i < 10) THEN GOTO 1 | ||
... | ||
**** 5 file main.c line 13 function main | ||
Control dependencies: <N> | ||
|
||
// 5 file main.c line 13 function main | ||
1: a = 2; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
int a; | ||
|
||
void func() | ||
{ | ||
} | ||
|
||
void main(void) | ||
{ | ||
func(); | ||
|
||
if(a < 10) | ||
{ | ||
a = 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// Assignment has a control dependency on the if | ||
\/\/ ([0-9]+).*\n.*IF.*a < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 1 | ||
-- | ||
^warning: ignoring | ||
-- | ||
The regex above match output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the goto statement. | ||
|
||
// <N> file main.c line 7 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 11 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test regexes above actually ignore the line numbers and the comments currently just give examples of the kind of output that they would match. But I can change the line numbers in the output examples to match the tests. |
||
IF !(i < 10) THEN GOTO 1 | ||
... | ||
**** 3 file main.c line 9 function main | ||
Control dependencies: <N> | ||
|
||
// 3 file main.c line 9 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 13 |
||
a = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
int a; | ||
|
||
void func() | ||
{ | ||
} | ||
|
||
void main(void) | ||
{ | ||
if(a < 7) | ||
{ | ||
goto L; | ||
} | ||
|
||
if(a < 10) | ||
{ | ||
func(); | ||
L: | ||
a = 1; | ||
a = 2; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// Assignment has a control dependency on the first if | ||
\/\/ ([0-9]+).*\n.*IF.*a < 7.*THEN(.*\n)*Control dependencies: (([0-9]+,\1)|(\1,[0-9]+))\n(.*\n){2,3}.*a = 2 | ||
// Assignment has a control dependency on the second if | ||
\/\/ ([0-9]+).*\n.*IF.*a < 10.*THEN(.*\n)*Control dependencies: (([0-9]+,\1)|(\1,[0-9]+))\n(.*\n){2,3}.*a = 2 | ||
-- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why checking only for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can add a check for |
||
^warning: ignoring | ||
-- | ||
The first regex above matches output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the goto statement. | ||
|
||
// <N> file main.c line 9 function main | ||
IF a < 7 THEN GOTO 1 | ||
... | ||
**** 6 file main.c line 19 function main | ||
Control dependencies: (<N>,...)|(...,<N>) | ||
|
||
// 6 file main.c line 19 function main | ||
a = 2; | ||
|
||
The second regex above matches output portions like shown below (with <N> being | ||
a location number). The intention is to check whether the assignment has a | ||
control dependency on the goto statement. | ||
|
||
// <N> file main.c line 14 function main | ||
IF !(a < 10) THEN GOTO 2 | ||
... | ||
**** 6 file main.c line 19 function main | ||
Control dependencies: (<N>,...)|(...,<N>) | ||
|
||
// 6 file main.c line 19 function main | ||
a = 2; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
int g_in1, g_in2; | ||
int g_out; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why global vars and not automatic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no reason for this. The variables do not matter for control dependencies. |
||
|
||
void main(void) | ||
{ | ||
int t; | ||
if(g_in1) | ||
{ | ||
if(g_in2) | ||
t = 0; | ||
else | ||
t = 1; | ||
|
||
g_out = 1; // depends on "if(g_in1) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CORE | ||
main.c | ||
--show --dependence-graph --text - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's with the dash at the end? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
\/\/ ([0-9]+) file.*\n.*IF.*g_in1.*THEN GOTO(.*\n)*Control dependencies: \1\n\n.*\n.*g_out = 1 | ||
-- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to check that neither 10 nor 12 have CD on 7? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'll add a check for that too. |
||
^warning: ignoring | ||
-- | ||
The regex above match output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the goto statement. | ||
|
||
// <N> file main.c line 7 function main | ||
IF !(g_in1 != 0) THEN GOTO 3 | ||
... | ||
**** 3 file main.c line 9 function main | ||
Control dependencies: <N> | ||
|
||
// 3 file main.c line 9 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 14 |
||
g_out = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
int a; | ||
|
||
void main(void) | ||
{ | ||
int i = 0; | ||
while(i < 10) | ||
{ | ||
a = 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// Assignment has a control dependency on the loop head | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 1 | ||
// Backedge has a control dependency on the loop head | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}\s*GOTO [0-9]+ | ||
// Loop head has a control dependency on itself | ||
Control dependencies: ([0-9]+)\n(.*\n)?\n.*\/\/ \1.*\n.*IF.*i < 10.*THEN | ||
-- | ||
^warning: ignoring | ||
-- | ||
The first regex above match output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the loop head. | ||
|
||
// <N> file main.c line 6 function main | ||
1: IF !(i < 10) THEN GOTO 2 | ||
... | ||
**** 3 file main.c line 8 function main | ||
Control dependencies: <N> | ||
|
||
// 3 file main.c line 8 function main | ||
a = 1; | ||
|
||
The second regex above match output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the backwards goto has a | ||
control dependency on the loop head. | ||
|
||
// <N> file main.c line 6 function main | ||
1: IF !(i < 10) THEN GOTO 2 | ||
... | ||
**** 4 file main.c line 6 function main | ||
Control dependencies: <N> | ||
|
||
// 4 file main.c line 6 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not be here rather line 8 or 9? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the source location assigned to the back edge of a loop is the source location of the loop head. |
||
GOTO 1 | ||
|
||
The third regex above match output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the loop head has a control | ||
dependency on itself. | ||
|
||
Control dependencies: <N> | ||
Data dependencies: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We focus only on CD. So, this info seams to be redundant/misleading? Remove? What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependency graph outputs both the control dependencies and the data dependencies. The regex above ignores the data dependencies actually. But the example here shows the typical output that the dependency graph produces and which would be matched by the above regex. |
||
|
||
// <N> file main.c line 6 function main | ||
1: IF !(i < 10) THEN GOTO 2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
int a; | ||
|
||
void main(void) | ||
{ | ||
int i = 0; | ||
while(i < 10) | ||
{ | ||
if(i < 7) | ||
{ | ||
a = 1; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// Assignment has a control dependency on the if | ||
\/\/ ([0-9]+).*\n.*IF.*i < 7.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 1 | ||
// If has a control dependency on the loop head | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*i < 7 | ||
-- | ||
^warning: ignoring | ||
// Assignment does not have a control dependency on the loop head | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 1 | ||
-- | ||
The first regex above matches output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the if. | ||
|
||
// <N> file main.c line 6 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 8 |
||
1: IF !(i < 7) THEN GOTO 2 | ||
... | ||
**** 3 file main.c line 8 function main | ||
Control dependencies: <N> | ||
|
||
// 3 file main.c line 8 function main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 10 |
||
a = 1; | ||
|
||
The second regex above matches output portions like shown below (with <N> being | ||
a location number). The intention is to check whether the if has a control | ||
dependency on the loop head. | ||
|
||
// <N> file main.c line 6 function main | ||
1: IF !(i < 10) THEN GOTO 3 | ||
|
||
**** 3 file main.c line 8 function main | ||
Control dependencies: <N> | ||
Data dependencies: 1 | ||
|
||
// 3 file main.c line 8 function main | ||
IF !(i < 7) THEN GOTO 2 | ||
|
||
The third regex above matches output portions like shown below (with <N> being a | ||
location number). The intention is to check that the assignment does not have a | ||
control dependency on the loop head. | ||
|
||
// <N> file main.c line 6 function main | ||
1: IF !(i < 10) THEN GOTO 3 | ||
... | ||
**** 4 file main.c line 10 function main | ||
Control dependencies: <N> | ||
|
||
// 4 file main.c line 10 function main | ||
a = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
int a; | ||
|
||
void main(void) | ||
{ | ||
int i = 0; | ||
|
||
if(i < 10) | ||
{ | ||
if(i < 7) | ||
{ | ||
a = 1; | ||
} | ||
|
||
a = 2; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
CORE | ||
main.c | ||
--dependence-graph --show | ||
activate-multi-line-match | ||
EXIT=0 | ||
SIGNAL=0 | ||
// Second assignment has a control dependency on the outer if | ||
\/\/ ([0-9]+).*\n.*IF.*i < 10.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 2 | ||
-- | ||
^warning: ignoring | ||
// Second assignment does not have a control dependency on the inner if | ||
\/\/ ([0-9]+).*\n.*IF.*i < 7.*THEN(.*\n)*Control dependencies: \1\n(.*\n){2,3}.*a = 2 | ||
-- | ||
The first regex above matches output portions like shown below (with <N> being a | ||
location number). The intention is to check whether the assignment has a control | ||
dependency on the outer if. | ||
|
||
// <N> file main.c line 7 function main | ||
IF !(i < 10) THEN GOTO 2 | ||
... | ||
**** 6 file main.c line 14 function main | ||
Control dependencies: <N> | ||
|
||
// 6 file main.c line 14 function main | ||
a = 2; | ||
|
||
The second regex above matches output portions like shown below (with <N> being | ||
a location number). The intention is to check that the assignment does not have | ||
a control dependency on the inner if. | ||
|
||
// <N> file main.c line 9 function main | ||
IF !(i < 7) THEN GOTO 1 | ||
... | ||
**** 6 file main.c line 14 function main | ||
Control dependencies: <N> | ||
|
||
// 6 file main.c line 14 function main | ||
a = 2; |
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.
There's only one
IF i < 10
how come it appears here twice with both dependencies?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.
That's because
a = 1
anda = 2
appear in the then and else branches of this if. So the statements in both branches have a control dependency on the goto that decides which branch to take.