AK: Move taint_for_optimizer to StdLibExtras.h

Additionally, split it into two versions (for IsIntegral<T> -- asking
to place value into register and for !IsIntegral<T> -- asking to place
value into memory with memory clobber), so that Clang is no more
completely confused about `taint_for_optimizer(AK::StringView&)`.
This commit is contained in:
Dan Klishch 2023-03-09 02:25:01 +03:00 committed by Andreas Kling
parent a9d192e882
commit 3c900765bc
Notes: sideshowbarker 2024-07-16 20:48:05 +09:00
2 changed files with 22 additions and 11 deletions

View file

@ -154,17 +154,6 @@ constexpr StaticStorage<false, bit_width<T>> get_storage_of(T value)
}
// ===== Utilities =====
template<typename T>
ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
{
if (!is_constant_evaluated()) {
asm volatile(""
: "+rm"(value)
:
: "memory");
}
}
ALWAYS_INLINE constexpr NativeWord extend_sign(bool sign)
{
return sign ? max_word : 0;

View file

@ -166,6 +166,28 @@ constexpr bool is_constant_evaluated()
#endif
}
template<typename T>
ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
requires(IsIntegral<T>)
{
if (!is_constant_evaluated()) {
asm volatile(""
: "+r"(value));
}
}
template<typename T>
ALWAYS_INLINE constexpr void taint_for_optimizer(T& value)
requires(!IsIntegral<T>)
{
if (!is_constant_evaluated()) {
asm volatile(""
:
: "m"(value)
: "memory");
}
}
// These can't be exported into the global namespace as they would clash with the C standard library.
#define __DEFINE_GENERIC_ABS(type, zero, intrinsic) \