[ome] Change the eliminator to be a module pass instead of a function pass.

This ensures that the pass manager runs the eliminator on all functions once
before running any further passes. Otherwise, due to the way the pass manager
runs functions, sometimes a function with unqualified ownership is visible from
a function with qualified ownership. This makes it impossible to have an
invariant that a pass either sees an entire qualified or unqualified world. This
is a useful feature that I would like to keep if I can.

rdar://29870610
This commit is contained in:
Michael Gottesman
2017-04-02 13:54:05 -07:00
parent d28e13a230
commit 85688b87bb

View File

@@ -252,31 +252,32 @@ bool OwnershipModelEliminatorVisitor::visitSwitchEnumInst(
namespace { namespace {
struct OwnershipModelEliminator : SILFunctionTransform { struct OwnershipModelEliminator : SILModuleTransform {
void run() override { void run() override {
SILFunction *F = getFunction(); for (auto &F : *getModule()) {
// Set F to have unqualified ownership.
F.setUnqualifiedOwnership();
// Set F to have unqualified ownership. bool MadeChange = false;
F->setUnqualifiedOwnership(); SILBuilder B(F);
OwnershipModelEliminatorVisitor Visitor(B);
bool MadeChange = false; for (auto &BB : F) {
SILBuilder B(*F); for (auto II = BB.begin(), IE = BB.end(); II != IE;) {
OwnershipModelEliminatorVisitor Visitor(B); // Since we are going to be potentially removing instructions, we need
// to make sure to grab out instruction and increment first.
SILInstruction *I = &*II;
++II;
for (auto &BB : *F) { MadeChange |= Visitor.visit(I);
for (auto II = BB.begin(), IE = BB.end(); II != IE;) { }
// Since we are going to be potentially removing instructions, we need
// to make sure to grab out instruction and increment first.
SILInstruction *I = &*II;
++II;
MadeChange |= Visitor.visit(I);
} }
}
if (MadeChange) { if (MadeChange) {
invalidateAnalysis( auto InvalidKind =
SILAnalysis::InvalidationKind::BranchesAndInstructions); SILAnalysis::InvalidationKind::BranchesAndInstructions;
invalidateAnalysis(&F, InvalidKind);
}
} }
} }