[llvm] r225710 - AsmParser: Factor duplicated code into ParseMDNode(), NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 12 14:26:48 PST 2015
Author: dexonsmith
Date: Mon Jan 12 16:26:48 2015
New Revision: 225710
URL: http://llvm.org/viewvc/llvm-project?rev=225710&view=rev
Log:
AsmParser: Factor duplicated code into ParseMDNode(), NFC
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=225710&r1=225709&r2=225710&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Jan 12 16:26:48 2015
@@ -1490,24 +1490,11 @@ bool LLParser::ParseInstructionMetadata(
unsigned MDK = M->getMDKindID(Name);
Lex.Lex();
- if (ParseToken(lltok::exclaim, "expected '!' here"))
+ MDNode *N;
+ if (ParseMDNode(N))
return true;
- // This code is similar to that of ParseMetadata. However, only MDNodes
- // are supported here.
- if (Lex.getKind() == lltok::lbrace) {
- MDNode *N;
- if (ParseMDTuple(N))
- return true;
- Inst->setMetadata(MDK, N);
- } else {
- MDNode *Node;
- if (ParseMDNodeID(Node))
- return true;
- // If we got the node, add it to the instruction.
- Inst->setMetadata(MDK, Node);
- }
-
+ Inst->setMetadata(MDK, N);
if (MDK == LLVMContext::MD_tbaa)
InstsWithTBAATag.push_back(Inst);
@@ -2912,6 +2899,23 @@ bool LLParser::ParseMDTuple(MDNode *&MD,
return false;
}
+/// MDNode:
+/// ::= !{ ... }
+/// ::= !7
+bool LLParser::ParseMDNode(MDNode *&N) {
+ return ParseToken(lltok::exclaim, "expected '!' here") ||
+ ParseMDNodeTail(N);
+}
+
+bool LLParser::ParseMDNodeTail(MDNode *&N) {
+ // !{ ... }
+ if (Lex.getKind() == lltok::lbrace)
+ return ParseMDTuple(N);
+
+ // !42
+ return ParseMDNodeID(N);
+}
+
/// ParseMetadataAsValue
/// ::= metadata i32 %local
/// ::= metadata i32 @global
@@ -2978,18 +2982,9 @@ bool LLParser::ParseMetadata(Metadata *&
// MDNode:
// !{ ... }
- if (Lex.getKind() == lltok::lbrace) {
- MDNode *N;
- if (ParseMDTuple(N))
- return true;
- MD = N;
- return false;
- }
-
- // Standalone metadata reference
- // !42
+ // !7
MDNode *N;
- if (ParseMDNodeID(N))
+ if (ParseMDNodeTail(N))
return true;
MD = N;
return false;
Modified: llvm/trunk/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=225710&r1=225709&r2=225710&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Mon Jan 12 16:26:48 2015
@@ -388,6 +388,8 @@ namespace llvm {
bool ParseValueAsMetadata(Metadata *&MD, PerFunctionState *PFS);
bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS);
bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false);
+ bool ParseMDNode(MDNode *&MD);
+ bool ParseMDNodeTail(MDNode *&MD);
bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
More information about the llvm-commits
mailing list