Skip to content

Commit 1cda26b

Browse files
committed
SwiftCompilerSources: add Value.isValidGlobalInitValue and FullApplySite.isSemanticCall
`Value.isValidGlobalInitValue` was privately used by the ObjectOutliner. Make it a generally usable utility.
1 parent 79dd2ed commit 1cda26b

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjectOutliner.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,27 +394,6 @@ private extension InstructionWorklist {
394394
}
395395
}
396396

397-
private extension Value {
398-
/// Returns true if this value is a valid in a static initializer, including all its operands.
399-
var isValidGlobalInitValue: Bool {
400-
guard let svi = self as? SingleValueInstruction else {
401-
return false
402-
}
403-
if let beginAccess = svi as? BeginAccessInst {
404-
return beginAccess.address.isValidGlobalInitValue
405-
}
406-
if !svi.isValidInStaticInitializerOfGlobal {
407-
return false
408-
}
409-
for op in svi.operands {
410-
if !op.value.isValidGlobalInitValue {
411-
return false
412-
}
413-
}
414-
return true
415-
}
416-
}
417-
418397
private extension AllocRefInstBase {
419398
var fieldsKnownStatically: Bool {
420399
if let allocDynamic = self as? AllocRefDynamicInst,

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,37 @@ extension Value {
131131
}
132132
return builder.createCopyValue(operand: self)
133133
}
134+
135+
/// True if this value is a valid in a static initializer, including all its operands.
136+
var isValidGlobalInitValue: Bool {
137+
guard let svi = self as? SingleValueInstruction else {
138+
return false
139+
}
140+
if let beginAccess = svi as? BeginAccessInst {
141+
return beginAccess.address.isValidGlobalInitValue
142+
}
143+
if !svi.isValidInStaticInitializerOfGlobal {
144+
return false
145+
}
146+
for op in svi.operands {
147+
if !op.value.isValidGlobalInitValue {
148+
return false
149+
}
150+
}
151+
return true
152+
}
153+
}
154+
155+
extension FullApplySite {
156+
func isSemanticCall(_ name: StaticString, withArgumentCount: Int) -> Bool {
157+
if arguments.count == withArgumentCount,
158+
let callee = referencedFunction,
159+
callee.hasSemanticsAttribute(name)
160+
{
161+
return true
162+
}
163+
return false
164+
}
134165
}
135166

136167
extension Builder {

0 commit comments

Comments
 (0)