Skip to content

Commit b682d54

Browse files
committed
[LexLifetimeElim] Removed flag from moves.
When eliminating lexical lifetimes, also eliminate the lifetimes introduced by move_values in addition to those introduced by begin_borrow and communicated via alloc_stack.
1 parent 3e3a98f commit b682d54

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: include/swift/SIL/SILInstruction.h

+1
Original file line numberDiff line numberDiff line change
@@ -8265,6 +8265,7 @@ class MoveValueInst
82658265
void setAllowsDiagnostics(bool newValue) { allowDiagnostics = newValue; }
82668266

82678267
bool isLexical() const { return lexical; };
8268+
void removeIsLexical() { lexical = false; }
82688269
};
82698270

82708271
/// Equivalent to a copy_addr to [init] except that it is used for diagnostics

Diff for: lib/SILOptimizer/Mandatory/LexicalLifetimeEliminator.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ class LexicalLifetimeEliminatorPass : public SILFunctionTransform {
4646
}
4747
continue;
4848
}
49-
49+
if (auto *mvi = dyn_cast<MoveValueInst>(&inst)) {
50+
if (mvi->isLexical()) {
51+
mvi->removeIsLexical();
52+
madeChange = true;
53+
}
54+
continue;
55+
}
5056
if (auto *asi = dyn_cast<AllocStackInst>(&inst)) {
5157
if (asi->isLexical()) {
5258
asi->removeIsLexical();

Diff for: test/SILOptimizer/lexical_lifetime_elim.sil

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Builtin
66

77
class Klass {}
88

9+
sil @getKlass : $() -> (@owned Klass)
10+
911
// CHECK-LABEL: sil [ossa] @lexical_lifetime_object : $@convention(thin) (@owned Klass) -> () {
1012
// CHECK: bb0(%0 : @owned $Klass):
1113
// CHECK-NEXT: %1 = begin_borrow %0 : $Klass
@@ -23,6 +25,19 @@ bb0(%0 : @owned $Klass):
2325
return %9999 : $()
2426
}
2527

28+
// CHECK-LABEL: sil [ossa] @lexical_lifetime_move : {{.*}} {
29+
// CHECK-NOT: move_value [lexical]
30+
// CHECK: move_value
31+
// CHECK-LABEL: } // end sil function 'lexical_lifetime_move'
32+
sil [ossa] @lexical_lifetime_move : $@convention(thin) () -> () {
33+
%getKlass = function_ref @getKlass : $@convention(thin) () -> (@owned Klass)
34+
%instance = apply %getKlass() : $@convention(thin) () -> (@owned Klass)
35+
%lifetime = move_value [lexical] %instance : $Klass
36+
destroy_value %lifetime : $Klass
37+
%retval = tuple ()
38+
return %retval : $()
39+
}
40+
2641
// CHECK-LABEL: sil [ossa] @lexical_lifetime_address : $@convention(thin) (@in Klass) -> () {
2742
// CHECK: bb0(%0 : $*Klass):
2843
// CHECK-NEXT: %1 = alloc_stack $Klass

0 commit comments

Comments
 (0)