Skip to content

Commit 8b3b16c

Browse files
author
Gabor Horvath
committed
Fix some fallout.
1 parent 5a63808 commit 8b3b16c

File tree

6 files changed

+132
-7
lines changed

6 files changed

+132
-7
lines changed

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,17 @@ bool OwnershipModelEliminatorVisitor::visitApplyInst(ApplyInst *ai) {
408408

409409
// Insert a retain for unowned results.
410410
SILBuilderWithScope builder(ai->getNextInstruction(), builderCtx);
411-
builder.emitDestructureValueOperation(
412-
ai->getLoc(), ai, [&](unsigned idx, SILValue v) {
413-
auto resultsIt = fnConv.getDirectSILResults().begin();
414-
if (resultsIt->getConvention() == ResultConvention::Unowned)
415-
builder.emitCopyValueOperation(ai->getLoc(), v);
416-
++resultsIt;
417-
});
411+
auto resultIt = fnConv.getDirectSILResults().begin();
412+
auto copyValue = [&](unsigned idx, SILValue v) {
413+
auto result = *resultIt;
414+
if (result.getConvention() == ResultConvention::Unowned)
415+
builder.emitCopyValueOperation(ai->getLoc(), v);
416+
++resultIt;
417+
};
418+
if (fnConv.getNumDirectSILResults() == 1)
419+
copyValue(0, ai);
420+
else
421+
builder.emitDestructureValueOperation(ai->getLoc(), ai, copyValue);
418422

419423
return changed;
420424
}

test/SILOptimizer/cse_objc_ossa.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import Foundation
99
@objc(XX) protocol XX {
1010
}
1111

12+
// CHECK-LABEL: sil [ossa] @cse_objc_protocol :
13+
// CHECK: objc_protocol #XX : $Protocol
14+
// CHECK-NOT: objc_protocol
15+
// CHECK: tuple (%0 : $Protocol, %0 : $Protocol)
16+
// CHECK-LABEL: } // end sil function 'cse_objc_protocol'
17+
sil [ossa] @cse_objc_protocol : $@convention(thin) () -> @owned (Protocol, Protocol) {
18+
bb0:
19+
%0 = objc_protocol #XX : $Protocol
20+
%1 = objc_protocol #XX : $Protocol
21+
%2 = tuple (%0: $Protocol, %1: $Protocol)
22+
%3 = copy_value %2
23+
return %3
24+
}
25+
1226
@objc protocol Walkable {
1327
func walk()
1428
}

test/SILOptimizer/cse_ossa.sil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,20 @@ bb0(%0 : $*Builtin.Int8):
695695
return %4 : $Builtin.Int64
696696
}
697697

698+
// CHECK-LABEL: sil [ossa] @cse_raw_pointer_to_ref :
699+
// CHECK: raw_pointer_to_ref
700+
// CHECK-NOT: raw_pointer_to_ref
701+
// CHECK: tuple
702+
// CHECK-LABEL: } // end sil function 'cse_raw_pointer_to_ref'
703+
sil [ossa] @cse_raw_pointer_to_ref : $@convention(thin) (Builtin.RawPointer) -> @owned (C, C) {
704+
bb0(%0 : $Builtin.RawPointer):
705+
%1 = raw_pointer_to_ref %0 : $Builtin.RawPointer to $C
706+
%2 = raw_pointer_to_ref %0 : $Builtin.RawPointer to $C
707+
%6 = tuple(%1: $C, %2: $C)
708+
%7 = copy_value %6
709+
return %7
710+
}
711+
698712
// CHECK-LABEL: sil [ossa] @cse_unchecked_addr_cast :
699713
// CHECK: unchecked_addr_cast
700714
// CHECK-NOT: unchecked_addr_cast

test/SILOptimizer/ossa_rauw_tests.sil

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,57 @@ bbExitBlock(%result : @owned $FakeOptional<Klass>):
302302
return %result : $FakeOptional<Klass>
303303
}
304304

305+
// CHECK-LABEL: sil [ossa] @owned_to_guaranteed_rauw_2 : $@convention(thin) (@guaranteed Klass) -> @owned (Klass, Klass) {
306+
// CHECK: bb0(
307+
// CHECK-NEXT: tuple
308+
// CHECK-NEXT: copy_value
309+
// CHECK-NEXT: return
310+
// CHECK: } // end sil function 'owned_to_guaranteed_rauw_2'
311+
sil [ossa] @owned_to_guaranteed_rauw_2 : $@convention(thin) (@guaranteed Klass) -> @owned (Klass, Klass) {
312+
bb0(%0 : @guaranteed $Klass):
313+
%1 = unchecked_bitwise_cast %0 : $Klass to $SubKlass
314+
%2 = unchecked_bitwise_cast %1 : $SubKlass to $Klass
315+
%3 = tuple(%2 : $Klass, %2 : $Klass)
316+
%4 = copy_value %3
317+
return %4 : $(Klass, Klass)
318+
}
319+
320+
// CHECK-LABEL: sil [ossa] @owned_to_guaranteed_rauw_2a : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned (Klass, Klass) {
321+
// CHECK: bb0(
322+
// CHECK-NEXT: unchecked_ref_cast
323+
// CHECK-NEXT: tuple
324+
// CHECK-NEXT: copy_value
325+
// CHECK-NEXT: return
326+
// CHECK: } // end sil function 'owned_to_guaranteed_rauw_2a'
327+
sil [ossa] @owned_to_guaranteed_rauw_2a : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned (Klass, Klass) {
328+
bb0(%0 : @guaranteed $Builtin.NativeObject):
329+
%0a = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
330+
%1 = unchecked_bitwise_cast %0a : $Klass to $SubKlass
331+
%2 = unchecked_bitwise_cast %1 : $SubKlass to $Klass
332+
%3 = tuple(%2 : $Klass, %2 : $Klass)
333+
%4 = copy_value %3
334+
return %4 : $(Klass, Klass)
335+
}
336+
337+
// We need the unchecked_ownership_conversion since our base value is
338+
// guaranteed, not a function argument, and our user is a function exiting
339+
// terminator.
340+
//
341+
// CHECK-LABEL: sil [ossa] @owned_to_guaranteed_rauw_2b : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned Klass {
342+
// CHECK: bb0(
343+
// CHECK-NEXT: unchecked_ref_cast
344+
// CHECK-NEXT: copy_value
345+
// CHECK-NEXT: return
346+
// CHECK: } // end sil function 'owned_to_guaranteed_rauw_2b'
347+
sil [ossa] @owned_to_guaranteed_rauw_2b : $@convention(thin) (@guaranteed Builtin.NativeObject) -> @owned Klass {
348+
bb0(%0 : @guaranteed $Builtin.NativeObject):
349+
%0a = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
350+
%1 = unchecked_bitwise_cast %0a : $Klass to $SubKlass
351+
%2 = unchecked_bitwise_cast %1 : $SubKlass to $Klass
352+
%3 = copy_value %2
353+
return %3 : $Klass
354+
}
355+
305356
// CHECK-LABEL: sil [ossa] @unowned_to_guaranteed_rauw_2_loop : $@convention(thin) (@guaranteed Klass) -> @owned FakeOptional<(Klass, Klass)> {
306357
// CHECK: bb0([[ARG:%.*]] : @guaranteed $Klass):
307358
// CHECK-NOT: unchecked_bitwise_cast
@@ -358,6 +409,19 @@ bbExitBlock(%result : @owned $FakeOptional<(Klass, Klass)>):
358409
return %result : $FakeOptional<(Klass, Klass)>
359410
}
360411

412+
// CHECK-LABEL: sil [ossa] @owned_to_guaranteed_rauw_3 : $@convention(thin) (@guaranteed Klass) -> @owned Klass {
413+
// CHECK: bb0(
414+
// CHECK-NEXT: copy_value
415+
// CHECK-NEXT: return
416+
// CHECK: } // end sil function 'owned_to_guaranteed_rauw_3'
417+
sil [ossa] @owned_to_guaranteed_rauw_3 : $@convention(thin) (@guaranteed Klass) -> @owned Klass {
418+
bb0(%0 : @guaranteed $Klass):
419+
%1 = unchecked_bitwise_cast %0 : $Klass to $SubKlass
420+
%2 = unchecked_bitwise_cast %1 : $SubKlass to $Klass
421+
%3 = copy_value %2
422+
return %3 : $Klass
423+
}
424+
361425
//===---
362426
// Guaranteed Tests
363427
//

test/SILOptimizer/simplify_unconditional_check_cast.sil

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ bb0(%0 : $@thick T.Type):
3737
return %1
3838
}
3939

40+
// CHECK-LABEL: sil [ossa] @test_non_metatype :
41+
// CHECK: %1 = unconditional_checked_cast %0
42+
// CHECK-NEXT: %2 = copy_value %1
43+
// CHECK-NEXT: return %2
44+
// CHECK: } // end sil function 'test_non_metatype'
45+
sil [ossa] @test_non_metatype : $@convention(thin) (@guaranteed C) -> @owned any PC {
46+
bb0(%0 : @guaranteed $C):
47+
%1 = unconditional_checked_cast %0 to any PC
48+
%2 = copy_value %1
49+
return %2
50+
}
4051

4152
// CHECK-LABEL: sil [ossa] @test_non_existential_target :
4253
// CHECK: %1 = unconditional_checked_cast %0

test/SILOptimizer/simplify_value_to_bridge_object.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ bb0(%0 : $Builtin.Int64):
1717
%4 = value_to_bridge_object %3 : $Builtin.Int64
1818
return %4 : $Builtin.BridgeObject
1919
}
20+
21+
// CHECK-LABEL: sil [ossa] @keep_both_vtbo_instructions
22+
// CHECK: %1 = value_to_bridge_object %0
23+
// CHECK: %2 = value_to_bridge_object %0
24+
// CHECK: %3 = tuple (%1 : $Builtin.BridgeObject, %2 : $Builtin.BridgeObject)
25+
// CHECK: %4 = copy_value %3
26+
// CHECK: return %4
27+
// CHECK: } // end sil function 'keep_both_vtbo_instructions'
28+
sil [ossa] @keep_both_vtbo_instructions : $@convention(thin) (Builtin.Int64) -> @owned (Builtin.BridgeObject, Builtin.BridgeObject) {
29+
bb0(%0 : $Builtin.Int64):
30+
%1 = value_to_bridge_object %0 : $Builtin.Int64
31+
%2 = unchecked_trivial_bit_cast %1 : $Builtin.BridgeObject to $UInt64
32+
%3 = struct_extract %2 : $UInt64, #UInt64._value
33+
%4 = value_to_bridge_object %3 : $Builtin.Int64
34+
%5 = tuple (%1 : $Builtin.BridgeObject, %4 : $Builtin.BridgeObject)
35+
%6 = copy_value %5
36+
return %6
37+
}

0 commit comments

Comments
 (0)