Skip to content

Commit 5c9d468

Browse files
authored
Merge pull request #1925 from swiftwasm/main
[pull] swiftwasm from main
2 parents f04b4cb + dd55f1f commit 5c9d468

File tree

18 files changed

+94
-82
lines changed

18 files changed

+94
-82
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ following (non-exhaustive) set of useful options::
122122
- ``--test``: Test the toolchain after it has been compiled. This is off by default.
123123
- ``--distcc``: Use distcc to speed up the build by distributing the c++ part of
124124
the swift build. This is off by default.
125+
- ``--sccache``: Use sccache to speed up subsequent builds of the compiler by
126+
caching more c++ build artifacts. This is off by default.
125127

126128
More options may be added over time. Please pass ``--help`` to
127129
``build-toolchain`` to see the full set of options.

docs/CompilerPerformance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ are helpful in such cases:
815815
816816
- `llvm-bcanalyzer` can print (in rough form) the contents of LLVM bitcode
817817
streams, such as Swift module files and the PCH/PCM files clang stores its
818-
serialized ASTs in. The latter requires combing `llvm-objdump` and
819-
`llvm-bcanalyzer` in the following fashion: `llvm-objdump -raw-clang-ast
818+
serialized ASTs in. The latter requires combining `llvm-objdump` and
819+
`llvm-bcanalyzer` in the following fashion: `llvm-objdump --raw-clang-ast
820820
file.pcm | llvm-bcanalyzer -dump`
821821
822822
- `llvm-dwarfdump` and `llvm-dis` can be used to print textual representations

docs/DevelopmentTips.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ Compilation times for the compiler and the standard library can be agonizing, es
3333
```
3434
$ brew install sccache
3535
$ sccache --start-server
36-
$ ./swift/utils/build-script MY_ARGS --cmake-c-launcher $(which sccache) --cmake-cxx-launcher $(which sccache)
36+
$ ./swift/utils/build-script MY_ARGS --sccache
3737
```
3838

39+
If you want to always use sccache, you can `export SWIFT_USE_SCCACHE=1` and the build script will pick it up.
40+
3941
Given the size of artifacts generated, you might also want to bump the cache size from the default 10GB to something larger, say by putting `export SCCACHE_CACHE_SIZE="50G"` in your dotfile(s).
4042

4143
You can run some compiles to see if it is actually doing something by running `sccache --show-stats`. Depending on the exact compilation task you're running, you might see very different cache hit rates. For example, `sccache` is particularly effective if you're rebuilding LLVM, which doesn't change so frequently from the Swift compiler's perspective. On the other hand, if you're changing the compiler's AST, the cache hit rate is likely to be much lower.

docs/HowToGuides/GettingStarted.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
246246
```sh
247247
utils/build-script --skip-build-benchmarks \
248248
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
249-
--cmake-c-launcher="$(which sccache)" --cmake-cxx-launcher="$(which sccache)" \
250-
--release-debuginfo --test
249+
--sccache --release-debuginfo --test
251250
```
252251
- Via Xcode:
253252
```sh
254253
utils/build-script --skip-build-benchmarks \
255254
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
256-
--cmake-c-launcher="$(which sccache)" --cmake-cxx-launcher="$(which sccache)" \
257-
--release-debuginfo --test \
255+
--sccache --release-debuginfo --test \
258256
--xcode
259257
```
260258
This will create a directory

include/swift/SILOptimizer/Analysis/FunctionOrder.h

Lines changed: 12 additions & 15 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,29 +44,24 @@ class BottomUpFunctionOrder {
4344
llvm::SmallSetVector<SILFunction *, 4> DFSStack;
4445

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

6050
/// Get the SCCs in bottom-up order.
6151
ArrayRef<SCC> getSCCs() {
52+
if (!TheSCCs.empty())
53+
return TheSCCs;
54+
55+
FindSCCs(M);
6256
return TheSCCs;
6357
}
6458

65-
/// Get a flattened view of all functions in all the SCCs in bottom-up order
66-
ArrayRef<SILFunction *> getBottomUpOrder() {
59+
/// Get a flattened view of all functions in all the SCCs in
60+
/// bottom-up order
61+
ArrayRef<SILFunction *> getFunctions() {
6762
if (!TheFunctions.empty())
6863
return TheFunctions;
64+
6965
for (auto SCC : getSCCs())
7066
for (auto *F : SCC)
7167
TheFunctions.push_back(F);
@@ -75,6 +71,7 @@ class BottomUpFunctionOrder {
7571

7672
private:
7773
void DFS(SILFunction *F);
74+
void FindSCCs(SILModule &M);
7875
};
7976

8077
} // end namespace swift

lib/SILOptimizer/Analysis/FunctionOrder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ void BottomUpFunctionOrder::DFS(SILFunction *Start) {
7474
}
7575
}
7676

77+
void BottomUpFunctionOrder::FindSCCs(SILModule &M) {
78+
for (auto &F : M)
79+
DFS(&F);
80+
}

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,8 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
514514
return;
515515

516516
BasicCalleeAnalysis *BCA = getAnalysis<BasicCalleeAnalysis>();
517-
BottomUpFunctionOrder BottomUpOrder(BCA);
518-
BottomUpOrder.computeBottomUpOrder(Mod);
519-
auto BottomUpFunctions = BottomUpOrder.getBottomUpOrder();
517+
BottomUpFunctionOrder BottomUpOrder(*Mod, BCA);
518+
auto BottomUpFunctions = BottomUpOrder.getFunctions();
520519

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

@@ -569,47 +568,6 @@ runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx) {
569568
++Entry.PipelineIdx;
570569
}
571570
clearRestartPipeline();
572-
573-
if (TailIdx == (FunctionWorklist.size() - 1)) {
574-
// No new functions to process
575-
continue;
576-
}
577-
578-
// Compute the bottom up order of the new functions and the callees in it
579-
BottomUpFunctionOrder SubBottomUpOrder(BCA);
580-
// Initialize BottomUpFunctionOrder with new functions
581-
for (auto It = FunctionWorklist.begin() + TailIdx + 1;
582-
It != FunctionWorklist.end(); It++) {
583-
SubBottomUpOrder.computeBottomUpOrder(It->F);
584-
}
585-
auto NewFunctionsBottomUp = SubBottomUpOrder.getBottomUpOrder();
586-
SmallPtrSet<SILFunction *, 8> NewBottomUpSet(NewFunctionsBottomUp.begin(),
587-
NewFunctionsBottomUp.end());
588-
589-
// Remove all the functions in the new bottom up order from FunctionWorklist
590-
llvm::DenseMap<SILFunction *, WorklistEntry> FunctionsToReorder;
591-
auto RemoveFn = [&FunctionsToReorder,
592-
&NewBottomUpSet](WorklistEntry Entry) {
593-
if (NewBottomUpSet.find(Entry.F) == NewBottomUpSet.end()) {
594-
return false;
595-
}
596-
FunctionsToReorder.insert(std::make_pair(Entry.F, Entry));
597-
return true;
598-
};
599-
std::remove_if(FunctionWorklist.begin(), FunctionWorklist.end(), RemoveFn);
600-
FunctionWorklist.erase((FunctionWorklist.begin() + FunctionWorklist.size() -
601-
FunctionsToReorder.size()),
602-
FunctionWorklist.end());
603-
604-
// Add back the functions in the new bottom up order to the FunctionWorklist
605-
for (auto it = NewFunctionsBottomUp.rbegin();
606-
it != NewFunctionsBottomUp.rend(); it++) {
607-
auto Entry = FunctionsToReorder.find(*it);
608-
if (Entry == FunctionsToReorder.end()) {
609-
continue;
610-
}
611-
FunctionWorklist.push_back((*Entry).second);
612-
}
613571
}
614572
}
615573

lib/SILOptimizer/UtilityPasses/FunctionOrderPrinter.cpp

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

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

test/DebugInfo/inlined-generics-basic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +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-
// IR: ![[LET_BOOL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[BOOL]])
9797
// IR: ![[TAU_0_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sxD",
9898
// IR: ![[LET_TAU_0_0:[0-9]+]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[TAU_0_0]])
9999
// IR: ![[TAU_1_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,11 +2809,6 @@ static std::string getCustomBaselinePath(llvm::Triple Triple, bool ABI) {
28092809

28102810
static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
28112811
SwiftDeclCollector Collector(Ctx);
2812-
// If the baseline path has been given, honor that.
2813-
if (!options::BaselineFilePath.empty()) {
2814-
Collector.deSerialize(options::BaselineFilePath);
2815-
return Collector.getSDKRoot();
2816-
}
28172812
CompilerInvocation Invok;
28182813
llvm::StringSet<> Modules;
28192814
// We need to call prepareForDump to parse target triple.
@@ -2823,7 +2818,10 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
28232818
assert(Modules.size() == 1 &&
28242819
"Cannot find builtin baseline for more than one module");
28252820
std::string Path;
2826-
if (!options::BaselineDirPath.empty()) {
2821+
// If the baseline path has been given, honor that.
2822+
if (!options::BaselineFilePath.empty()) {
2823+
Path = options::BaselineFilePath;
2824+
} else if (!options::BaselineDirPath.empty()) {
28272825
Path = getCustomBaselinePath(Invok.getLangOptions().Target,
28282826
Ctx.checkingABI());
28292827
} else if (options::UseEmptyBaseline) {

0 commit comments

Comments
 (0)