[PATCH] D44965: [llvm][Instrumentation/MC] Add Call Graph Profile pass and object file emission.

Michael Spencer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 27 17:11:09 PDT 2018


Bigcheese created this revision.
Bigcheese added reviewers: espindola, mehdi_amini, tejohnson, ruiu.
Herald added subscribers: arichardson, mgorny, emaste.

This patch adds support for generating a call graph profile from Branch Frequency Info and embedding that profile into an object file to pass to the linker.  Linker support for this feature (without reading from the object file) is being reviewed at https://reviews.llvm.org/D36351 and appears to be nearing completion.

Generating the CG Profile
-------------------------

The CGProfile module pass simply gets the block profile count for each BB and scans for call instructions.  For each call instruction it adds an edge from the current function to the called function with the current BB block profile count as the weight.

After scanning all the functions, it generates an appending module flag containing the data. The format looks like:

  !llvm.module.flags = !{!0} 
   
  !0 = !{i32 5, !"CG Profile", !1} 
  !1 = !{!2, !3, !4} ; List of edges
  !2 = !{!"a", !"b", i64 32} ; Edge from a to b with a weight of 32
  !3 = !{!"freq", !"a", i64 11} 
  !4 = !{!"freq", !"b", i64 20} 



Object FIle Representation
--------------------------

At codegen time this is emitted into the ELF file a pair of symbol indices and a weight.  In assembly it looks like:

  .cg_profile a, b, 32 
  .cg_profile freq, a, 11 
  .cg_profile freq, b, 20 

When writing an ELF file these are put into a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).


https://reviews.llvm.org/D44965

Files:
  include/llvm/BinaryFormat/ELF.h
  include/llvm/InitializePasses.h
  include/llvm/LinkAllPasses.h
  include/llvm/MC/MCAssembler.h
  include/llvm/MC/MCELFStreamer.h
  include/llvm/MC/MCStreamer.h
  include/llvm/Object/ELFTypes.h
  include/llvm/Transforms/Instrumentation.h
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  lib/MC/ELFObjectWriter.cpp
  lib/MC/MCAsmStreamer.cpp
  lib/MC/MCELFStreamer.cpp
  lib/MC/MCParser/ELFAsmParser.cpp
  lib/MC/MCSectionELF.cpp
  lib/MC/MCStreamer.cpp
  lib/Object/ELF.cpp
  lib/ObjectYAML/ELFYAML.cpp
  lib/Transforms/IPO/PassManagerBuilder.cpp
  lib/Transforms/Instrumentation/CGProfile.cpp
  lib/Transforms/Instrumentation/CMakeLists.txt
  lib/Transforms/Instrumentation/Instrumentation.cpp
  test/Instrumentation/cgprofile.ll
  test/MC/AsmParser/directive_cgprofile.s
  test/MC/ELF/cgprofile.ll
  tools/llvm-readobj/ELFDumper.cpp
  tools/llvm-readobj/ObjDumper.h
  tools/llvm-readobj/llvm-readobj.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44965.139879.patch
Type: text/x-patch
Size: 28632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/d37f4984/attachment.bin>


More information about the llvm-commits mailing list