-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil] Add a move_value instruction. #39267
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,6 +249,9 @@ OPERAND_OWNERSHIP(DestroyingConsume, EndLifetime) | |
OPERAND_OWNERSHIP(DestroyingConsume, BeginCOWMutation) | ||
OPERAND_OWNERSHIP(DestroyingConsume, EndCOWMutation) | ||
|
||
// TODO: Should this be a forwarding consume. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should be |
||
OPERAND_OWNERSHIP(DestroyingConsume, MoveValue) | ||
|
||
// Instructions that move an owned value. | ||
OPERAND_OWNERSHIP(ForwardingConsume, CheckedCastValueBranch) | ||
OPERAND_OWNERSHIP(ForwardingConsume, UnconditionalCheckedCastValue) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5271,6 +5271,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> { | |
"convention"); | ||
} | ||
|
||
void checkMoveValueInst(MoveValueInst *mvi) { | ||
require(mvi->getOperand()->getType().isObject(), | ||
"Operand value should be an object"); | ||
require(mvi->getType() == mvi->getOperand()->getType(), | ||
"Result and operand must have the same type, today."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clearly this type restriction needs to be relaxed once you have moveOnly SIL types |
||
} | ||
|
||
void verifyEpilogBlocks(SILFunction *F) { | ||
bool FoundReturnBlock = false; | ||
bool FoundThrowBlock = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %swift -disable-legacy-type-info -target x86_64-apple-macosx10.9 -module-name main %s -emit-ir -o - | %FileCheck %s | ||
|
||
// REQUIRES: CODEGENERATOR=X86 | ||
|
||
sil_stage canonical | ||
|
||
import Builtin | ||
|
||
// CHECK-LABEL: define swiftcc %swift.refcounted* @move_value_test( | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: ret | ||
// CHECK-NEXT: } | ||
sil @move_value_test : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { | ||
bb0(%0 : $Builtin.NativeObject): | ||
%1 = move_value %0 : $Builtin.NativeObject | ||
return %1 : $Builtin.NativeObject | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,25 @@ bb0(%0 : @owned $Builtin.NativeObject): | |
%2 = tuple () | ||
return %2 : $() | ||
} | ||
|
||
// CHECK-LABEL: sil [ossa] @test_movevalue_parsing : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { | ||
// CHECK: bb0(%0 : | ||
// CHECK-NEXT: %1 = move_value %0 : $Builtin.NativeObject | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } // end sil function 'test_movevalue_parsing' | ||
sil [ossa] @test_movevalue_parsing : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { | ||
bb0(%0 : @owned $Builtin.NativeObject): | ||
%1 = move_value %0 : $Builtin.NativeObject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: |
||
return %1 : $Builtin.NativeObject | ||
} | ||
|
||
// CHECK-LABEL: sil @test_movevalue_parsing_non_ossa : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { | ||
// CHECK: bb0(%0 : | ||
// CHECK-NEXT: %1 = move_value %0 : $Builtin.NativeObject | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } // end sil function 'test_movevalue_parsing_non_ossa' | ||
sil @test_movevalue_parsing_non_ossa : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject { | ||
bb0(%0 : $Builtin.NativeObject): | ||
%1 = move_value %0 : $Builtin.NativeObject | ||
return %1 : $Builtin.NativeObject | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gottesmm Both the operand and result of
move_value
may be either moveOnly or copyable.Whether either value is moveOnly depends on its type. The important thing about this operation is that it can do a type conversion in either direction between 'moveOnly T' and 'T'. It can also simply perform a move without doing any type conversion.
For the purpose of SIL ownership, it simply forwards an owned value. It has no special properties.