@@ -30,34 +30,75 @@ namespace swift {
30
30
31
31
class AccessSummaryAnalysis : public BottomUpIPAnalysis {
32
32
public:
33
- // / Summarizes the accesses that a function begins on an argument.
34
- class ArgumentSummary {
33
+ class SubAccessSummary {
35
34
private:
36
35
// / The kind of access begun on the argument.
37
- // / 'None' means no access performed.
38
- Optional<SILAccessKind> Kind = None;
36
+ SILAccessKind Kind;
39
37
40
38
// / The location of the access. Used for diagnostics.
41
39
SILLocation AccessLoc = SILLocation((Expr *)nullptr );
42
40
41
+ const IndexTrieNode *SubPath = nullptr ;
42
+
43
43
public:
44
- Optional<SILAccessKind> getAccessKind () const { return Kind; }
44
+ SubAccessSummary (SILAccessKind Kind, SILLocation AccessLoc,
45
+ const IndexTrieNode *SubPath)
46
+ : Kind(Kind), AccessLoc(AccessLoc), SubPath(SubPath) {}
47
+
48
+ SILAccessKind getAccessKind () const { return Kind; }
45
49
46
50
SILLocation getAccessLoc () const { return AccessLoc; }
47
51
52
+ const IndexTrieNode *getSubPath () const { return SubPath; }
53
+
54
+ // / The lattice operation on SubAccessSummaries summaries.
55
+ bool mergeWith (const SubAccessSummary &other);
56
+
57
+ // / Merge in an access to the argument of the given kind at the given
58
+ // / location with the given suppath. Returns true if the merge caused the
59
+ // / summary to change.
60
+ bool mergeWith (SILAccessKind otherKind, SILLocation otherLoc,
61
+ const IndexTrieNode *otherSubPath);
62
+
63
+ // / Returns a description of the summary. For debugging and testing
64
+ // / purposes.
65
+ std::string getDescription (SILType BaseType, SILModule &M) const ;
66
+ };
67
+
68
+ typedef llvm::SmallDenseMap<const IndexTrieNode *, SubAccessSummary, 8 >
69
+ SubAccessMap;
70
+
71
+ // / Summarizes the accesses that a function begins on an argument, including
72
+ // / the projection subpath that was accessed.
73
+ class ArgumentSummary {
74
+ private:
75
+ SubAccessMap SubAccesses;
76
+
77
+ public:
48
78
// / The lattice operation on argument summaries.
49
79
bool mergeWith (const ArgumentSummary &other);
50
80
51
81
// / Merge in an access to the argument of the given kind at the given
52
82
// / location. Returns true if the merge caused the summary to change.
53
- bool mergeWith (SILAccessKind otherKind, SILLocation otherLoc);
83
+ bool mergeWith (SILAccessKind otherKind, SILLocation otherLoc,
84
+ const IndexTrieNode *otherSubPath);
54
85
55
86
// / Returns a description of the summary. For debugging and testing
56
87
// / purposes.
57
- StringRef getDescription () const ;
88
+ std::string getDescription (SILType BaseType, SILModule &M) const ;
89
+
90
+ // / Returns the accesses that the function performs to subpaths of the
91
+ // / argument.
92
+ const SubAccessMap &getSubAccesses () const { return SubAccesses; }
93
+
94
+ // / Returns the sorted subaccess summaries into the passed-in storage.
95
+ // / The accesses are sorted lexicographically by increasing subpath
96
+ // / length and projection index.
97
+ void getSortedSubAccesses (SmallVectorImpl<SubAccessSummary> &storage) const ;
58
98
};
59
99
60
- // / Summarizes the accesses that a function begins on its arguments.
100
+ // / Summarizes the accesses that a function begins on its arguments or
101
+ // / projections from its arguments.
61
102
class FunctionSummary {
62
103
private:
63
104
llvm::SmallVector<ArgumentSummary, 6 > ArgAccesses;
@@ -77,10 +118,9 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
77
118
78
119
// / Returns the number of argument in the summary.
79
120
unsigned getArgumentCount () const { return ArgAccesses.size (); }
80
- };
81
121
82
- friend raw_ostream & operator << (raw_ostream &os,
83
- const FunctionSummary &summary) ;
122
+ void print (raw_ostream &os, SILFunction *fn) const ;
123
+ } ;
84
124
85
125
class FunctionInfo ;
86
126
// / Records a flow of a caller's argument to a called function.
@@ -151,6 +191,10 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
151
191
return SubPathTrie;
152
192
}
153
193
194
+ // / Returns an IndexTrieNode that represents the single subpath accessed from
195
+ // / BAI or the root if no such node exists.
196
+ const IndexTrieNode *findSubPathAccessed (BeginAccessInst *BAI);
197
+
154
198
virtual void initialize (SILPassManager *PM) override {}
155
199
virtual void invalidate () override ;
156
200
virtual void invalidate (SILFunction *F, InvalidationKind K) override ;
@@ -164,6 +208,17 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
164
208
return S->getKind () == AnalysisKind::AccessSummary;
165
209
}
166
210
211
+ // / Returns a description of the subpath suitable for use in diagnostics.
212
+ // / The base type must be the type of the root of the path.
213
+ static std::string getSubPathDescription (SILType BaseType,
214
+ const IndexTrieNode *SubPath,
215
+ SILModule &M);
216
+
217
+ // / Performs a lexicographic comparison of two subpaths, first by path length
218
+ // / and then by index of the last path component. Returns true when lhs
219
+ // / is less than rhs.
220
+ static bool compareSubPaths (const IndexTrieNode *lhs,
221
+ const IndexTrieNode *rhs);
167
222
private:
168
223
typedef BottomUpFunctionOrder<FunctionInfo> FunctionOrder;
169
224
0 commit comments