mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-09 05:13:01 +00:00
AsmParser: Switch some vectors to maps
This speeds up parsing .ll files with metadata nodes with large IDs. llvm-svn: 228812
This commit is contained in:
parent
1810ed44f8
commit
9d531d29e7
@ -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 *&Result) {
|
||||
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 *&Result) {
|
||||
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, const Twine &Msg, bool AllowVoid) {
|
||||
|
||||
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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user