[llvm-branch-commits] [llvm-branch] r323735 - Merging r322108, r322123 and r322131:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 30 01:31:00 PST 2018


Author: hans
Date: Tue Jan 30 01:31:00 2018
New Revision: 323735

URL: http://llvm.org/viewvc/llvm-project?rev=323735&view=rev
Log:
Merging r322108, r322123 and r322131:

------------------------------------------------------------------------
r322108 | rafael | 2018-01-09 20:29:33 +0100 (Tue, 09 Jan 2018) | 3 lines

Make one of the emitFill methods non virtual. NFC.

This is just preparatory work to fix PR35858.
------------------------------------------------------------------------

------------------------------------------------------------------------
r322123 | rafael | 2018-01-09 22:55:10 +0100 (Tue, 09 Jan 2018) | 3 lines

Don't create MCFillFragment directly.

Instead use higher level APIs that take care of most bookkeeping.
------------------------------------------------------------------------

------------------------------------------------------------------------
r322131 | rafael | 2018-01-09 23:48:37 +0100 (Tue, 09 Jan 2018) | 4 lines

Use a MCExpr for the size of MCFillFragment.

This allows the size to be found during ralaxation. This fixes
pr35858.
------------------------------------------------------------------------

Added:
    llvm/branches/release_60/test/MC/X86/eval-fill.s
      - copied unchanged from r322131, llvm/trunk/test/MC/X86/eval-fill.s
Modified:
    llvm/branches/release_60/   (props changed)
    llvm/branches/release_60/include/llvm/MC/MCFragment.h
    llvm/branches/release_60/include/llvm/MC/MCObjectStreamer.h
    llvm/branches/release_60/include/llvm/MC/MCStreamer.h
    llvm/branches/release_60/lib/MC/MCAsmStreamer.cpp
    llvm/branches/release_60/lib/MC/MCAssembler.cpp
    llvm/branches/release_60/lib/MC/MCMachOStreamer.cpp
    llvm/branches/release_60/lib/MC/MCObjectStreamer.cpp
    llvm/branches/release_60/lib/MC/MCStreamer.cpp
    llvm/branches/release_60/lib/MC/MCWinCOFFStreamer.cpp
    llvm/branches/release_60/lib/MC/WasmObjectWriter.cpp

Propchange: llvm/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 30 01:31:00 2018
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,321751,321789,321791,321806,321862,321870,321872,321878,321980,321991,321993-321994,322003,322053,322056,322103,322106,322223,322272,322313,322372,322473,322623,322644,322724,322767,322875,322878-322879,322900,322904-322905,322973,322993,323034,323190,323307,323369,323371,323384
+/llvm/trunk:155241,321751,321789,321791,321806,321862,321870,321872,321878,321980,321991,321993-321994,322003,322053,322056,322103,322106,322108,322123,322131,322223,322272,322313,322372,322473,322623,322644,322724,322767,322875,322878-322879,322900,322904-322905,322973,322993,323034,323190,323307,323369,323371,323384

Modified: llvm/branches/release_60/include/llvm/MC/MCFragment.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/include/llvm/MC/MCFragment.h?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/include/llvm/MC/MCFragment.h (original)
+++ llvm/branches/release_60/include/llvm/MC/MCFragment.h Tue Jan 30 01:31:00 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/branches/release_60/include/llvm/MC/MCObjectStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/include/llvm/MC/MCObjectStreamer.h?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/include/llvm/MC/MCObjectStreamer.h (original)
+++ llvm/branches/release_60/include/llvm/MC/MCObjectStreamer.h Tue Jan 30 01:31:00 2018
@@ -161,7 +161,6 @@ public:
   bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
                           const MCExpr *Expr, SMLoc Loc) override;
   using MCStreamer::emitFill;
-  void emitFill(uint64_t NumBytes, uint8_t FillValue) override;
   void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
                 SMLoc Loc = SMLoc()) override;
   void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,

Modified: llvm/branches/release_60/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/include/llvm/MC/MCStreamer.h?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/include/llvm/MC/MCStreamer.h (original)
+++ llvm/branches/release_60/include/llvm/MC/MCStreamer.h Tue Jan 30 01:31:00 2018
@@ -662,7 +662,7 @@ public:
 
   /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
   /// This implements directives such as '.space'.
-  virtual void emitFill(uint64_t NumBytes, uint8_t FillValue);
+  void emitFill(uint64_t NumBytes, uint8_t FillValue);
 
   /// \brief Emit \p Size bytes worth of the value specified by \p FillValue.
   ///

Modified: llvm/branches/release_60/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCAsmStreamer.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCAsmStreamer.cpp Tue Jan 30 01:31:00 2018
@@ -192,9 +192,6 @@ public:
 
   void EmitGPRel32Value(const MCExpr *Value) override;
 
-
-  void emitFill(uint64_t NumBytes, uint8_t FillValue) override;
-
   void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
                 SMLoc Loc = SMLoc()) override;
 
@@ -965,17 +962,12 @@ void MCAsmStreamer::EmitGPRel32Value(con
   EmitEOL();
 }
 
-/// emitFill - Emit NumBytes bytes worth of the value specified by
-/// FillValue.  This implements directives such as '.space'.
-void MCAsmStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
-  if (NumBytes == 0) return;
-
-  const MCExpr *E = MCConstantExpr::create(NumBytes, getContext());
-  emitFill(*E, FillValue);
-}
-
 void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
                              SMLoc Loc) {
+  int64_t IntNumBytes;
+  if (NumBytes.evaluateAsAbsolute(IntNumBytes) && IntNumBytes == 0)
+    return;
+
   if (const char *ZeroDirective = MAI->getZeroDirective()) {
     // FIXME: Emit location directives
     OS << ZeroDirective;

Modified: llvm/branches/release_60/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCAssembler.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCAssembler.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCAssembler.cpp Tue Jan 30 01:31:00 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/branches/release_60/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCMachOStreamer.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCMachOStreamer.cpp Tue Jan 30 01:31:00 2018
@@ -411,29 +411,19 @@ void MCMachOStreamer::EmitLocalCommonSym
 
 void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
                                    uint64_t Size, unsigned ByteAlignment) {
-  getAssembler().registerSection(*Section);
-
-  // The symbol may not be present, which only creates the section.
-  if (!Symbol)
-    return;
-
   // On darwin all virtual sections have zerofill type.
   assert(Section->isVirtualSection() && "Section does not have zerofill type!");
 
-  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
-
-  getAssembler().registerSymbol(*Symbol);
+  PushSection();
+  SwitchSection(Section);
 
-  // Emit an align fragment if necessary.
-  if (ByteAlignment != 1)
-    new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, Section);
-
-  MCFragment *F = new MCFillFragment(0, Size, Section);
-  Symbol->setFragment(F);
-
-  // Update the maximum alignment on the zero fill section if necessary.
-  if (ByteAlignment > Section->getAlignment())
-    Section->setAlignment(ByteAlignment);
+  // The symbol may not be present, which only creates the section.
+  if (Symbol) {
+    EmitValueToAlignment(ByteAlignment, 0, 1, 0);
+    EmitLabel(Symbol);
+    EmitZeros(Size);
+  }
+  PopSection();
 }
 
 // This should always be called with the thread local bss section.  Like the

Modified: llvm/branches/release_60/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCObjectStreamer.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCObjectStreamer.cpp Tue Jan 30 01:31:00 2018
@@ -577,28 +577,13 @@ bool MCObjectStreamer::EmitRelocDirectiv
   return false;
 }
 
-void MCObjectStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
-  assert(getCurrentSectionOnly() && "need a section");
-  insert(new MCFillFragment(FillValue, NumBytes));
-}
-
 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
                                 SMLoc Loc) {
   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;
-  }
-
-  emitFill(IntNumBytes, FillValue);
+  assert(getCurrentSectionOnly() && "need a section");
+  insert(new MCFillFragment(FillValue, NumBytes, Loc));
 }
 
 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,

Modified: llvm/branches/release_60/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCStreamer.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCStreamer.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCStreamer.cpp Tue Jan 30 01:31:00 2018
@@ -184,8 +184,7 @@ void MCStreamer::EmitGPRel32Value(const
 /// Emit NumBytes bytes worth of the value specified by FillValue.
 /// This implements directives such as '.space'.
 void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
-  for (uint64_t i = 0, e = NumBytes; i != e; ++i)
-    EmitIntValue(FillValue, 1);
+  emitFill(*MCConstantExpr::create(NumBytes, getContext()), FillValue);
 }
 
 void MCStreamer::emitFill(uint64_t NumValues, int64_t Size, int64_t Expr) {

Modified: llvm/branches/release_60/lib/MC/MCWinCOFFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/MCWinCOFFStreamer.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/MCWinCOFFStreamer.cpp (original)
+++ llvm/branches/release_60/lib/MC/MCWinCOFFStreamer.cpp Tue Jan 30 01:31:00 2018
@@ -257,20 +257,13 @@ void MCWinCOFFStreamer::EmitLocalCommonS
   auto *Symbol = cast<MCSymbolCOFF>(S);
 
   MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
-  getAssembler().registerSection(*Section);
-  if (Section->getAlignment() < ByteAlignment)
-    Section->setAlignment(ByteAlignment);
-
-  getAssembler().registerSymbol(*Symbol);
+  PushSection();
+  SwitchSection(Section);
+  EmitValueToAlignment(ByteAlignment, 0, 1, 0);
+  EmitLabel(Symbol);
   Symbol->setExternal(false);
-
-  if (ByteAlignment != 1)
-    new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0,
-                        ByteAlignment, Section);
-
-  MCFillFragment *Fragment = new MCFillFragment(
-      /*Value=*/0, Size, Section);
-  Symbol->setFragment(Fragment);
+  EmitZeros(Size);
+  PopSection();
 }
 
 void MCWinCOFFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,

Modified: llvm/branches/release_60/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/MC/WasmObjectWriter.cpp?rev=323735&r1=323734&r2=323735&view=diff
==============================================================================
--- llvm/branches/release_60/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/branches/release_60/lib/MC/WasmObjectWriter.cpp Tue Jan 30 01:31:00 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();




More information about the llvm-branch-commits mailing list