How to read the value of callee saved register?


I’m trying to impement an llvm jit that integrates with jvm hotspot jit. Hotspot uses callee saved registers e.g. r28 (aarch64) to store pointers to some internal structures.

I’m wondering how can I read the value of such registers in llvm IR.

If you’re asking to do that in LLVM IR, you probably can’t. LLVM IR is a (mostly) target independent format. More importantly, register allocation happens (way) after LLVM IR. You can, however, (i) write a Machine IR Pass to read from the desired registers after register allocation (ii) use inline assembly in LLVM IR to read the desired register values.

There is an intrinsic for it. N.B. you should disable the register with something like -ffixed-x28. If I am not mistaken, there is a verification error otherwise.

Thanks folks, I’ll take a look!

I’ll probay end up with read_register intrinsic, but I want to ask anyway.
I’ve never wrote MIR passes before. Do you mean I would need to define custom intrinsic and then match it in MIR pass?

It really depends on how you’re going to read the register value. For instance, if you’re using some builtins / runtime functions to collect such value, in the MIR Pass you can simply insert function calls to those builtins and read from the desired register, after RA is finished.

Ok, thank a lot!