[llvm-commits] [llvm] r171866 - in /llvm/trunk: lib/CodeGen/AsmPrinter/AsmPrinter.cpp test/CodeGen/ARM/fp128.ll test/CodeGen/PowerPC/fp128.ll

Duncan Sands baldrick at free.fr
Tue Jan 8 09:11:08 PST 2013


Hi Tim,

On 08/01/13 17:56, Tim Northover wrote:
> Author: tnorthover
> Date: Tue Jan  8 10:56:23 2013
> New Revision: 171866
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171866&view=rev
> Log:
> Allow the asm printer to print fp128 values properly.

while this seems correct and the approach is in keeping with the rest of the
function, it would be nicer to get rid of all the cases: rather than having a
method for half-float, for float, for double etc, have one bit of code that
handles all of them uniformly (including future types!).  After all, something
like the following would always work for all types:

   - print a comment based on the type name (use a type name helper to avoid a
    switch on the type), print the value using APFloat::toString;
   - get the value as an array of uint64_t using APInt::getRawData
   - blast it out as a bunch of bytes, ints or whatever (here you have to be
   careful about endianness)

Ciao, Duncan.


>
> Added:
>      llvm/trunk/test/CodeGen/ARM/fp128.ll   (with props)
>      llvm/trunk/test/CodeGen/PowerPC/fp128.ll   (with props)
> Modified:
>      llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=171866&r1=171865&r2=171866&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Jan  8 10:56:23 2013
> @@ -1784,27 +1784,30 @@
>       return;
>     }
>
> -  if (CFP->getType()->isX86_FP80Ty()) {
> +  if (CFP->getType()->isX86_FP80Ty() || CFP->getType()->isFP128Ty()) {
>       // all long double variants are printed as hex
>       // API needed to prevent premature destruction
>       APInt API = CFP->getValueAPF().bitcastToAPInt();
>       const uint64_t *p = API.getRawData();
>       if (AP.isVerbose()) {
>         // Convert to double so we can print the approximate val as a comment.
> -      APFloat DoubleVal = CFP->getValueAPF();
> -      bool ignored;
> -      DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
> -                        &ignored);
> -      AP.OutStreamer.GetCommentOS() << "x86_fp80 ~= "
> -        << DoubleVal.convertToDouble() << '\n';
> +      SmallString<8> StrVal;
> +      CFP->getValueAPF().toString(StrVal);
> +
> +      const char *TyNote = CFP->getType()->isFP128Ty() ? "fp128 " : "x86_fp80 ";
> +      AP.OutStreamer.GetCommentOS() << TyNote << StrVal << '\n';
>       }
>
> +    // The 80-bit type is made of a 64-bit and 16-bit value, the 128-bit has 2
> +    // 64-bit words.
> +    uint32_t TrailingSize = CFP->getType()->isFP128Ty() ? 8 : 2;
> +
>       if (AP.TM.getDataLayout()->isBigEndian()) {
> -      AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
> +      AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
>         AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
>       } else {
>         AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
> -      AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
> +      AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
>       }
>
>       // Emit the tail padding for the long double.
>
> Added: llvm/trunk/test/CodeGen/ARM/fp128.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/fp128.ll?rev=171866&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/ARM/fp128.ll (added)
> +++ llvm/trunk/test/CodeGen/ARM/fp128.ll Tue Jan  8 10:56:23 2013
> @@ -0,0 +1,10 @@
> +; RUN: llc -march=arm < %s | FileCheck --check-prefix=LITTLEENDIAN %s
> +
> + at var = global fp128 0xL00000000000000008000000000000000
> +
> +; CHECK-LITTLEENDIAN: var:
> +; CHECK-LITTLEENDIAN-NEXT: .long   0                       @ fp128 -0
> +; CHECK-LITTLEENDIAN-NEXT: .long   0
> +; CHECK-LITTLEENDIAN-NEXT: .long   0
> +; CHECK-LITTLEENDIAN-NEXT: .long   2147483648
> +
>
> Propchange: llvm/trunk/test/CodeGen/ARM/fp128.ll
> ------------------------------------------------------------------------------
>      svn:eol-style = native
>
> Added: llvm/trunk/test/CodeGen/PowerPC/fp128.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/fp128.ll?rev=171866&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/PowerPC/fp128.ll (added)
> +++ llvm/trunk/test/CodeGen/PowerPC/fp128.ll Tue Jan  8 10:56:23 2013
> @@ -0,0 +1,8 @@
> +; RUN: llc -march=ppc64 < %s | FileCheck --check-prefix=BIGENDIAN %s
> +
> + at var = global fp128 0xL00000000000000008000000000000000
> +
> +; CHECK-BIGENDIAN: var:
> +; CHECK-BIGENDIAN-NEXT: .quad   -9223372036854775808    # fp128 -0
> +; CHECK-BIGENDIAN-NEXT: .quad   0
> +
>
> Propchange: llvm/trunk/test/CodeGen/PowerPC/fp128.ll
> ------------------------------------------------------------------------------
>      svn:eol-style = native
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list