1717#ifndef SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
1818#define SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
1919
20+ #include " swift/Basic/OptionSet.h"
2021#include " swift/SIL/ApplySite.h"
2122#include " swift/SIL/DebugUtils.h"
2223#include " swift/SIL/MemAccessUtils.h"
2627namespace swift {
2728
2829class VariableNameInferrer {
30+ public:
31+ enum class Flag {
32+ // / If set then we should look through get and set accessors and infer their
33+ // / name from self.
34+ // /
35+ // / DISCUSSION: This may not be the correct semantics for all name inference
36+ // / since we may want to consider computed properties to be tied to self.
37+ InferSelfThroughAllAccessors = 0x1 ,
38+ };
39+
40+ using Options = OptionSet<Flag>;
41+
42+ private:
2943 // / The stacklist that we use to process from use->
3044 StackList<PointerUnion<SILInstruction *, SILValue>> variableNamePath;
3145
@@ -37,10 +51,21 @@ class VariableNameInferrer {
3751 // / The final string we computed.
3852 SmallString<64 > &resultingString;
3953
54+ // / Options that control how we do our walk.
55+ // /
56+ // / Example: In certain cases we may want to impute self as a name for
57+ // / computed getters/setters and in other cases we may not want to.
58+ Options options;
59+
4060public:
4161 VariableNameInferrer (SILFunction *fn, SmallString<64 > &resultingString)
4262 : variableNamePath(fn), resultingString(resultingString) {}
4363
64+ VariableNameInferrer (SILFunction *fn, Options options,
65+ SmallString<64 > &resultingString)
66+ : variableNamePath(fn), resultingString(resultingString),
67+ options (options) {}
68+
4469 // / Attempts to infer a name from just uses of \p searchValue.
4570 // /
4671 // / Returns true if we found a name.
@@ -100,11 +125,16 @@ class VariableNameInferrer {
100125
101126private:
102127 void drainVariableNamePath ();
128+ void popSingleVariableName ();
103129
104130 // / Finds the SILValue that either provides the direct debug information or
105131 // / that has a debug_value user that provides the name of the value.
106132 SILValue findDebugInfoProvidingValue (SILValue searchValue);
107133
134+ // / Do not call this directly. Used just to improve logging for
135+ // / findDebugInfoProvidingValue.
136+ SILValue findDebugInfoProvidingValueHelper (SILValue searchValue);
137+
108138 // / Given an initialized once allocation inst without a ValueDecl or a
109139 // / DebugVariable provided name, attempt to find a root value from its
110140 // / initialization.
0 commit comments