Skip to content

Commit a35947a

Browse files
authored
Merge pull request #10860 from devincoughlin/exclusivity-separate-stored-props-4.0
2 parents 5600fa8 + 5997323 commit a35947a

File tree

6 files changed

+544
-172
lines changed

6 files changed

+544
-172
lines changed

include/swift/SILOptimizer/Analysis/AccessSummaryAnalysis.h

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,75 @@ namespace swift {
3030

3131
class AccessSummaryAnalysis : public BottomUpIPAnalysis {
3232
public:
33-
/// Summarizes the accesses that a function begins on an argument.
34-
class ArgumentSummary {
33+
class SubAccessSummary {
3534
private:
3635
/// The kind of access begun on the argument.
37-
/// 'None' means no access performed.
38-
Optional<SILAccessKind> Kind = None;
36+
SILAccessKind Kind;
3937

4038
/// The location of the access. Used for diagnostics.
4139
SILLocation AccessLoc = SILLocation((Expr *)nullptr);
4240

41+
const IndexTrieNode *SubPath = nullptr;
42+
4343
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; }
4549

4650
SILLocation getAccessLoc() const { return AccessLoc; }
4751

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:
4878
/// The lattice operation on argument summaries.
4979
bool mergeWith(const ArgumentSummary &other);
5080

5181
/// Merge in an access to the argument of the given kind at the given
5282
/// 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);
5485

5586
/// Returns a description of the summary. For debugging and testing
5687
/// 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;
5898
};
5999

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.
61102
class FunctionSummary {
62103
private:
63104
llvm::SmallVector<ArgumentSummary, 6> ArgAccesses;
@@ -77,10 +118,9 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
77118

78119
/// Returns the number of argument in the summary.
79120
unsigned getArgumentCount() const { return ArgAccesses.size(); }
80-
};
81121

82-
friend raw_ostream &operator<<(raw_ostream &os,
83-
const FunctionSummary &summary);
122+
void print(raw_ostream &os, SILFunction *fn) const;
123+
};
84124

85125
class FunctionInfo;
86126
/// Records a flow of a caller's argument to a called function.
@@ -151,6 +191,10 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
151191
return SubPathTrie;
152192
}
153193

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+
154198
virtual void initialize(SILPassManager *PM) override {}
155199
virtual void invalidate() override;
156200
virtual void invalidate(SILFunction *F, InvalidationKind K) override;
@@ -164,6 +208,17 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
164208
return S->getKind() == AnalysisKind::AccessSummary;
165209
}
166210

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);
167222
private:
168223
typedef BottomUpFunctionOrder<FunctionInfo> FunctionOrder;
169224

0 commit comments

Comments
 (0)