summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'src/cfg')
-rw-r--r--src/cfg/Relooper.cpp66
-rw-r--r--src/cfg/cfg-traversal.h18
-rw-r--r--src/cfg/liveness-traversal.h27
3 files changed, 74 insertions, 37 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 "
diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h
index abaf63c5b..79c561de0 100644
--- a/src/cfg/cfg-traversal.h
+++ b/src/cfg/cfg-traversal.h
@@ -79,22 +79,26 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
}
void link(BasicBlock* from, BasicBlock* to) {
- if (!from || !to)
+ if (!from || !to) {
return; // if one of them is not reachable, ignore
+ }
from->out.push_back(to);
to->in.push_back(from);
}
static void doEndBlock(SubType* self, Expression** currp) {
auto* curr = (*currp)->cast<Block>();
- if (!curr->name.is())
+ if (!curr->name.is()) {
return;
+ }
auto iter = self->branches.find(curr);
- if (iter == self->branches.end())
+ if (iter == self->branches.end()) {
return;
+ }
auto& origins = iter->second;
- if (origins.size() == 0)
+ if (origins.size() == 0) {
return;
+ }
// we have branches to here, so we need a new block
auto* last = self->currBasicBlock;
self->startBasicBlock();
@@ -270,8 +274,9 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
queue.erase(iter);
alive.insert(curr);
for (auto* out : curr->out) {
- if (!alive.count(out))
+ if (!alive.count(out)) {
queue.insert(out);
+ }
}
}
return alive;
@@ -305,8 +310,9 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
std::map<BasicBlock*, size_t> debugIds;
void generateDebugIds() {
- if (debugIds.size() > 0)
+ if (debugIds.size() > 0) {
return;
+ }
for (auto& block : basicBlocks) {
debugIds[block.get()] = debugIds.size();
}
diff --git a/src/cfg/liveness-traversal.h b/src/cfg/liveness-traversal.h
index b26898460..a0ce214bc 100644
--- a/src/cfg/liveness-traversal.h
+++ b/src/cfg/liveness-traversal.h
@@ -50,10 +50,12 @@ struct LivenessAction {
LivenessAction(What what, Index index, Expression** origin)
: what(what), index(index), origin(origin), effective(false) {
assert(what != Other);
- if (what == Get)
+ if (what == Get) {
assert((*origin)->is<GetLocal>());
- if (what == Set)
+ }
+ if (what == Set) {
assert((*origin)->is<SetLocal>());
+ }
}
LivenessAction(Expression** origin) : what(Other), origin(origin) {}
@@ -153,14 +155,17 @@ struct LivenessWalker : public CFGWalker<SubType, VisitorType, Liveness> {
// need to count to see if worth it.
// TODO: an if can have two copies
GetLocal* getCopy(SetLocal* set) {
- if (auto* get = set->value->dynCast<GetLocal>())
+ if (auto* get = set->value->dynCast<GetLocal>()) {
return get;
+ }
if (auto* iff = set->value->dynCast<If>()) {
- if (auto* get = iff->ifTrue->dynCast<GetLocal>())
+ if (auto* get = iff->ifTrue->dynCast<GetLocal>()) {
return get;
+ }
if (iff->ifFalse) {
- if (auto* get = iff->ifFalse->dynCast<GetLocal>())
+ if (auto* get = iff->ifFalse->dynCast<GetLocal>()) {
return get;
+ }
}
}
return nullptr;
@@ -188,8 +193,9 @@ struct LivenessWalker : public CFGWalker<SubType, VisitorType, Liveness> {
// keep working while stuff is flowing
std::unordered_set<BasicBlock*> queue;
for (auto& curr : CFGWalker<SubType, VisitorType, Liveness>::basicBlocks) {
- if (liveBlocks.count(curr.get()) == 0)
+ if (liveBlocks.count(curr.get()) == 0) {
continue; // ignore dead blocks
+ }
queue.insert(curr.get());
// do the first scan through the block, starting with nothing live at the
// end, and updating the liveness at the start
@@ -203,15 +209,17 @@ struct LivenessWalker : public CFGWalker<SubType, VisitorType, Liveness> {
auto* curr = *iter;
queue.erase(iter);
LocalSet live;
- if (!mergeStartsAndCheckChange(curr->out, curr->contents.end, live))
+ if (!mergeStartsAndCheckChange(curr->out, curr->contents.end, live)) {
continue;
+ }
assert(curr->contents.end.size() < live.size());
curr->contents.end = live;
scanLivenessThroughActions(curr->contents.actions, live);
// liveness is now calculated at the start. if something
// changed, all predecessor blocks need recomputation
- if (curr->contents.start == live)
+ if (curr->contents.start == live) {
continue;
+ }
assert(curr->contents.start.size() < live.size());
curr->contents.start = live;
for (auto* in : curr->in) {
@@ -226,8 +234,9 @@ struct LivenessWalker : public CFGWalker<SubType, VisitorType, Liveness> {
bool mergeStartsAndCheckChange(std::vector<BasicBlock*>& blocks,
LocalSet& old,
LocalSet& ret) {
- if (blocks.size() == 0)
+ if (blocks.size() == 0) {
return false;
+ }
ret = blocks[0]->contents.start;
if (blocks.size() > 1) {
// more than one, so we must merge