mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK
Summary: TypeID summaries are used by CFI and need to be serialized by ThinLTO indexing for later use by LTO Backend. Reviewers: tejohnson, pcc Subscribers: mehdi_amini, inglorion, eraman, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D42611 llvm-svn: 325182
This commit is contained in:
parent
b8f97b94a0
commit
f35a8dc055
@ -263,6 +263,11 @@ enum GlobalValueSummarySymtabCodes {
|
||||
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 {
|
||||
|
@ -671,7 +671,6 @@ private:
|
||||
|
||||
/// Mapping from type identifiers to summary information for that type
|
||||
/// identifier.
|
||||
// FIXME: Add bitcode read/write support for this field.
|
||||
std::map<std::string, TypeIdSummary> TypeIdMap;
|
||||
|
||||
/// Mapping from original ID to GUID. If original ID can map to multiple
|
||||
|
@ -5071,6 +5071,56 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
|
||||
return Ret;
|
||||
}
|
||||
|
||||
static void
|
||||
parseWholeProgramDevirtResolutionByArg(ArrayRef<uint64_t> 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<WholeProgramDevirtResolution::ByArg::Kind>(Record[Slot++]);
|
||||
B.Info = Record[Slot++];
|
||||
B.Byte = Record[Slot++];
|
||||
B.Bit = Record[Slot++];
|
||||
}
|
||||
|
||||
static void parseWholeProgramDevirtResolution(ArrayRef<uint64_t> Record,
|
||||
StringRef Strtab, size_t &Slot,
|
||||
TypeIdSummary &TypeId) {
|
||||
uint64_t Id = Record[Slot++];
|
||||
WholeProgramDevirtResolution &Wpd = TypeId.WPDRes[Id];
|
||||
|
||||
Wpd.TheKind = static_cast<WholeProgramDevirtResolution::Kind>(Record[Slot++]);
|
||||
Wpd.SingleImplName = {Strtab.data() + Record[Slot],
|
||||
static_cast<size_t>(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<uint64_t> Record,
|
||||
StringRef Strtab,
|
||||
ModuleSummaryIndex &TheIndex) {
|
||||
size_t Slot = 0;
|
||||
TypeIdSummary &TypeId = TheIndex.getOrInsertTypeIdSummary(
|
||||
{Strtab.data() + Record[Slot], static_cast<size_t>(Record[Slot + 1])});
|
||||
Slot += 2;
|
||||
|
||||
TypeId.TTRes.TheKind = static_cast<TypeTestResolution::Kind>(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 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
|
||||
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
|
||||
break;
|
||||
}
|
||||
|
||||
case bitc::FS_CFI_FUNCTION_DECLS: {
|
||||
std::set<std::string> &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
|
||||
for (unsigned I = 0; I != Record.size(); I += 2)
|
||||
@ -5395,6 +5446,10 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
|
||||
{Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
|
||||
break;
|
||||
}
|
||||
|
||||
case bitc::FS_TYPE_ID:
|
||||
parseTypeIdSummaryRecord(Record, Strtab, TheIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
llvm_unreachable("Exit infinite loop");
|
||||
|
@ -3366,6 +3366,51 @@ static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream,
|
||||
FS->type_checked_load_const_vcalls());
|
||||
}
|
||||
|
||||
static void writeWholeProgramDevirtResolutionByArg(
|
||||
SmallVector<uint64_t, 64> &NameVals, const std::vector<uint64_t> &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<uint64_t, 64> &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<uint64_t, 64> &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<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
|
||||
@ -3783,6 +3828,14 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,9 @@ declare i1 @llvm.type.test(i8* %ptr, metadata %type) nounwind readnone
|
||||
; COMBINED: <GLOBALVAL_SUMMARY_BLOCK
|
||||
; COMBINED: <CFI_FUNCTION_DEFS op0=0 op1=3/>
|
||||
; COMBINED: <CFI_FUNCTION_DECLS op0=3 op1=3/>
|
||||
; COMBINED: <TYPE_ID op0=6 op1=7 op2=4 op3=7 op4=0 op5=0 op6=0 op7=0/>
|
||||
; COMBINED: </GLOBALVAL_SUMMARY_BLOCK>
|
||||
|
||||
; COMBINED: <STRTAB_BLOCK
|
||||
; COMBINED-NEXT: <BLOB abbrevid=4/> blob data = 'foobar'
|
||||
; COMBINED-NEXT: <BLOB abbrevid=4/> blob data = 'foobartypeid1'
|
||||
; COMBINED-NEXT: </STRTAB_BLOCK>
|
||||
|
@ -324,6 +324,7 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID,
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user