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:
Erik Eckstein
2023-08-09 19:26:45 +02:00
parent 7e33e554ef
commit 538d7306bd

View File

@@ -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
}
}