[llvm] r342573 - [ThinLTO] Extract getReferencedTypeIds from [NFC]
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 19 11:51:25 PDT 2018
Author: vitalybuka
Date: Wed Sep 19 11:51:25 2018
New Revision: 342573
URL: http://llvm.org/viewvc/llvm-project?rev=342573&view=rev
Log:
[ThinLTO] Extract getReferencedTypeIds from [NFC]
Summary: Refactoring before D52201
Reviewers: eugenis, tejohnson
Subscribers: pcc, inglorion, hiraditya, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D52203
Modified:
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=342573&r1=342572&r2=342573&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Wed Sep 19 11:51:25 2018
@@ -3358,14 +3358,10 @@ void IndexBitcodeWriter::writeModStrings
/// Write the function type metadata related records that need to appear before
/// a function summary entry (whether per-module or combined).
-static void writeFunctionTypeMetadataRecords(
- BitstreamWriter &Stream, FunctionSummary *FS,
- std::set<GlobalValue::GUID> &ReferencedTypeIds) {
- if (!FS->type_tests().empty()) {
+static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream,
+ FunctionSummary *FS) {
+ if (!FS->type_tests().empty())
Stream.EmitRecord(bitc::FS_TYPE_TESTS, FS->type_tests());
- for (auto &TT : FS->type_tests())
- ReferencedTypeIds.insert(TT);
- }
SmallVector<uint64_t, 64> Record;
@@ -3377,7 +3373,6 @@ static void writeFunctionTypeMetadataRec
for (auto &VF : VFs) {
Record.push_back(VF.GUID);
Record.push_back(VF.Offset);
- ReferencedTypeIds.insert(VF.GUID);
}
Stream.EmitRecord(Ty, Record);
};
@@ -3392,7 +3387,6 @@ static void writeFunctionTypeMetadataRec
for (auto &VC : VCs) {
Record.clear();
Record.push_back(VC.VFunc.GUID);
- ReferencedTypeIds.insert(VC.VFunc.GUID);
Record.push_back(VC.VFunc.Offset);
Record.insert(Record.end(), VC.Args.begin(), VC.Args.end());
Stream.EmitRecord(Ty, Record);
@@ -3405,6 +3399,33 @@ static void writeFunctionTypeMetadataRec
FS->type_checked_load_const_vcalls());
}
+/// Collect type IDs from type tests used by function.
+static void
+getReferencedTypeIds(FunctionSummary *FS,
+ std::set<GlobalValue::GUID> &ReferencedTypeIds) {
+ if (!FS->type_tests().empty())
+ for (auto &TT : FS->type_tests())
+ ReferencedTypeIds.insert(TT);
+
+ auto GetReferencedTypesFromVFuncIdVec =
+ [&](ArrayRef<FunctionSummary::VFuncId> VFs) {
+ for (auto &VF : VFs)
+ ReferencedTypeIds.insert(VF.GUID);
+ };
+
+ GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
+ GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
+
+ auto GetReferencedTypesFromConstVCallVec =
+ [&](ArrayRef<FunctionSummary::ConstVCall> VCs) {
+ for (auto &VC : VCs)
+ ReferencedTypeIds.insert(VC.VFunc.GUID);
+ };
+
+ GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
+ GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
+}
+
static void writeWholeProgramDevirtResolutionByArg(
SmallVector<uint64_t, 64> &NameVals, const std::vector<uint64_t> &args,
const WholeProgramDevirtResolution::ByArg &ByArg) {
@@ -3458,8 +3479,7 @@ void ModuleBitcodeWriterBase::writePerMo
NameVals.push_back(ValueID);
FunctionSummary *FS = cast<FunctionSummary>(Summary);
- std::set<GlobalValue::GUID> ReferencedTypeIds;
- writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds);
+ writeFunctionTypeMetadataRecords(Stream, FS);
NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
NameVals.push_back(FS->instCount());
@@ -3769,7 +3789,8 @@ void IndexBitcodeWriter::writeCombinedGl
}
auto *FS = cast<FunctionSummary>(S);
- writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds);
+ writeFunctionTypeMetadataRecords(Stream, FS);
+ getReferencedTypeIds(FS, ReferencedTypeIds);
NameVals.push_back(*ValueId);
NameVals.push_back(Index.getModuleId(FS->modulePath()));
More information about the llvm-commits
mailing list