From 57458fd3a3ddde9de31c3d390563cfb59236dee4 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 21 Sep 2015 21:07:50 +0000 Subject: [PATCH] auto and range-for-ify some things to make changing container types a bit easier in the (possibly near) future llvm-svn: 248212 --- lib/AsmParser/LLParser.cpp | 61 ++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index d7a05fe99c8..f7c24191746 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -730,8 +730,7 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc, unsigned L, if (GlobalValue *Val = M->getNamedValue(Name)) { // See if this was a redefinition. If so, there is no entry in // ForwardRefVals. - std::map >::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::string &Name, LocTy NameLoc, return Error(NameLoc, "redefinition of global '@" + Name + "'"); } } else { - std::map >::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(const std::string &Name, Type *Ty, // If this is a forward reference for the value, see if we already created a // forward ref record. if (!Val) { - std::map >::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(unsigned ID, Type *Ty, LocTy Loc) { // If this is a forward reference for the value, see if we already created a // forward ref record. if (!Val) { - std::map >::iterator - I = ForwardRefValIDs.find(ID); + auto I = ForwardRefValIDs.find(ID); if (I != ForwardRefValIDs.end()) Val = I->second.first; } @@ -2217,23 +2213,22 @@ LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f, LLParser::PerFunctionState::~PerFunctionState() { // If there were any forward referenced non-basicblock values, delete them. - for (std::map >::iterator - I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I) - if (!isa(I->second.first)) { - I->second.first->replaceAllUsesWith( - UndefValue::get(I->second.first->getType())); - delete I->second.first; - I->second.first = nullptr; - } - for (std::map >::iterator - I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I) - if (!isa(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(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(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::GetVal(const std::string &Name, Type *Ty, // If this is a forward reference for the value, see if we already created a // forward ref record. if (!Val) { - std::map >::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::GetVal(unsigned ID, Type *Ty, LocTy Loc, // If this is a forward reference for the value, see if we already created a // forward ref record. if (!Val) { - std::map >::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::SetInstName(int NameID, return P.Error(NameLoc, "instruction expected to be numbered '%" + Twine(NumberedVals.size()) + "'"); - std::map >::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::SetInstName(int NameID, } // Otherwise, the instruction had a name. Resolve forward refs and set it. - std::map >::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(Function *&Fn, bool isDefine) { 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 >::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(Function *&Fn, bool isDefine) { } else { // If this is a definition of a forward referenced function, make sure the // types agree. - std::map >::iterator I - = ForwardRefValIDs.find(NumberedVals.size()); + auto I = ForwardRefValIDs.find(NumberedVals.size()); if (I != ForwardRefValIDs.end()) { Fn = cast(I->second.first); if (Fn->getType() != PFT)