<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 25, 2014 at 11:36 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="">On Mon, Aug 25, 2014 at 11:08 AM, Akira Hatanaka <span dir="ltr"><<a href="mailto:ahatanak@gmail.com" target="_blank">ahatanak@gmail.com</a>></span> wrote:<br>
<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 dir="ltr">I think this is preventing constants in the constant pool (e.g., floating point literal) from being placed in the mergeable constant sections?<div>
<br></div><div>We want to keep the const arrays declared in the program (s_dashArraySize1) out of the mergeable constant sections, but don't mind placing constants in the constant pool or constant arrays that the compiler defines, such as switch.table and memset_pattern, in the mergeable sections.</div>
</div></blockquote><div><br></div></div><div>Ah, ok.</div><div><br></div><div><div>diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div><div>index 55e1756..93f33af 100644</div>
<div>--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div><div>+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div><div>@@ -626,15 +626,6 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,</div><div>
cast<GlobalVariable>(GV)) < 32)</div><div> return UStringSection;</div><div> </div><div>- if (Kind.isMergeableConst()) {</div><div class=""><div>- if (Kind.isMergeableConst4())</div><div>- return FourByteConstantSection;</div>
<div>- if (Kind.isMergeableConst8())</div><div>- return EightByteConstantSection;</div><div>- if (Kind.isMergeableConst16())</div><div>- return SixteenByteConstantSection;</div></div><div>- }</div><div>-</div>
<div>
// Otherwise, if it is readonly, but not something we can specially optimize,</div><div> // just drop it in .const.</div><div> if (Kind.isReadOnly())</div></div><div><br></div><div>$ echo 'static const int s_dashArraysSize1[4] = {2, 2, 4, 6};</div>
<div class="">
<div><br></div><div>int foo1(int a) {</div><div> return s_dashArraysSize1[a];</div></div><div>}' | ~/llvm/Debug+Asserts/bin/clang -x c -target i686-apple-darwin11 - -S -o -</div><div><br></div><div><div> .section __TEXT,__text,regular,pure_instructions</div>
<div> .macosx_version_min 10, 7</div><div> .globl _foo1</div><div> .align 4, 0x90</div><div>_foo1: ## @foo1</div><div>## BB#0: ## %entry</div>
<div> pushl %ebp</div><div> movl %esp, %ebp</div><div> pushl %eax</div><div> calll L0$pb</div><div>L0$pb:</div><div> popl %eax</div><div> movl 8(%ebp), %ecx</div><div>
movl %ecx, -4(%ebp)</div><div> movl -4(%ebp), %ecx</div><div> movl _s_dashArraysSize1-L0$pb(%eax,%ecx,4), %eax</div><div> addl $4, %esp</div><div> popl %ebp</div><div> retl </div>
<div> </div><div> .section __TEXT,__const</div><div> .align 2 ## @s_dashArraysSize1</div><div class=""><div>_s_dashArraysSize1:</div><div> .long 2 ## 0x2</div>
<div> .long 2 ## 0x2</div><div> .long 4 ## 0x4</div><div> .long 6 ## 0x6</div></div></div><div><br></div><div>Is this what you wanted?</div>
<div><div class="h5">
<div> </div></div></div></div></div></div></blockquote><div><br></div><div>This assembly output looks fine, but probably the change made in SelectSectionForGlobal will place constants such as switch.table and memset_pattern in __const too, which isn't what we want.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><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 dir="ltr">
</div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 25, 2014 at 10:37 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<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 dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><div>On Mon, Aug 25, 2014 at 9:54 AM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br>
<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><div><br>
On Aug 25, 2014, at 8:26 AM, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> wrote:<br>
<br>
> On 21 August 2014 19:32, Akira Hatanaka <<a href="mailto:ahatanak@gmail.com" target="_blank">ahatanak@gmail.com</a>> wrote:<br>
>> Is there a way to distinguish between GlobalValues that are user-defined and<br>
>> those that are compiler-defined? I am looking for a function that I can use<br>
>> to tell if a GlobalValue is user-defined , something like<br>
>> "GlobalValue::isUserDefined", which returns true for user-defined<br>
>> GlobalValue.<br>
>><br>
>> I'm trying to make changes to prevent llvm from placing user-defined<br>
>> constant arrays in the merge able constant sections. Currently, clang places<br>
>> 16-byte constant arrays that are marked "unnamed_addr" into __literal16 for<br>
>> macho (see following example).<br>
>><br>
>> $ cat test1.c<br>
>><br>
>> static const int s_dashArraysSize1[4] = {2, 2, 4, 6};<br>
>><br>
>><br>
>> int foo1(int a) {<br>
>><br>
>> return s_dashArraysSize1[a];<br>
>><br>
>> }<br>
>><br>
>><br>
>> $ clang test1.c -S -O3 -o - | tail -n 10<br>
>><br>
>> .section __TEXT,__literal16,16byte_literals<br>
>><br>
>> .align 4 ## @s_dashArraysSize1<br>
>><br>
>> _s_dashArraysSize1:<br>
>><br>
>> .long 2 ## 0x2<br>
>><br>
>> .long 2 ## 0x2<br>
>><br>
>> .long 4 ## 0x4<br>
>><br>
>> .long 6 ## 0x6<br>
>><br>
>><br>
>><br>
>> This is not desirable because macho linker wasn't originally designed to<br>
>> handle user-defined symbols in those sections and having to handle them<br>
>> complicates the linker. Also, there is no benefit in doing so, since the<br>
>> linker currently doesn't try to merge user-defined variables anyway.<br>
><br>
> What does "user-defined" means in here? Since the linker can is<br>
> involved, I assume it has something to do with the final symbol name.<br>
><br>
> At the linker level (symbol names, sections, atoms, relocations, etc),<br>
> what exactly that is not supported?<br>
<br>
<br>
</div></div>The literalN sections were developed long ago to support coalescing of unnamed constants like 9.897 in source code for architectures that could not embed large constants in instructions. The linker could knew how to break up the section (e.g. __literal8 is always 8 byte chunks) and coalesce copies by content.<br>
<br>
~6 years ago we discovered that gcc would sometimes put user named constants into the literal sections (e.g. const double foo 9.897). This was an issue because C language rules say &a != &b, but if ‘a’ and ‘b’ are the contain the same literal value from different translation units, the linker could merge them to the same address. For whatever reason, we could not fix gcc, so we changed to linker to never coalesce items in literal sections if there was a (non ‘L’ and non ‘l’) symbol on it.<br>
<br>
The current state of LLVM is that is it going out of its way to move “named” constants from __const section to __literalN section. But the only possible advantage to doing that is that the hopes that the linker might coalesce it. But the linker won’t coalesce it because it is named. So, is there a way to keep the named values in the __const section?<br>
</blockquote><div><br></div></div></div><div>I believe the following patch would be the minimal needed to do this, there is some dead code that could be removed as well.</div><div><br></div><div><div>diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div>
<div>index 55e1756..bf78ce1 100644</div><div>--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div><div>+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp</div><div>@@ -667,12 +667,6 @@ TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind,</div>
<div> if (Kind.isDataRel() || Kind.isReadOnlyWithRel())</div><div> return ConstDataSection;</div><div> </div><div>- if (Kind.isMergeableConst4())</div><div>- return FourByteConstantSection;</div><div>- if (Kind.isMergeableConst8())</div>
<div>- return EightByteConstantSection;</div><div>- if (Kind.isMergeableConst16())</div><div>- return SixteenByteConstantSection;</div><div> return ReadOnlySection; // .const</div><div> }</div></div><div> </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">
<span><font color="#888888"><br>
-Nick<br>
</font></span><div><div><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>