@@ -281,19 +281,34 @@ class EscapeAnalysis : public SILAnalysis {
281
281
282
282
// / Mapping from nodes in a calleee-graph to nodes in a caller-graph.
283
283
class CGNodeMap {
284
+ // / The map itself.
284
285
llvm::DenseMap<CGNode *, CGNode *> Map;
286
+
287
+ // / The list of source nodes (= keys in Map), which is used as a work-list.
288
+ llvm::SmallVector<CGNode *, 8 > MappedNodes;
285
289
public:
286
- void insert (CGNode *From, CGNode *To) {
287
- assert (!From->isMerged && !To->isMerged );
290
+
291
+ // / Adds a mapping and pushes the \p From node into the work-list
292
+ // / MappedNodes.
293
+ void add (CGNode *From, CGNode *To) {
294
+ assert (From && To && !From->isMerged && !To->isMerged );
288
295
Map[From] = To;
296
+ if (!From->isInWorkList ) {
297
+ MappedNodes.push_back (From);
298
+ From->isInWorkList = true ;
299
+ }
289
300
}
301
+ // / Looks up a node in the mapping.
290
302
CGNode *get (CGNode *From) const {
291
303
auto Iter = Map.find (From);
292
304
if (Iter == Map.end ())
293
305
return nullptr ;
294
306
295
307
return Iter->second ->getMergeTarget ();
296
308
}
309
+ const SmallVectorImpl<CGNode *> &getMappedNodes () const {
310
+ return MappedNodes;
311
+ }
297
312
};
298
313
299
314
public:
@@ -387,9 +402,13 @@ class EscapeAnalysis : public SILAnalysis {
387
402
// / content node is scheduled to be merged with \p pointsTo.
388
403
void updatePointsTo (CGNode *InitialNode, CGNode *pointsTo);
389
404
390
- // / Merges all defer-edges from the callee graph.
391
- bool addDeferEdgesFromCallee (CGNode *CalleeSource,
392
- const CGNodeMap &Callee2CallerMapping);
405
+ // / Utility function to clear the isInWorkList flags of all nodes in
406
+ // / \p WorkList.
407
+ static void clearWorkListFlags (const SmallVectorImpl<CGNode *> &WorkList) {
408
+ for (CGNode *Node : WorkList) {
409
+ Node->isInWorkList = false ;
410
+ }
411
+ }
393
412
394
413
public:
395
414
// / Constructs a connection graph for a function.
@@ -434,14 +453,19 @@ class EscapeAnalysis : public SILAnalysis {
434
453
CGNode *getContentNode (CGNode *AddrNode);
435
454
436
455
// / Get or creates a pseudo node for the function return value.
437
- CGNode *getReturnNode (ReturnInst *RI ) {
456
+ CGNode *getReturnNode () {
438
457
if (!ReturnNode) {
439
- ReturnNode = allocNode (RI , NodeType::Return);
458
+ ReturnNode = allocNode (nullptr , NodeType::Return);
440
459
ReturnNode->mergeEscapeState (EscapeState::Arguments);
441
460
}
442
461
return ReturnNode;
443
462
}
444
463
464
+ // / Returns the node for the function return value if present.
465
+ CGNode *getReturnNodeOrNull () const {
466
+ return ReturnNode;
467
+ }
468
+
445
469
// / Returns the node of the "exact" value \p V (no projections are skipped)
446
470
// / if one exists.
447
471
CGNode *getNodeOrNull (ValueBase *V) {
@@ -504,8 +528,9 @@ class EscapeAnalysis : public SILAnalysis {
504
528
// / e.g. release or apply instructions.
505
529
void getUsePoints (llvm::SmallPtrSetImpl<ValueBase *> &Values, CGNode *Node);
506
530
507
- // / Merges the graph of a callee function (called by \p FAS) into this graph.
508
- bool mergeCalleeGraph (FullApplySite FAS, ConnectionGraph *CalleeGraph);
531
+ // / Merges the \p SourceGraph into this graph. The \p Mapping contains the
532
+ // / initial node mapping of the nodes to start the merge.
533
+ bool mergeFrom (ConnectionGraph *SourceGraph, CGNodeMap &Mapping);
509
534
510
535
// / Propagates the escape states through the graph.
511
536
void propagateEscapeStates ();
@@ -584,6 +609,17 @@ class EscapeAnalysis : public SILAnalysis {
584
609
// / Merge the graphs of all known callees into this graph.
585
610
bool mergeAllCallees (ConnectionGraph *ConGraph, CallGraph &CG);
586
611
612
+ // / Merges the graph of a callee function into the graph of
613
+ // / a caller function, whereas \p FAS is the call-site.
614
+ bool mergeCalleeGraph (FullApplySite FAS,
615
+ ConnectionGraph *CallerGraph,
616
+ ConnectionGraph *CalleeGraph);
617
+
618
+ // / Create a summary graph \p SummaryGraph from \p Graph. It just contains
619
+ // / the content nodes of \p Graph.
620
+ void createSummaryGraph (ConnectionGraph *SummaryGraph,
621
+ ConnectionGraph *Graph);
622
+
587
623
// / Set all arguments and return values of all callees to global escaping.
588
624
void finalizeGraphConservatively (ConnectionGraph *ConGraph);
589
625
0 commit comments