From 4666953ce229cd7a8b042e5f80ecc97b4eae3636 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Sun, 31 May 2020 23:49:57 -0700 Subject: [StackSafety] Add info into function summary Summary: This patch adds optional field into function summary, implements asm and bitcode serialization. YAML serialization is omitted and can be added later if needed. This patch includes this information into summary only if module contains at least one sanitize_memtag function. In a near future MTE is the user of the analysis. Later if needed we can provede more direct control on when information is included into summary. Reviewers: eugenis Subscribers: hiraditya, steven_wu, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80908 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 48 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 615b646..2f9331e 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5804,6 +5804,41 @@ static void parseTypeIdSummaryRecord(ArrayRef Record, parseWholeProgramDevirtResolution(Record, Strtab, Slot, TypeId); } +static std::vector +parseParamAccesses(ArrayRef Record) { + auto ReadRange = [&]() { + APInt Lower(FunctionSummary::ParamAccess::RangeWidth, + BitcodeReader::decodeSignRotatedValue(Record.front())); + Record = Record.drop_front(); + APInt Upper(FunctionSummary::ParamAccess::RangeWidth, + BitcodeReader::decodeSignRotatedValue(Record.front())); + Record = Record.drop_front(); + ConstantRange Range{Lower, Upper}; + assert(!Range.isFullSet()); + assert(!Range.isUpperSignWrapped()); + return Range; + }; + + std::vector PendingParamAccesses; + while (!Record.empty()) { + PendingParamAccesses.emplace_back(); + FunctionSummary::ParamAccess &ParamAccess = PendingParamAccesses.back(); + ParamAccess.ParamNo = Record.front(); + Record = Record.drop_front(); + ParamAccess.Use = ReadRange(); + ParamAccess.Calls.resize(Record.front()); + Record = Record.drop_front(); + for (auto &Call : ParamAccess.Calls) { + Call.ParamNo = Record.front(); + Record = Record.drop_front(); + Call.Callee = Record.front(); + Record = Record.drop_front(); + Call.Offsets = ReadRange(); + } + } + return PendingParamAccesses; +} + void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo( ArrayRef Record, size_t &Slot, TypeIdCompatibleVtableInfo &TypeId) { @@ -5881,6 +5916,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { PendingTypeCheckedLoadVCalls; std::vector PendingTypeTestAssumeConstVCalls, PendingTypeCheckedLoadConstVCalls; + std::vector PendingParamAccesses; while (true) { Expected MaybeEntry = Stream.advanceSkippingSubblocks(); @@ -5979,7 +6015,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { std::move(PendingTypeTestAssumeVCalls), std::move(PendingTypeCheckedLoadVCalls), std::move(PendingTypeTestAssumeConstVCalls), - std::move(PendingTypeCheckedLoadConstVCalls)); + std::move(PendingTypeCheckedLoadConstVCalls), + std::move(PendingParamAccesses)); auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID); FS->setModulePath(getThisModule()->first()); FS->setOriginalName(VIAndOriginalGUID.second); @@ -6121,7 +6158,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { std::move(PendingTypeTestAssumeVCalls), std::move(PendingTypeCheckedLoadVCalls), std::move(PendingTypeTestAssumeConstVCalls), - std::move(PendingTypeCheckedLoadConstVCalls)); + std::move(PendingTypeCheckedLoadConstVCalls), + std::move(PendingParamAccesses)); LastSeenSummary = FS.get(); LastSeenGUID = VI.getGUID(); FS->setModulePath(ModuleIdMap[ModuleId]); @@ -6242,6 +6280,12 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { case bitc::FS_BLOCK_COUNT: TheIndex.addBlockCount(Record[0]); + break; + + case bitc::FS_PARAM_ACCESS: { + PendingParamAccesses = parseParamAccesses(Record); + break; + } } } llvm_unreachable("Exit infinite loop"); -- cgit v1.1