[llvm] r228812 - AsmParser: Switch some vectors to maps
David Majnemer
david.majnemer at gmail.com
Tue Feb 10 23:43:56 PST 2015
Author: majnemer
Date: Wed Feb 11 01:43:56 2015
New Revision: 228812
URL: http://llvm.org/viewvc/llvm-project?rev=228812&view=rev
Log:
AsmParser: Switch some vectors to maps
This speeds up parsing .ll files with metadata nodes with large IDs.
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=228812&r1=228811&r2=228812&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Feb 11 01:43:56 2015
@@ -117,10 +117,10 @@ bool LLParser::ValidateEndOfModule() {
return Error(ForwardRefBlockAddresses.begin()->first.Loc,
"expected function name in blockaddress");
- for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i)
- if (NumberedTypes[i].second.isValid())
- return Error(NumberedTypes[i].second,
- "use of undefined type '%" + Twine(i) + "'");
+ for (const auto &NT : NumberedTypes)
+ if (NT.second.second.isValid())
+ return Error(NT.second.second,
+ "use of undefined type '%" + Twine(NT.first) + "'");
for (StringMap<std::pair<Type*, LocTy> >::iterator I =
NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I)
@@ -149,9 +149,10 @@ bool LLParser::ValidateEndOfModule() {
Twine(ForwardRefMDNodes.begin()->first) + "'");
// Resolve metadata cycles.
- for (auto &N : NumberedMetadata)
- if (N && !N->isResolved())
- N->resolveCycles();
+ for (auto &N : NumberedMetadata) {
+ if (N.second && !N.second->isResolved())
+ N.second->resolveCycles();
+ }
// Look for intrinsic functions and CallInst that need to be upgraded
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
@@ -304,9 +305,6 @@ bool LLParser::ParseUnnamedType() {
ParseToken(lltok::kw_type, "expected 'type' after '='"))
return true;
- if (TypeID >= NumberedTypes.size())
- NumberedTypes.resize(TypeID+1);
-
Type *Result = nullptr;
if (ParseStructDefinition(TypeLoc, "",
NumberedTypes[TypeID], Result)) return true;
@@ -527,7 +525,7 @@ bool LLParser::ParseMDNodeID(MDNode *&Re
return true;
// If not a forward reference, just return it now.
- if (MID < NumberedMetadata.size() && NumberedMetadata[MID] != nullptr) {
+ if (NumberedMetadata.count(MID)) {
Result = NumberedMetadata[MID];
return false;
}
@@ -536,8 +534,6 @@ bool LLParser::ParseMDNodeID(MDNode *&Re
auto &FwdRef = ForwardRefMDNodes[MID];
FwdRef = std::make_pair(MDTuple::getTemporary(Context, None), Lex.getLoc());
- if (NumberedMetadata.size() <= MID)
- NumberedMetadata.resize(MID+1);
Result = FwdRef.first.get();
NumberedMetadata[MID].reset(Result);
return false;
@@ -604,10 +600,7 @@ bool LLParser::ParseStandaloneMetadata()
assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
} else {
- if (MetadataID >= NumberedMetadata.size())
- NumberedMetadata.resize(MetadataID+1);
-
- if (NumberedMetadata[MetadataID] != nullptr)
+ if (NumberedMetadata.count(MetadataID))
return TokError("Metadata id is already used");
NumberedMetadata[MetadataID].reset(Init);
}
@@ -1704,8 +1697,6 @@ bool LLParser::ParseType(Type *&Result,
case lltok::LocalVarID: {
// Type ::= %4
- if (Lex.getUIntVal() >= NumberedTypes.size())
- NumberedTypes.resize(Lex.getUIntVal()+1);
std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.getUIntVal()];
// If the type hasn't been defined yet, create a forward definition and
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=228812&r1=228811&r2=228812&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Wed Feb 11 01:43:56 2015
@@ -108,9 +108,9 @@ namespace llvm {
// Type resolution handling data structures. The location is set when we
// have processed a use of the type but not a definition yet.
StringMap<std::pair<Type*, LocTy> > NamedTypes;
- std::vector<std::pair<Type*, LocTy> > NumberedTypes;
+ std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
- std::vector<TrackingMDNodeRef> NumberedMetadata;
+ std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
// Global Value reference information.
More information about the llvm-commits
mailing list