mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
MandatoryPerformanceOptimizations: better handling of statically initialized globals which contain a pointer to another global
E.g. ``` var p = Point(x: 10, y: 20) let o = UnsafePointer(&p) ``` MandatoryPerformanceOptimization must inline the accessor to the referenced global.
This commit is contained in:
@@ -225,7 +225,7 @@ private extension Value {
|
||||
var singleUseValue: any Value = self
|
||||
var path = SmallProjectionPath()
|
||||
while true {
|
||||
guard let use = singleUseValue.uses.singleNonDebugUse else {
|
||||
guard let use = singleUseValue.uses.singleRelevantUse else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -247,6 +247,8 @@ private extension Value {
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
case is PointerToAddressInst, is AddressToPointerInst, is BeginAccessInst:
|
||||
break
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -334,3 +336,27 @@ fileprivate struct FunctionWorklist {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension UseList {
|
||||
var singleRelevantUse: Operand? {
|
||||
var singleUse: Operand?
|
||||
for use in self {
|
||||
switch use.instruction {
|
||||
case is DebugValueInst,
|
||||
// The initializer value of a global can contain access instructions if it references another
|
||||
// global variable by address, e.g.
|
||||
// var p = Point(x: 10, y: 20)
|
||||
// let o = UnsafePointer(&p)
|
||||
// Therefore ignore the `end_access` use of a `begin_access`.
|
||||
is EndAccessInst:
|
||||
continue
|
||||
default:
|
||||
if singleUse != nil {
|
||||
return nil
|
||||
}
|
||||
singleUse = use
|
||||
}
|
||||
}
|
||||
return singleUse
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user