summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-24 22:04:41 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-24 22:04:41 +0000
commit3d4cd756b6044837542acac3483e4cca7bc55814 (patch)
tree318f59eeec88d71fd46a82c96974a8d92f395d59 /llvm/lib/AsmParser
parent327e9bd399f8c1846b1cb967b03cd9f1e54af1e7 (diff)
downloadbcm5719-llvm-3d4cd756b6044837542acac3483e4cca7bc55814.tar.gz
bcm5719-llvm-3d4cd756b6044837542acac3483e4cca7bc55814.zip
IR: Add assembly/bitcode support for function metadata attachments
Add serialization support for function metadata attachments (added in r235783). The syntax is: define @foo() !attach !0 { Metadata attachments are only allowed on functions with bodies. Since they come before the `{`, they're not really part of the body; since they require a body, they're not really part of the header. In `LLParser` I gave them a separate function called from `ParseDefine()`, `ParseOptionalFunctionMetadata()`. In bitcode, I'm using the same `METADATA_ATTACHMENT` record used by instructions. Instruction metadata attachments are included in a special "attachment" block at the end of a `Function`. The attachment records are laid out like this: InstID (KindID MetadataID)+ Note that these records always have an odd number of fields. The new code takes advantage of this to recognize function attachments (which don't need an instruction ID): (KindID MetadataID)+ This means we can use the same attachment block already used for instructions. This is part of PR23340. llvm-svn: 235785
Diffstat (limited to 'llvm/lib/AsmParser')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp17
-rw-r--r--llvm/lib/AsmParser/LLParser.h1
2 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f2a6056d15c..172f3092048 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -360,13 +360,14 @@ bool LLParser::ParseDeclare() {
}
/// toplevelentity
-/// ::= 'define' FunctionHeader '{' ...
+/// ::= 'define' FunctionHeader (!dbg !56)* '{' ...
bool LLParser::ParseDefine() {
assert(Lex.getKind() == lltok::kw_define);
Lex.Lex();
Function *F;
return ParseFunctionHeader(F, true) ||
+ ParseOptionalFunctionMetadata(*F) ||
ParseFunctionBody(*F);
}
@@ -1523,6 +1524,20 @@ bool LLParser::ParseInstructionMetadata(Instruction &Inst) {
return false;
}
+/// ParseOptionalFunctionMetadata
+/// ::= (!dbg !57)*
+bool LLParser::ParseOptionalFunctionMetadata(Function &F) {
+ while (Lex.getKind() == lltok::MetadataVar) {
+ unsigned MDK;
+ MDNode *N;
+ if (ParseMetadataAttachment(MDK, N))
+ return true;
+
+ F.setMetadata(MDK, N);
+ }
+ return false;
+}
+
/// ParseOptionalAlignment
/// ::= /* empty */
/// ::= 'align' 4
diff --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h
index ea18b58d32f..a43a4b06a94 100644
--- a/llvm/lib/AsmParser/LLParser.h
+++ b/llvm/lib/AsmParser/LLParser.h
@@ -394,6 +394,7 @@ namespace llvm {
bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &MDs);
bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD);
bool ParseInstructionMetadata(Instruction &Inst);
+ bool ParseOptionalFunctionMetadata(Function &F);
template <class FieldTy>
bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
OpenPOWER on IntegriCloud