diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-01 17:41:37 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-01 17:41:51 -0700 |
commit | 9193b8b795c67b08d311406ea1394f8928e610b7 (patch) | |
tree | ad8020645ff2637218d71a7a3acb925fe937a195 | |
parent | 3c58fd7d832ce71579b3cb7cb4765d37d70102e2 (diff) |
remove more unneeded break and continue statements in relooper1.4.7
-rw-r--r-- | src/relooper/Relooper.cpp | 22 | ||||
-rw-r--r-- | src/relooper/test.txt | 1 | ||||
-rw-r--r-- | src/relooper/test4.txt | 1 | ||||
-rw-r--r-- | src/relooper/test_fuzz1.txt | 11 | ||||
-rw-r--r-- | src/relooper/test_fuzz5.txt | 24 | ||||
-rw-r--r-- | src/relooper/test_fuzz6.txt | 1 | ||||
-rw-r--r-- | tools/shared.py | 2 |
7 files changed, 26 insertions, 36 deletions
diff --git a/src/relooper/Relooper.cpp b/src/relooper/Relooper.cpp index e91c6e74..8c72b0a6 100644 --- a/src/relooper/Relooper.cpp +++ b/src/relooper/Relooper.cpp @@ -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--; diff --git a/src/relooper/test.txt b/src/relooper/test.txt index 84a8c905..d657c6af 100644 --- a/src/relooper/test.txt +++ b/src/relooper/test.txt @@ -126,7 +126,6 @@ do { break; } // block D - break; } } while(0); if (label == 33) { diff --git a/src/relooper/test4.txt b/src/relooper/test4.txt index f0bfb972..3427ff18 100644 --- a/src/relooper/test4.txt +++ b/src/relooper/test4.txt @@ -7,7 +7,6 @@ do { break; } //21 - break; } else { label = 4; } diff --git a/src/relooper/test_fuzz1.txt b/src/relooper/test_fuzz1.txt index 5122257e..b278e240 100644 --- a/src/relooper/test_fuzz1.txt +++ b/src/relooper/test_fuzz1.txt @@ -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; diff --git a/src/relooper/test_fuzz5.txt b/src/relooper/test_fuzz5.txt index 9548205c..29b2dba4 100644 --- a/src/relooper/test_fuzz5.txt +++ b/src/relooper/test_fuzz5.txt @@ -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; diff --git a/src/relooper/test_fuzz6.txt b/src/relooper/test_fuzz6.txt index bd45e8fd..d5a5ab7b 100644 --- a/src/relooper/test_fuzz6.txt +++ b/src/relooper/test_fuzz6.txt @@ -82,7 +82,6 @@ while(1) { print(56); state = check();// .................................................................................................................................................................................................................... print(34); state = check();// .......................................................................................................................................... label = 74; - continue; } print(62); state = check();// ....................................................................................... } diff --git a/tools/shared.py b/tools/shared.py index 645dfbe9..799a5bbe 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -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() |