Skip to content

SILCleanup => IRGenPrepare. #15973

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
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
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ PASS(TempRValueOpt, "temp-rvalue-opt",
"Remove short-lived immutable temporary copies")
PASS(SideEffectsDumper, "side-effects-dump",
"Print Side-Effect Information for all Functions")
PASS(SILCleanup, "cleanup",
"SIL Cleanup Preparation for IRGen")
PASS(IRGenPrepare, "irgen-prepare",
"Cleanup SIL in preparation for IRGen")
PASS(SILCombine, "sil-combine",
"Combine SIL Instructions via Peephole Optimization")
PASS(SILDebugInfoGenerator, "sil-debuginfo-gen",
Expand Down
3 changes: 2 additions & 1 deletion lib/SILOptimizer/Mandatory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(MANDATORY_SOURCES
Mandatory/AccessEnforcementSelection.cpp
Mandatory/AccessMarkerElimination.cpp
Mandatory/AddressLowering.cpp
Mandatory/ConstantPropagation.cpp
Mandatory/DefiniteInitialization.cpp
Mandatory/DIMemoryUseCollector.cpp
Mandatory/DIMemoryUseCollectorOwnership.cpp
Expand All @@ -10,8 +11,8 @@ set(MANDATORY_SOURCES
Mandatory/DiagnoseStaticExclusivity.cpp
Mandatory/DiagnoseUnreachable.cpp
Mandatory/GuaranteedARCOpts.cpp
Mandatory/IRGenPrepare.cpp
Mandatory/MandatoryInlining.cpp
Mandatory/PredictableMemOpt.cpp
Mandatory/ConstantPropagation.cpp
Mandatory/SemanticARCOpts.cpp
PARENT_SCOPE)
83 changes: 83 additions & 0 deletions lib/SILOptimizer/Mandatory/IRGenPrepare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//===--- IRGenPrepare.cpp -------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
///
/// Cleanup SIL to make it suitable for IRGen.
///
/// We perform the following canonicalizations:
///
/// 1. We remove calls to Builtin.staticReport(), which are not needed post SIL.
///
//===----------------------------------------------------------------------===//

#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"

using namespace swift;

static bool cleanFunction(SILFunction &fn) {
bool madeChange = false;

for (auto &bb : fn) {
for (auto i = bb.begin(), e = bb.end(); i != e;) {
// Make sure there is no iterator invalidation if the inspected
// instruction gets removed from the block.
SILInstruction *inst = &*i;
++i;

// Remove calls to Builtin.staticReport().
auto *bi = dyn_cast<BuiltinInst>(inst);
if (!bi) {
continue;
}

const BuiltinInfo &bInfo = bi->getBuiltinInfo();
if (bInfo.ID != BuiltinValueKind::StaticReport) {
continue;
}

// The call to the builtin should get removed before we reach
// IRGen.
recursivelyDeleteTriviallyDeadInstructions(bi, /* Force */ true);
madeChange = true;
}
}

return madeChange;
}

//===----------------------------------------------------------------------===//
// Top Level Entrypoint
//===----------------------------------------------------------------------===//

namespace {

class IRGenPrepare : public SILFunctionTransform {
void run() override {
bool shouldInvalidate = cleanFunction(*getFunction());
if (!shouldInvalidate)
return;
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
}
};

} // end anonymous namespace


SILTransform *swift::createIRGenPrepare() {
return new IRGenPrepare();
}
2 changes: 1 addition & 1 deletion lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ SILPassPipelinePlan
SILPassPipelinePlan::getLoweringPassPipeline() {
SILPassPipelinePlan P;
P.startPipeline("Address Lowering");
P.addSILCleanup();
P.addIRGenPrepare();
P.addAddressLowering();

return P;
Expand Down
1 change: 0 additions & 1 deletion lib/SILOptimizer/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ set(TRANSFORMS_SOURCES
Transforms/RedundantOverflowCheckRemoval.cpp
Transforms/ReleaseDevirtualizer.cpp
Transforms/RemovePin.cpp
Transforms/SILCleanup.cpp
Transforms/SILCodeMotion.cpp
Transforms/SILLowerAggregateInstrs.cpp
Transforms/SILMem2Reg.cpp
Expand Down
67 changes: 0 additions & 67 deletions lib/SILOptimizer/Transforms/SILCleanup.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions utils/pass-pipeline/src/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
PerfInliner = Pass('PerfInliner')
PerformanceConstantPropagation = Pass('PerformanceConstantPropagation')
PredictableMemoryOptimizations = Pass('PredictableMemoryOptimizations')
SILCleanup = Pass('SILCleanup')
IRGenPrepare = Pass('IRGenPrepare')
SILCombine = Pass('SILCombine')
SILLinker = Pass('SILLinker')
SROA = Pass('SROA')
Expand Down Expand Up @@ -89,7 +89,7 @@
PerfInliner,
PerformanceConstantPropagation,
PredictableMemoryOptimizations,
SILCleanup,
IRGenPrepare,
SILCombine,
SILLinker,
SROA,
Expand Down