Print emory for constant address

Hi all,

Consider a simple ll code:
%2 = load i32* %y, align 4

I intend to get the memory address of %2.
// variable name:y
value v = I.getOperand(0);
// ? I shows the entire instruction, not %2, then I.getName() would print an empty space which is %2, but I can’t get the memory when dereferencing it
errs()<< *&(I.getName())<<"\n”;

error: taking the address of an temporary object of type llvm::stringRef.

Please suggest what should I use to get the actual address of the register name %2.


If you just want to print %2 and not the whole instruction, I think you can use I.printAsOperand(errs())