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

Tim Northover t.p.northover at gmail.com
Wed Jan 9 05:00:26 PST 2013


> 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.

I've attached a patch which should implement this. It definitely seems
like an improvement to me. I'm including the final function inline as
well since it's one of those diffs that's very difficult to read. Ok
to commit?

Cheers.

Tim.

static void emitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
                                 AsmPrinter &AP) {
  APInt API = CFP->getValueAPF().bitcastToAPInt();

  // First print a comment with what we think the original floating-point value
  // should have been.
  if (AP.isVerbose()) {
    SmallString<8> StrVal;
    CFP->getValueAPF().toString(StrVal);

    CFP->getType()->print(AP.OutStreamer.GetCommentOS());
    AP.OutStreamer.GetCommentOS() << ' ' << StrVal << '\n';
  }

  // Now iterate through the APInt chunks, emitting them in endian-correct
  // order, possibly with a smaller chunk at beginning/end (e.g. for x87 80-bit
  // floats)
  unsigned NumBytes = API.getBitWidth() / 8;
  unsigned TrailingBytes = NumBytes % sizeof(uint64_t);
  const uint64_t *p = API.getRawData();

  // PPC's long double has odd notions of endianness compared to how LLVM
  // handles it: p[0] goes first for *big* endian on PPC.
  if (AP.TM.getDataLayout()->isBigEndian() != CFP->getType()->isPPC_FP128Ty()) {
    int Chunk = API.getNumWords() - 1;

    if (TrailingBytes)
      AP.OutStreamer.EmitIntValue(p[Chunk--], TrailingBytes, AddrSpace);

    for (; Chunk >= 0; --Chunk)
      AP.OutStreamer.EmitIntValue(p[Chunk], sizeof(uint64_t), AddrSpace);
  } else {
    unsigned Chunk;
    for (Chunk = 0; Chunk < NumBytes / sizeof(uint64_t); ++Chunk)
      AP.OutStreamer.EmitIntValue(p[Chunk], sizeof(uint64_t), AddrSpace);

    if (TrailingBytes)
      AP.OutStreamer.EmitIntValue(p[Chunk], TrailingBytes, AddrSpace);
  }

  // Emit the tail padding if needed.
  const DataLayout &TD = *AP.TM.getDataLayout();
  AP.OutStreamer.EmitZeros(TD.getTypeAllocSize(CFP->getType()) -
                           TD.getTypeStoreSize(CFP->getType()), AddrSpace);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simplify-float-asm-print.diff
Type: application/octet-stream
Size: 5531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130109/1c23084c/attachment.obj>


More information about the llvm-commits mailing list