@@ -25,10 +25,13 @@ public protocol Value : AnyObject, CustomStringConvertible {
2525 var definingInstruction : Instruction ? { get }
2626
2727 /// The block where the value is defined.
28- ///
29- /// It's not legal to get the definingBlock of an `Undef` value.
3028 var parentBlock : BasicBlock { get }
3129
30+ /// The function where the value lives in.
31+ ///
32+ /// It's not legal to get the parentFunction of an instruction in a global initializer.
33+ var parentFunction : Function { get }
34+
3235 /// True if the value has a trivial type.
3336 var hasTrivialType : Bool { get }
3437
@@ -113,6 +116,7 @@ extension Value {
113116
114117 public var uses : UseList { UseList ( bridged. getFirstUse ( ) ) }
115118
119+ // Default implementation for all values which have a parent block, like instructions and arguments.
116120 public var parentFunction : Function { parentBlock. parentFunction }
117121
118122 public var type : Type { bridged. getType ( ) . type }
@@ -206,8 +210,11 @@ extension BridgedValue {
206210public final class Undef : Value {
207211 public var definingInstruction : Instruction ? { nil }
208212
213+ public var parentFunction : Function { bridged. SILUndef_getParentFunction ( ) . function }
214+
209215 public var parentBlock : BasicBlock {
210- fatalError ( " undef has no defining block " )
216+ // By convention, undefs are considered to be defined at the entry of the function.
217+ parentFunction. entryBlock
211218 }
212219
213220 /// Undef has not parent function, therefore the default `hasTrivialType` does not work.
@@ -221,9 +228,12 @@ public final class Undef : Value {
221228
222229final class PlaceholderValue : Value {
223230 public var definingInstruction : Instruction ? { nil }
231+
224232 public var parentBlock : BasicBlock {
225233 fatalError ( " PlaceholderValue has no defining block " )
226234 }
235+
236+ public var parentFunction : Function { bridged. PlaceholderValue_getParentFunction ( ) . function }
227237}
228238
229239extension OptionalBridgedValue {
0 commit comments