Skip to content

Commit 1f53563

Browse files
committed
libswift: remove Instruction.mayReadRefCount
1 parent 40e805d commit 1f53563

File tree

4 files changed

+270
-239
lines changed

4 files changed

+270
-239
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let releaseDevirtualizerPass = FunctionPass(
5151

5252
if instruction is ReleaseValueInst || instruction is StrongReleaseInst {
5353
lastRelease = instruction as? RefCountingInst
54-
} else if instruction.mayRelease || instruction.mayReadRefCount {
54+
} else if instruction.mayRelease {
5555
lastRelease = nil
5656
}
5757
}
@@ -106,14 +106,14 @@ private func stripRCIdentityPreservingInsts(_ value: Value) -> Value? {
106106

107107
switch inst {
108108
// First strip off RC identity preserving casts.
109-
case is UpcastInst,
110-
is UncheckedRefCastInst,
111-
is InitExistentialRefInst,
112-
is OpenExistentialRefInst,
113-
is RefToBridgeObjectInst,
114-
is BridgeObjectToRefInst,
115-
is ConvertFunctionInst,
116-
is UncheckedEnumDataInst:
109+
case is UpcastInst,
110+
is UncheckedRefCastInst,
111+
is InitExistentialRefInst,
112+
is OpenExistentialRefInst,
113+
is RefToBridgeObjectInst,
114+
is BridgeObjectToRefInst,
115+
is ConvertFunctionInst,
116+
is UncheckedEnumDataInst:
117117
return inst.operands[0].value
118118

119119
// Then if we have a struct_extract that is extracting a non-trivial member
@@ -178,9 +178,18 @@ private extension TupleExtractInst {
178178

179179
let opType = operand.type
180180

181-
return opType.tupleElements.filter {
182-
!$0.isTrivial(in: function)
183-
}.count == 1
181+
var nonTrivialEltsCount = 0
182+
for elt in opType.tupleElements {
183+
if elt.isTrivial(in: function) {
184+
nonTrivialEltsCount += 1
185+
}
186+
187+
if nonTrivialEltsCount > 1 {
188+
return false
189+
}
190+
}
191+
192+
return true
184193
}
185194
}
186195

@@ -194,8 +203,17 @@ private extension StructExtractInst {
194203

195204
let structType = operand.type
196205

197-
return structType.getStructFields(in: function).filter {
198-
!$0.isTrivial(in: function)
199-
}.count == 1
206+
var nonTrivialFieldsCount = 0
207+
for field in structType.getStructFields(in: function) {
208+
if field.isTrivial(in: function) {
209+
nonTrivialFieldsCount += 1
210+
}
211+
212+
if nonTrivialFieldsCount > 1 {
213+
return false
214+
}
215+
}
216+
217+
return true
200218
}
201-
}
219+
}

0 commit comments

Comments
 (0)