@@ -76,18 +76,8 @@ void EscapeAnalysis::ConnectionGraph::invalidate() {
76
76
assert (!NeedMergeCallees);
77
77
}
78
78
79
- EscapeAnalysis::CGNode *EscapeAnalysis::ConnectionGraph::getNode (ValueBase *V) {
80
- if (isa<FunctionRefInst>(V))
81
- return nullptr ;
82
-
83
- if (!V->hasValue ())
84
- return nullptr ;
85
-
86
- if (!EA->isPointer (V))
87
- return nullptr ;
88
-
89
- V = skipProjections (V);
90
-
79
+ EscapeAnalysis::CGNode *EscapeAnalysis::ConnectionGraph::
80
+ getOrCreateNode (ValueBase *V) {
91
81
CGNode * &Node = Values2Nodes[V];
92
82
if (!Node) {
93
83
if (SILArgument *Arg = dyn_cast<SILArgument>(V)) {
@@ -923,6 +913,22 @@ bool EscapeAnalysis::isPointer(ValueBase *V) {
923
913
return IP;
924
914
}
925
915
916
+ EscapeAnalysis::CGNode *EscapeAnalysis::getNode (ConnectionGraph *ConGraph,
917
+ ValueBase *V) {
918
+ if (isa<FunctionRefInst>(V))
919
+ return nullptr ;
920
+
921
+ if (!V->hasValue ())
922
+ return nullptr ;
923
+
924
+ if (!isPointer (V))
925
+ return nullptr ;
926
+
927
+ V = skipProjections (V);
928
+
929
+ return ConGraph->getOrCreateNode (V);
930
+ }
931
+
926
932
void EscapeAnalysis::buildConnectionGraph (SILFunction *F,
927
933
ConnectionGraph *ConGraph) {
928
934
// We use a worklist for iteration to visit the blocks in dominance order.
@@ -952,7 +958,7 @@ void EscapeAnalysis::buildConnectionGraph(SILFunction *F,
952
958
// Create defer-edges from the block arguments to it's values in the
953
959
// predecessor's terminator instructions.
954
960
for (SILArgument *BBArg : BB.getBBArgs ()) {
955
- CGNode *ArgNode = ConGraph-> getNode (BBArg);
961
+ CGNode *ArgNode = getNode (ConGraph, BBArg);
956
962
if (!ArgNode)
957
963
continue ;
958
964
@@ -965,7 +971,7 @@ void EscapeAnalysis::buildConnectionGraph(SILFunction *F,
965
971
}
966
972
967
973
for (SILValue Src : Incoming) {
968
- CGNode *SrcArg = ConGraph-> getNode (Src);
974
+ CGNode *SrcArg = getNode (ConGraph, Src);
969
975
if (SrcArg) {
970
976
ConGraph->defer (ArgNode, SrcArg);
971
977
} else {
@@ -1017,20 +1023,20 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1017
1023
// array.uninitialized may have a first argument which is the
1018
1024
// allocated array buffer. The call is like a struct(buffer)
1019
1025
// instruction.
1020
- if (CGNode *BufferNode = ConGraph-> getNode (FAS.getArgument (0 ))) {
1021
- ConGraph->defer (ConGraph-> getNode (I), BufferNode);
1026
+ if (CGNode *BufferNode = getNode (ConGraph, FAS.getArgument (0 ))) {
1027
+ ConGraph->defer (getNode (ConGraph, I), BufferNode);
1022
1028
}
1023
1029
return ;
1024
1030
case ArrayCallKind::kGetArrayOwner :
1025
- if (CGNode *BufferNode = ConGraph-> getNode (ASC.getSelf ())) {
1026
- ConGraph->defer (ConGraph-> getNode (I), BufferNode);
1031
+ if (CGNode *BufferNode = getNode (ConGraph, ASC.getSelf ())) {
1032
+ ConGraph->defer (getNode (ConGraph, I), BufferNode);
1027
1033
}
1028
1034
return ;
1029
1035
case ArrayCallKind::kGetElement :
1030
1036
// This is like a load from a ref_element_addr.
1031
1037
if (FAS.getArgument (0 ).getType ().isAddress ()) {
1032
- if (CGNode *AddrNode = ConGraph-> getNode (ASC.getSelf ())) {
1033
- if (CGNode *DestNode = ConGraph-> getNode (FAS.getArgument (0 ))) {
1038
+ if (CGNode *AddrNode = getNode (ConGraph, ASC.getSelf ())) {
1039
+ if (CGNode *DestNode = getNode (ConGraph, FAS.getArgument (0 ))) {
1034
1040
// One content node for going from the array buffer pointer to
1035
1041
// the element address (like ref_element_addr).
1036
1042
CGNode *RefElement = ConGraph->getContentNode (AddrNode);
@@ -1046,8 +1052,8 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1046
1052
break ;
1047
1053
case ArrayCallKind::kGetElementAddress :
1048
1054
// This is like a ref_element_addr.
1049
- if (CGNode *SelfNode = ConGraph-> getNode (ASC.getSelf ())) {
1050
- ConGraph->defer (ConGraph-> getNode (I),
1055
+ if (CGNode *SelfNode = getNode (ConGraph, ASC.getSelf ())) {
1056
+ ConGraph->defer (getNode (ConGraph, I),
1051
1057
ConGraph->getContentNode (SelfNode));
1052
1058
}
1053
1059
return ;
@@ -1096,7 +1102,7 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1096
1102
case ValueKind::ReleaseValueInst:
1097
1103
case ValueKind::UnownedReleaseInst: {
1098
1104
SILValue OpV = I->getOperand (0 );
1099
- if (CGNode *AddrNode = ConGraph-> getNode (OpV)) {
1105
+ if (CGNode *AddrNode = getNode (ConGraph, OpV)) {
1100
1106
// A release instruction may deallocate the pointer operand. This may
1101
1107
// capture any content of the released object, but not the pointer to
1102
1108
// the object itself (because it will be a dangling pointer after
@@ -1115,10 +1121,10 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1115
1121
// We treat ref_element_addr like a load (see NodeType::Content).
1116
1122
case ValueKind::RefElementAddrInst:
1117
1123
if (isPointer (I)) {
1118
- CGNode *AddrNode = ConGraph-> getNode (I->getOperand (0 ));
1124
+ CGNode *AddrNode = getNode (ConGraph, I->getOperand (0 ));
1119
1125
if (!AddrNode) {
1120
1126
// A load from an address we don't handle -> be conservative.
1121
- CGNode *ValueNode = ConGraph-> getNode (I);
1127
+ CGNode *ValueNode = getNode (ConGraph, I);
1122
1128
ConGraph->setEscapesGlobal (ValueNode);
1123
1129
return ;
1124
1130
}
@@ -1130,8 +1136,8 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1130
1136
return ;
1131
1137
case ValueKind::StoreInst:
1132
1138
case ValueKind::StoreWeakInst:
1133
- if (CGNode *ValueNode = ConGraph-> getNode (I->getOperand (StoreInst::Src))) {
1134
- CGNode *AddrNode = ConGraph-> getNode (I->getOperand (StoreInst::Dest));
1139
+ if (CGNode *ValueNode = getNode (ConGraph, I->getOperand (StoreInst::Src))) {
1140
+ CGNode *AddrNode = getNode (ConGraph, I->getOperand (StoreInst::Dest));
1135
1141
if (AddrNode) {
1136
1142
// Create a defer-edge from the content to the stored value.
1137
1143
CGNode *PointsTo = ConGraph->getContentNode (AddrNode);
@@ -1146,10 +1152,10 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1146
1152
// The result of a partial_apply is a thick function which stores the
1147
1153
// boxed partial applied arguments. We create defer-edges from the
1148
1154
// partial_apply values to the arguments.
1149
- CGNode *ResultNode = ConGraph-> getNode (I);
1155
+ CGNode *ResultNode = getNode (ConGraph, I);
1150
1156
assert (ResultNode && " thick functions must have a CG node" );
1151
1157
for (const Operand &Op : I->getAllOperands ()) {
1152
- if (CGNode *ArgNode = ConGraph-> getNode (Op.get ())) {
1158
+ if (CGNode *ArgNode = getNode (ConGraph, Op.get ())) {
1153
1159
ConGraph->defer (ResultNode, ArgNode);
1154
1160
}
1155
1161
}
@@ -1162,7 +1168,7 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1162
1168
// resulting aggregate value.
1163
1169
CGNode *ResultNode = nullptr ;
1164
1170
for (const Operand &Op : I->getAllOperands ()) {
1165
- if (CGNode *FieldNode = ConGraph-> getNode (Op.get ())) {
1171
+ if (CGNode *FieldNode = getNode (ConGraph, Op.get ())) {
1166
1172
if (!ResultNode) {
1167
1173
// A small optimization to reduce the graph size: we re-use the
1168
1174
// first field node as result node.
@@ -1178,12 +1184,12 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
1178
1184
}
1179
1185
case ValueKind::UncheckedRefCastInst:
1180
1186
// A cast is almost like a projection.
1181
- if (CGNode *OpNode = ConGraph-> getNode (I->getOperand (0 ))) {
1187
+ if (CGNode *OpNode = getNode (ConGraph, I->getOperand (0 ))) {
1182
1188
ConGraph->setNode (I, OpNode);
1183
1189
}
1184
1190
break ;
1185
1191
case ValueKind::ReturnInst:
1186
- if (CGNode *ValueNd = ConGraph-> getNode (cast<ReturnInst>(I)->getOperand ())) {
1192
+ if (CGNode *ValueNd = getNode (ConGraph, cast<ReturnInst>(I)->getOperand ())) {
1187
1193
ConGraph->defer (ConGraph->getReturnNode (),
1188
1194
ValueNd);
1189
1195
}
@@ -1210,8 +1216,8 @@ bool EscapeAnalysis::isArrayOrArrayStorage(SILValue V) {
1210
1216
void EscapeAnalysis::setAllEscaping (SILInstruction *I,
1211
1217
ConnectionGraph *ConGraph) {
1212
1218
if (auto *TAI = dyn_cast<TryApplyInst>(I)) {
1213
- ConGraph-> setEscapesGlobal (TAI->getNormalBB ()->getBBArg (0 ));
1214
- ConGraph-> setEscapesGlobal (TAI->getErrorBB ()->getBBArg (0 ));
1219
+ setEscapesGlobal (ConGraph, TAI->getNormalBB ()->getBBArg (0 ));
1220
+ setEscapesGlobal (ConGraph, TAI->getErrorBB ()->getBBArg (0 ));
1215
1221
}
1216
1222
// Even if the instruction does not write memory we conservatively set all
1217
1223
// operands to escaping, because they may "escape" to the result value in
@@ -1220,11 +1226,11 @@ void EscapeAnalysis::setAllEscaping(SILInstruction *I,
1220
1226
for (const Operand &Op : I->getAllOperands ()) {
1221
1227
SILValue OpVal = Op.get ();
1222
1228
if (!isNonWritableMemoryAddress (OpVal.getDef ()))
1223
- ConGraph-> setEscapesGlobal (OpVal);
1229
+ setEscapesGlobal (ConGraph, OpVal);
1224
1230
}
1225
1231
// Even if the instruction does not write memory it could e.g. return the
1226
1232
// address of global memory. Therefore we have to define it as escaping.
1227
- ConGraph-> setEscapesGlobal (I);
1233
+ setEscapesGlobal (ConGraph, I);
1228
1234
}
1229
1235
1230
1236
void EscapeAnalysis::recompute () {
@@ -1256,7 +1262,7 @@ void EscapeAnalysis::recompute() {
1256
1262
1257
1263
DEBUG (llvm::dbgs () << " build initial graph for " << F->getName () << ' \n ' );
1258
1264
1259
- auto *ConGraph = new (Allocator.Allocate ()) ConnectionGraph (F, this );
1265
+ auto *ConGraph = new (Allocator.Allocate ()) ConnectionGraph (F);
1260
1266
Function2ConGraph[F] = ConGraph;
1261
1267
buildConnectionGraph (F, ConGraph);
1262
1268
@@ -1348,8 +1354,8 @@ bool EscapeAnalysis::mergeCalleeGraph(FullApplySite FAS,
1348
1354
// of the apply site.
1349
1355
SILValue CallerArg = (Idx < numCallerArgs ? FAS.getArgument (Idx) :
1350
1356
FAS.getCallee ());
1351
- if (CGNode *CalleeNd = CalleeGraph-> getNode (Callee->getArgument (Idx))) {
1352
- Callee2CallerMapping.add (CalleeNd, CallerGraph-> getNode (CallerArg));
1357
+ if (CGNode *CalleeNd = getNode (CalleeGraph, Callee->getArgument (Idx))) {
1358
+ Callee2CallerMapping.add (CalleeNd, getNode (CallerGraph, CallerArg));
1353
1359
}
1354
1360
}
1355
1361
@@ -1361,7 +1367,7 @@ bool EscapeAnalysis::mergeCalleeGraph(FullApplySite FAS,
1361
1367
} else {
1362
1368
CallerReturnVal = FAS.getInstruction ();
1363
1369
}
1364
- CGNode *CallerRetNd = CallerGraph-> getNode (CallerReturnVal);
1370
+ CGNode *CallerRetNd = getNode (CallerGraph, CallerReturnVal);
1365
1371
Callee2CallerMapping.add (RetNd, CallerRetNd);
1366
1372
}
1367
1373
return CallerGraph->mergeFrom (CalleeGraph, Callee2CallerMapping);
@@ -1374,8 +1380,8 @@ void EscapeAnalysis::createSummaryGraph(ConnectionGraph *SummaryGraph,
1374
1380
CGNodeMap Mapping;
1375
1381
SILFunction *F = Graph->getFunction ();
1376
1382
for (SILArgument *Arg : F->getArguments ()) {
1377
- if (CGNode *ArgNd = Graph-> getNode (Arg)) {
1378
- Mapping.add (ArgNd, SummaryGraph-> getNode (Arg));
1383
+ if (CGNode *ArgNd = getNode (Graph, Arg)) {
1384
+ Mapping.add (ArgNd, getNode (SummaryGraph, Arg));
1379
1385
}
1380
1386
}
1381
1387
if (CGNode *RetNd = Graph->getReturnNodeOrNull ()) {
0 commit comments