|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
| 13 | +#include "swift/SILOptimizer/Utils/InstructionDeleter.h" |
13 | 14 | #include "swift/SIL/SILFunction.h"
|
| 15 | +#include "swift/SIL/Test.h" |
14 | 16 | #include "swift/SILOptimizer/Utils/ConstExpr.h"
|
15 | 17 | #include "swift/SILOptimizer/Utils/DebugOptUtils.h"
|
16 |
| -#include "swift/SILOptimizer/Utils/InstructionDeleter.h" |
17 | 18 | #include "swift/SILOptimizer/Utils/InstOptUtils.h"
|
18 | 19 |
|
19 | 20 | using namespace swift;
|
@@ -60,6 +61,14 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
|
60 | 61 | if (!hasOnlyEndOfScopeOrEndOfLifetimeUses(inst)) {
|
61 | 62 | return false;
|
62 | 63 | }
|
| 64 | + |
| 65 | + for (auto result : inst->getResults()) { |
| 66 | + if (result->getType().isPureMoveOnly() && |
| 67 | + result->getOwnershipKind() == OwnershipKind::Owned) { |
| 68 | + return false; |
| 69 | + } |
| 70 | + } |
| 71 | + |
63 | 72 | // If inst is a copy or beginning of scope, inst is dead, since we know that
|
64 | 73 | // it is used only in a destroy_value or end-of-scope instruction.
|
65 | 74 | if (getSingleValueCopyOrCast(inst))
|
@@ -289,6 +298,22 @@ bool InstructionDeleter::deleteIfDead(SILInstruction *inst, bool fixLifetime) {
|
289 | 298 | return false;
|
290 | 299 | }
|
291 | 300 |
|
| 301 | +namespace swift::test { |
| 302 | +// Arguments: |
| 303 | +// - instruction: the instruction to delete |
| 304 | +// Dumps: |
| 305 | +// - the function |
| 306 | +static FunctionTest DeleterDeleteIfDeadTest( |
| 307 | + "deleter-delete-if-dead", [](auto &function, auto &arguments, auto &test) { |
| 308 | + auto *inst = arguments.takeInstruction(); |
| 309 | + InstructionDeleter deleter; |
| 310 | + llvm::dbgs() << "Deleting-if-dead " << *inst; |
| 311 | + auto deleted = deleter.deleteIfDead(inst); |
| 312 | + llvm::dbgs() << "deleteIfDead returned " << deleted << "\n"; |
| 313 | + function.dump(); |
| 314 | + }); |
| 315 | +} // namespace swift::test |
| 316 | + |
292 | 317 | void InstructionDeleter::forceDeleteAndFixLifetimes(SILInstruction *inst) {
|
293 | 318 | SILFunction *fun = inst->getFunction();
|
294 | 319 | bool preserveDebugInfo =
|
|
0 commit comments