diff options
author | Teresa Johnson <tejohnson@google.com> | 2018-05-26 02:34:13 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2018-05-26 02:34:13 +0000 |
commit | 08d5b4ef0d0839761e3b7546efcd3ee0454742ea (patch) | |
tree | 1962452dfea56ccff172d7612ec1a8c982de27e2 /llvm/lib/AsmParser/LLParser.cpp | |
parent | ffebfe10c1cfc2eae92ddd0dc1b212595ac47864 (diff) | |
download | bcm5719-llvm-08d5b4ef0d0839761e3b7546efcd3ee0454742ea.tar.gz bcm5719-llvm-08d5b4ef0d0839761e3b7546efcd3ee0454742ea.zip |
[ThinLTO] Print module summary index to assembly
Summary:
Implements AsmWriter support for printing the module summary index to
assembly with the format discussed in the RFC "LLVM Assembly format for
ThinLTO Summary".
Implements just enough of the parsing support to recognize and ignore
the summary entries. As agreed in the RFC thread, this will be the
behavior when assembling the IR. A follow on change will implement
parsing/assembling of the summary entries for use by tools that
currently build the summary index from bitcode.
Reviewers: dexonsmith, pcc
Subscribers: inglorion, eraman, steven_wu, dblaikie, llvm-commits
Differential Revision: https://reviews.llvm.org/D46699
llvm-svn: 333335
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index afdf542d13f..0d478d4090b 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -282,6 +282,10 @@ bool LLParser::ParseTopLevelEntities() { case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break; case lltok::ComdatVar: if (parseComdat()) return true; break; case lltok::exclaim: if (ParseStandaloneMetadata()) return true; break; + case lltok::SummaryID: + if (ParseSummaryEntry()) + return true; + break; case lltok::MetadataVar:if (ParseNamedMetadata()) return true; break; case lltok::kw_attributes: if (ParseUnnamedAttrGrp()) return true; break; case lltok::kw_uselistorder: if (ParseUseListOrder()) return true; break; @@ -711,6 +715,55 @@ bool LLParser::ParseStandaloneMetadata() { return false; } +// Skips a single module summary entry. +bool LLParser::SkipModuleSummaryEntry() { + // Each module summary entry consists of a tag for the entry + // type, followed by a colon, then the fields surrounded by nested sets of + // parentheses. The "tag:" looks like a Label. Once parsing support is + // in place we will look for the tokens corresponding to the expected tags. + if (ParseToken(lltok::LabelStr, + "expected 'label' at start of summary entry") || + ParseToken(lltok::lparen, "expected '(' at start of summary entry")) + return true; + // Now walk through the parenthesized entry, until the number of open + // parentheses goes back down to 0 (the first '(' was parsed above). + unsigned NumOpenParen = 1; + do { + switch (Lex.getKind()) { + case lltok::lparen: + NumOpenParen++; + break; + case lltok::rparen: + NumOpenParen--; + break; + case lltok::Eof: + return TokError("found end of file while parsing summary entry"); + default: + // Skip everything in between parentheses. + break; + } + Lex.Lex(); + } while (NumOpenParen > 0); + return false; +} + +/// ParseSummaryEntry: +/// ::= SummaryID '=' ... +bool LLParser::ParseSummaryEntry() { + assert(Lex.getKind() == lltok::SummaryID); + // unsigned SummaryID = Lex.getUIntVal(); + + Lex.Lex(); + if (ParseToken(lltok::equal, "expected '=' here")) + return true; + + // TODO: Support parsing into a ModuleSummaryIndex object saved in + // the LLParser. For now, skip the summary entry. + if (SkipModuleSummaryEntry()) + return true; + return false; +} + static bool isValidVisibilityForLinkage(unsigned V, unsigned L) { return !GlobalValue::isLocalLinkage((GlobalValue::LinkageTypes)L) || (GlobalValue::VisibilityTypes)V == GlobalValue::DefaultVisibility; |