<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 17, 2018 at 12:30 AM, Michael Spencer via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Bigcheese created this revision.<br>
Bigcheese added reviewers: espindola, ruiu.<br>
Herald added subscribers: mgorny, mehdi_amini.<br>
<br>
This adds the LLVM side of <a href="https://reviews.llvm.org/D36351" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D36351</a>.<br>
<br>
The purpose of this patch is to get call graph edge counts from LLVM IR to the linker.<br>
<br>
The IR pass uses Block Frequency Info to generate module flags metadata in the format:<br>
<br>
  !28 = !{i32 5, !"CG Profile", !29}<br>
  !29 = !{!30, !31, !32, !33, !34, !35}<br>
  !30 = !{!"main", !"_Z3foov", i64 1}<br>
  !31 = !{!"main", !"_Z3barv", i64 1}<br>
  !32 = !{!"_Z3foov", !"_Z5adenav", i64 6}<br>
  !33 = !{!"_Z3foov", !"puts", i64 1}<br>
  !34 = !{!"_Z3barv", !"puts", i64 1}<br>
  !35 = !{!"_Z5adenav", !"puts", i64 10}<br>
<br>
Where `!28` is the modules flag for call graph profile info whose 3rd element is a list of (from name, to name, count) triplets.<br>
<br>
This data is then written to the object file in the `.note.llvm.cgprofile` section as an array of:<br>
<br>
uint32_t: From Symbol Index<br>
uint32_t: To Symbol Index<br>
uint64_t: Call Count<br>
<br>
This also adds the `.cg_profile` directive to the assembly parser/printer as:<br>
<br>
`.cg_profile <from symbol name>, <to symbol name>, <call count>`<br>
<br>
Which generates the above triplets.<br>
<br>
I've yet to write non-lld tests for this, and I'll do so before commit.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D42161" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D42161</a><br>
<br>
Files:<br>
  include/llvm/InitializePasses.<wbr>h<br>
  include/llvm/LinkAllPasses.h<br>
  include/llvm/MC/MCAssembler.h<br>
  include/llvm/MC/MCELFStreamer.<wbr>h<br>
  include/llvm/MC/MCStreamer.h<br>
  include/llvm/Object/ELFTypes.h<br>
  include/llvm/Transforms/<wbr>Instrumentation.h<br>
  lib/CodeGen/<wbr>TargetLoweringObjectFileImpl.<wbr>cpp<br>
  lib/MC/ELFObjectWriter.cpp<br>
  lib/MC/MCAsmStreamer.cpp<br>
  lib/MC/MCELFStreamer.cpp<br>
  lib/MC/MCParser/ELFAsmParser.<wbr>cpp<br>
  lib/MC/MCStreamer.cpp<br>
  lib/Transforms/IPO/<wbr>PassManagerBuilder.cpp<br>
  lib/Transforms/<wbr>Instrumentation/CGProfile.cpp<br>
  lib/Transforms/<wbr>Instrumentation/CMakeLists.txt<br>
  lib/Transforms/<wbr>Instrumentation/<wbr>Instrumentation.cpp<br>
  tools/llvm-readobj/ELFDumper.<wbr>cpp<br>
  tools/llvm-readobj/ObjDumper.h<br>
  tools/llvm-readobj/llvm-<wbr>readobj.cpp<br>
<br>
</blockquote></div><br></div><div class="gmail_extra">

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">ping</span><div class="gmail_extra" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br clear="all"><div><div class="gmail_signature">- Michael Spencer</div></div></div>

<br></div></div>