[llvm] r248212 - auto and range-for-ify some things to make changing container types a bit easier in the (possibly near) future
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 14:07:50 PDT 2015
Author: dblaikie
Date: Mon Sep 21 16:07:50 2015
New Revision: 248212
URL: http://llvm.org/viewvc/llvm-project?rev=248212&view=rev
Log:
auto and range-for-ify some things to make changing container types a bit easier in the (possibly near) future
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=248212&r1=248211&r2=248212&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Sep 21 16:07:50 2015
@@ -730,8 +730,7 @@ bool LLParser::ParseAlias(const std::str
if (GlobalValue *Val = M->getNamedValue(Name)) {
// See if this was a redefinition. If so, there is no entry in
// ForwardRefVals.
- std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
- I = ForwardRefVals.find(Name);
+ auto I = ForwardRefVals.find(Name);
if (I == ForwardRefVals.end())
return Error(NameLoc, "redefinition of global named '@" + Name + "'");
@@ -814,8 +813,7 @@ bool LLParser::ParseGlobal(const std::st
return Error(NameLoc, "redefinition of global '@" + Name + "'");
}
} else {
- std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
- I = ForwardRefValIDs.find(NumberedVals.size());
+ auto I = ForwardRefValIDs.find(NumberedVals.size());
if (I != ForwardRefValIDs.end()) {
GVal = I->second.first;
ForwardRefValIDs.erase(I);
@@ -1081,8 +1079,7 @@ GlobalValue *LLParser::GetGlobalVal(cons
// If this is a forward reference for the value, see if we already created a
// forward ref record.
if (!Val) {
- std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
- I = ForwardRefVals.find(Name);
+ auto I = ForwardRefVals.find(Name);
if (I != ForwardRefVals.end())
Val = I->second.first;
}
@@ -1113,8 +1110,7 @@ GlobalValue *LLParser::GetGlobalVal(unsi
// If this is a forward reference for the value, see if we already created a
// forward ref record.
if (!Val) {
- std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
- I = ForwardRefValIDs.find(ID);
+ auto I = ForwardRefValIDs.find(ID);
if (I != ForwardRefValIDs.end())
Val = I->second.first;
}
@@ -2217,23 +2213,22 @@ LLParser::PerFunctionState::PerFunctionS
LLParser::PerFunctionState::~PerFunctionState() {
// If there were any forward referenced non-basicblock values, delete them.
- for (std::map<std::string, std::pair<Value*, LocTy> >::iterator
- I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I)
- if (!isa<BasicBlock>(I->second.first)) {
- I->second.first->replaceAllUsesWith(
- UndefValue::get(I->second.first->getType()));
- delete I->second.first;
- I->second.first = nullptr;
- }
-
- for (std::map<unsigned, std::pair<Value*, LocTy> >::iterator
- I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I)
- if (!isa<BasicBlock>(I->second.first)) {
- I->second.first->replaceAllUsesWith(
- UndefValue::get(I->second.first->getType()));
- delete I->second.first;
- I->second.first = nullptr;
- }
+
+ for (const auto &P : ForwardRefVals) {
+ if (isa<BasicBlock>(P.second.first))
+ continue;
+ P.second.first->replaceAllUsesWith(
+ UndefValue::get(P.second.first->getType()));
+ delete P.second.first;
+ }
+
+ for (const auto &P : ForwardRefValIDs) {
+ if (isa<BasicBlock>(P.second.first))
+ continue;
+ P.second.first->replaceAllUsesWith(
+ UndefValue::get(P.second.first->getType()));
+ delete P.second.first;
+ }
}
bool LLParser::PerFunctionState::FinishFunction() {
@@ -2260,8 +2255,7 @@ Value *LLParser::PerFunctionState::GetVa
// If this is a forward reference for the value, see if we already created a
// forward ref record.
if (!Val) {
- std::map<std::string, std::pair<Value*, LocTy> >::iterator
- I = ForwardRefVals.find(Name);
+ auto I = ForwardRefVals.find(Name);
if (I != ForwardRefVals.end())
Val = I->second.first;
}
@@ -2334,8 +2328,7 @@ Value *LLParser::PerFunctionState::GetVa
// If this is a forward reference for the value, see if we already created a
// forward ref record.
if (!Val) {
- std::map<unsigned, std::pair<Value*, LocTy> >::iterator
- I = ForwardRefValIDs.find(ID);
+ auto I = ForwardRefValIDs.find(ID);
if (I != ForwardRefValIDs.end())
Val = I->second.first;
}
@@ -2421,8 +2414,7 @@ bool LLParser::PerFunctionState::SetInst
return P.Error(NameLoc, "instruction expected to be numbered '%" +
Twine(NumberedVals.size()) + "'");
- std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
- ForwardRefValIDs.find(NameID);
+ auto FI = ForwardRefValIDs.find(NameID);
if (FI != ForwardRefValIDs.end()) {
Value *Sentinel = FI->second.first;
if (Sentinel->getType() != Inst->getType())
@@ -2450,8 +2442,7 @@ bool LLParser::PerFunctionState::SetInst
}
// Otherwise, the instruction had a name. Resolve forward refs and set it.
- std::map<std::string, std::pair<Value*, LocTy> >::iterator
- FI = ForwardRefVals.find(NameStr);
+ auto FI = ForwardRefVals.find(NameStr);
if (FI != ForwardRefVals.end()) {
Value *Sentinel = FI->second.first;
if (Sentinel->getType() != Inst->getType())
@@ -4439,8 +4430,7 @@ bool LLParser::ParseFunctionHeader(Funct
if (!FunctionName.empty()) {
// If this was a definition of a forward reference, remove the definition
// from the forward reference table and fill in the forward ref.
- std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI =
- ForwardRefVals.find(FunctionName);
+ auto FRVI = ForwardRefVals.find(FunctionName);
if (FRVI != ForwardRefVals.end()) {
Fn = M->getFunction(FunctionName);
if (!Fn)
@@ -4462,8 +4452,7 @@ bool LLParser::ParseFunctionHeader(Funct
} else {
// If this is a definition of a forward referenced function, make sure the
// types agree.
- std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator I
- = ForwardRefValIDs.find(NumberedVals.size());
+ auto I = ForwardRefValIDs.find(NumberedVals.size());
if (I != ForwardRefValIDs.end()) {
Fn = cast<Function>(I->second.first);
if (Fn->getType() != PFT)
More information about the llvm-commits
mailing list