<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 31, 2010, at 7:05 PM, Chris Lattner wrote:</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Dec 31, 2010, at 12:43 PM, Jakob Stoklund Olesen wrote:</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>1. Pinned local variables are treated no differently than normal local variables except when they are used as operands for inline asm. This is what Rafael's patch implements. I suppose you could warn if such a variable is never used for inline asm.</div></div></blockquote><div>[...]</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>2. Global variables pinned to a reserved register. This is just an odd way of accessing a register, and it is fairly easy to support in the front end by emitting empty inline asm instead of reads and writes to the global.</div></div></blockquote><div><br></div><div>Right, llvm-gcc does this.  This is vaguely bogus but it is (obviously) used and useful to support.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>3. Global variables pinned to an allocatable register. For this to work, the backend must treat the pinned register as reserved, effectively changing the calling convention of all functions in the compilation unit. Other compilation units would have to be built with -ffixed-<i>reg.</i> I really don't want to support this if it can at all be avoided.</div></div></blockquote></div></div></blockquote><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div><div><font class="Apple-style-span" color="#000000">[...]</font></div></div></div></blockquote><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Interestingly enough, GCC emits a warning:</div><div><br></div><div><div>$ cat t.c</div><div>register int foo asm("rax");</div><div>void f() {</div><div>  foo = 42;</div><div>}</div><div><br></div></div><div><div>t.c:1: warning: call-clobbered register used for global register variable</div></div></div></div></blockquote><div><br></div><div>Yes, the documentation says that you should only use callee-saved registers, otherwise any library function you call will clobber your global.</div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><div>My opinion is that the warning is a (really low priority) QoI issue and that we should implement #2 and forget about people who get burned with #3.</div></div></div></div></blockquote><div><br></div><div>I'm fine with that, but it does mean that we silently miscompile #3 because the register can be allocated normally.</div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><div>We should not implement -ffixed-reg if possible IMO, though it has been discussed on llvmdev as useful for people who have GC'd languages etc, and I vaguely recall the Haskell folks doing some work in this area.  To do this right we'd have to do something like this:</div><div><a href="http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt">http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt</a></div></div></div></div></blockquote><div><br></div><div>I would prefer that approach too. It lets the register allocator decide if the register global is really more important than all the locals it interferes with.</div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>We could permit:</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>asm ("" : "={esp}"(foo));</div><div>The curly brace syntax for inline asm constraints also obsoletes pinned local variables.</div></div></blockquote><br></div><div>Lets not extend GCC assembly syntax anymore! :)</div></div></blockquote></div><br><div>Yeah, fair enough.</div><div><br></div><div>/jakob</div><div><br></div></body></html>