Summary: I realized that control variable analysis was broken when we had multiple back-edges for the same loop. This is often the case when we have a switch statement combined with continue in a loop (see `test_switch` in `switch_continue.c`) or when we have disjunctive guards in do-while loops. This diff fixes that by - defining a loop by its loophead (the target of its backedges) rather than its back-edges. Then it converts back-edge list to a map from loop_head to sources of the loop's back-edges. - collecting multiple guard nodes that come from potentially multiple exit nodes per loop head In addition, it also removes the wrong assumption that an exit node belongs to a single loop head. Reviewed By: mbouaziz Differential Revision: D8398061 fbshipit-source-id: abaf288master
parent
bd725602ee
commit
f80af7be93
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
int test_switch() {
|
||||
int value = 0;
|
||||
// infinite loop
|
||||
while (value < 100) {
|
||||
switch (value) {
|
||||
// code before the first case statement gets skipped but can be used to
|
||||
// declare variables
|
||||
int x = 1;
|
||||
x = value + 1;
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
continue;
|
||||
case 2:
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
value++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unroll_loop_FP(int n) {
|
||||
int ret = 0;
|
||||
int loop = n + 3 / 4;
|
||||
switch (n % 8) {
|
||||
case 0:
|
||||
do {
|
||||
ret++;
|
||||
case 3:
|
||||
ret++;
|
||||
if (1) {
|
||||
case 2:
|
||||
ret++;
|
||||
}
|
||||
case 1:
|
||||
ret++;
|
||||
} while (--loop > 0);
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package codetoanalyze.java.performance;
|
||||
|
||||
public class Continue{
|
||||
int continue_outer_loop_FN ()
|
||||
{
|
||||
outer:
|
||||
for (int i = 2; i < 1000; i++) {
|
||||
for (int j = 2; j < i; j++) {
|
||||
if (i % j == 0)
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package codetoanalyze.java.performance;
|
||||
|
||||
public class Switch{
|
||||
// Cost 51
|
||||
private static void vanilla_switch(int i){
|
||||
|
||||
for (int p = 0; p < 100; p++)
|
||||
{
|
||||
switch (p) {
|
||||
case 0:
|
||||
i++;
|
||||
break;
|
||||
case 1: case 2: case 3:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//797
|
||||
private static int test_switch() {
|
||||
int value = 0;
|
||||
// infinite loop
|
||||
while (value < 100) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
continue;
|
||||
case 2:
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
value++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue