Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit f647299

Browse files
committed
Merge branch 'tensorflow' of github.com:apple/swift into tensorflow-stage
* 'tensorflow' of github.com:apple/swift: Re-add swiftlang#30710 Set SWIFTCI_USE_LOCAL_DEPS=1 update-checkout-config.json: adjust for tensorflow merge
2 parents 15cd450 + ebec235 commit f647299

File tree

7 files changed

+107
-52
lines changed

7 files changed

+107
-52
lines changed

include/swift/SILOptimizer/Analysis/FunctionOrder.h

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

3333
private:
34-
SILModule &M;
3534
llvm::SmallVector<SCC, 32> TheSCCs;
3635
llvm::SmallVector<SILFunction *, 32> TheFunctions;
3736

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

4645
public:
47-
BottomUpFunctionOrder(SILModule &M, BasicCalleeAnalysis *BCA)
48-
: M(M), BCA(BCA), NextDFSNum(0) {}
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
4961

5062
/// Get the SCCs in bottom-up order.
5163
ArrayRef<SCC> getSCCs() {
52-
if (!TheSCCs.empty())
53-
return TheSCCs;
54-
55-
FindSCCs(M);
5664
return TheSCCs;
5765
}
5866

59-
/// Get a flattened view of all functions in all the SCCs in
60-
/// bottom-up order
61-
ArrayRef<SILFunction *> getFunctions() {
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
6271
if (!TheFunctions.empty())
6372
return TheFunctions;
64-
6573
for (auto SCC : getSCCs())
6674
for (auto *F : SCC)
6775
TheFunctions.push_back(F);
@@ -71,7 +79,6 @@ class BottomUpFunctionOrder {
7179

7280
private:
7381
void DFS(SILFunction *F);
74-
void FindSCCs(SILModule &M);
7582
};
7683

7784
} // end namespace swift

lib/SILOptimizer/Analysis/FunctionOrder.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,3 @@ 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: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,11 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
533533
return;
534534

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

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

@@ -587,6 +590,49 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
587590
++Entry.PipelineIdx;
588591
}
589592
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
590636
}
591637
}
592638

lib/SILOptimizer/UtilityPasses/FunctionOrderPrinter.cpp

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

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

test/DebugInfo/inlined-generics-basic.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ 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]])
9594
// IR: ![[INT:[0-9]+]] = !DICompositeType({{.*}}name: "Int"
9695
// 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
9799
// IR: ![[TAU_0_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sxD",
98100
// IR: ![[LET_TAU_0_0:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TAU_0_0]])
99101
// IR: ![[TAU_1_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",

utils/build-toolchain-tensorflow

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ SWIFT_TOOLCHAIN_DIR="/Library/Developer/Toolchains/${TOOLCHAIN_NAME}.xctoolchain
173173
SYMBOLS_PACKAGE="${SRC_DIR}/${SYM_ARCHIVE}"
174174
DRY_RUN="${DRY_RUN}"
175175

176+
# Instructs swift-driver, et al to use local clones.
177+
export SWIFTCI_USE_LOCAL_DEPS=1
178+
176179
if [ ${INSTALLER_PACKAGE} ]; then
177180
INSTALLER_PACKAGE="darwin_toolchain_installer_package=${TOOLCHAIN_NAME}-osx.pkg"
178181
fi

utils/update_checkout/update-checkout-config.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -317,36 +317,6 @@
317317
"tensorflow-swift-apis": "master"
318318
}
319319
},
320-
321-
"tensorflow": {
322-
"aliases": ["tensorflow"],
323-
"repos": {
324-
"llvm-project": "582da3a4d2e364f982ae391e2b4d1cea31679592",
325-
"swift": "tensorflow",
326-
"cmark": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
327-
"llbuild": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
328-
"swift-tools-support-core": "0.1.8",
329-
"swiftpm": "swift-DEVELOPMENT-SNAPSHOT-2020-09-28-a",
330-
"swift-argument-parser": "0.3.1",
331-
"swift-driver": "70243bde9b4879237d5ad75a7f35fbba073b4eab",
332-
"swift-syntax": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
333-
"swift-stress-tester": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
334-
"swift-corelibs-xctest": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
335-
"swift-corelibs-foundation": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
336-
"swift-corelibs-libdispatch": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
337-
"swift-integration-tests": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
338-
"swift-xcode-playground-support": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
339-
"ninja": "release",
340-
"icu": "release-65-1",
341-
"yams": "3.0.1-tensorflow",
342-
"indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2020-09-11-a",
343-
"sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2020-09-28-a",
344-
"PythonKit": "master",
345-
"swift-format": "main",
346-
"tensorflow": "v2.3.0",
347-
"tensorflow-swift-apis": "master"
348-
}
349-
},
350320
"release/5.3-20201012": {
351321
"aliases": ["release/5.3-20201012"],
352322
"repos": {
@@ -370,6 +340,36 @@
370340
"sourcekit-lsp": "release/5.3-20201012",
371341
"swift-format": "main"
372342
}
343+
},
344+
345+
"tensorflow": {
346+
"aliases": ["tensorflow"],
347+
"repos": {
348+
"llvm-project": "6c506631395e47c229e0e0442688ecb951bb69e8",
349+
"swift": "tensorflow",
350+
"cmark": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
351+
"llbuild": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
352+
"swift-tools-support-core": "0.1.8",
353+
"swiftpm": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
354+
"swift-argument-parser": "0.3.1",
355+
"swift-driver": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
356+
"swift-syntax": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
357+
"swift-stress-tester": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
358+
"swift-corelibs-xctest": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
359+
"swift-corelibs-foundation": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
360+
"swift-corelibs-libdispatch": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
361+
"swift-integration-tests": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
362+
"swift-xcode-playground-support": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
363+
"ninja": "release",
364+
"icu": "release-65-1",
365+
"yams": "3.0.1-tensorflow",
366+
"indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
367+
"sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2020-10-27-a",
368+
"PythonKit": "master",
369+
"swift-format": "main",
370+
"tensorflow": "v2.3.0",
371+
"tensorflow-swift-apis": "master"
372+
}
373373
}
374374
}
375375
}

0 commit comments

Comments
 (0)