<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 21, 2016 at 2:18 AM, Neil Henning <span dir="ltr"><<a href="mailto:llvm@duskborn.com">llvm@duskborn.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 bgcolor="#FFFFFF">
    Hey all,<br>
    <br>
    For LinkModules, <i><b>dest</b></i> is a fully materialized module,
    <i><b>src</b></i> is a lazily loaded module.<br></div></blockquote><div><br></div><div>It's not clear to me then why your change to materialize the dest copy is helping then.</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"><div bgcolor="#FFFFFF">
    <br>
    From what I understood, getLinkedToGlobal() is finding the function
    in <i><b>src</b></i> that matches some function declaration in <i><b>dest</b></i>,
    and given that <i><b>src</b></i> is lazily loaded it could be
    un-materialized.<br></div></blockquote><div><br></div><div>It does the reverse (finds function in dest that matches function in src):</div><br>  /// Given a global in the source module, return the global in the<br>  /// destination module that is being linked to, if any.<br>  GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) {</div><div class="gmail_quote"><pre style="margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);padding-top:0.5em;outline:none;font-size:medium;line-height:16.25px"><span style="display:block"><br></span></pre><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 bgcolor="#FFFFFF">
    The functions I need brought in from <i><b>src</b></i><i><b></b></i>
    into <i><b>dest</b></i> are always declarations in <i><b>dest</b></i>.
    The problem is that (for some reason) the combination of
    Linker::LinkOnlyNeeded and a function that is not materialized will
    not copy the function body from <i><b>src</b></i> into <i><b>dest</b></i>. </div></blockquote><div><br></div><div>From your subsequent email:</div><span style="font-size:12.8px">> So (post morning-coffee) - I did some more digging.</span><br style="font-size:12.8px">> <br style="font-size:12.8px"><span style="font-size:12.8px">> It seems that it will correctly bring over a function from </span><i style="font-size:12.8px"><b>src</b></i><span style="font-size:12.8px"> that is explicitly called in </span><i style="font-size:12.8px"><b>dest</b></i><span style="font-size:12.8px">, but it won't bring over any functions</span></div><div class="gmail_quote"><span style="font-size:12.8px">> that are called by a </span><i style="font-size:12.8px"><b>src</b></i><span style="font-size:12.8px"> function from another </span><i style="font-size:12.8px"><b>src </b></i><span style="font-size:12.8px">function.</span></div><div class="gmail_quote"><span style="font-size:12.8px">> I may have dug too deep in the rabbit hole when blaming lazily loaded modules for the fault - is it perhaps as simple as</span></div><div class="gmail_quote"><span style="font-size:12.8px">> LinkOnlyNeeded does not work when importing a function that calls another function?</span> </div><div class="gmail_quote"><br></div><div class="gmail_quote">So in that case linkIfNeeded will return false since you have LinkOnlyNeeded and there is no declaration in the dest module (it isn't needed by the dest module). I'm not completely sure what should happen here with LinkOnlyNeeded. There is handling in the IRMover to lazily add references to link that are encountered when copying over bodies, however, this only happens when the reference value is LinkOnce (since it could be discarded in the source module). It may be that in the case LinkOnlyNeeded is designed for this functionality wasn't needed - it was specific to a special situation in linking CUDA, see <a href="http://reviews.llvm.org/D12459">http://reviews.llvm.org/D12459</a>. I'm guessing to handle your case you would want to change ModuleLinker::addLazyFor() to be more aggressive in the LinkOnlyNeeded case.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Teresa</div><div class="gmail_quote"> <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 bgcolor="#FFFFFF">
    <br>
    Cheers,<br>
    -Neil.<div><div><br>
    <br>
    <div>On 20/04/16 20:39, Teresa Johnson
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Wed, Apr 20, 2016 at 12:28 PM,
            Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com"></a><a href="mailto:rafael.espindola@gmail.com">rafael.espindola@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"><span>
                      <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 style="word-wrap:break-word">
                          <div>
                            <div>
                              <div>
                                <div><br>
                                </div>
                              </div>
                            </div>
                            <div>I understood from his description that
                              he reversed the destination and source so
                              that destination is the user code.</div>
                            <div>I assumed it was not lazy loaded, but
                              that would explain the question then :)</div>
                            <div><br>
                            </div>
                            <div>Neil: can you clarify? If Teresa is
                              right, why aren't you materializing the
                              destination module entirely?</div>
                            <span>
                              <div><br>
                              </div>
                            </span></div>
                        </div>
                      </blockquote>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                    </span>
                    <div>I don't think it has ever been tried to use a
                      lazy destination. Having said that, I don't think
                      isMaterializable should return true for a
                      declaration.</div>
                  </div>
                </div>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>Looking at isMaterializable, I'm now a little confused
              about Neil's case - the materializable bit is set to true
              only when the MODULE_CODE_FUNCTION indicated that it was
              !isproto, which means it should have a definition in that
              module. So I agree with you that isMaterializable
              shouldn't be returning true when the symbol is only
              available as a declaration. <br>
            </div>
            <div><br>
            </div>
            <div>Neil - what case are you trying to handle here? If
              there is a materializable definition in the dest module,
              wouldn't you want to use that instead of linking one in
              from the source module?</div>
            <div><br>
            </div>
            <div>Teresa</div>
            <div><br>
            </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 dir="ltr">
                <div class="gmail_extra">
                  <div class="gmail_quote"><span>
                      <div><br>
                      </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 style="word-wrap:break-word">
                          <div><span>
                              <div><br>
                              </div>
                            </span>
                            <div>Even materializing functions from the
                              source module on the fly isn't supported
                              right now, is it?</div>
                            <span><font color="#888888">
                                <div><br>
                                </div>
                              </font></span></div>
                        </div>
                      </blockquote>
                      <div> </div>
                    </span>
                    <div>It is.</div>
                    <div><br>
                    </div>
                    <div>Neil, the flag is linked to
                      llvm-link's -only-needed command line option. At
                      least for simple cases it seems to be working.
                      Given</div>
                    <div><br>
                    </div>
                    <div>
                      <div>declare void @g()</div>
                      <div>define void @f() {</div>
                      <div>  call void @g()</div>
                      <div>  ret void</div>
                      <div>}</div>
                    </div>
                    <div><br>
                    </div>
                    <div>and</div>
                    <div><br>
                    </div>
                    <div>
                      <div>define void @g() {</div>
                      <div>  ret void</div>
                      <div>}</div>
                      <div>define void @h() {</div>
                      <div>  ret void</div>
                      <div>}</div>
                    </div>
                    <div><br>
                    </div>
                    <div><br>
                    </div>
                    <div>linking with "llvm-link -only-needed test1.bc
                      test2.bc" will bring in g, but not h. Can you
                      write a testcase showing what you were expecting
                      it to do but it is not?</div>
                    <div><br>
                    </div>
                    <div>Cheers,</div>
                    <div>Rafael</div>
                    <div><br>
                    </div>
                  </div>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
          <br clear="all">
          <div><br>
          </div>
          -- <br>
          <div><span style="font-family:times;font-size:medium">
              <table cellpadding="0" cellspacing="0">
                <tbody>
                  <tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small">
                    <td style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px" nowrap>Teresa Johnson |</td>
                    <td style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px" nowrap> Software Engineer |</td>
                    <td style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px" nowrap> <a href="mailto:tejohnson@google.com">tejohnson@google.com</a> |</td>
                    <td style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px" nowrap> <a href="tel:408-460-2413" value="+14084602413">408-460-2413</a></td>
                  </tr>
                </tbody>
              </table>
            </span></div>
        </div>
      </div>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><span style="font-family:times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com">tejohnson@google.com</a> |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> <a href="tel:408-460-2413" value="+14084602413">408-460-2413</a></td></tr></tbody></table></span></div>
</div></div>