Skip to content
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
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/Utils/BasicBlockOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class SinkAddressProjections {
///
/// getInBlockProjectionOperandValues() can be called before or after cloning.
bool cloneProjections();

SWIFT_DEBUG_DUMP;
};

/// Clone a single basic block and any required successor edges within the same
Expand Down
13 changes: 13 additions & 0 deletions lib/SILOptimizer/Utils/BasicBlockOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,16 @@ bool SinkAddressProjections::cloneProjections() {
}
return true;
}

void SinkAddressProjections::dump() const {
llvm::dbgs() << "Old projections: ";
for (auto *proj : oldProjections) {
proj->dump();
}
if (auto *np = newProjections) {
llvm::dbgs() << "New projections: ";
for (auto *proj : *np) {
proj->dump();
}
}
}
19 changes: 16 additions & 3 deletions lib/SILOptimizer/Utils/InstructionDeleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ bool InstructionDeleter::trackIfDead(SILInstruction *inst) {
bool fixLifetime = inst->getFunction()->hasOwnership();
if (isInstructionTriviallyDead(inst)
|| isScopeAffectingInstructionDead(inst, fixLifetime)) {
assert(!isIncidentalUse(inst) &&
(!isa<DestroyValueInst>(inst) ||
canTriviallyDeleteOSSAEndScopeInst(inst)) &&
assert(!isIncidentalUse(inst)
|| canTriviallyDeleteOSSAEndScopeInst(inst) &&
"Incidental uses cannot be removed in isolation. "
"They would be removed iff the operand is dead");
getCallbacks().notifyWillBeDeleted(inst);
Expand Down Expand Up @@ -356,6 +355,20 @@ static FunctionTest DeleterDeleteIfDeadTest(
llvm::outs() << "deleteIfDead returned " << deleted << "\n";
function.print(llvm::outs());
});

// Arguments:
// - instruction: the instruction to delete
// Dumps:
// - the function
static FunctionTest DeleterTrackIfDeadTest(
"deleter_track_if_dead", [](auto &function, auto &arguments, auto &test) {
auto *inst = arguments.takeInstruction();
InstructionDeleter deleter;
llvm::outs() << "Tracking " << *inst;
deleter.trackIfDead(inst);
deleter.cleanupDeadInstructions();
function.print(llvm::outs());
});
} // namespace swift::test

void InstructionDeleter::forceDeleteAndFixLifetimes(SILInstruction *inst) {
Expand Down
15 changes: 15 additions & 0 deletions test/SILOptimizer/instruction_deleter.sil
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ sil [ossa] @doDeleteLoadTake : $() -> () {
%retval = tuple ()
return %retval : $()
}

// CHECK-LABEL: begin running test {{.*}} on trackEndBorrow
// CHECK: Tracking end_borrow undef : $C
// CHECK: sil [ossa] @trackEndBorrow : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK-NOT: end_borrow
// CHECK-LABEL: } // end sil function 'trackEndBorrow'
// CHECK-LABEL: end running test {{.*}} on trackEndBorrow
sil [ossa] @trackEndBorrow : $() -> () {
bb0:
specify_test "deleter_track_if_dead @instruction"
end_borrow undef : $C
%retval = tuple ()
return %retval : $()
}