[llvm] b303159 - [ThinLTO] parse flags and blockcount summaries

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 09:50:35 PDT 2020


Author: Nick Desaulniers
Date: 2020-07-20T09:50:22-07:00
New Revision: b3031593eaf577037a1ff7f7bc4f446eee83d91e

URL: https://github.com/llvm/llvm-project/commit/b3031593eaf577037a1ff7f7bc4f446eee83d91e
DIFF: https://github.com/llvm/llvm-project/commit/b3031593eaf577037a1ff7f7bc4f446eee83d91e.diff

LOG: [ThinLTO] parse flags and blockcount summaries

Forked from pr/46523, we were having a hard time running llvm-extract on
IR from a thinLTO build of the Linux kernel.

$ llvm-extract --func jeq_imm jit-42f488b63a04fdaa931315bdadecb6d23e20529a.ll
llvm-extract: jit-42f488b63a04fdaa931315bdadecb6d23e20529a.ll:47463:8:
error: Expected 'gv', 'module', or 'typeid' at the start of summary
entry
^209 = flags: 8
       ^

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D82917

Added: 
    llvm/test/Assembler/thinlto-blockcount-summary.ll
    llvm/test/Assembler/thinlto-flags-summary.ll

Modified: 
    llvm/lib/AsmParser/LLParser.cpp
    llvm/test/Assembler/thinlto-bad-summary1.ll
    llvm/test/Assembler/thinlto-summary.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 78dcf45d8782..cb19b1cdb213 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -788,13 +788,20 @@ bool LLParser::ParseStandaloneMetadata() {
 // 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.
+  // type, followed by a colon, then the fields which may be 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 (Lex.getKind() != lltok::kw_gv && Lex.getKind() != lltok::kw_module &&
-      Lex.getKind() != lltok::kw_typeid)
+      Lex.getKind() != lltok::kw_typeid && Lex.getKind() != lltok::kw_flags &&
+      Lex.getKind() != lltok::kw_blockcount)
     return TokError(
-        "Expected 'gv', 'module', or 'typeid' at the start of summary entry");
+        "Expected 'gv', 'module', 'typeid', 'flags' or 'blockcount' at the "
+        "start of summary entry");
+  if (Lex.getKind() == lltok::kw_flags)
+    return ParseSummaryIndexFlags();
+  if (Lex.getKind() == lltok::kw_blockcount)
+    return ParseBlockCount();
   Lex.Lex();
   if (ParseToken(lltok::colon, "expected ':' at start of summary entry") ||
       ParseToken(lltok::lparen, "expected '(' at start of summary entry"))
@@ -8169,7 +8176,8 @@ bool LLParser::ParseSummaryIndexFlags() {
   uint64_t Flags;
   if (ParseUInt64(Flags))
     return true;
-  Index->setFlags(Flags);
+  if (Index)
+    Index->setFlags(Flags);
   return false;
 }
 
@@ -8184,7 +8192,8 @@ bool LLParser::ParseBlockCount() {
   uint64_t BlockCount;
   if (ParseUInt64(BlockCount))
     return true;
-  Index->setBlockCount(BlockCount);
+  if (Index)
+    Index->setBlockCount(BlockCount);
   return false;
 }
 

diff  --git a/llvm/test/Assembler/thinlto-bad-summary1.ll b/llvm/test/Assembler/thinlto-bad-summary1.ll
index f76dc969d6ec..8ff5e06b189a 100644
--- a/llvm/test/Assembler/thinlto-bad-summary1.ll
+++ b/llvm/test/Assembler/thinlto-bad-summary1.ll
@@ -2,7 +2,7 @@
 ; summary type label.
 ; RUN: not opt %s 2>&1 | FileCheck %s
 
-; CHECK: error: Expected 'gv', 'module', or 'typeid' at the start of summary entry
+; CHECK: error: Expected 'gv', 'module', 'typeid', 'flags' or 'blockcount' at the start of summary entry
 
 ; ModuleID = 'thinlto-function-summary-callgraph.ll'
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

diff  --git a/llvm/test/Assembler/thinlto-blockcount-summary.ll b/llvm/test/Assembler/thinlto-blockcount-summary.ll
new file mode 100644
index 000000000000..0e5b618e95fa
--- /dev/null
+++ b/llvm/test/Assembler/thinlto-blockcount-summary.ll
@@ -0,0 +1,10 @@
+; Test that we can parse blockcount summaries.
+; RUN: opt %s -o /dev/null
+
+define void @main() {
+entry:
+    ret void
+}
+
+^0 = module: (path: "{{.*}}thinlto-bad-summary5.ll", hash: (0, 0, 0, 0, 0))
+^1 = blockcount: 1234

diff  --git a/llvm/test/Assembler/thinlto-flags-summary.ll b/llvm/test/Assembler/thinlto-flags-summary.ll
new file mode 100644
index 000000000000..cada38d74738
--- /dev/null
+++ b/llvm/test/Assembler/thinlto-flags-summary.ll
@@ -0,0 +1,10 @@
+; Test that we can parse flag summaries.
+; RUN: opt %s -o /dev/null
+
+define void @main() {
+entry:
+    ret void
+}
+
+^0 = module: (path: "{{.*}}thinlto-flags-summary.ll", hash: (0, 0, 0, 0, 0))
+^1 = flags: 8

diff  --git a/llvm/test/Assembler/thinlto-summary.ll b/llvm/test/Assembler/thinlto-summary.ll
index d018363b3b59..dfcc62669d9a 100644
--- a/llvm/test/Assembler/thinlto-summary.ll
+++ b/llvm/test/Assembler/thinlto-summary.ll
@@ -63,6 +63,8 @@
 ; Test the other kinds of type test resoultions
 ^27 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0)))
 ^28 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0)))
+^29 = flags: 8
+^30 = blockcount: 1888
 
 ; Make sure we get back from llvm-dis essentially what we put in via llvm-as.
 ; CHECK: ^0 = module: (path: "thinlto-summary1.o", hash: (1369602428, 2747878711, 259090915, 2507395659, 1141468049))
@@ -94,6 +96,8 @@
 ; CHECK: ^26 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7), wpdResolutions: ((offset: 0, wpdRes: (kind: branchFunnel)), (offset: 8, wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi")), (offset: 16, wpdRes: (kind: indir, resByArg: (args: (1, 2), byArg: (kind: indir, byte: 2, bit: 3), args: (3), byArg: (kind: uniformRetVal, info: 1), args: (4), byArg: (kind: uniqueRetVal, info: 1), args: (5), byArg: (kind: virtualConstProp))))))) ; guid = 7004155349499253778
 ; CHECK: ^27 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0))) ; guid = 9614786172484273522
 ; CHECK: ^28 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0))) ; guid = 17437243864166745132
+; CHECK: ^29 = flags: 8
+; CHECK: ^30 = blockcount: 1888
 
 ; Make sure parsing of a non-summary entry containing a ":" does not fail
 ; after summary parsing, which handles colons 
diff erently.


        


More information about the llvm-commits mailing list