mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The old invalidation lattice was incorrect because changes to control flow could cause changes to the call graph, so we've decided to change the way passes invalidate analysis. In the new scheme, the lattice is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches. Now, passes report which traits they preserve, which is the opposite of the previous implementation where passes needed to report what they invalidate. Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some of the code in a following commit. Swift SVN r26449
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
//===-- SILCleanup.cpp - Removes diagnostics instructions -----------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Cleanup SIL to make it suitable for IRGen. Specifically, removes the calls to
|
|
// Builtin.staticReport(), which are not needed post SIL.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/SILPasses/Passes.h"
|
|
#include "swift/SIL/SILFunction.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
#include "swift/SIL/SILModule.h"
|
|
#include "swift/SILPasses/Utils/Local.h"
|
|
#include "swift/SILPasses/Transforms.h"
|
|
|
|
using namespace swift;
|
|
|
|
static void cleanFunction(SILFunction &Fn) {
|
|
for (auto &BB : Fn) {
|
|
auto I = BB.begin(), E = BB.end();
|
|
while (I != E) {
|
|
// Make sure there is no iterator invalidation if the inspected
|
|
// instruction gets removed from the block.
|
|
SILInstruction *Inst = I++;
|
|
|
|
// Remove calls to Builtin.staticReport().
|
|
if (BuiltinInst *BI = dyn_cast<BuiltinInst>(Inst)) {
|
|
const BuiltinInfo &B = BI->getBuiltinInfo();
|
|
if (B.ID == BuiltinValueKind::StaticReport) {
|
|
// The call to the builtin should get removed before we reach
|
|
// IRGen.
|
|
recursivelyDeleteTriviallyDeadInstructions(BI, /* Force */true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Rename functions with public_external linkage to prevent symbol conflict
|
|
// with stdlib.
|
|
if (Fn.isDefinition() && Fn.getLinkage() == SILLinkage::PublicExternal) {
|
|
Fn.setLinkage(SILLinkage::SharedExternal);
|
|
}
|
|
}
|
|
|
|
void swift::performSILCleanup(SILModule *M) {
|
|
for (auto &Fn : *M)
|
|
cleanFunction(Fn);
|
|
}
|
|
|
|
namespace {
|
|
class SILCleanup : public swift::SILFunctionTransform {
|
|
|
|
/// The entry point to the transformation.
|
|
void run() override {
|
|
cleanFunction(*getFunction());
|
|
invalidateAnalysis(SILAnalysis::PreserveKind::Nothing);
|
|
}
|
|
|
|
StringRef getName() override { return "SIL Cleanup"; }
|
|
};
|
|
} // end anonymous namespace
|
|
|
|
|
|
SILTransform *swift::createSILCleanup() {
|
|
return new SILCleanup();
|
|
}
|