@@ -90,6 +90,35 @@ public class Function: IRGlobal {
9090 }
9191 }
9292
93+ /// Computes the address of the specified basic block in this function, and
94+ /// always has an `i8*` type.
95+ ///
96+ /// Taking the address of the entry block is illegal.
97+ ///
98+ /// This value only has defined behavior when used as an operand to the
99+ /// `indirectbr` instruction, or for comparisons against null. Pointer
100+ /// equality tests between labels addresses results in undefined behavior
101+ /// — though, again, comparison against null is ok, and no label is equal to
102+ /// the null pointer. This may be passed around as an opaque pointer sized
103+ /// value as long as the bits are not inspected. This allows `ptrtoint` and
104+ /// arithmetic to be performed on these values so long as the original value
105+ /// is reconstituted before the indirectbr instruction.
106+ ///
107+ /// Finally, some targets may provide defined semantics when using the value
108+ /// as the operand to an inline assembly, but that is target specific.
109+ ///
110+ /// - parameter block: The basic block to compute the address of.
111+ ///
112+ /// - returns: An IRValue representing the address of the given basic block
113+ /// in this function, else nil if the address cannot be computed or the
114+ /// basic block does not reside in this function.
115+ public func address( of block: BasicBlock ) -> BasicBlock . Address ? {
116+ guard let addr = LLVMBlockAddress ( llvm, block. llvm) else {
117+ return nil
118+ }
119+ return BasicBlock . Address ( llvm: addr)
120+ }
121+
93122 /// Retrieves the previous function in the module, if there is one.
94123 public func previous( ) -> Function ? {
95124 guard let previous = LLVMGetPreviousFunction ( llvm) else { return nil }
0 commit comments