Skip to content

Commit 0280c60

Browse files
Merge pull request #34709 from texasmichelle/tf_1350
Remove workaround for SR-13820
2 parents 96ce6d3 + e1f0944 commit 0280c60

File tree

5 files changed

+22
-74
lines changed

5 files changed

+22
-74
lines changed

include/swift/SILOptimizer/Analysis/FunctionOrder.h

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

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

@@ -43,33 +44,24 @@ class BottomUpFunctionOrder {
4344
llvm::SmallSetVector<SILFunction *, 4> DFSStack;
4445

4546
public:
46-
// SWIFT_ENABLE_TENSORFLOW
47-
BottomUpFunctionOrder(BasicCalleeAnalysis *BCA)
48-
: BCA(BCA), NextDFSNum(0) {}
49-
50-
/// DFS on 'F' to compute bottom up order
51-
void computeBottomUpOrder(SILFunction *F) {
52-
DFS(F);
53-
}
54-
55-
/// DFS on all functions in the module to compute bottom up order
56-
void computeBottomUpOrder(SILModule *M) {
57-
for (auto &F : *M)
58-
DFS(&F);
59-
}
60-
// SWIFT_ENABLE_TENSORFLOW END
47+
BottomUpFunctionOrder(SILModule &M, BasicCalleeAnalysis *BCA)
48+
: M(M), BCA(BCA), NextDFSNum(0) {}
6149

6250
/// Get the SCCs in bottom-up order.
6351
ArrayRef<SCC> getSCCs() {
52+
if (!TheSCCs.empty())
53+
return TheSCCs;
54+
55+
FindSCCs(M);
6456
return TheSCCs;
6557
}
6658

67-
// SWIFT_ENABLE_TENSORFLOW
68-
/// Get a flattened view of all functions in all the SCCs in bottom-up order
69-
ArrayRef<SILFunction *> getBottomUpOrder() {
70-
// SWIFT_ENABLE_TENSORFLOW END
59+
/// Get a flattened view of all functions in all the SCCs in
60+
/// bottom-up order
61+
ArrayRef<SILFunction *> getFunctions() {
7162
if (!TheFunctions.empty())
7263
return TheFunctions;
64+
7365
for (auto SCC : getSCCs())
7466
for (auto *F : SCC)
7567
TheFunctions.push_back(F);
@@ -79,6 +71,7 @@ class BottomUpFunctionOrder {
7971

8072
private:
8173
void DFS(SILFunction *F);
74+
void FindSCCs(SILModule &M);
8275
};
8376

8477
} // end namespace swift

lib/SILOptimizer/Analysis/FunctionOrder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ void BottomUpFunctionOrder::DFS(SILFunction *Start) {
7373
TheSCCs.push_back(CurrentSCC);
7474
}
7575
}
76+
77+
void BottomUpFunctionOrder::FindSCCs(SILModule &M) {
78+
for (auto &F : M)
79+
DFS(&F);
80+
}

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,8 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
533533
return;
534534

535535
BasicCalleeAnalysis *BCA = getAnalysis<BasicCalleeAnalysis>();
536-
// SWIFT_ENABLE_TENSORFLOW
537-
BottomUpFunctionOrder BottomUpOrder(BCA);
538-
BottomUpOrder.computeBottomUpOrder(Mod);
539-
auto BottomUpFunctions = BottomUpOrder.getBottomUpOrder();
540-
// SWIFT_ENABLE_TENSORFLOW END
536+
BottomUpFunctionOrder BottomUpOrder(*Mod, BCA);
537+
auto BottomUpFunctions = BottomUpOrder.getFunctions();
541538

542539
assert(FunctionWorklist.empty() && "Expected empty function worklist!");
543540

@@ -590,49 +587,6 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
590587
++Entry.PipelineIdx;
591588
}
592589
clearRestartPipeline();
593-
594-
// SWIFT_ENABLE_TENSORFLOW
595-
if (TailIdx == (FunctionWorklist.size() - 1)) {
596-
// No new functions to process
597-
continue;
598-
}
599-
600-
// Compute the bottom up order of the new functions and the callees in it
601-
BottomUpFunctionOrder SubBottomUpOrder(BCA);
602-
// Initialize BottomUpFunctionOrder with new functions
603-
for (auto It = FunctionWorklist.begin() + TailIdx + 1;
604-
It != FunctionWorklist.end(); It++) {
605-
SubBottomUpOrder.computeBottomUpOrder(It->F);
606-
}
607-
auto NewFunctionsBottomUp = SubBottomUpOrder.getBottomUpOrder();
608-
SmallPtrSet<SILFunction *, 8> NewBottomUpSet(NewFunctionsBottomUp.begin(),
609-
NewFunctionsBottomUp.end());
610-
611-
// Remove all the functions in the new bottom up order from FunctionWorklist
612-
llvm::DenseMap<SILFunction *, WorklistEntry> FunctionsToReorder;
613-
auto RemoveFn = [&FunctionsToReorder,
614-
&NewBottomUpSet](WorklistEntry Entry) {
615-
if (NewBottomUpSet.find(Entry.F) == NewBottomUpSet.end()) {
616-
return false;
617-
}
618-
FunctionsToReorder.insert(std::make_pair(Entry.F, Entry));
619-
return true;
620-
};
621-
std::remove_if(FunctionWorklist.begin(), FunctionWorklist.end(), RemoveFn);
622-
FunctionWorklist.erase((FunctionWorklist.begin() + FunctionWorklist.size() -
623-
FunctionsToReorder.size()),
624-
FunctionWorklist.end());
625-
626-
// Add back the functions in the new bottom up order to the FunctionWorklist
627-
for (auto it = NewFunctionsBottomUp.rbegin();
628-
it != NewFunctionsBottomUp.rend(); it++) {
629-
auto Entry = FunctionsToReorder.find(*it);
630-
if (Entry == FunctionsToReorder.end()) {
631-
continue;
632-
}
633-
FunctionWorklist.push_back((*Entry).second);
634-
}
635-
// SWIFT_ENABLE_TENSORFLOW END
636590
}
637591
}
638592

lib/SILOptimizer/UtilityPasses/FunctionOrderPrinter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ class FunctionOrderPrinterPass : public SILModuleTransform {
3535
/// The entry point to the transformation.
3636
void run() override {
3737
BCA = getAnalysis<BasicCalleeAnalysis>();
38-
// SWIFT_ENABLE_TENSORFLOW
39-
BottomUpFunctionOrder Orderer(BCA);
40-
Orderer.computeBottomUpOrder(getModule());
41-
// SWIFT_ENABLE_TENSORFLOW END
38+
auto &M = *getModule();
39+
BottomUpFunctionOrder Orderer(M, BCA);
4240

4341
llvm::outs() << "Bottom up function order:\n";
4442
auto SCCs = Orderer.getSCCs();

test/DebugInfo/inlined-generics-basic.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ public class C<R> {
9191
// IR-LABEL: ret void
9292

9393
// IR: ![[BOOL:[0-9]+]] = !DICompositeType({{.*}}name: "Bool"
94+
// IR: ![[LET_BOOL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[BOOL]])
9495
// IR: ![[INT:[0-9]+]] = !DICompositeType({{.*}}name: "Int"
9596
// IR: ![[LET_INT:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[INT]])
96-
// SWIFT_ENABLE_TENSORFLOW
97-
// IR: ![[LET_BOOL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[BOOL]])
98-
// SWIFT_ENABLE_TENSORFLOW END
9997
// IR: ![[TAU_0_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sxD",
10098
// IR: ![[LET_TAU_0_0:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TAU_0_0]])
10199
// IR: ![[TAU_1_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",

0 commit comments

Comments
 (0)