remove more unneeded break and continue statements in relooper

This commit is contained in:
Alon Zakai 2013-06-01 17:41:37 -07:00
Родитель 3c58fd7d83
Коммит 9193b8b795
7 изменённых файлов: 26 добавлений и 36 удалений

Просмотреть файл

@ -136,10 +136,6 @@ void Block::Render(bool InLoop) {
bool SetLabel = true; // in some cases it is clear we can avoid setting label, see later
if (ProcessedBranchesOut.size() == 1 && ProcessedBranchesOut.begin()->second->Type == Branch::Direct) {
SetLabel = false;
}
// A setting of the label variable (label = x) is necessary if it can
// cause an impact. The main case is where we set label to x, then elsewhere
// we check if label is equal to that value, i.e., that label is an entry
@ -893,14 +889,17 @@ void Relooper::Calculate(Block *Entry) {
func(Loop->Next); \
}
// Find the single block that must be hit in a shape, or NULL if there is more than one
Block *FollowNaturalFlow(Shape *S) {
// Find the blocks that natural control flow can get us directly to, or through a multiple that we ignore
void FollowNaturalFlow(Shape *S, BlockSet &Out) {
SHAPE_SWITCH(S, {
return Simple->Inner;
Out.insert(Simple->Inner);
}, {
return NULL;
for (BlockShapeMap::iterator iter = Multiple->InnerMap.begin(); iter != Multiple->InnerMap.end(); iter++) {
FollowNaturalFlow(iter->second, Out);
}
FollowNaturalFlow(Multiple->Next, Out);
}, {
return FollowNaturalFlow(Loop->Inner);
FollowNaturalFlow(Loop->Inner, Out);
});
}
@ -908,7 +907,8 @@ void Relooper::Calculate(Block *Entry) {
// A flow operation is trivially unneeded if the shape we naturally get to by normal code
// execution is the same as the flow forces us to.
void RemoveUnneededFlows(Shape *Root, Shape *Natural=NULL) {
Block *NaturalBlock = FollowNaturalFlow(Natural);
BlockSet NaturalBlocks;
FollowNaturalFlow(Natural, NaturalBlocks);
Shape *Next = Root;
while (Next) {
Root = Next;
@ -923,7 +923,7 @@ void Relooper::Calculate(Block *Entry) {
for (BlockBranchMap::iterator iter = Simple->Inner->ProcessedBranchesOut.begin(); iter != Simple->Inner->ProcessedBranchesOut.end(); iter++) {
Block *Target = iter->first;
Branch *Details = iter->second;
if (Details->Type != Branch::Direct && Target == NaturalBlock) { // note: cannot handle split blocks
if (Details->Type != Branch::Direct && NaturalBlocks.find(Target) != NaturalBlocks.end()) { // note: cannot handle split blocks
Details->Type = Branch::Direct;
if (MultipleShape *Multiple = Shape::IsMultiple(Details->Ancestor)) {
Multiple->NeedLoop--;

Просмотреть файл

@ -126,7 +126,6 @@ do {
break;
}
// block D
break;
}
} while(0);
if (label == 33) {

Просмотреть файл

@ -7,7 +7,6 @@ do {
break;
}
//21
break;
} else {
label = 4;
}

Просмотреть файл

@ -3,13 +3,10 @@
print('entry'); var label; var state; var decisions = [4, 1, 7, 2, 6, 6, 8]; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }
print(5); state = check();
print(6); state = check();
do {
if (state == 7) {
print(7); state = check();
label = 3;
break;
}
} while(0);
if (state == 7) {
print(7); state = check();
label = 3;
}
L5: while(1) {
if (label == 3) {
label = 0;

Просмотреть файл

@ -3,22 +3,18 @@
print('entry'); var label; var state; var decisions = [133, 98, 134, 143, 162, 187, 130, 87, 91, 49, 102, 47, 9, 132, 179, 176, 157, 25, 64, 161, 57, 107, 16, 167, 185, 45, 191, 180, 23, 131]; var index = 0; function check() { if (index == decisions.length) throw 'HALT'; return decisions[index++] }
L1: while(1) {
print(7); state = check();
do {
if (state % 3 == 1) {
label = 3;
} else if (state % 3 == 0) {
print(8); state = check();
if (state % 2 == 0) {
label = 5;
break;
} else {
label = 7;
break;
}
if (state % 3 == 1) {
label = 3;
} else if (state % 3 == 0) {
print(8); state = check();
if (state % 2 == 0) {
label = 5;
} else {
break L1;
label = 7;
}
} while(0);
} else {
break;
}
while(1) {
if (label == 3) {
label = 0;

Просмотреть файл

@ -82,7 +82,6 @@ while(1) {
print(56); state = check();// ....................................................................................................................................................................................................................
print(34); state = check();// ..........................................................................................................................................
label = 74;
continue;
}
print(62); state = check();// .......................................................................................
}

Просмотреть файл

@ -295,7 +295,7 @@ def check_node_version():
# we re-check sanity when the settings are changed)
# We also re-check sanity and clear the cache when the version changes
EMSCRIPTEN_VERSION = '1.4.6'
EMSCRIPTEN_VERSION = '1.4.7'
def generate_sanity():
return EMSCRIPTEN_VERSION + '|' + get_llvm_target()