Skip to content

Commit dd1a201

Browse files
committed
[caller-analysis] Improve memory usage of FunctionInfo structs by using small data structures instead of large.
This converts a DenseMap to a SmallMapVector and a SetVector to a SmallSetVector. Both of these create large malloced data structures by default. This really makes no sense when there are many functions that don't use a partial apply or many applies. Additionally, by changing the DenseMap to a MapVector container, this commit is eliminating a potential source of non-determinism in the compiler since often times we are iterating over the DenseMap to produce the results. Today all of the usages of the DenseMap in this way are safe, but to defensively future proof this analysis, it makes sense to use a MapVector here.
1 parent 5976980 commit dd1a201

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/swift/SILOptimizer/Analysis/CallerAnalysis.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ class CallerAnalysis::FunctionInfo {
132132
friend class CallerAnalysis;
133133

134134
/// A list of all the functions this function calls or partially applies.
135-
llvm::SetVector<SILFunction *> Callees;
135+
llvm::SmallSetVector<SILFunction *, 4> Callees;
136+
136137
/// A list of all the callers this function has.
137138
llvm::SmallSet<SILFunction *, 4> Callers;
138139

@@ -143,7 +144,7 @@ class CallerAnalysis::FunctionInfo {
143144
/// function.
144145
/// This is a little bit off-topic because a partial_apply is not really
145146
/// a "call" of this function.
146-
llvm::DenseMap<SILFunction *, int> PartialAppliers;
147+
llvm::SmallMapVector<SILFunction *, int, 1> PartialAppliers;
147148

148149
public:
149150
/// Returns true if this function has at least one caller.

0 commit comments

Comments
 (0)