Skip to content

5.9: [LexicalLifetimeEliminator] Removed flag from move_values. #64983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
1 change: 1 addition & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -8265,6 +8265,7 @@ class MoveValueInst
void setAllowsDiagnostics(bool newValue) { allowDiagnostics = newValue; }

bool isLexical() const { return lexical; };
void removeIsLexical() { lexical = false; }
};

/// Equivalent to a copy_addr to [init] except that it is used for diagnostics
Expand Down
8 changes: 7 additions & 1 deletion lib/SILOptimizer/Mandatory/LexicalLifetimeEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ class LexicalLifetimeEliminatorPass : public SILFunctionTransform {
}
continue;
}

if (auto *mvi = dyn_cast<MoveValueInst>(&inst)) {
if (mvi->isLexical()) {
mvi->removeIsLexical();
madeChange = true;
}
continue;
}
if (auto *asi = dyn_cast<AllocStackInst>(&inst)) {
if (asi->isLexical()) {
asi->removeIsLexical();
Expand Down
15 changes: 15 additions & 0 deletions test/SILOptimizer/lexical_lifetime_elim.sil
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Builtin

class Klass {}

sil @getKlass : $() -> (@owned Klass)

// CHECK-LABEL: sil [ossa] @lexical_lifetime_object : $@convention(thin) (@owned Klass) -> () {
// CHECK: bb0(%0 : @owned $Klass):
// CHECK-NEXT: %1 = begin_borrow %0 : $Klass
Expand All @@ -23,6 +25,19 @@ bb0(%0 : @owned $Klass):
return %9999 : $()
}

// CHECK-LABEL: sil [ossa] @lexical_lifetime_move : {{.*}} {
// CHECK-NOT: move_value [lexical]
// CHECK: move_value
// CHECK-LABEL: } // end sil function 'lexical_lifetime_move'
sil [ossa] @lexical_lifetime_move : $@convention(thin) () -> () {
%getKlass = function_ref @getKlass : $@convention(thin) () -> (@owned Klass)
%instance = apply %getKlass() : $@convention(thin) () -> (@owned Klass)
%lifetime = move_value [lexical] %instance : $Klass
destroy_value %lifetime : $Klass
%retval = tuple ()
return %retval : $()
}

// CHECK-LABEL: sil [ossa] @lexical_lifetime_address : $@convention(thin) (@in Klass) -> () {
// CHECK: bb0(%0 : $*Klass):
// CHECK-NEXT: %1 = alloc_stack $Klass
Expand Down