23
23
using namespace swift ;
24
24
25
25
// ===----------------------------------------------------------------------===//
26
- // PMOMemoryObjectInfo Implementation
26
+ // PMOMemoryObjectInfo Implementation
27
27
// ===----------------------------------------------------------------------===//
28
28
29
- static unsigned getElementCountRec (SILModule &Module, SILType T) {
30
- // If this is a tuple, it is always recursively flattened.
31
- if (CanTupleType TT = T.getAs <TupleType>()) {
32
- unsigned NumElements = 0 ;
33
- for (unsigned i = 0 , e = TT->getNumElements (); i < e; i++)
34
- NumElements += getElementCountRec (Module, T.getTupleElementType (i));
35
- return NumElements;
36
- }
37
-
38
- // Otherwise, it is a single element.
39
- return 1 ;
40
- }
41
-
42
29
PMOMemoryObjectInfo::PMOMemoryObjectInfo (AllocationInst *allocation)
43
30
: MemoryInst(allocation) {
44
31
auto &module = MemoryInst->getModule ();
@@ -57,81 +44,6 @@ SILInstruction *PMOMemoryObjectInfo::getFunctionEntryPoint() const {
57
44
return &*getFunction ().begin ()->begin ();
58
45
}
59
46
60
- // / Given a symbolic element number, return the type of the element.
61
- static SILType getElementTypeRec (SILModule &Module, SILType T, unsigned EltNo) {
62
- // If this is a tuple type, walk into it.
63
- if (CanTupleType TT = T.getAs <TupleType>()) {
64
- for (unsigned i = 0 , e = TT->getNumElements (); i < e; i++) {
65
- auto FieldType = T.getTupleElementType (i);
66
- unsigned NumFieldElements = getElementCountRec (Module, FieldType);
67
- if (EltNo < NumFieldElements)
68
- return getElementTypeRec (Module, FieldType, EltNo);
69
- EltNo -= NumFieldElements;
70
- }
71
- // This can only happen if we look at a symbolic element number of an empty
72
- // tuple.
73
- llvm::report_fatal_error (" invalid element number" );
74
- }
75
-
76
- // Otherwise, it is a leaf element.
77
- assert (EltNo == 0 );
78
- return T;
79
- }
80
-
81
- // / getElementTypeRec - Return the swift type of the specified element.
82
- SILType PMOMemoryObjectInfo::getElementType (unsigned EltNo) const {
83
- auto &Module = MemoryInst->getModule ();
84
- return getElementTypeRec (Module, MemorySILType, EltNo);
85
- }
86
-
87
- // / Push the symbolic path name to the specified element number onto the
88
- // / specified std::string.
89
- static void getPathStringToElementRec (SILModule &Module, SILType T,
90
- unsigned EltNo, std::string &Result) {
91
- if (CanTupleType TT = T.getAs <TupleType>()) {
92
- unsigned FieldNo = 0 ;
93
- for (unsigned i = 0 , e = TT->getNumElements (); i < e; i++) {
94
- auto Field = TT->getElement (i);
95
- SILType FieldTy = T.getTupleElementType (i);
96
- unsigned NumFieldElements = getElementCountRec (Module, FieldTy);
97
-
98
- if (EltNo < NumFieldElements) {
99
- Result += ' .' ;
100
- if (Field.hasName ())
101
- Result += Field.getName ().str ();
102
- else
103
- Result += llvm::utostr (FieldNo);
104
- return getPathStringToElementRec (Module, FieldTy, EltNo, Result);
105
- }
106
-
107
- EltNo -= NumFieldElements;
108
-
109
- ++FieldNo;
110
- }
111
- llvm_unreachable (" Element number is out of range for this type!" );
112
- }
113
-
114
- // Otherwise, there are no subelements.
115
- assert (EltNo == 0 && " Element count problem" );
116
- }
117
-
118
- ValueDecl *
119
- PMOMemoryObjectInfo::getPathStringToElement (unsigned Element,
120
- std::string &Result) const {
121
- auto &Module = MemoryInst->getModule ();
122
-
123
- if (auto *VD = dyn_cast_or_null<ValueDecl>(getLoc ().getAsASTNode <Decl>()))
124
- Result = VD->getBaseName ().userFacingName ();
125
- else
126
- Result = " <unknown>" ;
127
-
128
- // Get the path through a tuple, if relevant.
129
- getPathStringToElementRec (Module, MemorySILType, Element, Result);
130
-
131
- // Otherwise, we can't.
132
- return nullptr ;
133
- }
134
-
135
47
// ===----------------------------------------------------------------------===//
136
48
// Scalarization Logic
137
49
// ===----------------------------------------------------------------------===//
0 commit comments