Skip to content

Commit 6a441d1

Browse files
Enna1github-actions[bot]
authored andcommitted
Automerge: [ThinLTO] Fix parsing null aliasee in alias summary (#169490)
In llvm/llvm-project@f8182f1, we add support for printing "null" aliasee in AsmWriter, but missing support in LLParser.
2 parents ee4ad77 + 91531f3 commit 6a441d1

File tree

4 files changed

+64
-51
lines changed

4 files changed

+64
-51
lines changed

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9994,25 +9994,26 @@ bool LLParser::parseAliasSummary(std::string Name, GlobalValue::GUID GUID,
99949994

99959995
ValueInfo AliaseeVI;
99969996
unsigned GVId;
9997-
if (parseGVReference(AliaseeVI, GVId))
9998-
return true;
9999-
10000-
if (parseToken(lltok::rparen, "expected ')' here"))
10001-
return true;
10002-
100039997
auto AS = std::make_unique<AliasSummary>(GVFlags);
10004-
100059998
AS->setModulePath(ModulePath);
100069999

10007-
// Record forward reference if the aliasee is not parsed yet.
10008-
if (AliaseeVI.getRef() == FwdVIRef) {
10009-
ForwardRefAliasees[GVId].emplace_back(AS.get(), Loc);
10010-
} else {
10011-
auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
10012-
assert(Summary && "Aliasee must be a definition");
10013-
AS->setAliasee(AliaseeVI, Summary);
10000+
if (!EatIfPresent(lltok::kw_null)) {
10001+
if (parseGVReference(AliaseeVI, GVId))
10002+
return true;
10003+
10004+
// Record forward reference if the aliasee is not parsed yet.
10005+
if (AliaseeVI.getRef() == FwdVIRef) {
10006+
ForwardRefAliasees[GVId].emplace_back(AS.get(), Loc);
10007+
} else {
10008+
auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
10009+
assert(Summary && "Aliasee must be a definition");
10010+
AS->setAliasee(AliaseeVI, Summary);
10011+
}
1001410012
}
1001510013

10014+
if (parseToken(lltok::rparen, "expected ')' here"))
10015+
return true;
10016+
1001610017
return addGlobalValueToIndex(Name, GUID,
1001710018
(GlobalValue::LinkageTypes)GVFlags.Linkage, ID,
1001810019
std::move(AS), Loc);

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7200,9 +7200,11 @@ template <bool AllowNullValueInfo>
72007200
std::pair<ValueInfo, GlobalValue::GUID>
72017201
ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
72027202
auto VGI = ValueIdToValueInfoMap[ValueId];
7203-
// We can have a null value info for memprof callsite info records in
7204-
// distributed ThinLTO index files when the callee function summary is not
7205-
// included in the index. The bitcode writer records 0 in that case,
7203+
// We can have a null value info in distributed ThinLTO index files:
7204+
// - For memprof callsite info records when the callee function summary is not
7205+
// included in the index.
7206+
// - For alias summary when its aliasee summary is not included in the index.
7207+
// The bitcode writer records 0 in these cases,
72067208
// and the caller of this helper will set AllowNullValueInfo to true.
72077209
assert(AllowNullValueInfo || std::get<0>(VGI));
72087210
return VGI;
@@ -7990,10 +7992,13 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
79907992
LastSeenSummary = AS.get();
79917993
AS->setModulePath(ModuleIdMap[ModuleId]);
79927994

7993-
auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeValueId));
7994-
auto AliaseeInModule = TheIndex.findSummaryInModule(AliaseeVI, AS->modulePath());
7995-
AS->setAliasee(AliaseeVI, AliaseeInModule);
7996-
7995+
auto AliaseeVI = std::get<0>(
7996+
getValueInfoFromValueId</*AllowNullValueInfo*/ true>(AliaseeValueId));
7997+
if (AliaseeVI) {
7998+
auto AliaseeInModule =
7999+
TheIndex.findSummaryInModule(AliaseeVI, AS->modulePath());
8000+
AS->setAliasee(AliaseeVI, AliaseeInModule);
8001+
}
79978002
ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
79988003
LastSeenGUID = VI.getGUID();
79998004
TheIndex.addGlobalValueSummary(VI, std::move(AS));

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5248,17 +5248,20 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
52485248
NameVals.push_back(ModuleIdMap[AS->modulePath()]);
52495249
NameVals.push_back(
52505250
getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS)));
5251-
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
5252-
assert(AliaseeValueId);
5251+
// Set value id to 0 when an alias is imported but the aliasee summary is
5252+
// not contained in the index.
5253+
auto AliaseeValueId =
5254+
AS->hasAliasee() ? SummaryToValueIdMap[&AS->getAliasee()] : 0;
52535255
NameVals.push_back(AliaseeValueId);
52545256

52555257
// Emit the finished record.
52565258
Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev);
52575259
NameVals.clear();
52585260
MaybeEmitOriginalName(*AS);
52595261

5260-
if (auto *FS = dyn_cast<FunctionSummary>(&AS->getAliasee()))
5261-
getReferencedTypeIds(FS, ReferencedTypeIds);
5262+
if (AS->hasAliasee())
5263+
if (auto *FS = dyn_cast<FunctionSummary>(&AS->getAliasee()))
5264+
getReferencedTypeIds(FS, ReferencedTypeIds);
52625265
}
52635266

52645267
SmallVector<StringRef, 4> Functions;

llvm/test/Assembler/thinlto-summary.ll

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,35 @@
4646
^18 = gv: (guid: 17, summaries: (alias: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1), aliasee: ^14)))
4747

4848
; Test all types of TypeIdInfo on function summaries.
49-
^19 = gv: (guid: 18, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 4, typeIdInfo: (typeTests: (^26, ^28)))))
50-
^20 = gv: (guid: 19, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 8, typeIdInfo: (typeTestAssumeVCalls: (vFuncId: (^29, offset: 16))))))
51-
^21 = gv: (guid: 20, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 5, typeIdInfo: (typeCheckedLoadVCalls: (vFuncId: (^27, offset: 16))))))
52-
^22 = gv: (guid: 21, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 15, typeIdInfo: (typeTestAssumeConstVCalls: ((vFuncId: (^29, offset: 16), args: (42)), (vFuncId: (^29, offset: 24)))))))
53-
^23 = gv: (guid: 22, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 5, typeIdInfo: (typeCheckedLoadConstVCalls: ((vFuncId: (^30, offset: 16), args: (42)))))))
49+
^19 = gv: (guid: 18, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 4, typeIdInfo: (typeTests: (^27, ^29)))))
50+
^20 = gv: (guid: 19, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 8, typeIdInfo: (typeTestAssumeVCalls: (vFuncId: (^30, offset: 16))))))
51+
^21 = gv: (guid: 20, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 5, typeIdInfo: (typeCheckedLoadVCalls: (vFuncId: (^28, offset: 16))))))
52+
^22 = gv: (guid: 21, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 15, typeIdInfo: (typeTestAssumeConstVCalls: ((vFuncId: (^30, offset: 16), args: (42)), (vFuncId: (^30, offset: 24)))))))
53+
^23 = gv: (guid: 22, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 5, typeIdInfo: (typeCheckedLoadConstVCalls: ((vFuncId: (^31, offset: 16), args: (42)))))))
5454

5555
; Function summary with an import type of declaration
5656
^24 = gv: (guid: 23, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, importType: declaration), insts: 5)))
5757

58+
; Alias summary with null aliasee.
59+
^25 = gv: (guid: 24, summaries: (alias: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1), aliasee: null)))
60+
5861
; GUID that are 64-bit
5962

60-
^25 = gv: (guid: 9123456789101112131, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, importType: definition), insts: 1)))
63+
^26 = gv: (guid: 9123456789101112131, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, importType: definition), insts: 1)))
6164

6265
; Test TypeId summaries:
6366

64-
^26 = typeid: (name: "_ZTS1C", summary: (typeTestRes: (kind: single, sizeM1BitWidth: 0)))
67+
^27 = typeid: (name: "_ZTS1C", summary: (typeTestRes: (kind: single, sizeM1BitWidth: 0)))
6568
; Test TypeId with other optional fields (alignLog2/sizeM1/bitMask/inlineBits)
66-
^27 = typeid: (name: "_ZTS1B", summary: (typeTestRes: (kind: inline, sizeM1BitWidth: 0, alignLog2: 1, sizeM1: 2, bitMask: 3, inlineBits: 4)))
69+
^28 = typeid: (name: "_ZTS1B", summary: (typeTestRes: (kind: inline, sizeM1BitWidth: 0, alignLog2: 1, sizeM1: 2, bitMask: 3, inlineBits: 4)))
6770
; Test the AllOnes resolution, and all kinds of WholeProgramDevirtResolution
6871
; types, including all optional resolution by argument kinds.
69-
^28 = 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)))))))
72+
^29 = 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)))))))
7073
; Test the other kinds of type test resoultions
71-
^29 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0)))
72-
^30 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0)))
73-
^31 = flags: 8
74-
^32 = blockcount: 1888
74+
^30 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0)))
75+
^31 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0)))
76+
^32 = flags: 8
77+
^33 = blockcount: 1888
7578

7679
; Make sure we get back from llvm-dis essentially what we put in via llvm-as.
7780
; CHECK: ^0 = module: (path: "thinlto-summary1.o", hash: (1369602428, 2747878711, 259090915, 2507395659, 1141468049))
@@ -95,20 +98,21 @@
9598
; CHECK: ^16 = gv: (guid: 15, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 1, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 1, noUnwind: 1, mayThrow: 1, hasUnknownCall: 1, mustBeUnreachable: 0))))
9699
; CHECK: ^17 = gv: (guid: 16, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 1, funcFlags: (readNone: 0, readOnly: 1, noRecurse: 0, returnDoesNotAlias: 1, noInline: 0, alwaysInline: 0, noUnwind: 0, mayThrow: 0, hasUnknownCall: 0, mustBeUnreachable: 1), calls: ((callee: ^15)))))
97100
; CHECK: ^18 = gv: (guid: 17, summaries: (alias: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0, importType: definition), aliasee: ^14)))
98-
; CHECK: ^19 = gv: (guid: 18, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 4, typeIdInfo: (typeTests: (^26, ^28)))))
99-
; CHECK: ^20 = gv: (guid: 19, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 8, typeIdInfo: (typeTestAssumeVCalls: (vFuncId: (^29, offset: 16))))))
100-
; CHECK: ^21 = gv: (guid: 20, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 5, typeIdInfo: (typeCheckedLoadVCalls: (vFuncId: (^27, offset: 16))))))
101-
; CHECK: ^22 = gv: (guid: 21, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 15, typeIdInfo: (typeTestAssumeConstVCalls: ((vFuncId: (^29, offset: 16), args: (42)), (vFuncId: (^29, offset: 24)))))))
102-
; CHECK: ^23 = gv: (guid: 22, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 5, typeIdInfo: (typeCheckedLoadConstVCalls: ((vFuncId: (^30, offset: 16), args: (42)))))))
101+
; CHECK: ^19 = gv: (guid: 18, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 4, typeIdInfo: (typeTests: (^27, ^29)))))
102+
; CHECK: ^20 = gv: (guid: 19, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 8, typeIdInfo: (typeTestAssumeVCalls: (vFuncId: (^30, offset: 16))))))
103+
; CHECK: ^21 = gv: (guid: 20, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 5, typeIdInfo: (typeCheckedLoadVCalls: (vFuncId: (^28, offset: 16))))))
104+
; CHECK: ^22 = gv: (guid: 21, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 15, typeIdInfo: (typeTestAssumeConstVCalls: ((vFuncId: (^30, offset: 16), args: (42)), (vFuncId: (^30, offset: 24)))))))
105+
; CHECK: ^23 = gv: (guid: 22, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: definition), insts: 5, typeIdInfo: (typeCheckedLoadConstVCalls: ((vFuncId: (^31, offset: 16), args: (42)))))))
103106
; CHECK: ^24 = gv: (guid: 23, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0, importType: declaration), insts: 5)))
104-
; CHECK: ^25 = gv: (guid: 9123456789101112131, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 1)))
105-
; CHECK: ^26 = typeid: (name: "_ZTS1C", summary: (typeTestRes: (kind: single, sizeM1BitWidth: 0))) ; guid = 1884921850105019584
106-
; CHECK: ^27 = typeid: (name: "_ZTS1B", summary: (typeTestRes: (kind: inline, sizeM1BitWidth: 0, alignLog2: 1, sizeM1: 2, bitMask: 3, inlineBits: 4))) ; guid = 6203814149063363976
107-
; CHECK: ^28 = 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
108-
; CHECK: ^29 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0))) ; guid = 9614786172484273522
109-
; CHECK: ^30 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0))) ; guid = 17437243864166745132
110-
; CHECK: ^31 = flags: 8
111-
; CHECK: ^32 = blockcount: 1888
107+
; CHECK: ^25 = gv: (guid: 24, summaries: (alias: (module: ^0, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0, importType: definition), aliasee: null)))
108+
; CHECK: ^26 = gv: (guid: 9123456789101112131, summaries: (function: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0, importType: definition), insts: 1)))
109+
; CHECK: ^27 = typeid: (name: "_ZTS1C", summary: (typeTestRes: (kind: single, sizeM1BitWidth: 0))) ; guid = 1884921850105019584
110+
; CHECK: ^28 = typeid: (name: "_ZTS1B", summary: (typeTestRes: (kind: inline, sizeM1BitWidth: 0, alignLog2: 1, sizeM1: 2, bitMask: 3, inlineBits: 4))) ; guid = 6203814149063363976
111+
; CHECK: ^29 = 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
112+
; CHECK: ^30 = typeid: (name: "_ZTS1D", summary: (typeTestRes: (kind: byteArray, sizeM1BitWidth: 0))) ; guid = 9614786172484273522
113+
; CHECK: ^31 = typeid: (name: "_ZTS1E", summary: (typeTestRes: (kind: unsat, sizeM1BitWidth: 0))) ; guid = 17437243864166745132
114+
; CHECK: ^32 = flags: 8
115+
; CHECK: ^33 = blockcount: 1888
112116

113117
; Make sure parsing of a non-summary entry containing a ":" does not fail
114118
; after summary parsing, which handles colons differently.

0 commit comments

Comments
 (0)