[LLVMdev] Improving support for the "Cold" Calling Convention

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Jan 14 13:38:50 PST 2013


On Dec 28, 2012, at 6:03 PM, Will Dietz <willdtz at gmail.com> wrote:

> I'm interested in fixing PR14481 (http://llvm.org/PR14481), regarding
> teaching LLVM that coldcc functions do not clobber any registers.
> 
> As a brief motivation why: this can have a significant performance
> benefits and is very useful for instrumenting code with many calls
> that are executed only very rarely.  Ubsan's runtime calls are a good
> example of this.

Hi Will,

Thanks for working on this, I think it would be great to have better support for ColdCC.

Unfortunately, the description in CallingConv.h of ColdCC as "preserves all registers" is probably a bit naïve. Some more work is required before it makes sense.

As a trivial example: Your patch claims that ColdCC calls preserve the instruction pointer, but if that were true, you would have an infinite loop.

It is only possible to preserve registers that can actually be saved - the ColdCC function may be calling other functions without the ColdCC calling convention, so it would need to save any registers they may clobber.

You also need to figure out how ColdCC functions return values. In %rax? Does a ColdCC function need to preserve the argument registers?

The x87 floating point stack registers and the aliasing MMX registers have their own set of problems that probably aren't worthwhile trying to fix.

Finally, I don't think it is possible to preserve the AVX registers either. If your ColdCC function is compiled without AVX support, it won't clobber the high part of the %ymm registers itself, but you could be calling other functions that were compiled with AVX support. Those functions may clobber %ymm registers, and the ColdCC function has no way of saving them.

/jakob





More information about the llvm-dev mailing list