[LLVMdev] Generating Floating point constants
Stéphane Letz
letz at free.fr
Wed Jun 2 11:05:02 PDT 2010
Le 2 juin 2010 à 19:48, Dale Johannesen a écrit :
>
> On Jun 2, 2010, at 3:28 AMPDT, Stéphane Letz wrote:
>
>>
>> Le 2 juin 2010 à 12:21, Eli Friedman a écrit :
>>
>>> On Wed, Jun 2, 2010 at 2:59 AM, Stéphane Letz <letz at free.fr> wrote:
>>>> Hi,
>>>>
>>>> We need to generate "Floating point constants" in our code. In http://llvm.org/docs/LangRef.html it is explained that FP has to follow special encoding rules to be handled by LLVM later one (hexadecimal coding...)
>>>>
>>>> Is there any code available in LLVM to handle this kind of "standard float to LLVM float" conversion?
>>>
>>> If you're writing C++ code, just stick your float into an APFloat and
>>> doesn't worry about the hexadecimal coding. If you're generating
>>> textual IR,
>>
>> Yes we are generating textual IR,
>>
>>> and you don't care about the precise hexadecimal
>>> representation, AFAIK just printing a decimal float works.
>>
>> Seems like some values cannot be assembled later on (for instance with "llc")
>
> Yes, there are floating point values (such as NaNs) that cannot be expressed in decimal, and others that would require a prohibitively large number of digits. You don't want to do that.
>
> The code that writes out APFloats is in WriteConstantInt [sic] in VMCore/AsmWriter.cpp. It's not set up to do conversions separately from writing out, but you should be able to figure it out.
>
>
Thanks... but this is linked to the LLVM code base right? Is there any self-contained code that can be used to handle floats when writing textual LLVM IR?
Thanks
Stéphane Letz
More information about the llvm-dev
mailing list