Skip to content

Remove workaround for SR-13820 #34709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions include/swift/SILOptimizer/Analysis/FunctionOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class BottomUpFunctionOrder {
typedef TinyPtrVector<SILFunction *> SCC;

private:
SILModule &M;
llvm::SmallVector<SCC, 32> TheSCCs;
llvm::SmallVector<SILFunction *, 32> TheFunctions;

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

public:
// SWIFT_ENABLE_TENSORFLOW
BottomUpFunctionOrder(BasicCalleeAnalysis *BCA)
: BCA(BCA), NextDFSNum(0) {}

/// DFS on 'F' to compute bottom up order
void computeBottomUpOrder(SILFunction *F) {
DFS(F);
}

/// DFS on all functions in the module to compute bottom up order
void computeBottomUpOrder(SILModule *M) {
for (auto &F : *M)
DFS(&F);
}
// SWIFT_ENABLE_TENSORFLOW END
BottomUpFunctionOrder(SILModule &M, BasicCalleeAnalysis *BCA)
: M(M), BCA(BCA), NextDFSNum(0) {}

/// Get the SCCs in bottom-up order.
ArrayRef<SCC> getSCCs() {
if (!TheSCCs.empty())
return TheSCCs;

FindSCCs(M);
return TheSCCs;
}

// SWIFT_ENABLE_TENSORFLOW
/// Get a flattened view of all functions in all the SCCs in bottom-up order
ArrayRef<SILFunction *> getBottomUpOrder() {
// SWIFT_ENABLE_TENSORFLOW END
/// Get a flattened view of all functions in all the SCCs in
/// bottom-up order
ArrayRef<SILFunction *> getFunctions() {
if (!TheFunctions.empty())
return TheFunctions;

for (auto SCC : getSCCs())
for (auto *F : SCC)
TheFunctions.push_back(F);
Expand All @@ -79,6 +71,7 @@ class BottomUpFunctionOrder {

private:
void DFS(SILFunction *F);
void FindSCCs(SILModule &M);
};

} // end namespace swift
Expand Down
5 changes: 5 additions & 0 deletions lib/SILOptimizer/Analysis/FunctionOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ void BottomUpFunctionOrder::DFS(SILFunction *Start) {
TheSCCs.push_back(CurrentSCC);
}
}

void BottomUpFunctionOrder::FindSCCs(SILModule &M) {
for (auto &F : M)
DFS(&F);
}
50 changes: 2 additions & 48 deletions lib/SILOptimizer/PassManager/PassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,8 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
return;

BasicCalleeAnalysis *BCA = getAnalysis<BasicCalleeAnalysis>();
// SWIFT_ENABLE_TENSORFLOW
BottomUpFunctionOrder BottomUpOrder(BCA);
BottomUpOrder.computeBottomUpOrder(Mod);
auto BottomUpFunctions = BottomUpOrder.getBottomUpOrder();
// SWIFT_ENABLE_TENSORFLOW END
BottomUpFunctionOrder BottomUpOrder(*Mod, BCA);
auto BottomUpFunctions = BottomUpOrder.getFunctions();

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

Expand Down Expand Up @@ -590,49 +587,6 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
++Entry.PipelineIdx;
}
clearRestartPipeline();

// SWIFT_ENABLE_TENSORFLOW
if (TailIdx == (FunctionWorklist.size() - 1)) {
// No new functions to process
continue;
}

// Compute the bottom up order of the new functions and the callees in it
BottomUpFunctionOrder SubBottomUpOrder(BCA);
// Initialize BottomUpFunctionOrder with new functions
for (auto It = FunctionWorklist.begin() + TailIdx + 1;
It != FunctionWorklist.end(); It++) {
SubBottomUpOrder.computeBottomUpOrder(It->F);
}
auto NewFunctionsBottomUp = SubBottomUpOrder.getBottomUpOrder();
SmallPtrSet<SILFunction *, 8> NewBottomUpSet(NewFunctionsBottomUp.begin(),
NewFunctionsBottomUp.end());

// Remove all the functions in the new bottom up order from FunctionWorklist
llvm::DenseMap<SILFunction *, WorklistEntry> FunctionsToReorder;
auto RemoveFn = [&FunctionsToReorder,
&NewBottomUpSet](WorklistEntry Entry) {
if (NewBottomUpSet.find(Entry.F) == NewBottomUpSet.end()) {
return false;
}
FunctionsToReorder.insert(std::make_pair(Entry.F, Entry));
return true;
};
std::remove_if(FunctionWorklist.begin(), FunctionWorklist.end(), RemoveFn);
FunctionWorklist.erase((FunctionWorklist.begin() + FunctionWorklist.size() -
FunctionsToReorder.size()),
FunctionWorklist.end());

// Add back the functions in the new bottom up order to the FunctionWorklist
for (auto it = NewFunctionsBottomUp.rbegin();
it != NewFunctionsBottomUp.rend(); it++) {
auto Entry = FunctionsToReorder.find(*it);
if (Entry == FunctionsToReorder.end()) {
continue;
}
FunctionWorklist.push_back((*Entry).second);
}
// SWIFT_ENABLE_TENSORFLOW END
}
}

Expand Down
6 changes: 2 additions & 4 deletions lib/SILOptimizer/UtilityPasses/FunctionOrderPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ class FunctionOrderPrinterPass : public SILModuleTransform {
/// The entry point to the transformation.
void run() override {
BCA = getAnalysis<BasicCalleeAnalysis>();
// SWIFT_ENABLE_TENSORFLOW
BottomUpFunctionOrder Orderer(BCA);
Orderer.computeBottomUpOrder(getModule());
// SWIFT_ENABLE_TENSORFLOW END
auto &M = *getModule();
BottomUpFunctionOrder Orderer(M, BCA);

llvm::outs() << "Bottom up function order:\n";
auto SCCs = Orderer.getSCCs();
Expand Down
4 changes: 1 addition & 3 deletions test/DebugInfo/inlined-generics-basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ public class C<R> {
// IR-LABEL: ret void

// IR: ![[BOOL:[0-9]+]] = !DICompositeType({{.*}}name: "Bool"
// IR: ![[LET_BOOL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[BOOL]])
// IR: ![[INT:[0-9]+]] = !DICompositeType({{.*}}name: "Int"
// IR: ![[LET_INT:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[INT]])
// SWIFT_ENABLE_TENSORFLOW
// IR: ![[LET_BOOL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[BOOL]])
// SWIFT_ENABLE_TENSORFLOW END
// IR: ![[TAU_0_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sxD",
// IR: ![[LET_TAU_0_0:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TAU_0_0]])
// IR: ![[TAU_1_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",
Expand Down