<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 25, 2016, at 9:09 AM, Chandler Carruth via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Oct 24, 2016 at 10:48 PM Chris Lattner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="gmail_msg" style="word-wrap: break-word;"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Oct 24, 2016, at 1:07 PM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" class="gmail_msg" target="_blank">peter@pcc.me.uk</a>> wrote:</div><br class="gmail_msg m_4142622730276185891Apple-interchange-newline"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">On Mon, Oct 10, 2016 at 8:12 PM, Peter Collingbourne<span class="Apple-converted-space"> </span><span dir="ltr" class="gmail_msg"><<a href="mailto:peter@pcc.me.uk" class="gmail_msg" target="_blank">peter@pcc.me.uk</a>></span><span class="Apple-converted-space"> </span>wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">The specific change I have in mind is to allow !range metadata on GlobalObjects. This would<br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">be similar to existing !range metadata, but it would apply to the "address" of the attached GlobalObject, rather than any value loaded from it. Its presence on a GlobalObject would also imply that the address of the GlobalObject is "fixed" at link time.</div></div></div></blockquote><div class="gmail_msg"> </div><div class="gmail_msg">Going back to IR-level representation: here is an alternative representation based on a suggestion from Eli.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Introduce a new type of GlobalValue called GlobalConstant. GlobalConstant would fit into the GlobalValue hierarchy like this:</div><div class="gmail_msg"><ul class="gmail_msg"><li class="gmail_msg">GlobalValue<br class="gmail_msg"></li><ul class="gmail_msg"><li class="gmail_msg">GlobalConstant</li><li class="gmail_msg">GlobalPointer</li><ul class="gmail_msg"><li class="gmail_msg">GlobalIndirectSymbol</li><ul class="gmail_msg"><li class="gmail_msg">GlobalAlias</li><li class="gmail_msg">GlobalIFunc</li></ul><li class="gmail_msg">GlobalObject</li><ul class="gmail_msg"><li class="gmail_msg">Function</li><li class="gmail_msg">GlobalVariable</li></ul></ul></ul></ul><div class="gmail_msg">GlobalValue would no longer be assumed to be of pointer type. The getType() overload that takes a PointerType, as well as getValueType() would be moved down to GlobalPointer. (A nice side benefit of this is that it would help flush out cases where we are unnecessarily depending on global pointee types.)</div></div></div></div></div></div></blockquote><br class="gmail_msg"></div></div><div class="gmail_msg" style="word-wrap: break-word;"><div class="gmail_msg">Hi Peter,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I agree that it makes sense to introduce a new GlobalConstant IR node for this sort of thing.  That said, have you considered a design where GlobalConstant is still required to be a pointer type?  If you did this, you would end up with a simpler and less invasive design of:</div><div class="gmail_msg"><ul class="gmail_msg"><li class="gmail_msg">GlobalValue<br class="gmail_msg"></li><ul class="gmail_msg"><li class="gmail_msg">GlobalConstant</li></ul></ul></div></div><div class="gmail_msg" style="word-wrap: break-word;"><div class="gmail_msg"><ul class="gmail_msg"><ul class="gmail_msg"><li class="gmail_msg">GlobalIndirectSymbol</li><ul class="gmail_msg"><li class="gmail_msg">GlobalAlias</li><li class="gmail_msg">GlobalIFunc</li></ul><li class="gmail_msg">GlobalObject</li><ul class="gmail_msg"><li class="gmail_msg">Function</li><li class="gmail_msg">GlobalVariable</li></ul></ul></ul></div></div><div class="gmail_msg" style="word-wrap: break-word;"><div class="gmail_msg"><ul class="gmail_msg"><ul class="gmail_msg"></ul></ul><div class="gmail_msg">I think that this would be better for (e.g.) the X86 backend anyway, since global objects can be assigned to specific addresses with linker maps, and thus have small addresses (and this is expressible with the range metadata).  This means that GlobalConstant and other GlobalValues should all be usable in the same places in principle.</div></div></div></blockquote><div class=""><br class=""></div><div class="">If this works, it does seem better. But I can imagine it being hard to take the "load" of the global constant and turn it into a direct reference to a symbolic immediate operand to an instruction.</div></div></div></div></blockquote><div><br class=""></div><div>The linker “could" do it I think. For example ld64 is pattern matching to "optimize away” load from the GOT when possible, replacing then with nop and propagating the constant address.</div><div><br class=""></div><div>It is still not perfect, as a register has to be used sometimes, and the nop will still be there taking space. But that may be enough for this use case?</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">And it isn't clear that you can assign the "foo" in Peter's example an address even with a linker map -- it isn't a global object at all, it is a symbolic name for an immediate IIUC? (It's entirely possible I've misunderstood either what Peter needs or what you're suggesting, but I'd at least like to understand it! =D)</div><div class=""><br class=""></div><div class="">-Chandler</div></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></body></html>