[llvm-dev] RFC: To add __attribute__((regmask("preserve/clobbered list here"))) in clang

Joerg Sonnenberger via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 18 10:32:09 PDT 2016

On Fri, Jul 15, 2016 at 02:54:26PM -0700, Mehdi Amini wrote:
> > (1) I really dislike an attribute providing a clobber list. Whether a
> > given register is clobbered or not is an implementation detail of a
> > specific version and can easily change. It is also something difficult
> > to reason about. The invariance that should be put into the ABI contract
> > is the inverse -- what registers a function is going to preserve. That
> > is even more important when looking at long time ABI stability. New
> > registers are introduced every so often. That shouldn't change the
> > meaning of a declaration.
> Interestingly your last point is the reason why I'd think a clobber
> list could be more appropriate for some cases: if I have a hand-written
> assembly function, and it is clobbering some registers, the fact that
> the client code enables AVX2 won’t make my routine clobbering these.

I want to be as defensive about assumptions as possible. Mixing code
with different compilation options, inlining etc. can all have funny
side effects, so I think it is really important to avoid making
unnecessary and questionable assumptions. The difference for persist vs
clobber list in the error cases is quite different. If the persist list
is too large, at most it will cause a performance penalty. A clobber
list that isn't correct will result in difficult to trace down
miscompiles. There is a lot of code that could benefit e.g. from a
mostly-preserve-all dprintf and the like. I think that's a valid use
case and shows that ABI implications should be kept in mind.

> Maybe a syntax with +/- could be used to express things like “all vector registers but these”.

Yes, there are a number of different ways to allow compact
specifications. The primary concern for me is that "vector register"
as base class is replaced with the appropiate ISA register classes
(matching the ISA features that added them). But in general, I believe
even a full manual specification of a preserve list can be very compact
and not much larger than a clobber list, if at all.


More information about the llvm-dev mailing list