[LLVMdev] clobbering callee-save registers

Adam Wick awick at uhsure.com
Sun May 19 12:02:35 PDT 2013


Hello -

Apologies if this is not the right forum for this question. I'd appreciate any pointers.

As background, I was trying to figure out a way to ensure that a function saves all the callee-save registers before executing, rather than just the ones it uses. I had guessed that marking them as clobbered would do this, but it turns out not to. Specifically, I would expect that on the x86-64, this function:

define i32 @testfun(i32 %arg)
{
  tail call void asm sideeffect  "" , "~{%r12},~{%r13}"()
  ret i32 %arg
}

Would cause both r12 and r13 to be pushed in the prologue and popped before returning, but it actually just compiles into this:

_testfun:                               ## @testfun
Ltmp69:
## BB#0:
     ## InlineAsm Start
     ## InlineAsm End
     movl>---%edi, %eax
     ret
Ltmp70:

Just in case it was being very clever, I changed the assembly to actually clobber r12 and r13 with no effect.

So, first: am I misunderstanding the semantics (or syntax) of clobbering a register? It seems surprising to me that this wouldn't mark the register as needing to be saved. Second: Is there a more canonical way to do what I'm trying to do here? I was hoping to inject some assembly that actually does (potentially) clobber some callee-saved registers, and would like a way to tell LLVM about them. Obviously there are other places to save them, as well, but informing LLVM about their usage and getting it to push them to the stack seemed the most elegant.

This is with the release version of LLVM 3.2.

Thanks!


- Adam





More information about the llvm-dev mailing list