[PATCH] Use MCFillFragment for zero-initialized data

Serge Pavlov sepavloff at gmail.com
Thu Jun 27 04:47:22 PDT 2013


  Updated test.

Hi rafael, grosbach,

http://llvm-reviews.chandlerc.com/D1043

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1043?vs=2567&id=2594#toc

Files:
  include/llvm/MC/MCObjectStreamer.h
  include/llvm/MC/MCStreamer.h
  lib/MC/MCAssembler.cpp
  lib/MC/MCObjectStreamer.cpp
  lib/MC/MCStreamer.cpp
  test/MC/ELF/bss-large.ll

Index: include/llvm/MC/MCObjectStreamer.h
===================================================================
--- include/llvm/MC/MCObjectStreamer.h
+++ include/llvm/MC/MCObjectStreamer.h
@@ -116,6 +116,7 @@
   virtual void EmitGPRel64Value(const MCExpr *Value);
   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
                         unsigned AddrSpace = 0);
+  virtual void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0);
   virtual void FinishImpl();
 
   /// @}
Index: include/llvm/MC/MCStreamer.h
===================================================================
--- include/llvm/MC/MCStreamer.h
+++ include/llvm/MC/MCStreamer.h
@@ -472,11 +472,9 @@
     virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
                           unsigned AddrSpace = 0);
 
-    /// EmitZeros - Emit NumBytes worth of zeros.  This is a convenience
-    /// function that just wraps EmitFill.
-    void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0) {
-      EmitFill(NumBytes, 0, AddrSpace);
-    }
+    /// \brief EmitZeros - Emit NumBytes worth of zeros.
+    /// This function properly handles data in virtual sections.
+    virtual void EmitZeros(uint64_t NumBytes, unsigned AddrSpace = 0);
 
     /// EmitValueToAlignment - Emit some number of copies of @p Value until
     /// the byte alignment @p ByteAlignment is reached.
Index: lib/MC/MCAssembler.cpp
===================================================================
--- lib/MC/MCAssembler.cpp
+++ lib/MC/MCAssembler.cpp
@@ -708,12 +708,13 @@
       case MCFragment::FT_Align:
         // Check that we aren't trying to write a non-zero value into a virtual
         // section.
-        assert((!cast<MCAlignFragment>(it)->getValueSize() ||
-                !cast<MCAlignFragment>(it)->getValue()) &&
+        assert((cast<MCAlignFragment>(it)->getValueSize() == 0 ||
+                cast<MCAlignFragment>(it)->getValue() == 0) &&
                "Invalid align in virtual section!");
         break;
       case MCFragment::FT_Fill:
-        assert(!cast<MCFillFragment>(it)->getValueSize() &&
+        assert((cast<MCFillFragment>(it)->getValueSize() == 0 ||
+                cast<MCFillFragment>(it)->getValue() == 0) &&
                "Invalid fill in virtual section!");
         break;
       }
Index: lib/MC/MCObjectStreamer.cpp
===================================================================
--- lib/MC/MCObjectStreamer.cpp
+++ lib/MC/MCObjectStreamer.cpp
@@ -18,6 +18,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/Support/ErrorHandling.h"
 using namespace llvm;
 
@@ -374,6 +375,12 @@
   getOrCreateDataFragment()->getContents().append(NumBytes, FillValue);
 }
 
+void MCObjectStreamer::EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
+  assert(AddrSpace == 0 && "Address space must be 0!");
+  unsigned ItemSize = getCurrentSection().first->isVirtualSection() ? 0 : 1;
+  insert(new MCFillFragment(0, ItemSize, NumBytes));
+}
+
 void MCObjectStreamer::FinishImpl() {
   // Dump out the dwarf file & directory tables and line tables.
   const MCSymbol *LineSectionSymbol = NULL;
Index: lib/MC/MCStreamer.cpp
===================================================================
--- lib/MC/MCStreamer.cpp
+++ lib/MC/MCStreamer.cpp
@@ -154,6 +154,12 @@
     EmitValue(E, 1, AddrSpace);
 }
 
+/// EmitZeros - Emit NumBytes worth of zeros.  Implementation in this class
+/// just redirects to EmitFill.
+void MCStreamer::EmitZeros(uint64_t NumBytes, unsigned AddrSpace) {
+  EmitFill(NumBytes, 0, AddrSpace);
+}
+
 bool MCStreamer::EmitDwarfFileDirective(unsigned FileNo,
                                         StringRef Directory,
                                         StringRef Filename, unsigned CUID) {
Index: test/MC/ELF/bss-large.ll
===================================================================
--- /dev/null
+++ test/MC/ELF/bss-large.ll
@@ -0,0 +1,13 @@
+; RUN: llc -filetype=obj %s -o %t
+
+; PR16338 - ICE when compiling very large two-dimensional array
+; Check if a huge object can be put into bss section
+; C++ code is:
+;   int a[60666][60666];
+
+; ModuleID = 'test.c'
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at a0 = addrspace(1) global [4 x [4 x i32]] zeroinitializer, align 16
+ at a = global [60666 x [60666 x i32]] zeroinitializer, align 16
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1043.2.patch
Type: text/x-patch
Size: 4551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130627/514fc907/attachment.bin>


More information about the llvm-commits mailing list