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.