mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -252,31 +252,32 @@ bool OwnershipModelEliminatorVisitor::visitSwitchEnumInst(
|
||||
|
||||
namespace {
|
||||
|
||||
struct OwnershipModelEliminator : SILFunctionTransform {
|
||||
struct OwnershipModelEliminator : SILModuleTransform {
|
||||
void run() override {
|
||||
SILFunction *F = getFunction();
|
||||
for (auto &F : *getModule()) {
|
||||
// Set F to have unqualified ownership.
|
||||
F.setUnqualifiedOwnership();
|
||||
|
||||
// Set F to have unqualified ownership.
|
||||
F->setUnqualifiedOwnership();
|
||||
bool MadeChange = false;
|
||||
SILBuilder B(F);
|
||||
OwnershipModelEliminatorVisitor Visitor(B);
|
||||
|
||||
bool MadeChange = false;
|
||||
SILBuilder B(*F);
|
||||
OwnershipModelEliminatorVisitor Visitor(B);
|
||||
for (auto &BB : F) {
|
||||
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;
|
||||
|
||||
for (auto &BB : *F) {
|
||||
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);
|
||||
MadeChange |= Visitor.visit(I);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (MadeChange) {
|
||||
invalidateAnalysis(
|
||||
SILAnalysis::InvalidationKind::BranchesAndInstructions);
|
||||
if (MadeChange) {
|
||||
auto InvalidKind =
|
||||
SILAnalysis::InvalidationKind::BranchesAndInstructions;
|
||||
invalidateAnalysis(&F, InvalidKind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user