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