llvm.org GIT mirror llvm / 4a81fc6
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325182 91177308-0d34-0410-b5e6-96231b3b80d8 Vitaly Buka 2 years ago
6 changed file(s) with 116 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
262262 FS_PERMODULE_RELBF = 19,
263263 // Index-wide flags
264264 FS_FLAGS = 20,
265 // Maps type identifier to summary information for that type identifier.
266 // TYPE_ID: [typeid, kind, bitwidth, align, size, bitmask, inlinebits,
267 // n x (typeid, kind, name, numrba,
268 // numrba x (numarg, numarg x arg, kind, info, byte, bit))]
269 FS_TYPE_ID = 21,
265270 };
266271
267272 enum MetadataCodes {
670670
671671 /// Mapping from type identifiers to summary information for that type
672672 /// identifier.
673 // FIXME: Add bitcode read/write support for this field.
674673 std::map TypeIdMap;
675674
676675 /// Mapping from original ID to GUID. If original ID can map to multiple
50705070 return Ret;
50715071 }
50725072
5073 static void
5074 parseWholeProgramDevirtResolutionByArg(ArrayRef Record, size_t &Slot,
5075 WholeProgramDevirtResolution &Wpd) {
5076 uint64_t ArgNum = Record[Slot++];
5077 WholeProgramDevirtResolution::ByArg &B =
5078 Wpd.ResByArg[{Record.begin() + Slot, Record.begin() + Slot + ArgNum}];
5079 Slot += ArgNum;
5080
5081 B.TheKind =
5082 static_cast(Record[Slot++]);
5083 B.Info = Record[Slot++];
5084 B.Byte = Record[Slot++];
5085 B.Bit = Record[Slot++];
5086 }
5087
5088 static void parseWholeProgramDevirtResolution(ArrayRef Record,
5089 StringRef Strtab, size_t &Slot,
5090 TypeIdSummary &TypeId) {
5091 uint64_t Id = Record[Slot++];
5092 WholeProgramDevirtResolution &Wpd = TypeId.WPDRes[Id];
5093
5094 Wpd.TheKind = static_cast(Record[Slot++]);
5095 Wpd.SingleImplName = {Strtab.data() + Record[Slot],
5096 static_cast(Record[Slot + 1])};
5097 Slot += 2;
5098
5099 uint64_t ResByArgNum = Record[Slot++];
5100 for (uint64_t I = 0; I != ResByArgNum; ++I)
5101 parseWholeProgramDevirtResolutionByArg(Record, Slot, Wpd);
5102 }
5103
5104 static void parseTypeIdSummaryRecord(ArrayRef Record,
5105 StringRef Strtab,
5106 ModuleSummaryIndex &TheIndex) {
5107 size_t Slot = 0;
5108 TypeIdSummary &TypeId = TheIndex.getOrInsertTypeIdSummary(
5109 {Strtab.data() + Record[Slot], static_cast(Record[Slot + 1])});
5110 Slot += 2;
5111
5112 TypeId.TTRes.TheKind = static_cast(Record[Slot++]);
5113 TypeId.TTRes.SizeM1BitWidth = Record[Slot++];
5114 TypeId.TTRes.AlignLog2 = Record[Slot++];
5115 TypeId.TTRes.SizeM1 = Record[Slot++];
5116 TypeId.TTRes.BitMask = Record[Slot++];
5117 TypeId.TTRes.InlineBits = Record[Slot++];
5118
5119 while (Slot < Record.size())
5120 parseWholeProgramDevirtResolution(Record, Strtab, Slot, TypeId);
5121 }
5122
50735123 // Eagerly parse the entire summary block. This populates the GlobalValueSummary
50745124 // objects in the index.
50755125 Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
53875437 {Strtab.data() + Record[I], static_cast(Record[I + 1])});
53885438 break;
53895439 }
5440
53905441 case bitc::FS_CFI_FUNCTION_DECLS: {
53915442 std::set &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
53925443 for (unsigned I = 0; I != Record.size(); I += 2)
53945445 {Strtab.data() + Record[I], static_cast(Record[I + 1])});
53955446 break;
53965447 }
5448
5449 case bitc::FS_TYPE_ID:
5450 parseTypeIdSummaryRecord(Record, Strtab, TheIndex);
5451 break;
53975452 }
53985453 }
53995454 llvm_unreachable("Exit infinite loop");
33653365 FS->type_checked_load_const_vcalls());
33663366 }
33673367
3368 static void writeWholeProgramDevirtResolutionByArg(
3369 SmallVector &NameVals, const std::vector &args,
3370 const WholeProgramDevirtResolution::ByArg &ByArg) {
3371 NameVals.push_back(args.size());
3372 NameVals.insert(NameVals.end(), args.begin(), args.end());
3373
3374 NameVals.push_back(ByArg.TheKind);
3375 NameVals.push_back(ByArg.Info);
3376 NameVals.push_back(ByArg.Byte);
3377 NameVals.push_back(ByArg.Bit);
3378 }
3379
3380 static void writeWholeProgramDevirtResolution(
3381 SmallVector &NameVals, StringTableBuilder &StrtabBuilder,
3382 uint64_t Id, const WholeProgramDevirtResolution &Wpd) {
3383 NameVals.push_back(Id);
3384
3385 NameVals.push_back(Wpd.TheKind);
3386 NameVals.push_back(StrtabBuilder.add(Wpd.SingleImplName));
3387 NameVals.push_back(Wpd.SingleImplName.size());
3388
3389 NameVals.push_back(Wpd.ResByArg.size());
3390 for (auto &A : Wpd.ResByArg)
3391 writeWholeProgramDevirtResolutionByArg(NameVals, A.first, A.second);
3392 }
3393
3394 static void writeTypeIdSummaryRecord(SmallVector &NameVals,
3395 StringTableBuilder &StrtabBuilder,
3396 const std::string &Id,
3397 const TypeIdSummary &Summary) {
3398 NameVals.push_back(StrtabBuilder.add(Id));
3399 NameVals.push_back(Id.size());
3400
3401 NameVals.push_back(Summary.TTRes.TheKind);
3402 NameVals.push_back(Summary.TTRes.SizeM1BitWidth);
3403 NameVals.push_back(Summary.TTRes.AlignLog2);
3404 NameVals.push_back(Summary.TTRes.SizeM1);
3405 NameVals.push_back(Summary.TTRes.BitMask);
3406 NameVals.push_back(Summary.TTRes.InlineBits);
3407
3408 for (auto &W : Summary.WPDRes)
3409 writeWholeProgramDevirtResolution(NameVals, StrtabBuilder, W.first,
3410 W.second);
3411 }
3412
33683413 // Helper to emit a single function summary record.
33693414 void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
33703415 SmallVector &NameVals, GlobalValueSummary *Summary,
37823827 NameVals.clear();
37833828 }
37843829
3830 if (!Index.typeIds().empty()) {
3831 for (auto &S : Index.typeIds()) {
3832 writeTypeIdSummaryRecord(NameVals, StrtabBuilder, S.first, S.second);
3833 Stream.EmitRecord(bitc::FS_TYPE_ID, NameVals);
3834 NameVals.clear();
3835 }
3836 }
3837
37853838 Stream.ExitBlock();
37863839 }
37873840
2121 ; COMBINED:
2222 ; COMBINED:
2323 ; COMBINED:
24 ; COMBINED:
2425 ; COMBINED:
2526
2627 ; COMBINED:
27 ; COMBINED-NEXT: blob data = 'foobar'
28 ; COMBINED-NEXT: blob data = 'foobartypeid1'
2829 ; COMBINED-NEXT:
323323 STRINGIFY_CODE(FS, VALUE_GUID)
324324 STRINGIFY_CODE(FS, CFI_FUNCTION_DEFS)
325325 STRINGIFY_CODE(FS, CFI_FUNCTION_DECLS)
326 STRINGIFY_CODE(FS, TYPE_ID)
326327 }
327328 case bitc::METADATA_ATTACHMENT_ID:
328329 switch(CodeID) {