[PATCH] D42161: Add Call Graph Profile pass and ELF assembly support

Michael Spencer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 00:30:46 PST 2018


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

This adds the LLVM side of https://reviews.llvm.org/D36351.

The purpose of this patch is to get call graph edge counts from LLVM IR to the linker.

The IR pass uses Block Frequency Info to generate module flags metadata in the format:

  !28 = !{i32 5, !"CG Profile", !29}
  !29 = !{!30, !31, !32, !33, !34, !35}
  !30 = !{!"main", !"_Z3foov", i64 1}
  !31 = !{!"main", !"_Z3barv", i64 1}
  !32 = !{!"_Z3foov", !"_Z5adenav", i64 6}
  !33 = !{!"_Z3foov", !"puts", i64 1}
  !34 = !{!"_Z3barv", !"puts", i64 1}
  !35 = !{!"_Z5adenav", !"puts", i64 10}

Where `!28` is the modules flag for call graph profile info whose 3rd element is a list of (from name, to name, count) triplets.

This data is then written to the object file in the `.note.llvm.cgprofile` section as an array of:

uint32_t: From Symbol Index
uint32_t: To Symbol Index
uint64_t: Call Count

This also adds the `.cg_profile` directive to the assembly parser/printer as:

`.cg_profile <from symbol name>, <to symbol name>, <call count>`

Which generates the above triplets.

I've yet to write non-lld tests for this, and I'll do so before commit.


Repository:
  rL LLVM

https://reviews.llvm.org/D42161

Files:
  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/MCStreamer.cpp
  lib/Transforms/IPO/PassManagerBuilder.cpp
  lib/Transforms/Instrumentation/CGProfile.cpp
  lib/Transforms/Instrumentation/CMakeLists.txt
  lib/Transforms/Instrumentation/Instrumentation.cpp
  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: D42161.130098.patch
Type: text/x-patch
Size: 23409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/b6884940/attachment.bin>


More information about the llvm-commits mailing list