From: Peter Collingbourne Date: Sat, 11 Feb 2017 03:19:22 +0000 (+0000) Subject: Address Mehdi's post-commit review comments on r294795. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=049ef19b9c9a80e22b7db05037a8ef099a8ae461;p=llvm Address Mehdi's post-commit review comments on r294795. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294822 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/ModuleSummaryIndex.h b/include/llvm/IR/ModuleSummaryIndex.h index 12802e232a5..67c70f500e0 100644 --- a/include/llvm/IR/ModuleSummaryIndex.h +++ b/include/llvm/IR/ModuleSummaryIndex.h @@ -251,7 +251,8 @@ public: /// An "identifier" for a virtual function. This contains the type identifier /// represented as a GUID and the offset from the address point to the virtual - /// function pointer. + /// function pointer, where "address point" is as defined in the Itanium ABI: + /// https://mentorembedded.github.io/cxx-abi/abi.html#vtable-general struct VFuncId { GlobalValue::GUID GUID; uint64_t Offset; @@ -273,19 +274,26 @@ private: /// List of call edge pairs from this function. std::vector CallGraphEdgeList; - /// List of type identifiers used by this function in llvm.type.test - /// intrinsics other than by an llvm.assume intrinsic, represented as GUIDs. - std::vector TypeTests; - - /// List of virtual calls made by this function using (respectively) - /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do - /// not have all constant integer arguments. - std::vector TypeTestAssumeVCalls, TypeCheckedLoadVCalls; + /// All type identifier related information. Because these fields are + /// relatively uncommon we only allocate space for them if necessary. + struct TypeIdInfo { + /// List of type identifiers used by this function in llvm.type.test + /// intrinsics other than by an llvm.assume intrinsic, represented as GUIDs. + std::vector TypeTests; + + /// List of virtual calls made by this function using (respectively) + /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do + /// not have all constant integer arguments. + std::vector TypeTestAssumeVCalls, TypeCheckedLoadVCalls; + + /// List of virtual calls made by this function using (respectively) + /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with + /// all constant integer arguments. + std::vector TypeTestAssumeConstVCalls, + TypeCheckedLoadConstVCalls; + }; - /// List of virtual calls made by this function using (respectively) - /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with - /// all constant integer arguments. - std::vector TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls; + std::unique_ptr TIdInfo; public: /// Summary constructors. @@ -297,12 +305,16 @@ public: std::vector TypeTestAssumeConstVCalls, std::vector TypeCheckedLoadConstVCalls) : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)), - InstCount(NumInsts), CallGraphEdgeList(std::move(CGEdges)), - TypeTests(std::move(TypeTests)), - TypeTestAssumeVCalls(std::move(TypeTestAssumeVCalls)), - TypeCheckedLoadVCalls(std::move(TypeCheckedLoadVCalls)), - TypeTestAssumeConstVCalls(std::move(TypeTestAssumeConstVCalls)), - TypeCheckedLoadConstVCalls(std::move(TypeCheckedLoadConstVCalls)) {} + InstCount(NumInsts), CallGraphEdgeList(std::move(CGEdges)) { + if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() || + !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() || + !TypeCheckedLoadConstVCalls.empty()) + TIdInfo = llvm::make_unique(TypeIdInfo{ + std::move(TypeTests), std::move(TypeTestAssumeVCalls), + std::move(TypeCheckedLoadVCalls), + std::move(TypeTestAssumeConstVCalls), + std::move(TypeCheckedLoadConstVCalls)}); + } /// Check if this is a function summary. static bool classof(const GlobalValueSummary *GVS) { @@ -318,41 +330,51 @@ public: /// Returns the list of type identifiers used by this function in /// llvm.type.test intrinsics other than by an llvm.assume intrinsic, /// represented as GUIDs. - ArrayRef type_tests() const { return TypeTests; } + ArrayRef type_tests() const { + if (TIdInfo) + return TIdInfo->TypeTests; + return {}; + } /// Returns the list of virtual calls made by this function using /// llvm.assume(llvm.type.test) intrinsics that do not have all constant /// integer arguments. ArrayRef type_test_assume_vcalls() const { - return TypeTestAssumeVCalls; + if (TIdInfo) + return TIdInfo->TypeTestAssumeVCalls; + return {}; } /// Returns the list of virtual calls made by this function using /// llvm.type.checked.load intrinsics that do not have all constant integer /// arguments. ArrayRef type_checked_load_vcalls() const { - return TypeCheckedLoadVCalls; + if (TIdInfo) + return TIdInfo->TypeCheckedLoadVCalls; + return {}; } /// Returns the list of virtual calls made by this function using /// llvm.assume(llvm.type.test) intrinsics with all constant integer /// arguments. ArrayRef type_test_assume_const_vcalls() const { - return TypeTestAssumeConstVCalls; + if (TIdInfo) + return TIdInfo->TypeTestAssumeConstVCalls; + return {}; } /// Returns the list of virtual calls made by this function using /// llvm.type.checked.load intrinsics with all constant integer arguments. ArrayRef type_checked_load_const_vcalls() const { - return TypeCheckedLoadConstVCalls; + if (TIdInfo) + return TIdInfo->TypeCheckedLoadConstVCalls; + return {}; } }; template <> struct DenseMapInfo { - static inline FunctionSummary::VFuncId getEmptyKey() { - return {0, uint64_t(-1)}; - } - static inline FunctionSummary::VFuncId getTombstoneKey() { + static FunctionSummary::VFuncId getEmptyKey() { return {0, uint64_t(-1)}; } + static FunctionSummary::VFuncId getTombstoneKey() { return {0, uint64_t(-2)}; } static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R) { @@ -362,10 +384,10 @@ template <> struct DenseMapInfo { }; template <> struct DenseMapInfo { - static inline FunctionSummary::ConstVCall getEmptyKey() { + static FunctionSummary::ConstVCall getEmptyKey() { return {{0, uint64_t(-1)}, {}}; } - static inline FunctionSummary::ConstVCall getTombstoneKey() { + static FunctionSummary::ConstVCall getTombstoneKey() { return {{0, uint64_t(-2)}, {}}; } static bool isEqual(FunctionSummary::ConstVCall L, diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index fe73efef5a5..9f1a3d60132 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4847,6 +4847,10 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary( // "OriginalName" attachement. GlobalValueSummary *LastSeenSummary = nullptr; bool Combined = false; + + // We can expect to see any number of type ID information records before + // each function summary records; these variables store the information + // collected so far so that it can be used to create the summary object. std::vector PendingTypeTests; std::vector PendingTypeTestAssumeVCalls, PendingTypeCheckedLoadVCalls;