Status of "llvm.pcmarker" intrinsic?

Hi all,

I’ve seen previous messages about “llvm.pcmarker” not being supported on x86 (e.g. http://lists.llvm.org/pipermail/llvm-dev/2010-February/029239.html and http://lists.llvm.org/pipermail/llvm-dev/2012-June/051104.html). However, these messages are several years old – is the intrinsic still not implemented?

Rob Lyerly via llvm-dev <llvm-dev@lists.llvm.org> writes:

I've seen previous messages about "llvm.pcmarker" not being supported on
x86 (e.g. http://lists.llvm.org/pipermail/llvm-dev/2010-February/029239.html
and http://lists.llvm.org/pipermail/llvm-dev/2012-June/051104.html).
However, these messages are several years old -- is the intrinsic still not
implemented?

As far as I can tell llvm.pcmarker was only ever implemented for Alpha,
and that backend was removed in 2011. All of the code and documentation
relating to pcmarker has been dead for years, and should probably just
be removed.

There seems to be semantic overlap with stackmap, patchpoint, and statepoint as well.

I suspect we should remove pcmarker and forward serialize it in bitcode as a nop.

Philip

That’s kind of a shame because it did exactly what I needed – I’ll have to find another route!

I wanted to use “llvm.pcmarker” to find the address of a given IR instruction when generated using different back-ends. In particular, I wanted to be able to map the return address of a specific function call on x86-64 with the return address for the same function call on Aarch64. My plan was to develop a pass that dumped the pcmarker intrinsic after every function call site, so that I could correlate the return addresses between function call sites on both architectures.

I’m still a newbie in terms of LLVM internals, so I’m wondering what would be the easiest approach to accomplish this. I’ve seen elsewhere people recommending adding custom intrinsics that get converted into pseudo-instructions in the back-end. Those pseudo instructions would then generate a label when CodeGen’d…does this seem sane? Or is there an easier approach to solving this?

Wouldn’t you get precisely the same numbers (and in the same order) by dumping the return address of each function just before returning from it?

The mapping between PC and a given IR instruction (let alone source line of code) is a pretty fuzzy thing in the presence of even simple optimizations. The return address of a function is much more well-defined than the address of some arbitrary IR instruction.

You’re right about the mapping between IR instruction number and PC. I do realize adding the intrinsic in the IR wouldn’t lead to the exact return address – the store/restore procedure for each call site is call site/architecture-specific for sure. I was hoping to at least get an approximate value and then go from there, but it looks like I’ll have to take another path entirely.

Unfortunately, dumping the return value at runtime isn’t realistic for me. I’m building a tool that needs the mapping of return values between architectures at compile-time. I’m guessing my options are to A. modify the backend to record the return address of each CodeGen’d call (after all optimizations have been applied) or B. Build a stand-alone tool that goes through the generated machine code outside of LLVM.