@@ -9,24 +9,24 @@ Introduction
99============
1010
1111Branch Weight Metadata represents branch weights as its likeliness to be taken
12- (see :doc: `BlockFrequencyTerminology `). Metadata is assigned to an
13- ``Instruction `` that is a terminator as a ``MDNode `` of the ``MD_prof `` kind.
14- The first operator is always a ``MDString `` node with the string
15- "branch_weights". Number of operators depends on the terminator type.
12+ (see :doc: `BlockFrequencyTerminology `). Metadata is assigned to a
13+ terminator ``Instruction `` as an ``MDNode `` of the ``MD_prof `` kind.
14+ The first operand is always an ``MDString `` node with the string
15+ "branch_weights". The number of operands depends on the terminator type.
1616
17- Branch weights might be fetch from the profiling file, or generated based on
18- `__builtin_expect `_ and `__builtin_expect_with_probability `_ instruction .
17+ Branch weights might be fetched from the profiling file or generated based on
18+ `__builtin_expect `_ and `__builtin_expect_with_probability `_ instructions .
1919
20- All weights are represented as an unsigned 32-bit values, where higher value
21- indicates greater chance to be taken.
20+ All weights are represented as unsigned 32-bit values, where a higher value
21+ indicates a greater chance of being taken.
2222
2323Supported Instructions
2424======================
2525
2626``BranchInst ``
2727^^^^^^^^^^^^^^
2828
29- Metadata is only assigned to the conditional branches. There are two extra
29+ Metadata is only assigned to conditional branches. There are two extra
3030operands for the true and the false branch.
3131We optionally track if the metadata was added by ``__builtin_expect `` or
3232``__builtin_expect_with_probability `` with an optional field ``!"expected" ``.
@@ -43,7 +43,7 @@ We optionally track if the metadata was added by ``__builtin_expect`` or
4343 ``SwitchInst ``
4444^^^^^^^^^^^^^^
4545
46- Branch weights are assigned to every case (including the ``default `` case which
46+ Branch weights are assigned to every case (including the ``default `` case, which
4747is always case #0).
4848
4949.. code-block :: none
@@ -74,7 +74,7 @@ Branch weights are assigned to every destination.
7474
7575Calls may have branch weight metadata, containing the execution count of
7676the call. It is currently used in SamplePGO mode only, to augment the
77- block and entry counts which may not be accurate with sampling.
77+ block and entry counts, which may not be accurate with sampling.
7878
7979.. code-block :: none
8080
@@ -89,9 +89,9 @@ block and entry counts which may not be accurate with sampling.
8989
9090Invoke instruction may have branch weight metadata with one or two weights.
9191The second weight is optional and corresponds to the unwind branch.
92- If only one weight is set then it contains the execution count of the call
92+ If only one weight is set, then it contains the execution count of the call
9393and used in SamplePGO mode only as described for the call instruction. If both
94- weights are specified then the second weight contains count of unwind branch
94+ weights are specified then the second weight contains the count of unwind branch
9595taken and the first weights contains the execution count of the call minus
9696the count of unwind branch taken. Both weights specified are used to calculate
9797BranchProbability as for BranchInst and for SamplePGO the sum of both weights
@@ -139,7 +139,7 @@ true, in other case condition is likely to be false. For example:
139139^^^^^^^^^^^^^^^^^^^^
140140
141141The ``exp `` parameter is the value. The ``c `` parameter is the expected
142- value. If the expected value doesn't show on the cases list, the ``default ``
142+ value. If the expected value doesn't appear in the cases list, the ``default ``
143143case is assumed to be likely taken.
144144
145145.. code-block :: c++
@@ -159,15 +159,15 @@ Built-in ``expect.with.probability`` Instruction
159159``__builtin_expect_with_probability(long exp, long c, double probability) `` has
160160the same semantics as ``__builtin_expect ``, but the caller provides the
161161probability that ``exp == c ``. The last argument ``probability `` must be
162- constant floating-point expression and be in the range [0.0, 1.0] inclusive.
162+ a constant floating-point expression and be in the range [0.0, 1.0] inclusive.
163163The usage is also similar as ``__builtin_expect ``, for example:
164164
165165``if `` statement
166166^^^^^^^^^^^^^^^^
167167
168- If the expect comparison value ``c `` is equal to 1(true), and probability
168+ If the expected comparison value ``c `` is equal to 1(true), and probability
169169value ``probability `` is set to 0.8, that means the probability of condition
170- to be true is 80% while that of false is 20%.
170+ being true is 80% while that of false is 20%.
171171
172172.. code-block :: c++
173173
@@ -178,8 +178,8 @@ to be true is 80% while that of false is 20%.
178178``switch `` statement
179179^^^^^^^^^^^^^^^^^^^^
180180
181- This is basically the same as ``switch `` statement in ``__builtin_expect ``.
182- The probability that ``exp `` is equal to the expect value is given in
181+ This is similar to the ``switch `` statement in ``__builtin_expect ``.
182+ The probability that ``exp `` is equal to the expected value is given in
183183the third argument ``probability ``, while the probability of other value is
184184the average of remaining probability(``1.0 - probability ``). For example:
185185
@@ -195,8 +195,8 @@ the average of remaining probability(``1.0 - probability``). For example:
195195CFG Modifications
196196=================
197197
198- Branch Weight Metatada is not proof against CFG changes. If terminator operands'
199- are changed some action should be taken. In other case some misoptimizations may
198+ Branch Weight Metadata is not proof against CFG changes. If terminator operands'
199+ are changed, some action should be taken. Otherwise, misoptimizations may
200200occur due to incorrect branch prediction information.
201201
202202Function Entry Counts
@@ -212,7 +212,7 @@ invoked (in the case of instrumentation-based profiles). In the case of
212212sampling-based profiles, this operand is an approximation of how many times
213213the function was invoked.
214214
215- For example, in the code below, the instrumentation for function foo()
215+ For example, in the code below, the instrumentation for function `` foo() ``
216216indicates that it was called 2,590 times at runtime.
217217
218218.. code-block :: llvm
@@ -222,12 +222,12 @@ indicates that it was called 2,590 times at runtime.
222222 }
223223 !1 = !{!"function_entry_count", i64 2590}
224224
225- If "function_entry_count" has more than 2 operands, the later operands are
225+ If "function_entry_count" has more than 2 operands, the subsequent operands are
226226the GUID of the functions that needs to be imported by ThinLTO. This is only
227- set by sampling based profile. It is needed because the sampling based profile
227+ set by sampling- based profile. It is needed because the sampling- based profile
228228was collected on a binary that had already imported and inlined these functions,
229229and we need to ensure the IR matches in the ThinLTO backends for profile
230230annotation. The reason why we cannot annotate this on the callsite is that it
231- can only goes down 1 level in the call chain. For the cases where
232- foo_in_a_cc()->bar_in_b_cc()->baz_in_c_cc(), we will need to go down 2 levels
233- in the call chain to import both bar_in_b_cc and baz_in_c_cc.
231+ can only go down 1 level in the call chain. For the cases where
232+ `` foo_in_a_cc()->bar_in_b_cc()->baz_in_c_cc() `` , we will need to go down 2 levels
233+ in the call chain to import both `` bar_in_b_cc `` and `` baz_in_c_cc `` .
0 commit comments