<div dir="ltr"><span style="font-size:13px">+  mutable const coff_relocation *Reloc = nullptr;</span><br><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">Do we really need `mutable const`? I have a feeling that will leave most people scratching their heads (at least it did for me). Also it might be useful to put `Cache` or `Cached` somewhere in the variable name.</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">-- Sean Silva</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 24, 2015 at 4:03 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Wed Jun 24 18:03:17 2015<br>
New Revision: 240603<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D240603-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=51FuHkp-eHaGtbt1gVpVpu2pVkJAZfHSNwuDtxZkGoY&s=Q4trAwLWRmnwZqIF43K4ineyvHRyf1Pl8qVs-sXSNjo&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=240603&view=rev</a><br>
Log:<br>
COFF: Cache raw pointers to relocation tables.<br>
<br>
Getting an iterator to the relocation table is very hot operation<br>
in the linker. We do that not only to apply relocations but also<br>
to mark live sections and to do ICF.<br>
<br>
libObject's interface is slow. By caching pointers to the first<br>
relocation table entries makes the linker 6% faster to self-link.<br>
<br>
We probably need to fix libObject as well.<br>
<br>
Modified:<br>
    lld/trunk/COFF/Chunks.cpp<br>
    lld/trunk/COFF/Chunks.h<br>
<br>
Modified: lld/trunk/COFF/Chunks.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Chunks.cpp-3Frev-3D240603-26r1-3D240602-26r2-3D240603-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=51FuHkp-eHaGtbt1gVpVpu2pVkJAZfHSNwuDtxZkGoY&s=WJdHsTHesCejMcuIxintn9ti6IjSrHnkxYH16UZ1sqU&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=240603&r1=240602&r2=240603&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Chunks.cpp (original)<br>
+++ lld/trunk/COFF/Chunks.cpp Wed Jun 24 18:03:17 2015<br>
@@ -58,10 +58,8 @@ void SectionChunk::writeTo(uint8_t *Buf)<br>
   memcpy(Buf + FileOff, Data.data(), Data.size());<br>
<br>
   // Apply relocations.<br>
-  for (const auto &I : getSectionRef().relocations()) {<br>
-    const coff_relocation *Rel = File->getCOFFObj()->getCOFFRelocation(I);<br>
+  for (const coff_relocation *Rel = relBegin(), *E = relEnd(); Rel != E; ++Rel)<br>
     applyReloc(Buf, Rel);<br>
-  }<br>
 }<br>
<br>
 void SectionChunk::mark() {<br>
@@ -69,8 +67,8 @@ void SectionChunk::mark() {<br>
   Live = true;<br>
<br>
   // Mark all symbols listed in the relocation table for this section.<br>
-  for (const auto &I : getSectionRef().relocations()) {<br>
-    const coff_relocation *Rel = File->getCOFFObj()->getCOFFRelocation(I);<br>
+  for (const coff_relocation *Rel = relBegin(), *E = relEnd(); Rel != E;<br>
+       ++Rel) {<br>
     SymbolBody *B = File->getSymbolBody(Rel->SymbolTableIndex);<br>
     if (auto *Def = dyn_cast<Defined>(B))<br>
       Def->markLive();<br>
@@ -120,11 +118,11 @@ void SectionChunk::applyReloc(uint8_t *B<br>
 // which need to be fixed by the loader if load-time relocation is needed.<br>
 // Only called when base relocation is enabled.<br>
 void SectionChunk::getBaserels(std::vector<uint32_t> *Res, Defined *ImageBase) {<br>
-  for (const auto &I : getSectionRef().relocations()) {<br>
+  for (const coff_relocation *Rel = relBegin(), *E = relEnd(); Rel != E;<br>
+       ++Rel) {<br>
     // ADDR64 relocations contain absolute addresses.<br>
     // Symbol __ImageBase is special -- it's an absolute symbol, but its<br>
     // address never changes even if image is relocated.<br>
-    const coff_relocation *Rel = File->getCOFFObj()->getCOFFRelocation(I);<br>
     if (Rel->Type != IMAGE_REL_AMD64_ADDR64)<br>
       continue;<br>
     SymbolBody *Body = File->getSymbolBody(Rel->SymbolTableIndex);<br>
@@ -156,12 +154,6 @@ void SectionChunk::printDiscardedMessage<br>
   }<br>
 }<br>
<br>
-SectionRef SectionChunk::getSectionRef() const {<br>
-  DataRefImpl Ref;<br>
-  Ref.p = uintptr_t(Header);<br>
-  return SectionRef(Ref, File->getCOFFObj());<br>
-}<br>
-<br>
 StringRef SectionChunk::getDebugName() {<br>
   return Sym->getName();<br>
 }<br>
@@ -196,12 +188,10 @@ bool SectionChunk::equals(const SectionC<br>
     return false;<br>
<br>
   // Compare relocations<br>
-  auto Range1 = getSectionRef().relocations();<br>
-  auto Range2 = X->getSectionRef().relocations();<br>
-  auto End = Range1.end();<br>
-  for (auto I = Range1.begin(), J = Range2.begin(); I != End; ++I, ++J) {<br>
-    const coff_relocation *Rel1 = File->getCOFFObj()->getCOFFRelocation(*I);<br>
-    const coff_relocation *Rel2 = X->File->getCOFFObj()->getCOFFRelocation(*J);<br>
+  const coff_relocation *Rel1 = relBegin();<br>
+  const coff_relocation *End = relEnd();<br>
+  const coff_relocation *Rel2 = X->relBegin();<br>
+  for (; Rel1 != End; ++Rel1, ++Rel2) {<br>
     if (Rel1->Type != Rel2->Type)<br>
       return false;<br>
     if (Rel1->VirtualAddress != Rel2->VirtualAddress)<br>
@@ -230,6 +220,22 @@ void SectionChunk::replaceWith(SectionCh<br>
   Live = false;<br>
 }<br>
<br>
+const coff_relocation *SectionChunk::relBegin() const {<br>
+  if (!Reloc) {<br>
+    DataRefImpl Ref;<br>
+    Ref.p = uintptr_t(Header);<br>
+    SectionRef Sref(Ref, File->getCOFFObj());<br>
+    relocation_iterator It = Sref.relocation_begin();<br>
+    Reloc = File->getCOFFObj()->getCOFFRelocation(*It);<br>
+  }<br>
+  return Reloc;<br>
+}<br>
+<br>
+const coff_relocation *SectionChunk::relEnd() const {<br>
+  const coff_relocation *I = relBegin();<br>
+  return I + Header->NumberOfRelocations;<br>
+}<br>
+<br>
 CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) {<br>
   // Common symbols are aligned on natural boundaries up to 32 bytes.<br>
   // This is what MSVC link.exe does.<br>
<br>
Modified: lld/trunk/COFF/Chunks.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Chunks.h-3Frev-3D240603-26r1-3D240602-26r2-3D240603-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=51FuHkp-eHaGtbt1gVpVpu2pVkJAZfHSNwuDtxZkGoY&s=Gd0A3AZSW17TzLutd2EUnkhO4b_mqEsW-Hc1g2NDzjY&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=240603&r1=240602&r2=240603&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/COFF/Chunks.h (original)<br>
+++ lld/trunk/COFF/Chunks.h Wed Jun 24 18:03:17 2015<br>
@@ -149,12 +149,16 @@ public:<br>
<br>
 private:<br>
   void mark() override;<br>
-  SectionRef getSectionRef() const;<br>
   void applyReloc(uint8_t *Buf, const coff_relocation *Rel);<br>
<br>
   // A file this chunk was created from.<br>
   ObjectFile *File;<br>
<br>
+  // A raw pointer to the relocation table.<br>
+  mutable const coff_relocation *Reloc = nullptr;<br>
+  const coff_relocation *relBegin() const;<br>
+  const coff_relocation *relEnd() const;<br>
+<br>
   // A pointer pointing to a replacement for this chunk.<br>
   // Initially it points to "this" object. If this chunk is merged<br>
   // with other chunk by ICF, it points to another chunk,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>