On Wed, Aug 3, 2011 at 11:50 AM, Georg-Johann Lay <a...@gjlay.de> wrote: > Ulrich Weigand wrote: >> Richard Guenther wrote: >>> On Tue, Aug 2, 2011 at 3:23 PM, Ian Lance Taylor <i...@google.com> wrote: >>>> Richard Guenther <richard.guent...@gmail.com> writes: >>>>> I suggest to amend the documentation for local call-clobbered register >>>>> variables to say that the only valid sequence using them is from a >>>>> non-inlinable function that contains only direct initializations of the >>>>> register variables from constants or parameters. >>>> Let's just implement those requirements in the compiler itself. >>> Doesn't work for existing code, no? And if thinking new code then >>> I'd rather have explicit dependences (and a way to represent them). >>> Thus, for example >>> >>> asm ("scall" : : "asm("r0")" (10), ...) >>> >>> thus, why force new constraints when we already can figure out >>> local register vars by register name? Why not extend the constraint >>> syntax somehow to allow specifying the same effect? > > Yes this would be exact equivalence of > > register int var asm ("r0") = 10; > ... > asm ("scall" : : "r" (var), ...) > > >> Maybe it would be possible to implement this while keeping the syntax >> of existing code by (re-)defining the semantics of register asm to >> basically say that: >> >> If a variable X is declared as register asm for register Y, and X >> is later on used as operand to an inline asm, the register allocator >> will choose register Y to hold that asm operand. (And this is the >> full specification of register asm semantics, nothing beyond this >> is guaranteed.) > > Yes, that's reasonable. As I understand the docs, in code like > > void foo () > { > register int var asm ("r1") = 10; > asm (";; use r1"); > } > > there is nothing that connects var to the asm and assuming that > r1 holds 10 in the asm is a user error. > > The only place where the asm attached to a variable needs to have > effect are the inline asm sequences that explicitly refer to > respective variables. If there is no inline asm referencing a > local register variable, there is on difference to a non-register > auto variable; there could even be a warning that in such a case > that > > register int var asm ("r1") = 10; > > is equivalent to > > int var = 10; > >> It seems this semantics could be implemented very early on, probably >> in the frontend itself. The frontend would mark the *asm* statement >> as using the specified register (there would be no special handling >> of the *variable* as such, after the frontend is done). The optimizers >> would then simply be required to pass the asm-statement register >> annotations though, much like today they pass constraints through. >> At the point where register allocation decisions are made, those >> register annotations would then be acted on. >> >> Bye, >> Ulrich > > I wonder why it does not work like that in the current implementation. > Local register variable is just like using a similar constraint > (with the only difference that in general there is no such constraint, > otherwise the developer would use it). A pass like .asmcons could > take care of it just the same way it does for constraints and no > optimizer passed would have to bother if a variable is a local register > or not. > > This would render local register variables even more functional > because no one needed to care if there were implicit library calls > or things like that.
Yes, I like that idea. Richard.