Skip to content

Commit f51cdf7

Browse files
authored
Merge pull request #75755 from eeckstein/borrowed-from-verification
Fix a the borrowed-from verifier and fix a few passes which caused a verifier error
2 parents e21c117 + 21fedfa commit f51cdf7

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Verifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension BorrowedFromInst : VerifyableInstruction {
6767
var existingEVs = ValueSet(insertContentsOf: enclosingValues, context)
6868
defer { existingEVs.deinitialize() }
6969

70-
for computedEV in enclosingValues {
70+
for computedEV in computedEVs {
7171
require(existingEVs.contains(computedEV),
7272
"\(computedEV)\n missing in enclosing values of \(self)")
7373
}

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ class SILCombine : public SILFunctionTransform {
620620
bool Changed = Combiner.runOnFunction(*getFunction());
621621

622622
if (Changed) {
623+
updateBorrowedFrom(getPassManager(), getFunction());
623624
// Invalidate everything.
624625
invalidateAnalysis(SILAnalysis::InvalidationKind::FunctionBody);
625626
}

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h"
6363
#include "swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h"
6464
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
65+
#include "swift/SILOptimizer/Utils/OwnershipOptUtils.h"
6566
#include "llvm/ADT/SetVector.h"
6667

6768
using namespace swift;
@@ -634,6 +635,7 @@ void CopyPropagation::run() {
634635

635636
// Invalidate analyses.
636637
if (changed || deleter.hadCallbackInvocation()) {
638+
updateBorrowedFrom(getPassManager(), getFunction());
637639
// Preserves NonLocalAccessBlockAnalysis.
638640
accessBlockAnalysis->lockInvalidation();
639641
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2296,8 +2296,10 @@ class SILMem2Reg : public SILFunctionTransform {
22962296
bool madeChange = MemoryToRegisters(*f, da->get(f), deb,
22972297
accessBlockAnalysis, calleeAnalysis)
22982298
.run();
2299-
if (madeChange)
2299+
if (madeChange) {
2300+
updateBorrowedFrom(getPassManager(), f);
23002301
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
2302+
}
23012303
}
23022304
};
23032305

test/SILOptimizer/copy_propagation_borrow.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,22 @@ bb0(%0 : @guaranteed $C):
12071207
%7 = tuple ()
12081208
return %7 : $()
12091209
}
1210+
1211+
// CHECK-LABEL: sil [ossa] @test_updating_borrowed_from :
1212+
// CHECK: borrowed {{.*}} from {{.*}} %0 : $HasObject
1213+
// CHECK-LABEL: } // end sil function 'test_updating_borrowed_from'
1214+
sil [ossa] @test_updating_borrowed_from : $@convention(thin) (@guaranteed HasObject) -> () {
1215+
bb0(%0 : @guaranteed $HasObject):
1216+
%1 = destructure_struct %0 : $HasObject
1217+
%2 = copy_value %1 : $C
1218+
%3 = begin_borrow %2 : $C
1219+
br bb1(%3 : $C)
1220+
1221+
bb1(%5 : @reborrow @guaranteed $C):
1222+
%6 = borrowed %5 : $C from (%2 : $C)
1223+
end_borrow %6 : $C
1224+
destroy_value %2 : $C
1225+
%9 = tuple ()
1226+
return %9 : $()
1227+
}
1228+

test/SILOptimizer/sil_combine_misc_opts.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import Builtin
1212

1313
class Klass {}
1414

15+
struct S {
16+
var a: Klass
17+
}
18+
1519
sil @nativeobject_guaranteed_use : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
1620

1721
///////////
@@ -96,3 +100,22 @@ bb0(%0 : $*Builtin.NativeObject):
96100
%9999 = tuple()
97101
return %9999 : $()
98102
}
103+
104+
// CHECK-LABEL: sil [ossa] @test_updating_borrowed_from :
105+
// CHECK: borrowed {{.*}} from {{.*}} %0 : $S
106+
// CHECK-LABEL: } // end sil function 'test_updating_borrowed_from'
107+
sil [ossa] @test_updating_borrowed_from : $@convention(thin) (@guaranteed S) -> () {
108+
bb0(%0 : @guaranteed $S):
109+
%1 = destructure_struct %0 : $S
110+
%2 = copy_value %1 : $Klass
111+
%3 = begin_borrow %2 : $Klass
112+
br bb1(%3 : $Klass)
113+
114+
bb1(%5 : @reborrow @guaranteed $Klass):
115+
%6 = borrowed %5 : $Klass from (%2 : $Klass)
116+
end_borrow %6 : $Klass
117+
destroy_value %2 : $Klass
118+
%9 = tuple ()
119+
return %9 : $()
120+
}
121+

0 commit comments

Comments
 (0)