================
@@ -96,6 +101,37 @@ the ``<cmath>`` header file to conditionally make a 
function constexpr whenever
 the constant evaluation of the corresponding builtin (for example,
 ``std::fmax`` calls ``__builtin_fmax``) is supported in Clang.
 
+``__has_target_builtin``
+------------------------
+
+This function-like macro takes a single identifier argument that is the name of
+a builtin function, a builtin pseudo-function (taking one or more type
+arguments), or a builtin template.
+It evaluates to 1 if the builtin is supported on the current target or 0 if 
not.
+The behavior is different than ``__has_builtin`` when there is an auxiliary 
target,
+such when offloading to a target device.
----------------
Artem-B wrote:

I'd rephrase it to be more specific in terms of *what* the difference is rather 
than when it occurs.

`__has_builtin()` and `__has_target_builtin()` behave identically for normal 
C++ compilations.
For heterogeneous compilations that see source code intended for more than one 
target
* `__has_builtin()` returns true if the builtin is known to the compiler (i.e. 
it's available via one of the targets), but makes no promises whether it's 
available on the *current* target. We can parse it, but not necessarily codegen 
it.
* `__has_target_builtin()` returns true if the builtin can actually be 
codegen'ed for the current target.

`__has_target_builtin()` is, effectively, functional superset of CUDA's 
`__CUDA_ARCH__` -- it allows distinguishing both host and target architectures. 
It has to be treated with similar caution so it does not break consistency of 
the TU source code seen by the compiler across sub-compilations.



https://github.com/llvm/llvm-project/pull/126324
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to