summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2018-09-19 18:51:25 +0000
committerVitaly Buka <vitalybuka@google.com>2018-09-19 18:51:25 +0000
commit7e880a4f6de50b3f72156cb72c0749862b2d9ceb (patch)
tree749037be2e80893f2d0c12c7f1f25c654f6e0c58 /llvm/lib/Bitcode
parenta9e8765e3ebf1e0b455bc38bbb4ba5b8e7a4c9aa (diff)
downloadbcm5719-llvm-7e880a4f6de50b3f72156cb72c0749862b2d9ceb.tar.gz
bcm5719-llvm-7e880a4f6de50b3f72156cb72c0749862b2d9ceb.zip
[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 llvm-svn: 342573
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 1262401266e..576db06cf2e 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -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 writeFunctionTypeMetadataRecords(
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 writeFunctionTypeMetadataRecords(
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 writeFunctionTypeMetadataRecords(
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::writePerModuleFunctionSummaryRecord(
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::writeCombinedGlobalValueSummary() {
}
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()));
OpenPOWER on IntegriCloud