Commit 29841e84 by Jim Stichnoth

Subzero: Use range-based for loops with llvm::ilist<Inst> lists.

This reestablishes C++11 features lost after switching to llvm::ilist<> in two previous CLs: https://codereview.chromium.org/709533002/ https://codereview.chromium.org/794923002/ BUG= none R=jfb@chromium.org, jvoung@chromium.org Review URL: https://codereview.chromium.org/819403002
parent ae953202
......@@ -294,24 +294,22 @@ void Cfg::liveness(LivenessMode Mode) {
for (CfgNode *Node : Nodes) {
InstNumberT FirstInstNum = Inst::NumberSentinel;
InstNumberT LastInstNum = Inst::NumberSentinel;
for (auto I = Node->getPhis().begin(), E = Node->getPhis().end(); I != E;
++I) {
I->deleteIfDead();
if (Mode == Liveness_Intervals && !I->isDeleted()) {
for (Inst &I : Node->getPhis()) {
I.deleteIfDead();
if (Mode == Liveness_Intervals && !I.isDeleted()) {
if (FirstInstNum == Inst::NumberSentinel)
FirstInstNum = I->getNumber();
assert(I->getNumber() > LastInstNum);
LastInstNum = I->getNumber();
FirstInstNum = I.getNumber();
assert(I.getNumber() > LastInstNum);
LastInstNum = I.getNumber();
}
}
for (auto I = Node->getInsts().begin(), E = Node->getInsts().end(); I != E;
++I) {
I->deleteIfDead();
if (Mode == Liveness_Intervals && !I->isDeleted()) {
for (Inst &I : Node->getInsts()) {
I.deleteIfDead();
if (Mode == Liveness_Intervals && !I.isDeleted()) {
if (FirstInstNum == Inst::NumberSentinel)
FirstInstNum = I->getNumber();
assert(I->getNumber() > LastInstNum);
LastInstNum = I->getNumber();
FirstInstNum = I.getNumber();
assert(I.getNumber() > LastInstNum);
LastInstNum = I.getNumber();
}
}
if (Mode == Liveness_Intervals) {
......@@ -339,14 +337,13 @@ bool Cfg::validateLiveness() const {
Ostream &Str = Ctx->getStrDump();
for (CfgNode *Node : Nodes) {
Inst *FirstInst = nullptr;
for (auto Inst = Node->getInsts().begin(), E = Node->getInsts().end();
Inst != E; ++Inst) {
if (Inst->isDeleted())
for (Inst &Inst : Node->getInsts()) {
if (Inst.isDeleted())
continue;
if (FirstInst == nullptr)
FirstInst = Inst;
InstNumberT InstNumber = Inst->getNumber();
if (Variable *Dest = Inst->getDest()) {
FirstInst = &Inst;
InstNumberT InstNumber = Inst.getNumber();
if (Variable *Dest = Inst.getDest()) {
if (!Dest->getIgnoreLiveness()) {
bool Invalid = false;
const bool IsDest = true;
......@@ -359,20 +356,20 @@ bool Cfg::validateLiveness() const {
// temporary may be live at the end of the previous block,
// and if it is also assigned in the first instruction of
// this block, the adjacent live ranges get merged.
if (static_cast<class Inst *>(Inst) != FirstInst &&
!Inst->isDestNonKillable() &&
if (static_cast<class Inst *>(&Inst) != FirstInst &&
!Inst.isDestNonKillable() &&
Dest->getLiveRange().containsValue(InstNumber - 1, IsDest))
Invalid = true;
if (Invalid) {
Valid = false;
Str << "Liveness error: inst " << Inst->getNumber() << " dest ";
Str << "Liveness error: inst " << Inst.getNumber() << " dest ";
Dest->dump(this);
Str << " live range " << Dest->getLiveRange() << "\n";
}
}
}
for (SizeT I = 0; I < Inst->getSrcSize(); ++I) {
Operand *Src = Inst->getSrc(I);
for (SizeT I = 0; I < Inst.getSrcSize(); ++I) {
Operand *Src = Inst.getSrc(I);
SizeT NumVars = Src->getNumVars();
for (SizeT J = 0; J < NumVars; ++J) {
const Variable *Var = Src->getVar(J);
......@@ -380,7 +377,7 @@ bool Cfg::validateLiveness() const {
if (!Var->getIgnoreLiveness() &&
!Var->getLiveRange().containsValue(InstNumber, IsDest)) {
Valid = false;
Str << "Liveness error: inst " << Inst->getNumber() << " var ";
Str << "Liveness error: inst " << Inst.getNumber() << " var ";
Var->dump(this);
Str << " live range " << Var->getLiveRange() << "\n";
}
......
......@@ -57,10 +57,10 @@ void CfgNode::appendInst(Inst *Inst) {
// overlap with the range of any other block.
void CfgNode::renumberInstructions() {
InstNumberT FirstNumber = Func->getNextInstNumber();
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->renumber(Func);
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I)
I->renumber(Func);
for (Inst &I : Phis)
I.renumber(Func);
for (Inst &I : Insts)
I.renumber(Func);
InstCountEstimate = Func->getNextInstNumber() - FirstNumber;
}
......@@ -86,8 +86,8 @@ void CfgNode::computePredecessors() {
// instructions and appends assignment instructions to predecessor
// blocks. Note that this transformation preserves SSA form.
void CfgNode::placePhiLoads() {
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
auto Phi = llvm::dyn_cast<InstPhi>(I);
for (Inst &I : Phis) {
auto Phi = llvm::dyn_cast<InstPhi>(&I);
Insts.insert(Insts.begin(), Phi->lower(Func));
}
}
......@@ -186,11 +186,11 @@ void CfgNode::placePhiStores() {
// Consider every out-edge.
for (CfgNode *Succ : OutEdges) {
// Consider every Phi instruction at the out-edge.
for (auto I = Succ->Phis.begin(), E = Succ->Phis.end(); I != E; ++I) {
auto Phi = llvm::dyn_cast<InstPhi>(I);
for (Inst &I : Succ->Phis) {
auto Phi = llvm::dyn_cast<InstPhi>(&I);
Operand *Operand = Phi->getOperandForTarget(this);
assert(Operand);
Variable *Dest = I->getDest();
Variable *Dest = I.getDest();
assert(Dest);
InstAssign *NewInst = InstAssign::create(Func, Dest, Operand);
if (CmpInstDest == Operand)
......@@ -203,8 +203,8 @@ void CfgNode::placePhiStores() {
// Deletes the phi instructions after the loads and stores are placed.
void CfgNode::deletePhis() {
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->setDeleted();
for (Inst &I : Phis)
I.setDeleted();
}
// Splits the edge from Pred to this node by creating a new node and
......@@ -319,8 +319,8 @@ void CfgNode::advancedPhiLowering() {
} Desc[getPhis().size()];
size_t NumPhis = 0;
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
auto Inst = llvm::dyn_cast<InstPhi>(I);
for (Inst &I : Phis) {
auto Inst = llvm::dyn_cast<InstPhi>(&I);
if (!Inst->isDeleted()) {
Desc[NumPhis].Phi = Inst;
Desc[NumPhis].Dest = Inst->getDest();
......@@ -475,8 +475,8 @@ void CfgNode::advancedPhiLowering() {
Func->getVMetadata()->addNode(Split);
}
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->setDeleted();
for (Inst &I : Phis)
I.setDeleted();
}
// Does address mode optimization. Pass each instruction to the
......@@ -539,10 +539,10 @@ void CfgNode::livenessLightweight() {
continue;
I->livenessLightweight(Func, Live);
}
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted())
for (Inst &I : Phis) {
if (I.isDeleted())
continue;
I->livenessLightweight(Func, Live);
I.livenessLightweight(Func, Live);
}
}
......@@ -571,8 +571,8 @@ bool CfgNode::liveness(Liveness *Liveness) {
for (CfgNode *Succ : OutEdges) {
Live |= Liveness->getLiveIn(Succ);
// Mark corresponding argument of phis in successor as live.
for (auto I = Succ->Phis.begin(), E = Succ->Phis.end(); I != E; ++I) {
auto Phi = llvm::dyn_cast<InstPhi>(I);
for (Inst &I : Succ->Phis) {
auto Phi = llvm::dyn_cast<InstPhi>(&I);
Phi->livenessPhiOperand(Live, this, Liveness);
}
}
......@@ -589,12 +589,12 @@ bool CfgNode::liveness(Liveness *Liveness) {
// the block.
SizeT NumNonDeadPhis = 0;
InstNumberT FirstPhiNumber = Inst::NumberSentinel;
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted())
for (Inst &I : Phis) {
if (I.isDeleted())
continue;
if (FirstPhiNumber == Inst::NumberSentinel)
FirstPhiNumber = I->getNumber();
if (I->liveness(FirstPhiNumber, Live, Liveness, LiveBegin, LiveEnd))
FirstPhiNumber = I.getNumber();
if (I.liveness(FirstPhiNumber, Live, Liveness, LiveBegin, LiveEnd))
++NumNonDeadPhis;
}
......@@ -724,12 +724,12 @@ void CfgNode::contractIfEmpty() {
if (InEdges.empty())
return;
Inst *Branch = nullptr;
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (I->isDeleted())
for (Inst &I : Insts) {
if (I.isDeleted())
continue;
if (I->isUnconditionalBranch())
Branch = I;
else if (!I->isRedundantAssign())
if (I.isUnconditionalBranch())
Branch = &I;
else if (!I.isRedundantAssign())
return;
}
Branch->setDeleted();
......@@ -747,10 +747,9 @@ void CfgNode::contractIfEmpty() {
OutEdges.front()->InEdges.push_back(Pred);
}
}
for (auto I = Pred->getInsts().begin(), E = Pred->getInsts().end();
I != E; ++I) {
if (!I->isDeleted())
I->repointEdge(this, OutEdges.front());
for (Inst &I : Pred->getInsts()) {
if (!I.isDeleted())
I.repointEdge(this, OutEdges.front());
}
}
}
......@@ -767,9 +766,9 @@ void CfgNode::doBranchOpt(const CfgNode *NextNode) {
// first opportunity, unless there is some target lowering where we
// have the possibility of multiple such optimizations per block
// (currently not the case for x86 lowering).
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (!I->isDeleted()) {
Target->doBranchOpt(I, NextNode);
for (Inst &I : Insts) {
if (!I.isDeleted()) {
Target->doBranchOpt(&I, NextNode);
}
}
}
......@@ -872,26 +871,26 @@ void CfgNode::emit(Cfg *Func) const {
if (DecorateAsm)
emitRegisterUsage(Str, Func, this, true, LiveRegCount);
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted())
for (const Inst &I : Phis) {
if (I.isDeleted())
continue;
// Emitting a Phi instruction should cause an error.
I->emit(Func);
I.emit(Func);
}
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (I->isDeleted())
for (const Inst &I : Insts) {
if (I.isDeleted())
continue;
if (I->isRedundantAssign()) {
Variable *Dest = I->getDest();
if (DecorateAsm && Dest->hasReg() && !I->isLastUse(I->getSrc(0)))
if (I.isRedundantAssign()) {
Variable *Dest = I.getDest();
if (DecorateAsm && Dest->hasReg() && !I.isLastUse(I.getSrc(0)))
++LiveRegCount[Dest->getRegNum()];
continue;
}
I->emit(Func);
I.emit(Func);
if (DecorateAsm)
emitLiveRangesEnded(Str, Func, I, LiveRegCount);
emitLiveRangesEnded(Str, Func, &I, LiveRegCount);
Str << "\n";
updateStats(Func, I);
updateStats(Func, &I);
}
if (DecorateAsm)
emitRegisterUsage(Str, Func, this, false, LiveRegCount);
......@@ -901,19 +900,19 @@ void CfgNode::emitIAS(Cfg *Func) const {
Func->setCurrentNode(this);
Assembler *Asm = Func->getAssembler<Assembler>();
Asm->BindCfgNodeLabel(getIndex());
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I) {
if (I->isDeleted())
for (const Inst &I : Phis) {
if (I.isDeleted())
continue;
// Emitting a Phi instruction should cause an error.
I->emitIAS(Func);
I.emitIAS(Func);
}
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I) {
if (I->isDeleted())
for (const Inst &I : Insts) {
if (I.isDeleted())
continue;
if (I->isRedundantAssign())
if (I.isRedundantAssign())
continue;
I->emitIAS(Func);
updateStats(Func, I);
I.emitIAS(Func);
updateStats(Func, &I);
}
}
......@@ -958,10 +957,10 @@ void CfgNode::dump(Cfg *Func) const {
}
// Dump each instruction.
if (Func->getContext()->isVerbose(IceV_Instructions)) {
for (auto I = Phis.begin(), E = Phis.end(); I != E; ++I)
I->dumpDecorated(Func);
for (auto I = Insts.begin(), E = Insts.end(); I != E; ++I)
I->dumpDecorated(Func);
for (const Inst &I : Phis)
I.dumpDecorated(Func);
for (const Inst &I : Insts)
I.dumpDecorated(Func);
}
// Dump the live-out variables.
LivenessBV LiveOut;
......
......@@ -286,39 +286,37 @@ void VariablesMetadata::addNode(CfgNode *Node) {
if (Func->getNumVariables() >= Metadata.size())
Metadata.resize(Func->getNumVariables());
for (auto I = Node->getPhis().begin(), E = Node->getPhis().end(); I != E;
++I) {
if (I->isDeleted())
for (Inst &I : Node->getPhis()) {
if (I.isDeleted())
continue;
if (Variable *Dest = I->getDest()) {
if (Variable *Dest = I.getDest()) {
SizeT DestNum = Dest->getIndex();
assert(DestNum < Metadata.size());
Metadata[DestNum].markDef(Kind, I, Node);
Metadata[DestNum].markDef(Kind, &I, Node);
}
for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
if (const Variable *Var = llvm::dyn_cast<Variable>(I->getSrc(SrcNum))) {
for (SizeT SrcNum = 0; SrcNum < I.getSrcSize(); ++SrcNum) {
if (const Variable *Var = llvm::dyn_cast<Variable>(I.getSrc(SrcNum))) {
SizeT VarNum = Var->getIndex();
assert(VarNum < Metadata.size());
const bool IsFromDef = false;
const bool IsImplicit = false;
Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit);
Metadata[VarNum].markUse(Kind, &I, Node, IsFromDef, IsImplicit);
}
}
}
for (auto I = Node->getInsts().begin(), E = Node->getInsts().end(); I != E;
++I) {
if (I->isDeleted())
for (Inst &I : Node->getInsts()) {
if (I.isDeleted())
continue;
// Note: The implicit definitions (and uses) from InstFakeKill are
// deliberately ignored.
if (Variable *Dest = I->getDest()) {
if (Variable *Dest = I.getDest()) {
SizeT DestNum = Dest->getIndex();
assert(DestNum < Metadata.size());
Metadata[DestNum].markDef(Kind, I, Node);
Metadata[DestNum].markDef(Kind, &I, Node);
}
for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
Operand *Src = I->getSrc(SrcNum);
for (SizeT SrcNum = 0; SrcNum < I.getSrcSize(); ++SrcNum) {
Operand *Src = I.getSrc(SrcNum);
SizeT NumVars = Src->getNumVars();
for (SizeT J = 0; J < NumVars; ++J) {
const Variable *Var = Src->getVar(J);
......@@ -326,7 +324,7 @@ void VariablesMetadata::addNode(CfgNode *Node) {
assert(VarNum < Metadata.size());
const bool IsFromDef = false;
const bool IsImplicit = false;
Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit);
Metadata[VarNum].markUse(Kind, &I, Node, IsFromDef, IsImplicit);
}
}
}
......
......@@ -109,11 +109,10 @@ void LinearScan::initForGlobal() {
// Build the (ordered) list of FakeKill instruction numbers.
Kills.clear();
for (CfgNode *Node : Func->getNodes()) {
for (auto I = Node->getInsts().begin(), E = Node->getInsts().end(); I != E;
++I) {
if (auto Kill = llvm::dyn_cast<InstFakeKill>(I)) {
for (Inst &I : Node->getInsts()) {
if (auto Kill = llvm::dyn_cast<InstFakeKill>(&I)) {
if (!Kill->isDeleted() && !Kill->getLinked()->isDeleted())
Kills.push_back(I->getNumber());
Kills.push_back(I.getNumber());
}
}
}
......@@ -160,25 +159,24 @@ void LinearScan::initForInfOnly() {
std::vector<InstNumberT> LRBegin(Vars.size(), Inst::NumberSentinel);
std::vector<InstNumberT> LREnd(Vars.size(), Inst::NumberSentinel);
for (CfgNode *Node : Func->getNodes()) {
for (auto Inst = Node->getInsts().begin(), E = Node->getInsts().end();
Inst != E; ++Inst) {
if (Inst->isDeleted())
for (Inst &Inst : Node->getInsts()) {
if (Inst.isDeleted())
continue;
if (const Variable *Var = Inst->getDest()) {
if (const Variable *Var = Inst.getDest()) {
if (Var->hasReg() || Var->getWeight() == RegWeight::Inf) {
if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) {
LRBegin[Var->getIndex()] = Inst->getNumber();
LRBegin[Var->getIndex()] = Inst.getNumber();
++NumVars;
}
}
}
for (SizeT I = 0; I < Inst->getSrcSize(); ++I) {
Operand *Src = Inst->getSrc(I);
for (SizeT I = 0; I < Inst.getSrcSize(); ++I) {
Operand *Src = Inst.getSrc(I);
SizeT NumVars = Src->getNumVars();
for (SizeT J = 0; J < NumVars; ++J) {
const Variable *Var = Src->getVar(J);
if (Var->hasReg() || Var->getWeight() == RegWeight::Inf)
LREnd[Var->getIndex()] = Inst->getNumber();
LREnd[Var->getIndex()] = Inst.getNumber();
}
}
}
......
......@@ -669,14 +669,13 @@ void TargetX8632::addProlog(CfgNode *Node) {
// stack slots.
llvm::BitVector IsVarReferenced(Func->getNumVariables());
for (CfgNode *Node : Func->getNodes()) {
for (auto Inst = Node->getInsts().begin(), E = Node->getInsts().end();
Inst != E; ++Inst) {
if (Inst->isDeleted())
for (Inst &Inst : Node->getInsts()) {
if (Inst.isDeleted())
continue;
if (const Variable *Var = Inst->getDest())
if (const Variable *Var = Inst.getDest())
IsVarReferenced[Var->getIndex()] = true;
for (SizeT I = 0; I < Inst->getSrcSize(); ++I) {
Operand *Src = Inst->getSrc(I);
for (SizeT I = 0; I < Inst.getSrcSize(); ++I) {
Operand *Src = Inst.getSrc(I);
SizeT NumVars = Src->getNumVars();
for (SizeT J = 0; J < NumVars; ++J) {
const Variable *Var = Src->getVar(J);
......@@ -4155,9 +4154,8 @@ void TargetX8632::lowerUnreachable(const InstUnreachable * /*Inst*/) {
// Undef input.
void TargetX8632::prelowerPhis() {
CfgNode *Node = Context.getNode();
for (auto I = Node->getPhis().begin(), E = Node->getPhis().end(); I != E;
++I) {
auto Phi = llvm::dyn_cast<InstPhi>(I);
for (Inst &I : Node->getPhis()) {
auto Phi = llvm::dyn_cast<InstPhi>(&I);
if (Phi->isDeleted())
continue;
Variable *Dest = Phi->getDest();
......@@ -4221,11 +4219,11 @@ void TargetX8632::lowerPhiAssignments(CfgNode *Node,
// set. TODO(stichnot): This work is being repeated for every split
// edge to the successor, so consider updating LiveIn just once
// after all the edges are split.
for (auto I = Assignments.begin(), E = Assignments.end(); I != E; ++I) {
Variable *Dest = I->getDest();
for (const Inst &I : Assignments) {
Variable *Dest = I.getDest();
if (Dest->hasReg()) {
Available[Dest->getRegNum()] = false;
} else if (isMemoryOperand(I->getSrc(0))) {
} else if (isMemoryOperand(I.getSrc(0))) {
NeedsRegs = true; // Src and Dest are both in memory
}
}
......
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