2

If my code is generating LLVM SSA for a platform that is possibly different than the one on which it is currently running, how do I obtain values like FLT_MAX or FLT_EPSILON (or the same for doubles, or any other floating point width)?

I'm guessing it's not correct, in general, to obtain those values for my own system and use them. It's also not an acceptable solution to delegate the question to clang or gcc.

When generating LLVM code, how do I know what value to emit for FLT_MAX?

trbabb
  • 1,894
  • 18
  • 35
  • I haven't needed those, but I have generated other constants using [ConstantExpr](https://llvm.org/doxygen/classllvm_1_1ConstantExpr.html) and the constant's definition. LLVM then folded my constant expression to a simple constant. – arnt Mar 11 '21 at 10:54
  • It's very likely that your target (as well as your development machine for that matter) uses IEEE-754 floating point types. Does LLVM even support anything else? So you can just look up the value, and maybe write it as a hex float. – Nate Eldredge Mar 11 '21 at 22:23
  • @NateEldredge If LLVM's FloatType and DoubleType are guaranteed to be IEEE754 32 and 64 bit on all platforms, that might do the trick. – trbabb Mar 11 '21 at 23:45

1 Answers1

-1

FLT_MAX / FLT_EPSILON are entities specific to C/C++ and are not connected with LLVM. So, you'd need to resort to a C/C++ compiler in order to derive this. Alternatively, you'd need to keep the list of supported platforms and hard-code these values there for each supported platforms.

Anton Korobeynikov
  • 9,074
  • 25
  • 28
  • 2
    I believe OP is using `FLT_MAX` and `FLT_EPSILON` as placeholders for the concepts they provide values for, not the language-specific definitions of them. In other words, OP wants to know how to reference the maximum floating-point value and the so-called “epsilon” measure of precision of the floating-point format in LLVM IR. – Eric Postpischil Mar 11 '21 at 12:44