[llvm] r322131 - Use a MCExpr for the size of MCFillFragment.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 01:33:15 PST 2018


Merged along with dependents in r323735 (PR36139).

On Tue, Jan 9, 2018 at 11:48 PM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Tue Jan  9 14:48:37 2018
> New Revision: 322131
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322131&view=rev
> Log:
> Use a MCExpr for the size of MCFillFragment.
>
> This allows the size to be found during ralaxation. This fixes
> pr35858.
>
> Added:
>     llvm/trunk/test/MC/X86/eval-fill.s
> Modified:
>     llvm/trunk/include/llvm/MC/MCFragment.h
>     llvm/trunk/lib/MC/MCAssembler.cpp
>     llvm/trunk/lib/MC/MCObjectStreamer.cpp
>     llvm/trunk/lib/MC/WasmObjectWriter.cpp
>
> Modified: llvm/trunk/include/llvm/MC/MCFragment.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
> llvm/MC/MCFragment.h?rev=322131&r1=322130&r2=322131&view=diff
> ============================================================
> ==================
> --- llvm/trunk/include/llvm/MC/MCFragment.h (original)
> +++ llvm/trunk/include/llvm/MC/MCFragment.h Tue Jan  9 14:48:37 2018
> @@ -422,14 +422,21 @@ class MCFillFragment : public MCFragment
>    uint8_t Value;
>
>    /// The number of bytes to insert.
> -  uint64_t Size;
> +  const MCExpr &Size;
> +
> +  /// Source location of the directive that this fragment was created for.
> +  SMLoc Loc;
>
>  public:
> -  MCFillFragment(uint8_t Value, uint64_t Size, MCSection *Sec = nullptr)
> -      : MCFragment(FT_Fill, false, 0, Sec), Value(Value), Size(Size) {}
> +  MCFillFragment(uint8_t Value, const MCExpr &Size, SMLoc Loc,
> +                 MCSection *Sec = nullptr)
> +      : MCFragment(FT_Fill, false, 0, Sec), Value(Value), Size(Size),
> Loc(Loc) {
> +  }
>
>    uint8_t getValue() const { return Value; }
> -  uint64_t getSize() const { return Size; }
> +  const MCExpr &getSize() const { return Size; }
> +
> +  SMLoc getLoc() const { return Loc; }
>
>    static bool classof(const MCFragment *F) {
>      return F->getKind() == MCFragment::FT_Fill;
>
> Modified: llvm/trunk/lib/MC/MCAssembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/
> MCAssembler.cpp?rev=322131&r1=322130&r2=322131&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/MC/MCAssembler.cpp (original)
> +++ llvm/trunk/lib/MC/MCAssembler.cpp Tue Jan  9 14:48:37 2018
> @@ -281,8 +281,18 @@ uint64_t MCAssembler::computeFragmentSiz
>      return cast<MCRelaxableFragment>(F).getContents().size();
>    case MCFragment::FT_CompactEncodedInst:
>      return cast<MCCompactEncodedInstFragment>(F).getContents().size();
> -  case MCFragment::FT_Fill:
> -    return cast<MCFillFragment>(F).getSize();
> +  case MCFragment::FT_Fill: {
> +    auto &FF = cast<MCFillFragment>(F);
> +    int64_t Size = 0;
> +    if (!FF.getSize().evaluateAsAbsolute(Size, Layout))
> +      getContext().reportError(FF.getLoc(),
> +                               "expected assembly-time absolute
> expression");
> +    if (Size < 0) {
> +      getContext().reportError(FF.getLoc(), "invalid number of bytes");
> +      return 0;
> +    }
> +    return Size;
> +  }
>
>    case MCFragment::FT_LEB:
>      return cast<MCLEBFragment>(F).getContents().size();
> @@ -540,7 +550,7 @@ static void writeFragment(const MCAssemb
>      for (unsigned I = 1; I < MaxChunkSize; ++I)
>        Data[I] = Data[0];
>
> -    uint64_t Size = FF.getSize();
> +    uint64_t Size = FragmentSize;
>      for (unsigned ChunkSize = MaxChunkSize; ChunkSize; ChunkSize /= 2) {
>        StringRef Ref(Data, ChunkSize);
>        for (uint64_t I = 0, E = Size / ChunkSize; I != E; ++I)
>
> Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/
> MCObjectStreamer.cpp?rev=322131&r1=322130&r2=322131&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Tue Jan  9 14:48:37 2018
> @@ -582,19 +582,8 @@ void MCObjectStreamer::emitFill(const MC
>    MCDataFragment *DF = getOrCreateDataFragment();
>    flushPendingLabels(DF, DF->getContents().size());
>
> -  int64_t IntNumBytes;
> -  if (!NumBytes.evaluateAsAbsolute(IntNumBytes, getAssembler())) {
> -    getContext().reportError(Loc, "expected absolute expression");
> -    return;
> -  }
> -
> -  if (IntNumBytes < 0) {
> -    getContext().reportError(Loc, "invalid number of bytes");
> -    return;
> -  }
> -
>    assert(getCurrentSectionOnly() && "need a section");
> -  insert(new MCFillFragment(FillValue, IntNumBytes));
> +  insert(new MCFillFragment(FillValue, NumBytes, Loc));
>  }
>
>  void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
>
> Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/
> WasmObjectWriter.cpp?rev=322131&r1=322130&r2=322131&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
> +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Tue Jan  9 14:48:37 2018
> @@ -528,7 +528,10 @@ static void addData(SmallVectorImpl<char
>                                               Align->getMaxBytesToEmit());
>        DataBytes.resize(Size, Value);
>      } else if (auto *Fill = dyn_cast<MCFillFragment>(&Frag)) {
> -      DataBytes.insert(DataBytes.end(), Fill->getSize(),
> Fill->getValue());
> +      int64_t Size;
> +      if (!Fill->getSize().evaluateAsAbsolute(Size))
> +        llvm_unreachable("The fill should be an assembler constant");
> +      DataBytes.insert(DataBytes.end(), Size, Fill->getValue());
>      } else {
>        const auto &DataFrag = cast<MCDataFragment>(Frag);
>        const SmallVectorImpl<char> &Contents = DataFrag.getContents();
>
> Added: llvm/trunk/test/MC/X86/eval-fill.s
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/
> X86/eval-fill.s?rev=322131&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/MC/X86/eval-fill.s (added)
> +++ llvm/trunk/test/MC/X86/eval-fill.s Tue Jan  9 14:48:37 2018
> @@ -0,0 +1,17 @@
> +// RUN: llvm-mc -filetype=obj %s -o - -triple x86_64-pc-linux |
> llvm-readobj -s | FileCheck %s
> +
> +// CHECK:      Name: .text
> +// CHECK-NEXT: Type: SHT_PROGBITS
> +// CHECK-NEXT: Flags [
> +// CHECK-NEXT:   SHF_ALLOC
> +// CHECK-NEXT:   SHF_EXECINSTR
> +// CHECK-NEXT: ]
> +// CHECK-NEXT: Address:
> +// CHECK-NEXT: Offset:
> +// CHECK-NEXT: Size: 4092
> +
> +        .globl  foo
> +foo:
> +        .space 4
> +bar:
> +        .space  4092 - (bar - foo)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180130/8575764b/attachment.html>


More information about the llvm-commits mailing list