Skip to content

Commit d72f51c

Browse files
committed
[Doc] Document prof metadata in LangRef
Summary: Points to existing documentation for branch_weights and function_entry_count, and adds an example for VP value profile metadata. Reviewers: davidxl, reames Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34218 llvm-svn: 305475
1 parent 4749669 commit d72f51c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

llvm/docs/BranchWeightMetadata.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ Branch weights are assigned to every destination.
6464
[ , i32 <LABEL_BRANCH_WEIGHT> ... ]
6565
}
6666
67+
``CallInst``
68+
^^^^^^^^^^^^^^^^^^
69+
70+
Calls may have branch weight metadata, containing the execution count of
71+
the call. It is currently used in SamplePGO mode only, to augment the
72+
block and entry counts which may not be accurate with sampling.
73+
74+
.. code-block:: none
75+
76+
!0 = metadata !{
77+
metadata !"branch_weights",
78+
i32 <CALL_BRANCH_WEIGHT>
79+
}
80+
6781
Other
6882
^^^^^
6983

llvm/docs/LangRef.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,6 +5192,72 @@ Example:
51925192
!0 = !{i32* @a}
51935193
51945194
5195+
'``prof``' Metadata
5196+
^^^^^^^^^^^^^^^^^^^
5197+
5198+
The ``prof`` metadata is used to record profile data in the IR.
5199+
The first operand of the metadata node indicates the profile metadata
5200+
type. There are currently 3 types:
5201+
:ref:`branch_weights<prof_node_branch_weights>`,
5202+
:ref:`function_entry_count<prof_node_function_entry_count>`, and
5203+
:ref:`VP<prof_node_VP>`.
5204+
5205+
.. _prof_node_branch_weights:
5206+
5207+
branch_weights
5208+
""""""""""""""
5209+
5210+
Branch weight metadata attached to a branch, select, switch or call instruction
5211+
represents the likeliness of the associated branch being taken.
5212+
For more information, see :doc:`BranchWeightMetadata`.
5213+
5214+
.. _prof_node_function_entry_count:
5215+
5216+
function_entry_count
5217+
""""""""""""""""""""
5218+
5219+
Function entry count metadata can be attached to function definitions
5220+
to record the number of times the function is called. Used with BFI
5221+
information, it is also used to derive the basic block profile count.
5222+
For more information, see :doc:`BranchWeightMetadata`.
5223+
5224+
.. _prof_node_VP:
5225+
5226+
VP
5227+
""
5228+
5229+
VP (value profile) metadata can be attached to instructions that have
5230+
value profile information. Currently this is indirect calls (where it
5231+
records the hottest callees) and calls to memory intrinsics such as memcpy,
5232+
memmove, and memset (where it records the hottest byte lengths).
5233+
5234+
Each VP metadata node contains "VP" string, then a uint32_t value for the value
5235+
profiling kind, a uint64_t value for the total number of times the instruction
5236+
is executed, followed by uint64_t value and execution count pairs.
5237+
The value profiling kind is 0 for indirect call targets and 1 for memory
5238+
operations. For indirect call targets, each profile value is a hash
5239+
of the callee function name, and for memory operations each value is the
5240+
byte length.
5241+
5242+
Note that the value counts do not need to add up to the total count
5243+
listed in the third operand (in practice only the top hottest values
5244+
are tracked and reported).
5245+
5246+
Indirect call example:
5247+
5248+
.. code-block:: llvm
5249+
5250+
call void %f(), !prof !1
5251+
!1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410}
5252+
5253+
Note that the VP type is 0 (the second operand), which indicates this is
5254+
an indirect call value profile data. The third operand indicates that the
5255+
indirect call executed 1600 times. The 4th and 6th operands give the
5256+
hashes of the 2 hottest target functions' names (this is the same hash used
5257+
to represent function names in the profile database), and the 5th and 7th
5258+
operands give the execution count that each of the respective prior target
5259+
functions was called.
5260+
51955261
Module Flags Metadata
51965262
=====================
51975263

0 commit comments

Comments
 (0)