diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -629,7 +629,8 @@ std::unique_ptr TIdInfo; /// Uses for every parameter to this function. - std::vector ParamAccesses; + using ParamAccessesTy = std::vector; + std::unique_ptr ParamAccesses; public: FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, @@ -640,19 +641,20 @@ std::vector TypeCheckedLoadVCalls, std::vector TypeTestAssumeConstVCalls, std::vector TypeCheckedLoadConstVCalls, - std::vector ParamAccesses) + std::vector Params) : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)), InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount), - CallGraphEdgeList(std::move(CGEdges)), - ParamAccesses(std::move(ParamAccesses)) { + CallGraphEdgeList(std::move(CGEdges)) { if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() || !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() || !TypeCheckedLoadConstVCalls.empty()) - TIdInfo = std::make_unique(TypeIdInfo{ - std::move(TypeTests), std::move(TypeTestAssumeVCalls), - std::move(TypeCheckedLoadVCalls), - std::move(TypeTestAssumeConstVCalls), - std::move(TypeCheckedLoadConstVCalls)}); + TIdInfo = std::make_unique( + TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls), + std::move(TypeCheckedLoadVCalls), + std::move(TypeTestAssumeConstVCalls), + std::move(TypeCheckedLoadConstVCalls)}); + if (!Params.empty()) + ParamAccesses = std::make_unique(std::move(Params)); } // Gets the number of readonly and writeonly refs in RefEdgeList std::pair specialRefCounts() const; @@ -724,11 +726,20 @@ } /// Returns the list of known uses of pointer parameters. - ArrayRef paramAccesses() const { return ParamAccesses; } + ArrayRef paramAccesses() const { + if (ParamAccesses) + return *ParamAccesses; + return {}; + } /// Sets the list of known uses of pointer parameters. void setParamAccesses(std::vector NewParams) { - ParamAccesses = std::move(NewParams); + if (NewParams.empty()) + ParamAccesses.reset(); + else if (ParamAccesses) + *ParamAccesses = std::move(NewParams); + else + ParamAccesses = std::make_unique(std::move(NewParams)); } /// Add a type test to the summary. This is used by WholeProgramDevirt if we