Chromium Code Reviews| Index: src/IceCfgNode.cpp |
| diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp |
| index 0729585bf14f8bcad1fe5b84c8ac04f138f6c700..212f742c53959789acaf5a036fd548303ea96eff 100644 |
| --- a/src/IceCfgNode.cpp |
| +++ b/src/IceCfgNode.cpp |
| @@ -52,16 +52,25 @@ void CfgNode::appendInst(Inst *Instr) { |
| } |
| } |
| -// Renumbers the non-deleted instructions in the node. This needs to be done in |
| -// preparation for live range analysis. The instruction numbers in a block must |
| -// be monotonically increasing. The range of instruction numbers in a block, |
| -// from lowest to highest, must not overlap with the range of any other block. |
| +namespace { |
| +template <typename List> void removeDeletedAndRenumber(List *L, Cfg *Func) { |
|
John
2016/03/14 13:27:15
You don't need a template here -- L is always an I
Jim Stichnoth
2016/03/14 13:51:15
In one case it's InstList, in another case it's Ph
John
2016/03/14 14:55:50
Well, not a big deal --hence the previous LGTM, bu
|
| + const bool DoDelete = |
| + BuildDefs::minimal() || !GlobalContext::getFlags().getKeepDeletedInsts(); |
| + auto I = L->begin(), E = L->end(), Next = I; |
| + for (++Next; I != E; I = Next++) { |
|
Eric Holk
2016/03/14 13:20:14
Does a ranged for loop work here?
Jim Stichnoth
2016/03/14 13:51:16
I don't think so, because erase(I) invalidates ite
Eric Holk
2016/03/14 14:01:03
Ah, I see. I figured you had a good reason :)
|
| + if (DoDelete && I->isDeleted()) { |
| + L->erase(I); |
| + } else { |
| + I->renumber(Func); |
| + } |
| + } |
| +} |
| +} // end of anonymous namespace |
| + |
| void CfgNode::renumberInstructions() { |
| InstNumberT FirstNumber = Func->getNextInstNumber(); |
| - for (Inst &I : Phis) |
| - I.renumber(Func); |
| - for (Inst &I : Insts) |
| - I.renumber(Func); |
| + removeDeletedAndRenumber(&Phis, Func); |
| + removeDeletedAndRenumber(&Insts, Func); |
| InstCountEstimate = Func->getNextInstNumber() - FirstNumber; |
| } |