Getting the position of a BasicBlock that doesn't exist anymore in the backend

Hello,

In our LLVM backend we needto output certain labels in the AsmPrinter in order to access certain data through those labels. These labels are related to BlockAddress objects (that come from above) and they should be put into a position that is related to the BasicBlock pointed by that BlockAddress.

The problem I'm hitting is that if the BasicBlock that the BlockAddress points to is optimized away by the LLVM optimizer the BlockAddress becomes unreliable and the BasicBlock it points to is not anymore in the Function it was supposed to be. Because of this I'm not able to actually decide the position where to output the label anymore (because I rely on the position of the BasicBlock in the Function to decide the position of the label).

The most desirable situation would be to be able to know which is the BasicBlock that is immediately after in the stream and point to that, but I don't know if there is a reliable way to do that ( I tried to use the ->getPrevNode() ->getNextNode() on the BasicBlock object pointed by the BlockAddress, but I get unreliable results). Any idea?

Cheers,
Marcello