Skip to content

Commit 57f2a78

Browse files
committed
[StackSafety,NFC] Reduce FunctionSummary size
Most compiler infocations will not need ParamAccess, so we can optimize memory usage there with smaller unique_ptr instead of empty vector. Suggested in D80908 review. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D83458
1 parent bed3e1a commit 57f2a78

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ class FunctionSummary : public GlobalValueSummary {
629629
std::unique_ptr<TypeIdInfo> TIdInfo;
630630

631631
/// Uses for every parameter to this function.
632-
std::vector<ParamAccess> ParamAccesses;
632+
using ParamAccessesTy = std::vector<ParamAccess>;
633+
std::unique_ptr<ParamAccessesTy> ParamAccesses;
633634

634635
public:
635636
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
@@ -640,19 +641,20 @@ class FunctionSummary : public GlobalValueSummary {
640641
std::vector<VFuncId> TypeCheckedLoadVCalls,
641642
std::vector<ConstVCall> TypeTestAssumeConstVCalls,
642643
std::vector<ConstVCall> TypeCheckedLoadConstVCalls,
643-
std::vector<ParamAccess> ParamAccesses)
644+
std::vector<ParamAccess> Params)
644645
: GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
645646
InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount),
646-
CallGraphEdgeList(std::move(CGEdges)),
647-
ParamAccesses(std::move(ParamAccesses)) {
647+
CallGraphEdgeList(std::move(CGEdges)) {
648648
if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
649649
!TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
650650
!TypeCheckedLoadConstVCalls.empty())
651-
TIdInfo = std::make_unique<TypeIdInfo>(TypeIdInfo{
652-
std::move(TypeTests), std::move(TypeTestAssumeVCalls),
653-
std::move(TypeCheckedLoadVCalls),
654-
std::move(TypeTestAssumeConstVCalls),
655-
std::move(TypeCheckedLoadConstVCalls)});
651+
TIdInfo = std::make_unique<TypeIdInfo>(
652+
TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls),
653+
std::move(TypeCheckedLoadVCalls),
654+
std::move(TypeTestAssumeConstVCalls),
655+
std::move(TypeCheckedLoadConstVCalls)});
656+
if (!Params.empty())
657+
ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(Params));
656658
}
657659
// Gets the number of readonly and writeonly refs in RefEdgeList
658660
std::pair<unsigned, unsigned> specialRefCounts() const;
@@ -724,11 +726,20 @@ class FunctionSummary : public GlobalValueSummary {
724726
}
725727

726728
/// Returns the list of known uses of pointer parameters.
727-
ArrayRef<ParamAccess> paramAccesses() const { return ParamAccesses; }
729+
ArrayRef<ParamAccess> paramAccesses() const {
730+
if (ParamAccesses)
731+
return *ParamAccesses;
732+
return {};
733+
}
728734

729735
/// Sets the list of known uses of pointer parameters.
730736
void setParamAccesses(std::vector<ParamAccess> NewParams) {
731-
ParamAccesses = std::move(NewParams);
737+
if (NewParams.empty())
738+
ParamAccesses.reset();
739+
else if (ParamAccesses)
740+
*ParamAccesses = std::move(NewParams);
741+
else
742+
ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(NewParams));
732743
}
733744

734745
/// Add a type test to the summary. This is used by WholeProgramDevirt if we

0 commit comments

Comments
 (0)