1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[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
This commit is contained in:
Nick Desaulniers 2020-07-20 09:50:22 -07:00
parent 6a998dc1d5
commit 72d9dcdd94
5 changed files with 41 additions and 8 deletions

View File

@ -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;
}

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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 differently.