Commit f44f371b by Jim Stichnoth

Subzero: Auto-awesome iterators.

Use C++11 'auto' where practical to make iteration more concise. Use C++11 range-based for loops where possible. BUG= none R=jfb@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/619893002
parent fac55170
...@@ -82,9 +82,8 @@ void Cfg::translate() { ...@@ -82,9 +82,8 @@ void Cfg::translate() {
} }
void Cfg::computePredecessors() { void Cfg::computePredecessors() {
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->computePredecessors(); Node->computePredecessors();
}
} }
void Cfg::renumberInstructions() { void Cfg::renumberInstructions() {
...@@ -92,18 +91,16 @@ void Cfg::renumberInstructions() { ...@@ -92,18 +91,16 @@ void Cfg::renumberInstructions() {
GlobalContext::getTimerID("renumberInstructions"); GlobalContext::getTimerID("renumberInstructions");
TimerMarker T(IDrenumberInstructions, getContext()); TimerMarker T(IDrenumberInstructions, getContext());
NextInstNumber = 1; NextInstNumber = 1;
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->renumberInstructions(); Node->renumberInstructions();
}
} }
// placePhiLoads() must be called before placePhiStores(). // placePhiLoads() must be called before placePhiStores().
void Cfg::placePhiLoads() { void Cfg::placePhiLoads() {
static TimerIdT IDplacePhiLoads = GlobalContext::getTimerID("placePhiLoads"); static TimerIdT IDplacePhiLoads = GlobalContext::getTimerID("placePhiLoads");
TimerMarker T(IDplacePhiLoads, getContext()); TimerMarker T(IDplacePhiLoads, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->placePhiLoads(); Node->placePhiLoads();
}
} }
// placePhiStores() must be called after placePhiLoads(). // placePhiStores() must be called after placePhiLoads().
...@@ -111,17 +108,15 @@ void Cfg::placePhiStores() { ...@@ -111,17 +108,15 @@ void Cfg::placePhiStores() {
static TimerIdT IDplacePhiStores = static TimerIdT IDplacePhiStores =
GlobalContext::getTimerID("placePhiStores"); GlobalContext::getTimerID("placePhiStores");
TimerMarker T(IDplacePhiStores, getContext()); TimerMarker T(IDplacePhiStores, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->placePhiStores(); Node->placePhiStores();
}
} }
void Cfg::deletePhis() { void Cfg::deletePhis() {
static TimerIdT IDdeletePhis = GlobalContext::getTimerID("deletePhis"); static TimerIdT IDdeletePhis = GlobalContext::getTimerID("deletePhis");
TimerMarker T(IDdeletePhis, getContext()); TimerMarker T(IDdeletePhis, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->deletePhis(); Node->deletePhis();
}
} }
void Cfg::doArgLowering() { void Cfg::doArgLowering() {
...@@ -133,26 +128,23 @@ void Cfg::doArgLowering() { ...@@ -133,26 +128,23 @@ void Cfg::doArgLowering() {
void Cfg::doAddressOpt() { void Cfg::doAddressOpt() {
static TimerIdT IDdoAddressOpt = GlobalContext::getTimerID("doAddressOpt"); static TimerIdT IDdoAddressOpt = GlobalContext::getTimerID("doAddressOpt");
TimerMarker T(IDdoAddressOpt, getContext()); TimerMarker T(IDdoAddressOpt, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->doAddressOpt(); Node->doAddressOpt();
}
} }
void Cfg::doNopInsertion() { void Cfg::doNopInsertion() {
static TimerIdT IDdoNopInsertion = static TimerIdT IDdoNopInsertion =
GlobalContext::getTimerID("doNopInsertion"); GlobalContext::getTimerID("doNopInsertion");
TimerMarker T(IDdoNopInsertion, getContext()); TimerMarker T(IDdoNopInsertion, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->doNopInsertion(); Node->doNopInsertion();
}
} }
void Cfg::genCode() { void Cfg::genCode() {
static TimerIdT IDgenCode = GlobalContext::getTimerID("genCode"); static TimerIdT IDgenCode = GlobalContext::getTimerID("genCode");
TimerMarker T(IDgenCode, getContext()); TimerMarker T(IDgenCode, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->genCode(); Node->genCode();
}
} }
// Compute the stack frame layout. // Compute the stack frame layout.
...@@ -163,11 +155,9 @@ void Cfg::genFrame() { ...@@ -163,11 +155,9 @@ void Cfg::genFrame() {
// TODO: Consider folding epilog generation into the final // TODO: Consider folding epilog generation into the final
// emission/assembly pass to avoid an extra iteration over the node // emission/assembly pass to avoid an extra iteration over the node
// list. Or keep a separate list of exit nodes. // list. Or keep a separate list of exit nodes.
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
CfgNode *Node = *I;
if (Node->getHasReturn()) if (Node->getHasReturn())
getTarget()->addEpilog(Node); getTarget()->addEpilog(Node);
}
} }
// This is a lightweight version of live-range-end calculation. Marks // This is a lightweight version of live-range-end calculation. Marks
...@@ -179,9 +169,8 @@ void Cfg::livenessLightweight() { ...@@ -179,9 +169,8 @@ void Cfg::livenessLightweight() {
GlobalContext::getTimerID("livenessLightweight"); GlobalContext::getTimerID("livenessLightweight");
TimerMarker T(IDlivenessLightweight, getContext()); TimerMarker T(IDlivenessLightweight, getContext());
getVMetadata()->init(); getVMetadata()->init();
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->livenessLightweight(); Node->livenessLightweight();
}
} }
void Cfg::liveness(LivenessMode Mode) { void Cfg::liveness(LivenessMode Mode) {
...@@ -194,8 +183,8 @@ void Cfg::liveness(LivenessMode Mode) { ...@@ -194,8 +183,8 @@ void Cfg::liveness(LivenessMode Mode) {
llvm::BitVector NeedToProcess(Nodes.size(), true); llvm::BitVector NeedToProcess(Nodes.size(), true);
while (NeedToProcess.any()) { while (NeedToProcess.any()) {
// Iterate in reverse topological order to speed up convergence. // Iterate in reverse topological order to speed up convergence.
for (NodeList::reverse_iterator I = Nodes.rbegin(), E = Nodes.rend(); // TODO(stichnot): Use llvm::make_range with LLVM 3.5.
I != E; ++I) { for (auto I = Nodes.rbegin(), E = Nodes.rend(); I != E; ++I) {
CfgNode *Node = *I; CfgNode *Node = *I;
if (NeedToProcess[Node->getIndex()]) { if (NeedToProcess[Node->getIndex()]) {
NeedToProcess[Node->getIndex()] = false; NeedToProcess[Node->getIndex()] = false;
...@@ -203,24 +192,16 @@ void Cfg::liveness(LivenessMode Mode) { ...@@ -203,24 +192,16 @@ void Cfg::liveness(LivenessMode Mode) {
if (Changed) { if (Changed) {
// If the beginning-of-block liveness changed since the last // If the beginning-of-block liveness changed since the last
// iteration, mark all in-edges as needing to be processed. // iteration, mark all in-edges as needing to be processed.
const NodeList &InEdges = Node->getInEdges(); for (CfgNode *Pred : Node->getInEdges())
for (NodeList::const_iterator I1 = InEdges.begin(),
E1 = InEdges.end();
I1 != E1; ++I1) {
CfgNode *Pred = *I1;
NeedToProcess[Pred->getIndex()] = true; NeedToProcess[Pred->getIndex()] = true;
}
} }
} }
} }
} }
if (Mode == Liveness_Intervals) { if (Mode == Liveness_Intervals) {
// Reset each variable's live range. // Reset each variable's live range.
for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); for (Variable *Var : Variables)
I != E; ++I) { Var->resetLiveRange();
if (Variable *Var = *I)
Var->resetLiveRange();
}
} }
// Collect timing for just the portion that constructs the live // Collect timing for just the portion that constructs the live
// range intervals based on the end-of-live-range computation, for a // range intervals based on the end-of-live-range computation, for a
...@@ -229,9 +210,8 @@ void Cfg::liveness(LivenessMode Mode) { ...@@ -229,9 +210,8 @@ void Cfg::liveness(LivenessMode Mode) {
// and build each Variable's live range. // and build each Variable's live range.
static TimerIdT IDliveRange = GlobalContext::getTimerID("liveRange"); static TimerIdT IDliveRange = GlobalContext::getTimerID("liveRange");
TimerMarker T1(IDliveRange, getContext()); TimerMarker T1(IDliveRange, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (CfgNode *Node : Nodes)
(*I)->livenessPostprocess(Mode, getLiveness()); Node->livenessPostprocess(Mode, getLiveness());
}
if (Mode == Liveness_Intervals) { if (Mode == Liveness_Intervals) {
// Special treatment for live in-args. Their liveness needs to // Special treatment for live in-args. Their liveness needs to
// extend beyond the beginning of the function, otherwise an arg // extend beyond the beginning of the function, otherwise an arg
...@@ -280,13 +260,8 @@ bool Cfg::validateLiveness() const { ...@@ -280,13 +260,8 @@ bool Cfg::validateLiveness() const {
TimerMarker T(IDvalidateLiveness, getContext()); TimerMarker T(IDvalidateLiveness, getContext());
bool Valid = true; bool Valid = true;
Ostream &Str = Ctx->getStrDump(); Ostream &Str = Ctx->getStrDump();
for (NodeList::const_iterator I1 = Nodes.begin(), E1 = Nodes.end(); I1 != E1; for (CfgNode *Node : Nodes) {
++I1) { for (Inst *Inst : Node->getInsts()) {
CfgNode *Node = *I1;
InstList &Insts = Node->getInsts();
for (InstList::const_iterator I2 = Insts.begin(), E2 = Insts.end();
I2 != E2; ++I2) {
Inst *Inst = *I2;
if (Inst->isDeleted()) if (Inst->isDeleted())
continue; continue;
if (llvm::isa<InstFakeKill>(Inst)) if (llvm::isa<InstFakeKill>(Inst))
...@@ -327,8 +302,8 @@ bool Cfg::validateLiveness() const { ...@@ -327,8 +302,8 @@ bool Cfg::validateLiveness() const {
void Cfg::doBranchOpt() { void Cfg::doBranchOpt() {
static TimerIdT IDdoBranchOpt = GlobalContext::getTimerID("doBranchOpt"); static TimerIdT IDdoBranchOpt = GlobalContext::getTimerID("doBranchOpt");
TimerMarker T(IDdoBranchOpt, getContext()); TimerMarker T(IDdoBranchOpt, getContext());
for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
NodeList::iterator NextNode = I; auto NextNode = I;
++NextNode; ++NextNode;
(*I)->doBranchOpt(NextNode == E ? NULL : *NextNode); (*I)->doBranchOpt(NextNode == E ? NULL : *NextNode);
} }
...@@ -360,16 +335,11 @@ void Cfg::emit() { ...@@ -360,16 +335,11 @@ void Cfg::emit() {
Str << "\t.type\t" << MangledName << ",@function\n"; Str << "\t.type\t" << MangledName << ",@function\n";
} }
Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x"; Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x";
llvm::ArrayRef<uint8_t> Pad = getTarget()->getNonExecBundlePadding(); for (AsmCodeByte I : getTarget()->getNonExecBundlePadding())
for (llvm::ArrayRef<uint8_t>::iterator I = Pad.begin(), E = Pad.end(); Str.write_hex(I);
I != E; ++I) {
Str.write_hex(*I);
}
Str << "\n"; Str << "\n";
for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; for (CfgNode *Node : Nodes)
++I) { Node->emit(this);
(*I)->emit(this);
}
Str << "\n"; Str << "\n";
} }
...@@ -398,9 +368,7 @@ void Cfg::dump(const IceString &Message) { ...@@ -398,9 +368,7 @@ void Cfg::dump(const IceString &Message) {
resetCurrentNode(); resetCurrentNode();
if (getContext()->isVerbose(IceV_Liveness)) { if (getContext()->isVerbose(IceV_Liveness)) {
// Print summary info about variables // Print summary info about variables
for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); for (Variable *Var : Variables) {
I != E; ++I) {
Variable *Var = *I;
Str << "// multiblock="; Str << "// multiblock=";
if (getVMetadata()->isTracked(Var)) if (getVMetadata()->isTracked(Var))
Str << getVMetadata()->isMultiBlock(Var); Str << getVMetadata()->isMultiBlock(Var);
...@@ -412,13 +380,10 @@ void Cfg::dump(const IceString &Message) { ...@@ -412,13 +380,10 @@ void Cfg::dump(const IceString &Message) {
} }
} }
// Print each basic block // Print each basic block
for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; for (CfgNode *Node : Nodes)
++I) { Node->dump(this);
(*I)->dump(this); if (getContext()->isVerbose(IceV_Instructions))
}
if (getContext()->isVerbose(IceV_Instructions)) {
Str << "}\n"; Str << "}\n";
}
} }
} // end of namespace Ice } // end of namespace Ice
...@@ -55,14 +55,10 @@ void CfgNode::appendInst(Inst *Inst) { ...@@ -55,14 +55,10 @@ void CfgNode::appendInst(Inst *Inst) {
// instruction numbers in a block, from lowest to highest, must not // instruction numbers in a block, from lowest to highest, must not
// overlap with the range of any other block. // overlap with the range of any other block.
void CfgNode::renumberInstructions() { void CfgNode::renumberInstructions() {
for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis)
(*I)->renumber(Func); I->renumber(Func);
} for (Inst *I : Insts)
InstList::const_iterator I = Insts.begin(), E = Insts.end(); I->renumber(Func);
while (I != E) {
Inst *Inst = *I++;
Inst->renumber(Func);
}
} }
// When a node is created, the OutEdges are immediately knows, but the // When a node is created, the OutEdges are immediately knows, but the
...@@ -71,11 +67,8 @@ void CfgNode::renumberInstructions() { ...@@ -71,11 +67,8 @@ void CfgNode::renumberInstructions() {
// creating the InEdges list. // creating the InEdges list.
void CfgNode::computePredecessors() { void CfgNode::computePredecessors() {
OutEdges = (*Insts.rbegin())->getTerminatorEdges(); OutEdges = (*Insts.rbegin())->getTerminatorEdges();
for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); for (CfgNode *Succ : OutEdges)
I != E; ++I) { Succ->InEdges.push_back(this);
CfgNode *Node = *I;
Node->InEdges.push_back(this);
}
} }
// This does part 1 of Phi lowering, by creating a new dest variable // This does part 1 of Phi lowering, by creating a new dest variable
...@@ -90,10 +83,8 @@ void CfgNode::computePredecessors() { ...@@ -90,10 +83,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 (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis)
Inst *Inst = (*I)->lower(Func); Insts.insert(Insts.begin(), I->lower(Func));
Insts.insert(Insts.begin(), Inst);
}
} }
// This does part 2 of Phi lowering. For each Phi instruction at each // This does part 2 of Phi lowering. For each Phi instruction at each
...@@ -188,16 +179,12 @@ void CfgNode::placePhiStores() { ...@@ -188,16 +179,12 @@ void CfgNode::placePhiStores() {
} }
// Consider every out-edge. // Consider every out-edge.
for (NodeList::const_iterator I1 = OutEdges.begin(), E1 = OutEdges.end(); for (CfgNode *Succ : OutEdges) {
I1 != E1; ++I1) {
CfgNode *Target = *I1;
// Consider every Phi instruction at the out-edge. // Consider every Phi instruction at the out-edge.
for (PhiList::const_iterator I2 = Target->Phis.begin(), for (InstPhi *I : Succ->Phis) {
E2 = Target->Phis.end(); Operand *Operand = I->getOperandForTarget(this);
I2 != E2; ++I2) {
Operand *Operand = (*I2)->getOperandForTarget(this);
assert(Operand); assert(Operand);
Variable *Dest = (*I2)->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)
...@@ -210,9 +197,8 @@ void CfgNode::placePhiStores() { ...@@ -210,9 +197,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 (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis)
(*I)->setDeleted(); I->setDeleted();
}
} }
// Does address mode optimization. Pass each instruction to the // Does address mode optimization. Pass each instruction to the
...@@ -267,16 +253,16 @@ void CfgNode::livenessLightweight() { ...@@ -267,16 +253,16 @@ void CfgNode::livenessLightweight() {
SizeT NumVars = Func->getNumVariables(); SizeT NumVars = Func->getNumVariables();
llvm::BitVector Live(NumVars); llvm::BitVector Live(NumVars);
// Process regular instructions in reverse order. // Process regular instructions in reverse order.
for (InstList::const_reverse_iterator I = Insts.rbegin(), E = Insts.rend(); // TODO(stichnot): Use llvm::make_range with LLVM 3.5.
I != E; ++I) { for (auto I = Insts.rbegin(), E = Insts.rend(); I != E; ++I) {
if ((*I)->isDeleted()) if ((*I)->isDeleted())
continue; continue;
(*I)->livenessLightweight(Func, Live); (*I)->livenessLightweight(Func, Live);
} }
for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis) {
if ((*I)->isDeleted()) if (I->isDeleted())
continue; continue;
(*I)->livenessLightweight(Func, Live); I->livenessLightweight(Func, Live);
} }
} }
...@@ -295,21 +281,17 @@ bool CfgNode::liveness(Liveness *Liveness) { ...@@ -295,21 +281,17 @@ bool CfgNode::liveness(Liveness *Liveness) {
LiveBegin.assign(NumVars, Sentinel); LiveBegin.assign(NumVars, Sentinel);
LiveEnd.assign(NumVars, Sentinel); LiveEnd.assign(NumVars, Sentinel);
// Initialize Live to be the union of all successors' LiveIn. // Initialize Live to be the union of all successors' LiveIn.
for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); for (CfgNode *Succ : OutEdges) {
I != E; ++I) {
CfgNode *Succ = *I;
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 (PhiList::const_iterator I1 = Succ->Phis.begin(), E1 = Succ->Phis.end(); for (InstPhi *I : Succ->Phis)
I1 != E1; ++I1) { I->livenessPhiOperand(Live, this, Liveness);
(*I1)->livenessPhiOperand(Live, this, Liveness);
}
} }
Liveness->getLiveOut(this) = Live; Liveness->getLiveOut(this) = Live;
// Process regular instructions in reverse order. // Process regular instructions in reverse order.
for (InstList::const_reverse_iterator I = Insts.rbegin(), E = Insts.rend(); // TODO(stichnot): Use llvm::make_range with LLVM 3.5.
I != E; ++I) { for (auto I = Insts.rbegin(), E = Insts.rend(); I != E; ++I) {
if ((*I)->isDeleted()) if ((*I)->isDeleted())
continue; continue;
(*I)->liveness((*I)->getNumber(), Live, Liveness, this); (*I)->liveness((*I)->getNumber(), Live, Liveness, this);
...@@ -318,12 +300,12 @@ bool CfgNode::liveness(Liveness *Liveness) { ...@@ -318,12 +300,12 @@ bool CfgNode::liveness(Liveness *Liveness) {
// instruction number to be that of the earliest phi instruction in // instruction number to be that of the earliest phi instruction in
// the block. // the block.
InstNumberT FirstPhiNumber = Inst::NumberSentinel; InstNumberT FirstPhiNumber = Inst::NumberSentinel;
for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis) {
if ((*I)->isDeleted()) if (I->isDeleted())
continue; continue;
if (FirstPhiNumber == Inst::NumberSentinel) if (FirstPhiNumber == Inst::NumberSentinel)
FirstPhiNumber = (*I)->getNumber(); FirstPhiNumber = I->getNumber();
(*I)->liveness(FirstPhiNumber, Live, Liveness, this); I->liveness(FirstPhiNumber, Live, Liveness, this);
} }
// When using the sparse representation, after traversing the // When using the sparse representation, after traversing the
...@@ -376,36 +358,33 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) { ...@@ -376,36 +358,33 @@ void CfgNode::livenessPostprocess(LivenessMode Mode, Liveness *Liveness) {
InstNumberT FirstInstNum = Inst::NumberSentinel; InstNumberT FirstInstNum = Inst::NumberSentinel;
InstNumberT LastInstNum = Inst::NumberSentinel; InstNumberT LastInstNum = Inst::NumberSentinel;
// Process phis in any order. Process only Dest operands. // Process phis in any order. Process only Dest operands.
for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *I : Phis) {
InstPhi *Inst = *I; I->deleteIfDead();
Inst->deleteIfDead(); if (I->isDeleted())
if (Inst->isDeleted())
continue; continue;
if (FirstInstNum == Inst::NumberSentinel) if (FirstInstNum == Inst::NumberSentinel)
FirstInstNum = Inst->getNumber(); FirstInstNum = I->getNumber();
assert(Inst->getNumber() > LastInstNum); assert(I->getNumber() > LastInstNum);
LastInstNum = Inst->getNumber(); LastInstNum = I->getNumber();
} }
// Process instructions // Process instructions
for (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E; for (Inst *I : Insts) {
++I) { I->deleteIfDead();
Inst *Inst = *I; if (I->isDeleted())
Inst->deleteIfDead();
if (Inst->isDeleted())
continue; continue;
if (FirstInstNum == Inst::NumberSentinel) if (FirstInstNum == Inst::NumberSentinel)
FirstInstNum = Inst->getNumber(); FirstInstNum = I->getNumber();
assert(Inst->getNumber() > LastInstNum); assert(I->getNumber() > LastInstNum);
LastInstNum = Inst->getNumber(); LastInstNum = I->getNumber();
// Create fake live ranges for a Kill instruction, but only if the // Create fake live ranges for a Kill instruction, but only if the
// linked instruction is still alive. // linked instruction is still alive.
if (Mode == Liveness_Intervals) { if (Mode == Liveness_Intervals) {
if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(Inst)) { if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) {
if (!Kill->getLinked()->isDeleted()) { if (!Kill->getLinked()->isDeleted()) {
SizeT NumSrcs = Inst->getSrcSize(); SizeT NumSrcs = I->getSrcSize();
for (SizeT i = 0; i < NumSrcs; ++i) { for (SizeT Src = 0; Src < NumSrcs; ++Src) {
Variable *Var = llvm::cast<Variable>(Inst->getSrc(i)); Variable *Var = llvm::cast<Variable>(I->getSrc(Src));
InstNumberT InstNumber = Inst->getNumber(); InstNumberT InstNumber = I->getNumber();
Liveness->addLiveRange(Var, InstNumber, InstNumber, 1); Liveness->addLiveRange(Var, InstNumber, InstNumber, 1);
} }
} }
...@@ -454,10 +433,8 @@ void CfgNode::doBranchOpt(const CfgNode *NextNode) { ...@@ -454,10 +433,8 @@ 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 (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E; for (Inst *I : Insts)
++I) { Target->doBranchOpt(I, NextNode);
Target->doBranchOpt(*I, NextNode);
}
} }
// ======================== Dump routines ======================== // // ======================== Dump routines ======================== //
...@@ -469,38 +446,35 @@ void CfgNode::emit(Cfg *Func) const { ...@@ -469,38 +446,35 @@ void CfgNode::emit(Cfg *Func) const {
Str << Func->getContext()->mangleName(Func->getFunctionName()) << ":\n"; Str << Func->getContext()->mangleName(Func->getFunctionName()) << ":\n";
} }
Str << getAsmName() << ":\n"; Str << getAsmName() << ":\n";
for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { for (InstPhi *Phi : Phis) {
InstPhi *Phi = *I;
if (Phi->isDeleted()) if (Phi->isDeleted())
continue; continue;
// Emitting a Phi instruction should cause an error. // Emitting a Phi instruction should cause an error.
Inst *Instr = Phi; Inst *Instr = Phi;
Instr->emit(Func); Instr->emit(Func);
} }
for (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E; for (Inst *I : Insts) {
++I) { if (I->isDeleted())
Inst *Inst = *I;
if (Inst->isDeleted())
continue; continue;
// Here we detect redundant assignments like "mov eax, eax" and // Here we detect redundant assignments like "mov eax, eax" and
// suppress them. // suppress them.
if (Inst->isRedundantAssign()) if (I->isRedundantAssign())
continue; continue;
if (Func->UseIntegratedAssembler()) { if (Func->UseIntegratedAssembler()) {
(*I)->emitIAS(Func); I->emitIAS(Func);
} else { } else {
(*I)->emit(Func); I->emit(Func);
} }
// Update emitted instruction count, plus fill/spill count for // Update emitted instruction count, plus fill/spill count for
// Variable operands without a physical register. // Variable operands without a physical register.
if (uint32_t Count = (*I)->getEmitInstCount()) { if (uint32_t Count = I->getEmitInstCount()) {
Func->getContext()->statsUpdateEmitted(Count); Func->getContext()->statsUpdateEmitted(Count);
if (Variable *Dest = (*I)->getDest()) { if (Variable *Dest = I->getDest()) {
if (!Dest->hasReg()) if (!Dest->hasReg())
Func->getContext()->statsUpdateFills(); Func->getContext()->statsUpdateFills();
} }
for (SizeT S = 0; S < (*I)->getSrcSize(); ++S) { for (SizeT S = 0; S < I->getSrcSize(); ++S) {
if (Variable *Src = llvm::dyn_cast<Variable>((*I)->getSrc(S))) { if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) {
if (!Src->hasReg()) if (!Src->hasReg())
Func->getContext()->statsUpdateSpills(); Func->getContext()->statsUpdateSpills();
} }
...@@ -519,11 +493,12 @@ void CfgNode::dump(Cfg *Func) const { ...@@ -519,11 +493,12 @@ void CfgNode::dump(Cfg *Func) const {
// Dump list of predecessor nodes. // Dump list of predecessor nodes.
if (Func->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { if (Func->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) {
Str << " // preds = "; Str << " // preds = ";
for (NodeList::const_iterator I = InEdges.begin(), E = InEdges.end(); bool First = true;
I != E; ++I) { for (CfgNode *I : InEdges) {
if (I != InEdges.begin()) if (First)
Str << ", "; Str << ", ";
Str << "%" << (*I)->getName(); First = false;
Str << "%" << I->getName();
} }
Str << "\n"; Str << "\n";
} }
...@@ -542,16 +517,10 @@ void CfgNode::dump(Cfg *Func) const { ...@@ -542,16 +517,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 (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; for (InstPhi *I : Phis)
++I) { I->dumpDecorated(Func);
const Inst *Inst = *I; for (Inst *I : Insts)
Inst->dumpDecorated(Func); I->dumpDecorated(Func);
}
InstList::const_iterator I = Insts.begin(), E = Insts.end();
while (I != E) {
Inst *Inst = *I++;
Inst->dumpDecorated(Func);
}
} }
// Dump the live-out variables. // Dump the live-out variables.
llvm::BitVector LiveOut; llvm::BitVector LiveOut;
...@@ -569,11 +538,12 @@ void CfgNode::dump(Cfg *Func) const { ...@@ -569,11 +538,12 @@ void CfgNode::dump(Cfg *Func) const {
// Dump list of successor nodes. // Dump list of successor nodes.
if (Func->getContext()->isVerbose(IceV_Succs)) { if (Func->getContext()->isVerbose(IceV_Succs)) {
Str << " // succs = "; Str << " // succs = ";
for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); bool First = true;
I != E; ++I) { for (CfgNode *I : OutEdges) {
if (I != OutEdges.begin()) if (First)
Str << ", "; Str << ", ";
Str << "%" << (*I)->getName(); First = false;
Str << "%" << I->getName();
} }
Str << "\n"; Str << "\n";
} }
......
...@@ -70,9 +70,8 @@ public: ...@@ -70,9 +70,8 @@ public:
Func->setInternal(F->hasInternalLinkage()); Func->setInternal(F->hasInternalLinkage());
// The initial definition/use of each arg is the entry node. // The initial definition/use of each arg is the entry node.
for (Function::const_arg_iterator ArgI = F->arg_begin(), for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE;
ArgE = F->arg_end(); ++ArgI) {
ArgI != ArgE; ++ArgI) {
Func->addArg(mapValueToIceVar(ArgI)); Func->addArg(mapValueToIceVar(ArgI));
} }
...@@ -80,14 +79,10 @@ public: ...@@ -80,14 +79,10 @@ public:
// blocks in the original linearized order. Otherwise the ICE // blocks in the original linearized order. Otherwise the ICE
// linearized order will be affected by branch targets in // linearized order will be affected by branch targets in
// terminator instructions. // terminator instructions.
for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; for (const BasicBlock &BBI : *F)
++BBI) { mapBasicBlockToNode(&BBI);
mapBasicBlockToNode(BBI); for (const BasicBlock &BBI : *F)
} convertBasicBlock(&BBI);
for (Function::const_iterator BBI = F->begin(), BBE = F->end(); BBI != BBE;
++BBI) {
convertBasicBlock(BBI);
}
Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock()));
Func->computePredecessors(); Func->computePredecessors();
...@@ -564,9 +559,8 @@ private: ...@@ -564,9 +559,8 @@ private:
Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) {
Ice::CfgNode *Node = mapBasicBlockToNode(BB); Ice::CfgNode *Node = mapBasicBlockToNode(BB);
for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end(); for (const Instruction &II : *BB) {
II != II_e; ++II) { Ice::Inst *Inst = convertInstruction(&II);
Ice::Inst *Inst = convertInstruction(II);
Node->appendInst(Inst); Node->appendInst(Inst);
} }
return Node; return Node;
...@@ -632,12 +626,12 @@ void Converter::convertToIce() { ...@@ -632,12 +626,12 @@ void Converter::convertToIce() {
} }
void Converter::convertFunctions() { void Converter::convertFunctions() {
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { for (const Function &I : *Mod) {
if (I->empty()) if (I.empty())
continue; continue;
LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext());
Cfg *Fcn = FunctionConverter.convertFunction(I); Cfg *Fcn = FunctionConverter.convertFunction(&I);
translateFcn(Fcn); translateFcn(Fcn);
} }
......
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
TypePool() : NextPoolID(0) {} TypePool() : NextPoolID(0) {}
ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) {
TupleType TupleKey = std::make_pair(Ty, Key); TupleType TupleKey = std::make_pair(Ty, Key);
typename ContainerType::const_iterator Iter = Pool.find(TupleKey); auto Iter = Pool.find(TupleKey);
if (Iter != Pool.end()) if (Iter != Pool.end())
return Iter->second; return Iter->second;
ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++);
...@@ -52,12 +52,8 @@ public: ...@@ -52,12 +52,8 @@ public:
ConstantList getConstantPool() const { ConstantList getConstantPool() const {
ConstantList Constants; ConstantList Constants;
Constants.reserve(Pool.size()); Constants.reserve(Pool.size());
// TODO: replace the loop with std::transform + lambdas. for (auto &I : Pool)
for (typename ContainerType::const_iterator I = Pool.begin(), Constants.push_back(I.second);
E = Pool.end();
I != E; ++I) {
Constants.push_back(I->second);
}
return Constants; return Constants;
} }
...@@ -86,7 +82,7 @@ public: ...@@ -86,7 +82,7 @@ public:
UndefPool() : NextPoolID(0) {} UndefPool() : NextPoolID(0) {}
ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
ContainerType::iterator I = Pool.find(Ty); auto I = Pool.find(Ty);
if (I != Pool.end()) if (I != Pool.end())
return I->second; return I->second;
ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++); ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++);
......
...@@ -420,11 +420,8 @@ InstFakeKill::InstFakeKill(Cfg *Func, const VarList &KilledRegs, ...@@ -420,11 +420,8 @@ InstFakeKill::InstFakeKill(Cfg *Func, const VarList &KilledRegs,
const Inst *Linked) const Inst *Linked)
: InstHighLevel(Func, Inst::FakeKill, KilledRegs.size(), NULL), : InstHighLevel(Func, Inst::FakeKill, KilledRegs.size(), NULL),
Linked(Linked) { Linked(Linked) {
for (VarList::const_iterator I = KilledRegs.begin(), E = KilledRegs.end(); for (Variable *Var : KilledRegs)
I != E; ++I) {
Variable *Var = *I;
addSource(Var); addSource(Var);
}
} }
// ======================== Dump routines ======================== // // ======================== Dump routines ======================== //
......
...@@ -207,7 +207,7 @@ Intrinsics::Intrinsics() { ...@@ -207,7 +207,7 @@ Intrinsics::Intrinsics() {
for (size_t I = 0; I < IceIntrinsicsTableSize; ++I) { for (size_t I = 0; I < IceIntrinsicsTableSize; ++I) {
const struct IceIntrinsicsEntry_ &Entry = IceIntrinsicsTable[I]; const struct IceIntrinsicsEntry_ &Entry = IceIntrinsicsTable[I];
assert(Entry.Info.NumTypes <= kMaxIntrinsicParameters); assert(Entry.Info.NumTypes <= kMaxIntrinsicParameters);
map.insert(std::make_pair(IceString(Entry.IntrinsicName), Entry.Info)); Map.insert(std::make_pair(IceString(Entry.IntrinsicName), Entry.Info));
} }
} }
...@@ -215,8 +215,8 @@ Intrinsics::~Intrinsics() {} ...@@ -215,8 +215,8 @@ Intrinsics::~Intrinsics() {}
const Intrinsics::FullIntrinsicInfo * const Intrinsics::FullIntrinsicInfo *
Intrinsics::find(const IceString &Name) const { Intrinsics::find(const IceString &Name) const {
IntrinsicMap::const_iterator it = map.find(Name); auto it = Map.find(Name);
if (it == map.end()) if (it == Map.end())
return NULL; return NULL;
return &it->second; return &it->second;
} }
......
...@@ -157,7 +157,7 @@ public: ...@@ -157,7 +157,7 @@ public:
private: private:
// TODO(jvoung): May want to switch to something like LLVM's StringMap. // TODO(jvoung): May want to switch to something like LLVM's StringMap.
typedef std::map<IceString, FullIntrinsicInfo> IntrinsicMap; typedef std::map<IceString, FullIntrinsicInfo> IntrinsicMap;
IntrinsicMap map; IntrinsicMap Map;
Intrinsics(const Intrinsics &) LLVM_DELETED_FUNCTION; Intrinsics(const Intrinsics &) LLVM_DELETED_FUNCTION;
Intrinsics &operator=(const Intrinsics &) LLVM_DELETED_FUNCTION; Intrinsics &operator=(const Intrinsics &) LLVM_DELETED_FUNCTION;
......
...@@ -123,13 +123,12 @@ bool LiveRange::overlaps(const LiveRange &Other) const { ...@@ -123,13 +123,12 @@ bool LiveRange::overlaps(const LiveRange &Other) const {
bool LiveRange::overlaps(InstNumberT OtherBegin) const { bool LiveRange::overlaps(InstNumberT OtherBegin) const {
bool Result = false; bool Result = false;
for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; for (const RangeElementType &I : Range) {
++I) { if (OtherBegin < I.first) {
if (OtherBegin < I->first) {
Result = false; Result = false;
break; break;
} }
if (OtherBegin < I->second) { if (OtherBegin < I.second) {
Result = true; Result = true;
break; break;
} }
...@@ -148,9 +147,8 @@ bool LiveRange::overlaps(InstNumberT OtherBegin) const { ...@@ -148,9 +147,8 @@ bool LiveRange::overlaps(InstNumberT OtherBegin) const {
// number. This is only used for validating the live range // number. This is only used for validating the live range
// calculation. // calculation.
bool LiveRange::containsValue(InstNumberT Value) const { bool LiveRange::containsValue(InstNumberT Value) const {
for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; for (const RangeElementType &I : Range) {
++I) { if (I.first <= Value && Value <= I.second)
if (I->first <= Value && Value <= I->second)
return true; return true;
} }
return false; return false;
...@@ -282,11 +280,7 @@ void VariablesMetadata::init() { ...@@ -282,11 +280,7 @@ void VariablesMetadata::init() {
Metadata.resize(Func->getNumVariables()); Metadata.resize(Func->getNumVariables());
// Mark implicit args as being used in the entry node. // Mark implicit args as being used in the entry node.
const VarList &ImplicitArgList = Func->getImplicitArgs(); for (Variable *Var : Func->getImplicitArgs()) {
for (VarList::const_iterator I = ImplicitArgList.begin(),
E = ImplicitArgList.end();
I != E; ++I) {
const Variable *Var = *I;
const Inst *NoInst = NULL; const Inst *NoInst = NULL;
const CfgNode *EntryNode = Func->getEntryNode(); const CfgNode *EntryNode = Func->getEntryNode();
const bool IsFromDef = false; const bool IsFromDef = false;
...@@ -297,30 +291,28 @@ void VariablesMetadata::init() { ...@@ -297,30 +291,28 @@ void VariablesMetadata::init() {
SizeT NumNodes = Func->getNumNodes(); SizeT NumNodes = Func->getNumNodes();
for (SizeT N = 0; N < NumNodes; ++N) { for (SizeT N = 0; N < NumNodes; ++N) {
CfgNode *Node = Func->getNodes()[N]; CfgNode *Node = Func->getNodes()[N];
const InstList &Insts = Node->getInsts(); for (Inst *I : Node->getInsts()) {
for (InstList::const_iterator I = Insts.begin(), E = Insts.end(); I != E; if (I->isDeleted())
++I) {
if ((*I)->isDeleted())
continue; continue;
if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(*I)) { if (InstFakeKill *Kill = llvm::dyn_cast<InstFakeKill>(I)) {
// A FakeKill instruction indicates certain Variables (usually // A FakeKill instruction indicates certain Variables (usually
// physical scratch registers) are redefined, so we register // physical scratch registers) are redefined, so we register
// them as defs. // them as defs.
for (SizeT SrcNum = 0; SrcNum < (*I)->getSrcSize(); ++SrcNum) { for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) {
Variable *Var = llvm::cast<Variable>((*I)->getSrc(SrcNum)); Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum));
SizeT VarNum = Var->getIndex(); SizeT VarNum = Var->getIndex();
assert(VarNum < Metadata.size()); assert(VarNum < Metadata.size());
Metadata[VarNum].markDef(Kill, Node); Metadata[VarNum].markDef(Kill, Node);
} }
continue; // no point in executing the rest continue; // no point in executing the rest
} }
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(*I, Node); Metadata[DestNum].markDef(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);
...@@ -328,7 +320,7 @@ void VariablesMetadata::init() { ...@@ -328,7 +320,7 @@ void VariablesMetadata::init() {
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(*I, Node, IsFromDef, IsImplicit); Metadata[VarNum].markUse(I, Node, IsFromDef, IsImplicit);
} }
} }
} }
...@@ -440,11 +432,12 @@ void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const { ...@@ -440,11 +432,12 @@ void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const {
void LiveRange::dump(Ostream &Str) const { void LiveRange::dump(Ostream &Str) const {
Str << "(weight=" << Weight << ") "; Str << "(weight=" << Weight << ") ";
for (RangeType::const_iterator I = Range.begin(), E = Range.end(); I != E; bool First = true;
++I) { for (const RangeElementType &I : Range) {
if (I != Range.begin()) if (First)
Str << ", "; Str << ", ";
Str << "[" << (*I).first << ":" << (*I).second << ")"; First = false;
Str << "[" << I.first << ":" << I.second << ")";
} }
} }
......
...@@ -88,9 +88,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -88,9 +88,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
static TimerIdT IDinitUnhandled = static TimerIdT IDinitUnhandled =
GlobalContext::getTimerID("initUnhandled"); GlobalContext::getTimerID("initUnhandled");
TimerMarker T(IDinitUnhandled, Func->getContext()); TimerMarker T(IDinitUnhandled, Func->getContext());
for (VarList::const_iterator I = Vars.begin(), E = Vars.end(); I != E; for (Variable *Var : Vars) {
++I) {
Variable *Var = *I;
// Explicitly don't consider zero-weight variables, which are // Explicitly don't consider zero-weight variables, which are
// meant to be spill slots. // meant to be spill slots.
if (Var->getWeight() == RegWeight::Zero) if (Var->getWeight() == RegWeight::Zero)
...@@ -151,8 +149,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -151,8 +149,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
} }
// Check for active ranges that have expired or become inactive. // Check for active ranges that have expired or become inactive.
for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; for (auto I = Active.begin(), E = Active.end(); I != E; I = Next) {
I = Next) {
Next = I; Next = I;
++Next; ++Next;
LiveRangeWrapper Item = *I; LiveRangeWrapper Item = *I;
...@@ -188,8 +185,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -188,8 +185,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
} }
// Check for inactive ranges that have expired or reactivated. // Check for inactive ranges that have expired or reactivated.
for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); for (auto I = Inactive.begin(), E = Inactive.end(); I != E; I = Next) {
I != E; I = Next) {
Next = I; Next = I;
++Next; ++Next;
LiveRangeWrapper Item = *I; LiveRangeWrapper Item = *I;
...@@ -280,10 +276,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -280,10 +276,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
// Remove registers from the Free[] list where an Inactive range // Remove registers from the Free[] list where an Inactive range
// overlaps with the current range. // overlaps with the current range.
for (UnorderedRanges::const_iterator I = Inactive.begin(), for (const LiveRangeWrapper &Item : Inactive) {
E = Inactive.end();
I != E; ++I) {
LiveRangeWrapper Item = *I;
if (Item.overlaps(Cur)) { if (Item.overlaps(Cur)) {
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
// Don't assert(Free[RegNum]) because in theory (though // Don't assert(Free[RegNum]) because in theory (though
...@@ -304,9 +297,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -304,9 +297,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
// Disable AllowOverlap if an Active variable, which is not // Disable AllowOverlap if an Active variable, which is not
// Prefer, shares Prefer's register, and has a definition within // Prefer, shares Prefer's register, and has a definition within
// Cur's live range. // Cur's live range.
for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); for (const LiveRangeWrapper &Item : Active) {
AllowOverlap && I != E; ++I) {
LiveRangeWrapper Item = *I;
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
if (Item.Var != Prefer && RegNum == PreferReg && if (Item.Var != Prefer && RegNum == PreferReg &&
overlapsDefs(Func, Cur, Item.Var)) { overlapsDefs(Func, Cur, Item.Var)) {
...@@ -317,14 +308,13 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -317,14 +308,13 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
// Remove registers from the Free[] list where an Unhandled range // Remove registers from the Free[] list where an Unhandled range
// overlaps with the current range and is precolored. // overlaps with the current range and is precolored.
// Cur.endsBefore(*I) is an early exit check that turns a // Cur.endsBefore(Item) is an early exit check that turns a
// guaranteed O(N^2) algorithm into expected linear complexity. // guaranteed O(N^2) algorithm into expected linear complexity.
llvm::SmallBitVector PrecoloredUnhandled(RegMask.size()); llvm::SmallBitVector PrecoloredUnhandled(RegMask.size());
// Note: PrecoloredUnhandled is only used for dumping. // Note: PrecoloredUnhandled is only used for dumping.
for (OrderedRanges::const_iterator I = Unhandled.begin(), for (const LiveRangeWrapper &Item : Unhandled) {
E = Unhandled.end(); if (Cur.endsBefore(Item))
I != E && !Cur.endsBefore(*I); ++I) { break;
LiveRangeWrapper Item = *I;
if (Item.Var->hasReg() && Item.overlaps(Cur)) { if (Item.Var->hasReg() && Item.overlaps(Cur)) {
int32_t ItemReg = Item.Var->getRegNum(); // Note: not getRegNumTmp() int32_t ItemReg = Item.Var->getRegNum(); // Note: not getRegNumTmp()
Free[ItemReg] = false; Free[ItemReg] = false;
...@@ -381,19 +371,14 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -381,19 +371,14 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
// lowest-weight register and see if Cur has higher weight. // lowest-weight register and see if Cur has higher weight.
std::vector<RegWeight> Weights(RegMask.size()); std::vector<RegWeight> Weights(RegMask.size());
// Check Active ranges. // Check Active ranges.
for (UnorderedRanges::const_iterator I = Active.begin(), E = Active.end(); for (const LiveRangeWrapper &Item : Active) {
I != E; ++I) {
LiveRangeWrapper Item = *I;
assert(Item.overlaps(Cur)); assert(Item.overlaps(Cur));
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
assert(Item.Var->hasRegTmp()); assert(Item.Var->hasRegTmp());
Weights[RegNum].addWeight(Item.range().getWeight()); Weights[RegNum].addWeight(Item.range().getWeight());
} }
// Same as above, but check Inactive ranges instead of Active. // Same as above, but check Inactive ranges instead of Active.
for (UnorderedRanges::const_iterator I = Inactive.begin(), for (const LiveRangeWrapper &Item : Inactive) {
E = Inactive.end();
I != E; ++I) {
LiveRangeWrapper Item = *I;
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
assert(Item.Var->hasRegTmp()); assert(Item.Var->hasRegTmp());
if (Item.overlaps(Cur)) if (Item.overlaps(Cur))
...@@ -402,10 +387,9 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -402,10 +387,9 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
// Check Unhandled ranges that overlap Cur and are precolored. // Check Unhandled ranges that overlap Cur and are precolored.
// Cur.endsBefore(*I) is an early exit check that turns a // Cur.endsBefore(*I) is an early exit check that turns a
// guaranteed O(N^2) algorithm into expected linear complexity. // guaranteed O(N^2) algorithm into expected linear complexity.
for (OrderedRanges::const_iterator I = Unhandled.begin(), for (const LiveRangeWrapper &Item : Unhandled) {
E = Unhandled.end(); if (Cur.endsBefore(Item))
I != E && !Cur.endsBefore(*I); ++I) { break;
LiveRangeWrapper Item = *I;
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
if (RegNum < 0) if (RegNum < 0)
continue; continue;
...@@ -436,8 +420,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -436,8 +420,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
} else { } else {
// Evict all live ranges in Active that register number // Evict all live ranges in Active that register number
// MinWeightIndex is assigned to. // MinWeightIndex is assigned to.
for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); for (auto I = Active.begin(), E = Active.end(); I != E; I = Next) {
I != E; I = Next) {
Next = I; Next = I;
++Next; ++Next;
LiveRangeWrapper Item = *I; LiveRangeWrapper Item = *I;
...@@ -455,8 +438,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -455,8 +438,7 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
} }
} }
// Do the same for Inactive. // Do the same for Inactive.
for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end(); for (auto I = Inactive.begin(), E = Inactive.end(); I != E; I = Next) {
I != E; I = Next) {
Next = I; Next = I;
++Next; ++Next;
LiveRangeWrapper Item = *I; LiveRangeWrapper Item = *I;
...@@ -496,26 +478,16 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) { ...@@ -496,26 +478,16 @@ void LinearScan::scan(const llvm::SmallBitVector &RegMaskFull) {
dump(Func); dump(Func);
} }
// Move anything Active or Inactive to Handled for easier handling. // Move anything Active or Inactive to Handled for easier handling.
for (UnorderedRanges::iterator I = Active.begin(), E = Active.end(); I != E; for (const LiveRangeWrapper &I : Active)
I = Next) { Handled.push_back(I);
Next = I; Active.clear();
++Next; for (const LiveRangeWrapper &I : Inactive)
Handled.push_back(*I); Handled.push_back(I);
Active.erase(I); Inactive.clear();
}
for (UnorderedRanges::iterator I = Inactive.begin(), E = Inactive.end();
I != E; I = Next) {
Next = I;
++Next;
Handled.push_back(*I);
Inactive.erase(I);
}
dump(Func); dump(Func);
// Finish up by assigning RegNumTmp->RegNum for each Variable. // Finish up by assigning RegNumTmp->RegNum for each Variable.
for (UnorderedRanges::const_iterator I = Handled.begin(), E = Handled.end(); for (const LiveRangeWrapper &Item : Handled) {
I != E; ++I) {
LiveRangeWrapper Item = *I;
int32_t RegNum = Item.Var->getRegNumTmp(); int32_t RegNum = Item.Var->getRegNumTmp();
if (Verbose) { if (Verbose) {
if (!Item.Var->hasRegTmp()) { if (!Item.Var->hasRegTmp()) {
...@@ -564,27 +536,23 @@ void LinearScan::dump(Cfg *Func) const { ...@@ -564,27 +536,23 @@ void LinearScan::dump(Cfg *Func) const {
Func->resetCurrentNode(); Func->resetCurrentNode();
Str << "**** Current regalloc state:\n"; Str << "**** Current regalloc state:\n";
Str << "++++++ Handled:\n"; Str << "++++++ Handled:\n";
for (UnorderedRanges::const_iterator I = Handled.begin(), E = Handled.end(); for (const LiveRangeWrapper &Item : Handled) {
I != E; ++I) { Item.dump(Func);
I->dump(Func);
Str << "\n"; Str << "\n";
} }
Str << "++++++ Unhandled:\n"; Str << "++++++ Unhandled:\n";
for (OrderedRanges::const_iterator I = Unhandled.begin(), E = Unhandled.end(); for (const LiveRangeWrapper &Item : Unhandled) {
I != E; ++I) { Item.dump(Func);
I->dump(Func);
Str << "\n"; Str << "\n";
} }
Str << "++++++ Active:\n"; Str << "++++++ Active:\n";
for (UnorderedRanges::const_iterator I = Active.begin(), E = Active.end(); for (const LiveRangeWrapper &Item : Active) {
I != E; ++I) { Item.dump(Func);
I->dump(Func);
Str << "\n"; Str << "\n";
} }
Str << "++++++ Inactive:\n"; Str << "++++++ Inactive:\n";
for (UnorderedRanges::const_iterator I = Inactive.begin(), E = Inactive.end(); for (const LiveRangeWrapper &Item : Inactive) {
I != E; ++I) { Item.dump(Func);
I->dump(Func);
Str << "\n"; Str << "\n";
} }
} }
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
namespace Ice { namespace Ice {
typedef uint8_t AsmCodeByte;
class Assembler; class Assembler;
// LoweringContext makes it easy to iterate through non-deleted // LoweringContext makes it easy to iterate through non-deleted
...@@ -52,6 +54,9 @@ public: ...@@ -52,6 +54,9 @@ public:
bool atEnd() const { return Cur == End; } bool atEnd() const { return Cur == End; }
InstList::iterator getCur() const { return Cur; } InstList::iterator getCur() const { return Cur; }
InstList::iterator getEnd() const { return End; } InstList::iterator getEnd() const { return End; }
// Adaptor to enable range-based for loops.
InstList::iterator begin() const { return getCur(); }
InstList::iterator end() const { return getEnd(); }
void insert(Inst *Inst); void insert(Inst *Inst);
Inst *getLastInserted() const; Inst *getLastInserted() const;
void advanceCur() { Cur = Next; } void advanceCur() { Cur = Next; }
...@@ -145,7 +150,7 @@ public: ...@@ -145,7 +150,7 @@ public:
virtual SizeT getFrameOrStackReg() const = 0; virtual SizeT getFrameOrStackReg() const = 0;
virtual size_t typeWidthInBytesOnStack(Type Ty) const = 0; virtual size_t typeWidthInBytesOnStack(Type Ty) const = 0;
virtual SizeT getBundleAlignLog2Bytes() const = 0; virtual SizeT getBundleAlignLog2Bytes() const = 0;
virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const = 0; virtual llvm::ArrayRef<AsmCodeByte> getNonExecBundlePadding() const = 0;
bool hasComputedFrame() const { return HasComputedFrame; } bool hasComputedFrame() const { return HasComputedFrame; }
bool shouldDoNopInsertion() const; bool shouldDoNopInsertion() const;
// Returns true if this function calls a function that has the // Returns true if this function calls a function that has the
......
...@@ -555,9 +555,7 @@ void TargetX8632::sortByAlignment(VarList &Dest, const VarList &Source) const { ...@@ -555,9 +555,7 @@ void TargetX8632::sortByAlignment(VarList &Dest, const VarList &Source) const {
X86_LOG2_OF_MAX_STACK_SLOT_SIZE - X86_LOG2_OF_MIN_STACK_SLOT_SIZE + 1; X86_LOG2_OF_MAX_STACK_SLOT_SIZE - X86_LOG2_OF_MIN_STACK_SLOT_SIZE + 1;
VarList Buckets[NumBuckets]; VarList Buckets[NumBuckets];
for (VarList::const_iterator I = Source.begin(), E = Source.end(); I != E; for (Variable *Var : Source) {
++I) {
Variable *Var = *I;
uint32_t NaturalAlignment = typeWidthInBytesOnStack(Var->getType()); uint32_t NaturalAlignment = typeWidthInBytesOnStack(Var->getType());
SizeT LogNaturalAlignment = llvm::findFirstSet(NaturalAlignment); SizeT LogNaturalAlignment = llvm::findFirstSet(NaturalAlignment);
assert(LogNaturalAlignment >= X86_LOG2_OF_MIN_STACK_SLOT_SIZE); assert(LogNaturalAlignment >= X86_LOG2_OF_MIN_STACK_SLOT_SIZE);
...@@ -698,9 +696,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -698,9 +696,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
// The entire spill locations area gets aligned to largest natural // The entire spill locations area gets aligned to largest natural
// alignment of the variables that have a spill slot. // alignment of the variables that have a spill slot.
uint32_t SpillAreaAlignmentBytes = 0; uint32_t SpillAreaAlignmentBytes = 0;
for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); for (Variable *Var : Variables) {
I != E; ++I) {
Variable *Var = *I;
if (Var->hasReg()) { if (Var->hasReg()) {
RegsUsed[Var->getRegNum()] = true; RegsUsed[Var->getRegNum()] = true;
continue; continue;
...@@ -726,10 +722,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -726,10 +722,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
SortedSpilledVariables.reserve(SpilledVariables.size()); SortedSpilledVariables.reserve(SpilledVariables.size());
sortByAlignment(SortedSpilledVariables, SpilledVariables); sortByAlignment(SortedSpilledVariables, SpilledVariables);
for (VarList::const_iterator I = SortedSpilledVariables.begin(), for (Variable *Var : SortedSpilledVariables) {
E = SortedSpilledVariables.end();
I != E; ++I) {
Variable *Var = *I;
size_t Increment = typeWidthInBytesOnStack(Var->getType()); size_t Increment = typeWidthInBytesOnStack(Var->getType());
if (!SpillAreaAlignmentBytes) if (!SpillAreaAlignmentBytes)
SpillAreaAlignmentBytes = Increment; SpillAreaAlignmentBytes = Increment;
...@@ -837,10 +830,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -837,10 +830,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
size_t GlobalsSpaceUsed = SpillAreaPaddingBytes; size_t GlobalsSpaceUsed = SpillAreaPaddingBytes;
LocalsSize.assign(LocalsSize.size(), 0); LocalsSize.assign(LocalsSize.size(), 0);
size_t NextStackOffset = GlobalsSpaceUsed; size_t NextStackOffset = GlobalsSpaceUsed;
for (VarList::const_iterator I = SortedSpilledVariables.begin(), for (Variable *Var : SortedSpilledVariables) {
E = SortedSpilledVariables.end();
I != E; ++I) {
Variable *Var = *I;
size_t Increment = typeWidthInBytesOnStack(Var->getType()); size_t Increment = typeWidthInBytesOnStack(Var->getType());
if (SimpleCoalescing && VMetadata->isTracked(Var)) { if (SimpleCoalescing && VMetadata->isTracked(Var)) {
if (VMetadata->isMultiBlock(Var)) { if (VMetadata->isMultiBlock(Var)) {
...@@ -866,10 +856,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -866,10 +856,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
// Assign stack offsets to variables that have been linked to spilled // Assign stack offsets to variables that have been linked to spilled
// variables. // variables.
for (VarList::const_iterator I = VariablesLinkedToSpillSlots.begin(), for (Variable *Var : VariablesLinkedToSpillSlots) {
E = VariablesLinkedToSpillSlots.end();
I != E; ++I) {
Variable *Var = *I;
Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo(); Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo();
Var->setStackOffset(Linked->getStackOffset()); Var->setStackOffset(Linked->getStackOffset());
} }
...@@ -904,6 +891,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -904,6 +891,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
void TargetX8632::addEpilog(CfgNode *Node) { void TargetX8632::addEpilog(CfgNode *Node) {
InstList &Insts = Node->getInsts(); InstList &Insts = Node->getInsts();
InstList::reverse_iterator RI, E; InstList::reverse_iterator RI, E;
// TODO(stichnot): Use llvm::make_range with LLVM 3.5.
for (RI = Insts.rbegin(), E = Insts.rend(); RI != E; ++RI) { for (RI = Insts.rbegin(), E = Insts.rend(); RI != E; ++RI) {
if (llvm::isa<InstX8632Ret>(*RI)) if (llvm::isa<InstX8632Ret>(*RI))
break; break;
...@@ -979,9 +967,8 @@ template <typename T> void TargetX8632::emitConstantPool() const { ...@@ -979,9 +967,8 @@ template <typename T> void TargetX8632::emitConstantPool() const {
Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align
<< "\n"; << "\n";
Str << "\t.align\t" << Align << "\n"; Str << "\t.align\t" << Align << "\n";
for (ConstantList::const_iterator I = Pool.begin(), E = Pool.end(); I != E; for (Constant *C : Pool) {
++I) { typename T::IceType *Const = llvm::cast<typename T::IceType>(C);
typename T::IceType *Const = llvm::cast<typename T::IceType>(*I);
typename T::PrimitiveFpType Value = Const->getValue(); typename T::PrimitiveFpType Value = Const->getValue();
// Use memcpy() to copy bits from Value into RawValue in a way // Use memcpy() to copy bits from Value into RawValue in a way
// that avoids breaking strict-aliasing rules. // that avoids breaking strict-aliasing rules.
...@@ -4332,9 +4319,7 @@ void TargetX8632::postLower() { ...@@ -4332,9 +4319,7 @@ void TargetX8632::postLower() {
// The first pass also keeps track of which instruction is the last // The first pass also keeps track of which instruction is the last
// use for each infinite-weight variable. After the last use, the // use for each infinite-weight variable. After the last use, the
// variable is released to the free list. // variable is released to the free list.
for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; for (Inst *Inst : Context) {
++I) {
const Inst *Inst = *I;
if (Inst->isDeleted()) if (Inst->isDeleted())
continue; continue;
// Don't consider a FakeKill instruction, because (currently) it // Don't consider a FakeKill instruction, because (currently) it
...@@ -4366,10 +4351,8 @@ void TargetX8632::postLower() { ...@@ -4366,10 +4351,8 @@ void TargetX8632::postLower() {
// The second pass colors infinite-weight variables. // The second pass colors infinite-weight variables.
llvm::SmallBitVector AvailableRegisters = WhiteList; llvm::SmallBitVector AvailableRegisters = WhiteList;
llvm::SmallBitVector FreedRegisters(WhiteList.size()); llvm::SmallBitVector FreedRegisters(WhiteList.size());
for (InstList::iterator I = Context.getCur(), E = Context.getEnd(); I != E; for (Inst *Inst : Context) {
++I) {
FreedRegisters.reset(); FreedRegisters.reset();
const Inst *Inst = *I;
if (Inst->isDeleted()) if (Inst->isDeleted())
continue; continue;
// Skip FakeKill instructions like above. // Skip FakeKill instructions like above.
......
...@@ -49,9 +49,9 @@ public: ...@@ -49,9 +49,9 @@ public:
return (typeWidthInBytes(Ty) + 3) & ~3; return (typeWidthInBytes(Ty) + 3) & ~3;
} }
SizeT getBundleAlignLog2Bytes() const override { return 5; } SizeT getBundleAlignLog2Bytes() const override { return 5; }
llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const override { llvm::ArrayRef<AsmCodeByte> getNonExecBundlePadding() const override {
static const uint8_t Padding[] = { 0xF4 }; static const AsmCodeByte Padding[] = { 0xF4 };
return llvm::ArrayRef<uint8_t>(Padding, 1); return llvm::ArrayRef<AsmCodeByte>(Padding, 1);
} }
void emitVariable(const Variable *Var) const override; void emitVariable(const Variable *Var) const override;
void lowerArguments() override; void lowerArguments() override;
......
...@@ -101,8 +101,8 @@ typedef std::multimap<double, IceString> DumpMapType; ...@@ -101,8 +101,8 @@ typedef std::multimap<double, IceString> DumpMapType;
// Dump the Map items in reverse order of their time contribution. // Dump the Map items in reverse order of their time contribution.
void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) { void dumpHelper(Ostream &Str, const DumpMapType &Map, double TotalTime) {
for (DumpMapType::const_reverse_iterator I = Map.rbegin(), E = Map.rend(); // TODO(stichnot): Use llvm::make_range with LLVM 3.5.
I != E; ++I) { for (auto I = Map.rbegin(), E = Map.rend(); I != E; ++I) {
char buf[80]; char buf[80];
snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first, snprintf(buf, llvm::array_lengthof(buf), " %10.6f (%4.1f%%): ", I->first,
I->first * 100 / TotalTime); I->first * 100 / TotalTime);
......
...@@ -58,19 +58,15 @@ void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) { ...@@ -58,19 +58,15 @@ void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) {
Ostream &errs = Ctx->getStrDump(); Ostream &errs = Ctx->getStrDump();
if (!GlobalPrefix.empty()) { if (!GlobalPrefix.empty()) {
uint32_t NameIndex = 0; uint32_t NameIndex = 0;
for (llvm::Module::global_iterator I = Mod->global_begin(), for (auto I = Mod->global_begin(), E = Mod->global_end(); I != E; ++I)
E = Mod->global_end();
I != E; ++I) {
setValueName(I, "global", GlobalPrefix, NameIndex, errs); setValueName(I, "global", GlobalPrefix, NameIndex, errs);
}
} }
const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix; const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix;
if (FunctionPrefix.empty()) if (FunctionPrefix.empty())
return; return;
uint32_t NameIndex = 0; uint32_t NameIndex = 0;
for (llvm::Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { for (llvm::Function &I : *Mod)
setValueName(I, "function", FunctionPrefix, NameIndex, errs); setValueName(&I, "function", FunctionPrefix, NameIndex, errs);
}
} }
void Translator::translateFcn(Cfg *Fcn) { void Translator::translateFcn(Cfg *Fcn) {
...@@ -100,9 +96,7 @@ void Translator::emitConstants() { ...@@ -100,9 +96,7 @@ void Translator::emitConstants() {
void Translator::convertGlobals(llvm::Module *Mod) { void Translator::convertGlobals(llvm::Module *Mod) {
std::unique_ptr<TargetGlobalInitLowering> GlobalLowering( std::unique_ptr<TargetGlobalInitLowering> GlobalLowering(
TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx));
for (llvm::Module::const_global_iterator I = Mod->global_begin(), for (auto I = Mod->global_begin(), E = Mod->global_end(); I != E; ++I) {
E = Mod->global_end();
I != E; ++I) {
if (!I->hasInitializer()) if (!I->hasInitializer())
continue; continue;
const llvm::Constant *Initializer = I->getInitializer(); const llvm::Constant *Initializer = I->getInitializer();
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
/// Converts LLVM type LLVMTy to an ICE type. Returns /// Converts LLVM type LLVMTy to an ICE type. Returns
/// Ice::IceType_NUM if unable to convert. /// Ice::IceType_NUM if unable to convert.
Type convertToIceType(llvm::Type *LLVMTy) const { Type convertToIceType(llvm::Type *LLVMTy) const {
std::map<llvm::Type *, Type>::const_iterator Pos = LLVM2IceMap.find(LLVMTy); auto Pos = LLVM2IceMap.find(LLVMTy);
if (Pos == LLVM2IceMap.end()) if (Pos == LLVM2IceMap.end())
return convertToIceTypeOther(LLVMTy); return convertToIceTypeOther(LLVMTy);
return Pos->second; return Pos->second;
......
...@@ -847,8 +847,7 @@ public: ...@@ -847,8 +847,7 @@ public:
Func->setInternal(LLVMFunc->hasInternalLinkage()); Func->setInternal(LLVMFunc->hasInternalLinkage());
CurrentNode = InstallNextBasicBlock(); CurrentNode = InstallNextBasicBlock();
Func->setEntryNode(CurrentNode); Func->setEntryNode(CurrentNode);
for (Function::const_arg_iterator ArgI = LLVMFunc->arg_begin(), for (auto ArgI = LLVMFunc->arg_begin(), ArgE = LLVMFunc->arg_end();
ArgE = LLVMFunc->arg_end();
ArgI != ArgE; ++ArgI) { ArgI != ArgE; ++ArgI) {
Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType()))); Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType())));
} }
...@@ -1387,11 +1386,7 @@ void FunctionParser::ExitBlock() { ...@@ -1387,11 +1386,7 @@ void FunctionParser::ExitBlock() {
// Before translating, check for blocks without instructions, and // Before translating, check for blocks without instructions, and
// insert unreachable. This shouldn't happen, but be safe. // insert unreachable. This shouldn't happen, but be safe.
unsigned Index = 0; unsigned Index = 0;
const Ice::NodeList &Nodes = Func->getNodes(); for (Ice::CfgNode *Node : Func->getNodes()) {
for (std::vector<Ice::CfgNode *>::const_iterator Iter = Nodes.begin(),
IterEnd = Nodes.end();
Iter != IterEnd; ++Iter, ++Index) {
Ice::CfgNode *Node = *Iter;
if (Node->getInsts().size() == 0) { if (Node->getInsts().size() == 0) {
std::string Buffer; std::string Buffer;
raw_string_ostream StrBuf(Buffer); raw_string_ostream StrBuf(Buffer);
...@@ -1400,6 +1395,7 @@ void FunctionParser::ExitBlock() { ...@@ -1400,6 +1395,7 @@ void FunctionParser::ExitBlock() {
// TODO(kschimpf) Remove error recovery once implementation complete. // TODO(kschimpf) Remove error recovery once implementation complete.
Node->appendInst(Ice::InstUnreachable::create(Func)); Node->appendInst(Ice::InstUnreachable::create(Func));
} }
++Index;
} }
Func->computePredecessors(); Func->computePredecessors();
// Note: Once any errors have been found, we turn off all // Note: Once any errors have been found, we turn off all
......
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