Skip to content

Commit 3c7d802

Browse files
committed
Add a flattened view of functions in BottomUpFunctionOrder.
Adds a new getFunctionsBottomUp() method that flattens the SCCs into a single list. I've also deferred computing the SCCs until they are asked for.
1 parent 790448f commit 3c7d802

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

include/swift/SILAnalysis/FunctionOrder.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class BottomUpFunctionOrder {
3131
typedef TinyPtrVector<SILFunction *> SCC;
3232

3333
private:
34+
SILModule &M;
3435
llvm::SmallVector<SCC, 32> TheSCCs;
36+
llvm::SmallVector<SILFunction *, 32> TheFunctions;
3537

3638
// The callee analysis we use to determine the callees at each call site.
3739
BasicCalleeAnalysis *BCA;
@@ -43,11 +45,29 @@ class BottomUpFunctionOrder {
4345

4446
public:
4547
BottomUpFunctionOrder(SILModule &M, BasicCalleeAnalysis *BCA)
46-
: BCA(BCA), NextDFSNum(0) {
48+
: M(M), BCA(BCA), NextDFSNum(0) {}
49+
50+
/// Get the SCCs in bottom-up order.
51+
ArrayRef<SCC> getSCCsBottomUp() {
52+
if (!TheSCCs.empty())
53+
return TheSCCs;
54+
4755
FindSCCs(M);
56+
return TheSCCs;
4857
}
4958

50-
ArrayRef<SCC> getBottomUpSCCs() { return TheSCCs; }
59+
/// Get a flattened view of all functions in all the SCCs in
60+
/// bottom-up order
61+
ArrayRef<SILFunction *> getFunctionsBottomUp() {
62+
if (!TheFunctions.empty())
63+
return TheFunctions;
64+
65+
for (auto SCC : getSCCsBottomUp())
66+
for (auto *F : SCC)
67+
TheFunctions.push_back(F);
68+
69+
return TheFunctions;
70+
}
5171

5272
private:
5373
void DFS(SILFunction *F);

lib/SILPasses/UtilityPasses/FunctionOrderPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FunctionOrderPrinterPass : public SILModuleTransform {
3939
BottomUpFunctionOrder Orderer(M, BCA);
4040

4141
llvm::outs() << "Bottom up function order:\n";
42-
auto SCCs = Orderer.getBottomUpSCCs();
42+
auto SCCs = Orderer.getSCCsBottomUp();
4343
for (auto &SCC : SCCs) {
4444
std::string Indent;
4545

0 commit comments

Comments
 (0)