Skip to content

[docs] Revise the doc for __builtin_allow_runtime_check #104886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3540,7 +3540,7 @@ the debugging experience.
``__builtin_allow_runtime_check``
---------------------------------

``__builtin_allow_runtime_check`` return true if the check at the current
``__builtin_allow_runtime_check`` returns true if the check at the current
program location should be executed. It is expected to be used to implement
``assert`` like checks which can be safely removed by optimizer.

Expand All @@ -3560,28 +3560,25 @@ program location should be executed. It is expected to be used to implement

**Description**

``__builtin_allow_runtime_check`` is lowered to ` ``llvm.allow.runtime.check``
``__builtin_allow_runtime_check`` is lowered to the `llvm.allow.runtime.check
<https://llvm.org/docs/LangRef.html#llvm-allow-runtime-check-intrinsic>`_
builtin.

The ``__builtin_allow_runtime_check()`` is expected to be used with control
flow conditions such as in ``if`` to guard expensive runtime checks. The
specific rules for selecting permitted checks can differ and are controlled by
the compiler options.

Flags to control checks:
* ``-mllvm -lower-allow-check-percentile-cutoff-hot=N`` where N is PGO hotness
cutoff in range ``[0, 999999]`` to disallow checks in hot code.
* ``-mllvm -lower-allow-check-random-rate=P`` where P is number in range
``[0.0, 1.0]`` representation probability of keeping a check.
* If both flags are specified, ``-lower-allow-check-random-rate`` takes
precedence.
* If none is specified, ``__builtin_allow_runtime_check`` is lowered as
``true``, allowing all checks.

Parameter ``kind`` is a string literal representing a user selected kind for
guarded check. It's unused now. It will enable kind-specific lowering in future.
E.g. a higher hotness cutoff can be used for more expensive kind of check.
intrinsic.

The ``__builtin_allow_runtime_check()`` can be used within constrol structures
like ``if`` to guard expensive runtime checks. The return value is determined
by the following compiler options and may differ per call site:

* ``-mllvm -lower-allow-check-percentile-cutoff-hot=N``: Disable checks in hot
code marked by the profile summary with a hotness cutoff in the range
``[0, 999999]`` (a larger N disables more checks).
* ``-mllvm -lower-allow-check-random-rate=P``: Keep a check with probability P,
a floating point number in the range ``[0.0, 1.0]``.
* If both options are specified, a check is disabled if either condition is satisfied.
* If neither is specified, all checks are allowed.

Parameter ``kind``, currently unused, is a string literal specifying the check
kind. Future compiler versions may use this to allow for more granular control,
such as applying different hotness cutoffs to different check kinds.

Query for this feature with ``__has_builtin(__builtin_allow_runtime_check)``.

Expand Down
Loading