From 1340dd37087c1d47a85a4461a8d33cd6ccbcfaaf Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 30 Dec 2009 05:48:36 +0000 Subject: [PATCH] now that instruction metadata is only parsed in one place, eliminate the parser-global MDsOnInst vector and make ParseInstructionMetadata return its result by-ref through an argument like the entire rest of the parser. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92302 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLParser.cpp | 18 ++++++++++-------- lib/AsmParser/LLParser.h | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 967842ad1e9..c6eeb56e14c 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -1065,7 +1065,9 @@ bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) { /// ParseInstructionMetadata /// ::= !dbg !42 (',' !dbg !57)* -bool LLParser::ParseInstructionMetadata() { +bool LLParser:: +ParseInstructionMetadata(SmallVectorImpl > &Result){ do { if (Lex.getKind() != lltok::MetadataVar) return TokError("expected metadata after comma"); @@ -1079,7 +1081,7 @@ bool LLParser::ParseInstructionMetadata() { return true; unsigned MDK = M->getMDKindID(Name.c_str()); - MDsOnInst.push_back(std::make_pair(MDK, Node)); + Result.push_back(std::make_pair(MDK, Node)); // If this is the end of the list, we're done. } while (EatIfPresent(lltok::comma)); @@ -2794,6 +2796,7 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) { // Parse the instructions in this block until we get a terminator. Instruction *Inst; + SmallVector, 4> MetadataOnInst; do { // This instruction may have three possibilities for a name: a) none // specified, b) name specified "%foo =", c) number specified: "%4 =". @@ -2822,22 +2825,21 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) { // With a normal result, we check to see if the instruction is followed by // a comma and metadata. if (EatIfPresent(lltok::comma)) - if (ParseInstructionMetadata()) + if (ParseInstructionMetadata(MetadataOnInst)) return true; break; case InstExtraComma: // If the instruction parser ate an extra comma at the end of it, it // *must* be followed by metadata. - if (ParseInstructionMetadata()) + if (ParseInstructionMetadata(MetadataOnInst)) return true; break; } // Set metadata attached with this instruction. - for (SmallVector, 2>::iterator - MDI = MDsOnInst.begin(), MDE = MDsOnInst.end(); MDI != MDE; ++MDI) - Inst->setMetadata(MDI->first, MDI->second); - MDsOnInst.clear(); + for (unsigned i = 0, e = MetadataOnInst.size(); i != e; ++i) + Inst->setMetadata(MetadataOnInst[i].first, MetadataOnInst[i].second); + MetadataOnInst.clear(); BB->getInstList().push_back(Inst); diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index f22c49b6305..803832f93d5 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -83,7 +83,6 @@ namespace llvm { std::vector NumberedTypes; std::vector > NumberedMetadata; std::map, LocTy> > ForwardRefMDNodes; - SmallVector, 2> MDsOnInst; struct UpRefRecord { /// Loc - This is the location of the upref. LocTy Loc; @@ -171,7 +170,8 @@ namespace llvm { bool ParseOptionalVisibility(unsigned &Visibility); bool ParseOptionalCallingConv(CallingConv::ID &CC); bool ParseOptionalAlignment(unsigned &Alignment); - bool ParseInstructionMetadata(); + bool ParseInstructionMetadata(SmallVectorImpl > &); bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); bool ParseIndexList(SmallVectorImpl &Indices,bool &AteExtraComma); bool ParseIndexList(SmallVectorImpl &Indices) { -- 2.34.1