Commit bfb410dd by Jim Stichnoth

Subzero: Improve the use of NodeList objects.

Currently NodeList is defined as std::vector<CfgNode*>, but in the future it may be desirable to change it to something like std::list<CfgNode*> so that it is easier to split edges and insert the new nodes at the right locations, rather than re-sorting them in a separate pass. This gets us closer by using foo.front() instead of foo[0]. There are still a couple more places using the [] operator, but the changes would be more intrusive. Also, a few instances of ".size()==0" are changed to the possibly more efficient ".empty()". BUG= none R=jvoung@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/704753007
parent c0d965fc
......@@ -148,7 +148,7 @@ void Cfg::reorderNodes() {
continue;
}
Node->setNeedsPlacement(false);
if (Node != getEntryNode() && Node->getInEdges().size() == 0) {
if (Node != getEntryNode() && Node->getInEdges().empty()) {
// The node has essentially been deleted since it is not a
// successor of any other node.
Unreachable.push_back(Node);
......@@ -164,7 +164,7 @@ void Cfg::reorderNodes() {
// If it's a (non-critical) edge where the successor has a single
// in-edge, then place it before the successor.
CfgNode *Succ = Node->getOutEdges()[0];
CfgNode *Succ = Node->getOutEdges().front();
if (Succ->getInEdges().size() == 1 &&
PlaceIndex[Succ->getIndex()] != NoPlace) {
Placed.insert(PlaceIndex[Succ->getIndex()], Node);
......@@ -173,7 +173,7 @@ void Cfg::reorderNodes() {
}
// Otherwise, place it after the (first) predecessor.
CfgNode *Pred = Node->getInEdges()[0];
CfgNode *Pred = Node->getInEdges().front();
auto PredPosition = PlaceIndex[Pred->getIndex()];
// It shouldn't be the case that PredPosition==NoPlace, but if
// that somehow turns out to be true, we just insert Node before
......@@ -189,12 +189,14 @@ void Cfg::reorderNodes() {
}
// Reorder Nodes according to the built-up lists.
SizeT Cur = 0;
SizeT OldSize = Nodes.size();
(void)OldSize;
Nodes.clear();
for (CfgNode *Node : Placed)
Nodes[Cur++] = Node;
Nodes.push_back(Node);
for (CfgNode *Node : Unreachable)
Nodes[Cur++] = Node;
assert(Cur == Nodes.size());
Nodes.push_back(Node);
assert(Nodes.size() == OldSize);
}
void Cfg::doArgLowering() {
......
......@@ -750,7 +750,7 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) {
// unconditional branch, contract the node by repointing all its
// in-edges to its successor.
void CfgNode::contractIfEmpty() {
if (InEdges.size() == 0)
if (InEdges.empty())
return;
Inst *Branch = NULL;
for (Inst *I : Insts) {
......@@ -763,18 +763,23 @@ void CfgNode::contractIfEmpty() {
}
Branch->setDeleted();
assert(OutEdges.size() == 1);
// Repoint all this node's in-edges to this node's successor.
for (CfgNode *Pred : InEdges) {
for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E;
++I) {
if (*I == this) {
*I = OutEdges[0];
OutEdges[0]->InEdges.push_back(Pred);
// Repoint all this node's in-edges to this node's successor, unless
// this node's successor is actually itself (in which case the
// statement "OutEdges.front()->InEdges.push_back(Pred)" could
// invalidate the iterator over this->InEdges).
if (OutEdges.front() != this) {
for (CfgNode *Pred : InEdges) {
for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); I != E;
++I) {
if (*I == this) {
*I = OutEdges.front();
OutEdges.front()->InEdges.push_back(Pred);
}
}
for (Inst *I : Pred->getInsts()) {
if (!I->isDeleted())
I->repointEdge(this, OutEdges.front());
}
}
for (Inst *I : Pred->getInsts()) {
if (!I->isDeleted())
I->repointEdge(this, OutEdges[0]);
}
}
InEdges.clear();
......
......@@ -4184,7 +4184,7 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node,
assert(Node->getOutEdges().size() == 1);
assert(Node->getInsts().empty());
assert(Node->getPhis().empty());
CfgNode *Succ = Node->getOutEdges()[0];
CfgNode *Succ = Node->getOutEdges().front();
getContext().init(Node);
// Register set setup similar to regAlloc() and postLower().
RegSetMask RegInclude = RegSet_All;
......
......@@ -1637,7 +1637,7 @@ void FunctionParser::ExitBlock() {
// insert unreachable. This shouldn't happen, but be safe.
unsigned Index = 0;
for (Ice::CfgNode *Node : Func->getNodes()) {
if (Node->getInsts().size() == 0) {
if (Node->getInsts().empty()) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
StrBuf << "Basic block " << Index << " contains no instructions";
......@@ -1908,7 +1908,7 @@ void FunctionParser::ProcessRecord() {
// RET: [opval?]
if (!isValidRecordSizeInRange(0, 1, "function block ret"))
return;
if (Values.size() == 0) {
if (Values.empty()) {
CurrentNode->appendInst(Ice::InstRet::create(Func));
} else {
CurrentNode->appendInst(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment