[llvm-dev] Use different LLVM IR functions for unsafe-fp / code gen options
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Tue Jul 12 09:41:29 PDT 2016
On 12 July 2016 at 06:10, Nikolay Haustov via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I don't think there is currently a way to overload function (have different
> versions) in bitcode library based on function attributes/metadata. Any
> other ways to do the same?
Depending on how hacky you want to get, a header containing this would work:
#ifdef __FAST_MATH__
#define USE_FAST_VERSION true
#else
#define USE_FAST_VERSION false
#endif
template<bool Fast> float log(float in);
#define log(x) log<USE_FAST_VERSION>(x);
I believe that could be made zero-overhead with linker trickery.
Other than that, you'd probably have to modify LLVM to support it. We
already seem to have a "call fast" annotation at the call-site so it'd
be a matter of redirecting the call at CodeGen time to one with a
special name (log$fast_math or something?), likely determined by your
ABI.
Tim.
More information about the llvm-dev
mailing list