Skip to content

Commit b05094f

Browse files
authored
Merge pull request #15973 from gottesmm/pr-6a0bf75d9fc53d10ccd9de4251fb9b080f22a6b5
SILCleanup => IRGenPrepare.
2 parents 275e101 + 245325c commit b05094f

File tree

7 files changed

+90
-74
lines changed

7 files changed

+90
-74
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ PASS(TempRValueOpt, "temp-rvalue-opt",
238238
"Remove short-lived immutable temporary copies")
239239
PASS(SideEffectsDumper, "side-effects-dump",
240240
"Print Side-Effect Information for all Functions")
241-
PASS(SILCleanup, "cleanup",
242-
"SIL Cleanup Preparation for IRGen")
241+
PASS(IRGenPrepare, "irgen-prepare",
242+
"Cleanup SIL in preparation for IRGen")
243243
PASS(SILCombine, "sil-combine",
244244
"Combine SIL Instructions via Peephole Optimization")
245245
PASS(SILDebugInfoGenerator, "sil-debuginfo-gen",

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(MANDATORY_SOURCES
22
Mandatory/AccessEnforcementSelection.cpp
33
Mandatory/AccessMarkerElimination.cpp
44
Mandatory/AddressLowering.cpp
5+
Mandatory/ConstantPropagation.cpp
56
Mandatory/DefiniteInitialization.cpp
67
Mandatory/DIMemoryUseCollector.cpp
78
Mandatory/DIMemoryUseCollectorOwnership.cpp
@@ -10,9 +11,9 @@ set(MANDATORY_SOURCES
1011
Mandatory/DiagnoseStaticExclusivity.cpp
1112
Mandatory/DiagnoseUnreachable.cpp
1213
Mandatory/GuaranteedARCOpts.cpp
14+
Mandatory/IRGenPrepare.cpp
1315
Mandatory/MandatoryInlining.cpp
1416
Mandatory/PredictableMemOpt.cpp
15-
Mandatory/ConstantPropagation.cpp
1617
Mandatory/SemanticARCOpts.cpp
1718
Mandatory/ClosureLifetimeFixup.cpp
1819
PARENT_SCOPE)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//===--- IRGenPrepare.cpp -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
///
13+
/// \file
14+
///
15+
/// Cleanup SIL to make it suitable for IRGen.
16+
///
17+
/// We perform the following canonicalizations:
18+
///
19+
/// 1. We remove calls to Builtin.staticReport(), which are not needed post SIL.
20+
///
21+
//===----------------------------------------------------------------------===//
22+
23+
#include "swift/SILOptimizer/PassManager/Passes.h"
24+
#include "swift/SIL/SILFunction.h"
25+
#include "swift/SIL/SILInstruction.h"
26+
#include "swift/SIL/SILModule.h"
27+
#include "swift/SILOptimizer/Utils/Local.h"
28+
#include "swift/SILOptimizer/PassManager/Transforms.h"
29+
30+
using namespace swift;
31+
32+
static bool cleanFunction(SILFunction &fn) {
33+
bool madeChange = false;
34+
35+
for (auto &bb : fn) {
36+
for (auto i = bb.begin(), e = bb.end(); i != e;) {
37+
// Make sure there is no iterator invalidation if the inspected
38+
// instruction gets removed from the block.
39+
SILInstruction *inst = &*i;
40+
++i;
41+
42+
// Remove calls to Builtin.staticReport().
43+
auto *bi = dyn_cast<BuiltinInst>(inst);
44+
if (!bi) {
45+
continue;
46+
}
47+
48+
const BuiltinInfo &bInfo = bi->getBuiltinInfo();
49+
if (bInfo.ID != BuiltinValueKind::StaticReport) {
50+
continue;
51+
}
52+
53+
// The call to the builtin should get removed before we reach
54+
// IRGen.
55+
recursivelyDeleteTriviallyDeadInstructions(bi, /* Force */ true);
56+
madeChange = true;
57+
}
58+
}
59+
60+
return madeChange;
61+
}
62+
63+
//===----------------------------------------------------------------------===//
64+
// Top Level Entrypoint
65+
//===----------------------------------------------------------------------===//
66+
67+
namespace {
68+
69+
class IRGenPrepare : public SILFunctionTransform {
70+
void run() override {
71+
bool shouldInvalidate = cleanFunction(*getFunction());
72+
if (!shouldInvalidate)
73+
return;
74+
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
75+
}
76+
};
77+
78+
} // end anonymous namespace
79+
80+
81+
SILTransform *swift::createIRGenPrepare() {
82+
return new IRGenPrepare();
83+
}

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ SILPassPipelinePlan
462462
SILPassPipelinePlan::getLoweringPassPipeline() {
463463
SILPassPipelinePlan P;
464464
P.startPipeline("Address Lowering");
465-
P.addSILCleanup();
465+
P.addIRGenPrepare();
466466
P.addAddressLowering();
467467

468468
return P;

lib/SILOptimizer/Transforms/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ set(TRANSFORMS_SOURCES
2323
Transforms/RedundantOverflowCheckRemoval.cpp
2424
Transforms/ReleaseDevirtualizer.cpp
2525
Transforms/RemovePin.cpp
26-
Transforms/SILCleanup.cpp
2726
Transforms/SILCodeMotion.cpp
2827
Transforms/SILLowerAggregateInstrs.cpp
2928
Transforms/SILMem2Reg.cpp

lib/SILOptimizer/Transforms/SILCleanup.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

utils/pass-pipeline/src/passes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
PerfInliner = Pass('PerfInliner')
4141
PerformanceConstantPropagation = Pass('PerformanceConstantPropagation')
4242
PredictableMemoryOptimizations = Pass('PredictableMemoryOptimizations')
43-
SILCleanup = Pass('SILCleanup')
43+
IRGenPrepare = Pass('IRGenPrepare')
4444
SILCombine = Pass('SILCombine')
4545
SILLinker = Pass('SILLinker')
4646
SROA = Pass('SROA')
@@ -89,7 +89,7 @@
8989
PerfInliner,
9090
PerformanceConstantPropagation,
9191
PredictableMemoryOptimizations,
92-
SILCleanup,
92+
IRGenPrepare,
9393
SILCombine,
9494
SILLinker,
9595
SROA,

0 commit comments

Comments
 (0)