<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 12:43 PM, Jakob Stoklund Olesen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 31, 2010, at 11:34 AM, Benjamin Kramer wrote:</div><blockquote type="cite"><div>To sum this up, should we consider using local register vars outside of asm statements<br>unsafe and just ignore them (as we do now)? While GCC supports them to some extent I don't<br>think it's worth to support it just to enable some premature optimizations. We don't even<br>need a warning in that case.</div></blockquote></div><br><div>There are three cases:</div><div><br></div><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><br></div><div>Yes, this sounds right. The warning should be something like "warning: register assignment ignored" to give people a head's up that they have useless code.</div><div><br></div><div>Right, llvm-gcc implements this, but not the warning. This is useful and documented by the GCC manual.</div><div><br></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><br></div><div>It is very hard for the frontend to distinguish between 2. and 3., it would have to know if a register is reserved. Even the backend has a hard time telling when %ebp (the frame pointer) is reserved.</div><div><br></div><div>I think we should consider not supporting pinned global variables, and instead provide a way of reading and writing specific registers with inline asm constraints.</div><div><br></div><div>Instead of:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>register unsigned long current_stack_pointer asm("esp");<br><span class="Apple-tab-span" style="white-space:pre"> </span>foo = current_stack_pointer;</div><div><br></div></div></blockquote><div><br></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><br></div><div>llvm-gcc doesn't produce the warning, and it compiles this into:</div><div><br></div><div><div>target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"</div><div>target triple = "x86_64-apple-darwin10.5"</div><div><br></div><div>define void @f() nounwind ssp noredzone {</div><div>entry:</div><div> tail call void asm sideeffect "", "{rax}"(i32 42) nounwind</div><div> ret void</div><div>}</div></div><div><br></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><br></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><br><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><br></div><div>-Chris</div><br></body></html>