summaryrefslogtreecommitdiff
path: root/src/cfg/Relooper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cfg/Relooper.cpp')
-rw-r--r--src/cfg/Relooper.cpp66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/cfg/Relooper.cpp b/src/cfg/Relooper.cpp
index 8a15fe75c..87dd4e379 100644
--- a/src/cfg/Relooper.cpp
+++ b/src/cfg/Relooper.cpp
@@ -48,8 +48,9 @@ static wasm::Expression* HandleFollowupMultiples(wasm::Expression* Ret,
Shape* Parent,
RelooperBuilder& Builder,
bool InLoop) {
- if (!Parent->Next)
+ if (!Parent->Next) {
return Ret;
+ }
auto* Curr = Ret->dynCast<wasm::Block>();
if (!Curr || Curr->name.is()) {
@@ -58,8 +59,9 @@ static wasm::Expression* HandleFollowupMultiples(wasm::Expression* Ret,
// for each multiple after us, we create a block target for breaks to reach
while (Parent->Next) {
auto* Multiple = Shape::IsMultiple(Parent->Next);
- if (!Multiple)
+ if (!Multiple) {
break;
+ }
for (auto& iter : Multiple->InnerMap) {
int Id = iter.first;
Shape* Body = iter.second;
@@ -120,10 +122,12 @@ Branch::Branch(std::vector<wasm::Index>&& ValuesInit,
wasm::Expression*
Branch::Render(RelooperBuilder& Builder, Block* Target, bool SetLabel) {
auto* Ret = Builder.makeBlock();
- if (Code)
+ if (Code) {
Ret->list.push_back(Code);
- if (SetLabel)
+ }
+ if (SetLabel) {
Ret->list.push_back(Builder.makeSetLabel(Target->Id));
+ }
if (Type == Break) {
Ret->list.push_back(Builder.makeBlockBreak(Target->Id));
} else if (Type == Continue) {
@@ -170,8 +174,9 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) {
if (IsCheckedMultipleEntry && InLoop) {
Ret->list.push_back(Builder.makeSetLabel(0));
}
- if (Code)
+ if (Code) {
Ret->list.push_back(Code);
+ }
if (!ProcessedBranchesOut.size()) {
Ret->finalize();
@@ -254,8 +259,9 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) {
Branch* Details;
if (iter != ProcessedBranchesOut.end()) {
Target = iter->first;
- if (Target == DefaultTarget)
+ if (Target == DefaultTarget) {
continue; // done at the end
+ }
Details = iter->second;
// must have a condition if this is not the default target
assert(Details->Condition);
@@ -318,8 +324,9 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) {
RemainingConditions = Now;
}
}
- if (IsDefault)
+ if (IsDefault) {
break;
+ }
}
// finalize the if-chains
@@ -385,16 +392,18 @@ wasm::Expression* Block::Render(RelooperBuilder& Builder, bool InLoop) {
// this is the default, and it has no content. So make the default be
// the leave
for (auto& Value : Table) {
- if (Value == SwitchDefault)
+ if (Value == SwitchDefault) {
Value = SwitchLeave;
+ }
}
SwitchDefault = SwitchLeave;
}
}
if (Details->SwitchValues) {
for (auto Value : *Details->SwitchValues) {
- while (Table.size() <= Value)
+ while (Table.size() <= Value) {
Table.push_back(SwitchDefault);
+ }
Table[Value] = CurrName;
}
}
@@ -478,10 +487,12 @@ Relooper::Relooper(wasm::Module* ModuleInit)
}
Relooper::~Relooper() {
- for (unsigned i = 0; i < Blocks.size(); i++)
+ for (unsigned i = 0; i < Blocks.size(); i++) {
delete Blocks[i];
- for (unsigned i = 0; i < Shapes.size(); i++)
+ }
+ for (unsigned i = 0; i < Shapes.size(); i++) {
delete Shapes[i];
+ }
}
void Relooper::AddBlock(Block* New, int Id) {
@@ -508,8 +519,9 @@ struct Liveness : public RelooperRecursor {
while (ToInvestigate.size() > 0) {
Block* Curr = ToInvestigate.front();
ToInvestigate.pop_front();
- if (contains(Live, Curr))
+ if (contains(Live, Curr)) {
continue;
+ }
Live.insert(Curr);
for (auto& iter : Curr->BranchesOut) {
ToInvestigate.push_back(iter.first);
@@ -905,20 +917,24 @@ private:
template<typename T>
static bool IsPossibleUniquePtrEquivalent(std::unique_ptr<T>& A,
std::unique_ptr<T>& B) {
- if (A == B)
+ if (A == B) {
return true;
- if (!A || !B)
+ }
+ if (!A || !B) {
return false;
+ }
return *A == *B;
}
// Checks if code is equivalent, allowing the code to also be nullptr
static bool IsPossibleCodeEquivalent(wasm::Expression* A,
wasm::Expression* B) {
- if (A == B)
+ if (A == B) {
return true;
- if (!A || !B)
+ }
+ if (!A || !B) {
return false;
+ }
return IsCodeEquivalent(A, B);
}
@@ -1025,8 +1041,9 @@ void Relooper::Calculate(Block* Entry) {
// Add incoming branches from live blocks, ignoring dead code
for (unsigned i = 0; i < Blocks.size(); i++) {
Block* Curr = Blocks[i];
- if (!contains(Live.Live, Curr))
+ if (!contains(Live.Live, Curr)) {
continue;
+ }
for (auto& iter : Curr->BranchesOut) {
iter.first->BranchesIn.insert(Curr);
}
@@ -1282,10 +1299,11 @@ void Relooper::Calculate(Block* Entry) {
Queue.pop_front();
// Curr must be in the ownership map if we are in the queue
Block* Owner = Helper.Ownership[Curr];
- if (!Owner)
+ if (!Owner) {
// we have been invalidated meanwhile after being reached from two
// entries
continue;
+ }
// Add all children
for (auto& iter : Curr->BranchesOut) {
Block* New = iter.first;
@@ -1298,8 +1316,9 @@ void Relooper::Calculate(Block* Entry) {
continue;
}
Block* NewOwner = Known->second;
- if (!NewOwner)
+ if (!NewOwner) {
continue; // We reached an invalidated node
+ }
if (NewOwner != Owner) {
// Invalidate this and all reachable that we have seen - we reached
// this from two locations
@@ -1321,8 +1340,9 @@ void Relooper::Calculate(Block* Entry) {
BlockList ToInvalidate;
for (auto* Child : CurrGroup) {
for (auto* Parent : Child->BranchesIn) {
- if (Ignore && contains(*Ignore, Parent))
+ if (Ignore && contains(*Ignore, Parent)) {
continue;
+ }
if (Helper.Ownership[Parent] != Helper.Ownership[Child]) {
ToInvalidate.push_back(Child);
}
@@ -1436,8 +1456,9 @@ void Relooper::Calculate(Block* Entry) {
NextEntries = &TempEntries[CurrTempIndex];
NextEntries->clear();
- if (Entries->size() == 0)
+ if (Entries->size() == 0) {
return Ret;
+ }
if (Entries->size() == 1) {
Block* Curr = *(Entries->begin());
if (Curr->BranchesIn.size() == 0) {
@@ -1525,8 +1546,9 @@ void Relooper::Calculate(Block* Entry) {
break;
}
}
- if (!DeadEnd)
+ if (!DeadEnd) {
break;
+ }
}
if (DeadEnd) {
PrintDebug("Removing nesting by not handling large group "