If bundle alignment is enabled, do not add data to a fragment with instructions
authorDerek Schuff <dschuff@google.com>
Fri, 15 Feb 2013 22:50:52 +0000 (22:50 +0000)
committerDerek Schuff <dschuff@google.com>
Fri, 15 Feb 2013 22:50:52 +0000 (22:50 +0000)
With bundle alignment, instructions all get their own MCFragments
(unless they are in a bundle-locked group). For instructions with
fixups, this is an MCDataFragment. Emitting actual data (e.g. for
.long) attempts to re-use MCDataFragments, which we don't want int
this case since it leads to fragments which exceed the bundle size.
So, don't reuse them in this case.
Also adds a test and fixes some formatting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175316 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCELFStreamer.cpp
lib/MC/MCObjectStreamer.cpp
test/MC/ARM/AlignedBundling/group-bundle-arm.s

index c4c8e6e4e7db8eff055365e0b06bf0cc29725228..8ddbfbbe8a44a1d557d9769df868610211c7f962 100644 (file)
@@ -386,7 +386,9 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
   if (Assembler.isBundlingEnabled()) {
     MCSectionData *SD = getCurrentSectionData();
     if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
-      DF = getOrCreateDataFragment();
+      // If we are bundle-locked, we re-use the current fragment.
+      // The bundle-locking directive ensures this is a new data fragment.
+      DF = cast<MCDataFragment>(getCurrentFragment());
     else if (!SD->isBundleLocked() && Fixups.size() == 0) {
       // Optimize memory usage by emitting the instruction to a
       // MCCompactEncodedInstFragment when not in a bundle-locked group and
@@ -394,8 +396,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
       MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment(SD);
       CEIF->getContents().append(Code.begin(), Code.end());
       return;
-    }
-    else {
+    } else {
       DF = new MCDataFragment(SD);
       if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
         // If this is a new fragment created for a bundle-locked group, and the
index fe435061eb40440486356708e0037ead56842f28..b6c7341469dfb37016ca8a124a72f866091367de 100644 (file)
@@ -59,7 +59,9 @@ MCFragment *MCObjectStreamer::getCurrentFragment() const {
 
 MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() const {
   MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
-  if (!F)
+  // When bundling is enabled, we don't want to add data to a fragment that
+  // already has instructions (see MCELFStreamer::EmitInstToData for details)
+  if (!F || (Assembler->isBundlingEnabled() && F->hasInstructions()))
     F = new MCDataFragment(getCurrentSectionData());
   return F;
 }
index 823d9e0cb8eaf37fd6ed81ca7e055e5e49d47b52..1d6735320007daf9153fcdd97c29c3f632fdb772 100644 (file)
@@ -5,8 +5,8 @@
 # instructions should not be inserted. However, for bundle-locked groups
 # it can be.
 
-       .syntax unified
-       .text
+  .syntax unified
+  .text
   .bundle_align_mode 4
 
   bx lr
 # CHECK-NEXT: 2c: nop
 # CHECK-NEXT: 30: bx
 
+  .align 4
+foo:
+  b foo
+  .long 3892240112
+  .long 3892240112
+  .long 3892240112
+  .long 3892240112
+  .long 3892240112
+  .long 3892240112
+# CHECK:  40: b
+