Index: clang/test/CodeGen/thinlto-distributed-cfi.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/thinlto-distributed-cfi.cpp
@@ -0,0 +1,96 @@
+// REQUIRES: x86-registered-target
+
+// Test that distribute ThinLTO with CFI creates working binary.
+
+// RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu -emit-llvm-bc \
+// RUN: -mconstructor-aliases -flto=thin -flto-unit -fvisibility hidden \
+// RUN: -fwhole-program-vtables -x c++ \
+// RUN: -fsanitize=cfi-derived-cast,,cfi-vcall \
+// RUN: -fsanitize-trap=cfi-derived-cast,cfi-vcall \
+// RUN: -fthin-link-bitcode=%t.indexing.o %s -o %t.o
+
+// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+// RUN: -o %t2.index \
+// RUN: -r=%t.o,_Znwm, \
+// RUN: -r=%t.o,_ZN1BC2Ev,p \
+// RUN: -r=%t.o,_ZN1CC2Ev,p \
+// RUN: -r=%t.o,_ZN1DC2Ev,p \
+// RUN: -r=%t.o,main,px \
+// RUN: -r=%t.o,_ZN1AC2Ev,p \
+// RUN: -r=%t.o,_ZN1B1fEv,p \
+// RUN: -r=%t.o,__cxa_pure_virtual, \
+// RUN: -r=%t.o,_ZN1C1fEv,p \
+// RUN: -r=%t.o,_ZN1D1dEii,p \
+// RUN: -r=%t.o,_ZTV1B, \
+// RUN: -r=%t.o,_ZTVN10__cxxabiv120__si_class_type_infoE, \
+// RUN: -r=%t.o,_ZTS1B,p \
+// RUN: -r=%t.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+// RUN: -r=%t.o,_ZTS1A,p \
+// RUN: -r=%t.o,_ZTI1A,p \
+// RUN: -r=%t.o,_ZTI1B,p \
+// RUN: -r=%t.o,_ZTV1A, \
+// RUN: -r=%t.o,_ZTV1C, \
+// RUN: -r=%t.o,_ZTS1C,p \
+// RUN: -r=%t.o,_ZTI1C,p \
+// RUN: -r=%t.o,_ZTV1D, \
+// RUN: -r=%t.o,_ZTS1D,p \
+// RUN: -r=%t.o,_ZTI1D,p \
+// RUN: -r=%t.o,__cxa_pure_virtual, \
+// RUN: -r=%t.o,_ZN1B1fEv, \
+// RUN: -r=%t.o,_ZN1C1fEv, \
+// RUN: -r=%t.o,_ZN1D1dEii, \
+// RUN: -r=%t.o,_ZTV1B,p \
+// RUN: -r=%t.o,_ZTI1A, \
+// RUN: -r=%t.o,_ZTI1B, \
+// RUN: -r=%t.o,_ZTV1A,p \
+// RUN: -r=%t.o,_ZTV1C,p \
+// RUN: -r=%t.o,_ZTI1C, \
+// RUN: -r=%t.o,_ZTV1D,p \
+// RUN: -r=%t.o,_ZTI1D,
+
+// Ensure that typeids are in the index.
+// RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
+// CHECK:
+// CHECK:
+// CHECK: d(b->f(), c->f()) != 57;
+}
Index: clang/test/CodeGen/thinlto-distributed.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/thinlto-distributed.c
@@ -0,0 +1,21 @@
+// REQUIRES: x86-registered-target
+
+// Trivial integration test for distributes ThinLTO
+
+// RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu -emit-llvm-bc \
+// RUN: -flto=thin -flto-unit \
+// RUN: -fthin-link-bitcode=%t.indexing.o %s -o %t.o
+
+// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+// RUN: -o %t2.index \
+// RUN: -r=%t.o,main,px
+
+// RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+// RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+// RUN: -o %t.native.o -x ir %t.o
+
+// RUN: %clang %t.native.o %t2.index.0 -o %t
+
+int main(int argc, char *argv[]) {
+ return 0;
+}
Index: llvm/include/llvm/Bitcode/LLVMBitCodes.h
===================================================================
--- llvm/include/llvm/Bitcode/LLVMBitCodes.h
+++ llvm/include/llvm/Bitcode/LLVMBitCodes.h
@@ -263,6 +263,11 @@
FS_PERMODULE_RELBF = 19,
// Index-wide flags
FS_FLAGS = 20,
+ // Maps type identifier to summary information for that type identifier.
+ // TYPE_ID: [typeid, kind, bitwidth, align, size, bitmask, inlinebits,
+ // n x (typeid, kind, name, numrba,
+ // numrba x (numarg, numarg x arg, kind, info, byte, bit))]
+ FS_TYPE_ID = 21,
};
enum MetadataCodes {
Index: llvm/include/llvm/IR/ModuleSummaryIndex.h
===================================================================
--- llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -710,7 +710,6 @@
/// Mapping from type identifiers to summary information for that type
/// identifier.
- // FIXME: Add bitcode read/write support for this field.
std::map TypeIdMap;
/// Mapping from original ID to GUID. If original ID can map to multiple
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5071,6 +5071,56 @@
return Ret;
}
+static void
+parseWholeProgramDevirtResolutionByArg(ArrayRef Record, size_t &Slot,
+ WholeProgramDevirtResolution &Wpd) {
+ uint64_t ArgNum = Record[Slot++];
+ WholeProgramDevirtResolution::ByArg &B =
+ Wpd.ResByArg[{Record.begin() + Slot, Record.begin() + Slot + ArgNum}];
+ Slot += ArgNum;
+
+ B.TheKind =
+ static_cast(Record[Slot++]);
+ B.Info = Record[Slot++];
+ B.Byte = Record[Slot++];
+ B.Bit = Record[Slot++];
+}
+
+static void parseWholeProgramDevirtResolution(ArrayRef Record,
+ StringRef Strtab, size_t &Slot,
+ TypeIdSummary &TypeId) {
+ uint64_t Id = Record[Slot++];
+ WholeProgramDevirtResolution &Wpd = TypeId.WPDRes[Id];
+
+ Wpd.TheKind = static_cast(Record[Slot++]);
+ Wpd.SingleImplName = {Strtab.data() + Record[Slot],
+ static_cast(Record[Slot + 1])};
+ Slot += 2;
+
+ uint64_t ResByArgNum = Record[Slot++];
+ for (uint64_t I = 0; I != ResByArgNum; ++I)
+ parseWholeProgramDevirtResolutionByArg(Record, Slot, Wpd);
+}
+
+static void parseTypeIdSummaryRecord(ArrayRef Record,
+ StringRef Strtab,
+ ModuleSummaryIndex &TheIndex) {
+ size_t Slot = 0;
+ TypeIdSummary &TypeId = TheIndex.getOrInsertTypeIdSummary(
+ {Strtab.data() + Record[Slot], static_cast(Record[Slot + 1])});
+ Slot += 2;
+
+ TypeId.TTRes.TheKind = static_cast(Record[Slot++]);
+ TypeId.TTRes.SizeM1BitWidth = Record[Slot++];
+ TypeId.TTRes.AlignLog2 = Record[Slot++];
+ TypeId.TTRes.SizeM1 = Record[Slot++];
+ TypeId.TTRes.BitMask = Record[Slot++];
+ TypeId.TTRes.InlineBits = Record[Slot++];
+
+ while (Slot < Record.size())
+ parseWholeProgramDevirtResolution(Record, Strtab, Slot, TypeId);
+}
+
// Eagerly parse the entire summary block. This populates the GlobalValueSummary
// objects in the index.
Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
@@ -5388,6 +5438,7 @@
{Strtab.data() + Record[I], static_cast(Record[I + 1])});
break;
}
+
case bitc::FS_CFI_FUNCTION_DECLS: {
std::set &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
for (unsigned I = 0; I != Record.size(); I += 2)
@@ -5395,6 +5446,10 @@
{Strtab.data() + Record[I], static_cast(Record[I + 1])});
break;
}
+
+ case bitc::FS_TYPE_ID:
+ parseTypeIdSummaryRecord(Record, Strtab, TheIndex);
+ break;
}
}
llvm_unreachable("Exit infinite loop");
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3359,6 +3359,51 @@
FS->type_checked_load_const_vcalls());
}
+static void writeWholeProgramDevirtResolutionByArg(
+ SmallVector &NameVals, const std::vector &args,
+ const WholeProgramDevirtResolution::ByArg &ByArg) {
+ NameVals.push_back(args.size());
+ NameVals.insert(NameVals.end(), args.begin(), args.end());
+
+ NameVals.push_back(ByArg.TheKind);
+ NameVals.push_back(ByArg.Info);
+ NameVals.push_back(ByArg.Byte);
+ NameVals.push_back(ByArg.Bit);
+}
+
+static void writeWholeProgramDevirtResolution(
+ SmallVector &NameVals, StringTableBuilder &StrtabBuilder,
+ uint64_t Id, const WholeProgramDevirtResolution &Wpd) {
+ NameVals.push_back(Id);
+
+ NameVals.push_back(Wpd.TheKind);
+ NameVals.push_back(StrtabBuilder.add(Wpd.SingleImplName));
+ NameVals.push_back(Wpd.SingleImplName.size());
+
+ NameVals.push_back(Wpd.ResByArg.size());
+ for (auto &A : Wpd.ResByArg)
+ writeWholeProgramDevirtResolutionByArg(NameVals, A.first, A.second);
+}
+
+static void writeTypeIdSummaryRecord(SmallVector &NameVals,
+ StringTableBuilder &StrtabBuilder,
+ const std::string &Id,
+ const TypeIdSummary &Summary) {
+ NameVals.push_back(StrtabBuilder.add(Id));
+ NameVals.push_back(Id.size());
+
+ NameVals.push_back(Summary.TTRes.TheKind);
+ NameVals.push_back(Summary.TTRes.SizeM1BitWidth);
+ NameVals.push_back(Summary.TTRes.AlignLog2);
+ NameVals.push_back(Summary.TTRes.SizeM1);
+ NameVals.push_back(Summary.TTRes.BitMask);
+ NameVals.push_back(Summary.TTRes.InlineBits);
+
+ for (auto &W : Summary.WPDRes)
+ writeWholeProgramDevirtResolution(NameVals, StrtabBuilder, W.first,
+ W.second);
+}
+
// Helper to emit a single function summary record.
void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
SmallVector &NameVals, GlobalValueSummary *Summary,
@@ -3776,6 +3821,14 @@
NameVals.clear();
}
+ if (!Index.typeIds().empty()) {
+ for (auto &S : Index.typeIds()) {
+ writeTypeIdSummaryRecord(NameVals, StrtabBuilder, S.first, S.second);
+ Stream.EmitRecord(bitc::FS_TYPE_ID, NameVals);
+ NameVals.clear();
+ }
+ }
+
Stream.ExitBlock();
}
Index: llvm/test/ThinLTO/X86/cfi-icall.ll
===================================================================
--- llvm/test/ThinLTO/X86/cfi-icall.ll
+++ llvm/test/ThinLTO/X86/cfi-icall.ll
@@ -22,8 +22,9 @@
; COMBINED:
; COMBINED:
+; COMBINED:
; COMBINED:
; COMBINED: blob data = 'foobar'
+; COMBINED-NEXT: blob data = 'foobartypeid1'
; COMBINED-NEXT:
Index: llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
===================================================================
--- llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -324,6 +324,7 @@
STRINGIFY_CODE(FS, VALUE_GUID)
STRINGIFY_CODE(FS, CFI_FUNCTION_DEFS)
STRINGIFY_CODE(FS, CFI_FUNCTION_DECLS)
+ STRINGIFY_CODE(FS, TYPE_ID)
}
case bitc::METADATA_ATTACHMENT_ID:
switch(CodeID) {