diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h index 9e551d3ae2bbe..2bbcda7093854 100644 --- a/llvm/include/llvm/AsmParser/LLParser.h +++ b/llvm/include/llvm/AsmParser/LLParser.h @@ -419,7 +419,7 @@ namespace llvm { bool parseParamAccessCall(FunctionSummary::ParamAccess::Call &Call, IdLocListType &IdLocList); bool parseParamAccessOffset(ConstantRange &Range); - bool parseOptionalRefs(std::vector &Refs); + bool parseOptionalRefs(SmallVectorImpl &Refs); bool parseTypeIdEntry(unsigned ID); bool parseTypeIdSummary(TypeIdSummary &TIS); bool parseTypeIdCompatibleVtableEntry(unsigned ID); diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index 6d39150a03bfd..7bd90d3ed7e9d 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -538,10 +538,13 @@ class GlobalValueSummary { /// (either by the initializer of a global variable, or referenced /// from within a function). This does not include functions called, which /// are listed in the derived FunctionSummary object. - std::vector RefEdgeList; + /// We use SmallVector instead of std::vector for its + /// smaller memory footprint. + SmallVector RefEdgeList; protected: - GlobalValueSummary(SummaryKind K, GVFlags Flags, std::vector Refs) + GlobalValueSummary(SummaryKind K, GVFlags Flags, + SmallVectorImpl &&Refs) : Kind(K), Flags(Flags), RefEdgeList(std::move(Refs)) { assert((K != AliasKind || Refs.empty()) && "Expect no references for AliasSummary"); @@ -641,7 +644,7 @@ class AliasSummary : public GlobalValueSummary { public: AliasSummary(GVFlags Flags) - : GlobalValueSummary(AliasKind, Flags, ArrayRef{}), + : GlobalValueSummary(AliasKind, Flags, SmallVector{}), AliaseeSummary(nullptr) {} /// Check if this is an alias summary. @@ -857,7 +860,7 @@ class FunctionSummary : public GlobalValueSummary { /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false, /*CanAutoHide=*/false, GlobalValueSummary::ImportKind::Definition), /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, - std::vector(), std::move(Edges), + SmallVector(), std::move(Edges), std::vector(), std::vector(), std::vector(), @@ -913,7 +916,7 @@ class FunctionSummary : public GlobalValueSummary { public: FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, - uint64_t EntryCount, std::vector Refs, + uint64_t EntryCount, SmallVectorImpl &&Refs, std::vector CGEdges, std::vector TypeTests, std::vector TypeTestAssumeVCalls, @@ -1166,7 +1169,7 @@ class GlobalVarSummary : public GlobalValueSummary { } VarFlags; GlobalVarSummary(GVFlags Flags, GVarFlags VarFlags, - std::vector Refs) + SmallVectorImpl &&Refs) : GlobalValueSummary(GlobalVarKind, Flags, std::move(Refs)), VarFlags(VarFlags) {} diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h index 6cc533f043a51..ec2907ca7662e 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h @@ -216,7 +216,7 @@ template <> struct CustomMappingTraits { } auto &Elem = V.try_emplace(KeyInt, /*IsAnalysis=*/false).first->second; for (auto &FSum : FSums) { - std::vector Refs; + SmallVector Refs; Refs.reserve(FSum.Refs.size()); for (auto &RefGUID : FSum.Refs) { auto It = V.try_emplace(RefGUID, /*IsAnalysis=*/false).first; @@ -229,9 +229,9 @@ template <> struct CustomMappingTraits { FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal, FSum.CanAutoHide, static_cast(FSum.ImportType)), - /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, Refs, - ArrayRef{}, std::move(FSum.TypeTests), - std::move(FSum.TypeTestAssumeVCalls), + /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, + std::move(Refs), ArrayRef{}, + std::move(FSum.TypeTests), std::move(FSum.TypeTestAssumeVCalls), std::move(FSum.TypeCheckedLoadVCalls), std::move(FSum.TypeTestAssumeConstVCalls), std::move(FSum.TypeCheckedLoadConstVCalls), diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index e9490ccba8215..39e7926ea43fe 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -99,10 +99,11 @@ extern cl::opt MemProfReportHintedSizes; // can only take an address of basic block located in the same function. // Set `RefLocalLinkageIFunc` to true if the analyzed value references a // local-linkage ifunc. -static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, - SetVector> &RefEdges, - SmallPtrSet &Visited, - bool &RefLocalLinkageIFunc) { +static bool +findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, + SetVector> &RefEdges, + SmallPtrSet &Visited, + bool &RefLocalLinkageIFunc) { bool HasBlockAddress = false; SmallVector Worklist; if (Visited.insert(CurUser).second) @@ -310,7 +311,7 @@ static void computeFunctionSummary( MapVector, std::vector>> CallGraphEdges; - SetVector> RefEdges, LoadRefEdges, + SetVector> RefEdges, LoadRefEdges, StoreRefEdges; SetVector> TypeTests; SetVector> @@ -568,16 +569,17 @@ static void computeFunctionSummary( if (PSI->hasPartialSampleProfile() && ScalePartialSampleProfileWorkingSetSize) Index.addBlockCount(F.size()); - std::vector Refs; + SmallVector Refs; if (IsThinLTO) { - auto AddRefEdges = [&](const std::vector &Instrs, - SetVector> &Edges, - SmallPtrSet &Cache) { - for (const auto *I : Instrs) { - Cache.erase(I); - findRefEdges(Index, I, Edges, Cache, HasLocalIFuncCallOrRef); - } - }; + auto AddRefEdges = + [&](const std::vector &Instrs, + SetVector> &Edges, + SmallPtrSet &Cache) { + for (const auto *I : Instrs) { + Cache.erase(I); + findRefEdges(Index, I, Edges, Cache, HasLocalIFuncCallOrRef); + } + }; // By now we processed all instructions in a function, except // non-volatile loads and non-volatile value stores. Let's find @@ -805,7 +807,7 @@ static void computeVariableSummary(ModuleSummaryIndex &Index, DenseSet &CantBePromoted, const Module &M, SmallVectorImpl &Types) { - SetVector> RefEdges; + SetVector> RefEdges; SmallPtrSet Visited; bool RefLocalIFunc = false; bool HasBlockAddress = @@ -961,7 +963,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex( /* MayThrow */ true, /* HasUnknownCall */ true, /* MustBeUnreachable */ false}, - /*EntryCount=*/0, ArrayRef{}, + /*EntryCount=*/0, SmallVector{}, ArrayRef{}, ArrayRef{}, ArrayRef{}, @@ -978,7 +980,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex( GlobalVarSummary::GVarFlags( false, false, cast(GV)->isConstant(), GlobalObject::VCallVisibilityPublic), - ArrayRef{}); + SmallVector{}); Index.addGlobalValueSummary(*GV, std::move(Summary)); } }); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index f41907f035125..5964355fd26cc 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -9388,7 +9388,7 @@ bool LLParser::parseFunctionSummary(std::string Name, GlobalValue::GUID GUID, std::vector Calls; FunctionSummary::TypeIdInfo TypeIdInfo; std::vector ParamAccesses; - std::vector Refs; + SmallVector Refs; std::vector Callsites; std::vector Allocs; // Default is all-zeros (conservative values). @@ -9476,7 +9476,7 @@ bool LLParser::parseVariableSummary(std::string Name, GlobalValue::GUID GUID, /* WriteOnly */ false, /* Constant */ false, GlobalObject::VCallVisibilityPublic); - std::vector Refs; + SmallVector Refs; VTableFuncList VTableFuncs; if (parseToken(lltok::colon, "expected ':' here") || parseToken(lltok::lparen, "expected '(' here") || @@ -9982,7 +9982,7 @@ bool LLParser::parseOptionalParamAccesses( /// OptionalRefs /// := 'refs' ':' '(' GVReference [',' GVReference]* ')' -bool LLParser::parseOptionalRefs(std::vector &Refs) { +bool LLParser::parseOptionalRefs(SmallVectorImpl &Refs) { assert(Lex.getKind() == lltok::kw_refs); Lex.Lex(); diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 654be985a3229..3d87f1e339c85 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -985,7 +985,7 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { Error parseValueSymbolTable( uint64_t Offset, DenseMap &ValueIdToLinkageMap); - std::vector makeRefList(ArrayRef Record); + SmallVector makeRefList(ArrayRef Record); std::vector makeCallList(ArrayRef Record, bool IsOldProfileFormat, bool HasProfile, @@ -7361,9 +7361,9 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { } } -std::vector +SmallVector ModuleSummaryIndexBitcodeReader::makeRefList(ArrayRef Record) { - std::vector Ret; + SmallVector Ret; Ret.reserve(Record.size()); for (uint64_t RefValueId : Record) Ret.push_back(std::get<0>(getValueInfoFromValueId(RefValueId))); @@ -7508,7 +7508,7 @@ void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord( parseTypeIdCompatibleVtableInfo(Record, Slot, TypeId); } -static void setSpecialRefs(std::vector &Refs, unsigned ROCnt, +static void setSpecialRefs(SmallVectorImpl &Refs, unsigned ROCnt, unsigned WOCnt) { // Readonly and writeonly refs are in the end of the refs list. assert(ROCnt + WOCnt <= Refs.size()); @@ -7658,7 +7658,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs; assert(Record.size() >= RefListStartIndex + NumRefs && "Record size inconsistent with number of references"); - std::vector Refs = makeRefList( + SmallVector Refs = makeRefList( ArrayRef(Record).slice(RefListStartIndex, NumRefs)); bool HasProfile = (BitCode == bitc::FS_PERMODULE_PROFILE); bool HasRelBF = (BitCode == bitc::FS_PERMODULE_RELBF); @@ -7733,7 +7733,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { GVF = getDecodedGVarFlags(Record[2]); RefArrayStart = 3; } - std::vector Refs = + SmallVector Refs = makeRefList(ArrayRef(Record).slice(RefArrayStart)); auto FS = std::make_unique(Flags, GVF, std::move(Refs)); @@ -7754,7 +7754,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { unsigned RefListStartIndex = 4; unsigned VTableListStartIndex = RefListStartIndex + NumRefs; auto Flags = getDecodedGVSummaryFlags(RawFlags, Version); - std::vector Refs = makeRefList( + SmallVector Refs = makeRefList( ArrayRef(Record).slice(RefListStartIndex, NumRefs)); VTableFuncList VTableFuncs; for (unsigned I = VTableListStartIndex, E = Record.size(); I != E; ++I) { @@ -7815,7 +7815,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs; assert(Record.size() >= RefListStartIndex + NumRefs && "Record size inconsistent with number of references"); - std::vector Refs = makeRefList( + SmallVector Refs = makeRefList( ArrayRef(Record).slice(RefListStartIndex, NumRefs)); bool HasProfile = (BitCode == bitc::FS_COMBINED_PROFILE); std::vector Edges = makeCallList( @@ -7875,7 +7875,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { GVF = getDecodedGVarFlags(Record[3]); RefArrayStart = 4; } - std::vector Refs = + SmallVector Refs = makeRefList(ArrayRef(Record).slice(RefArrayStart)); auto FS = std::make_unique(Flags, GVF, std::move(Refs));