[PowerPC] Implement writeNopData
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 4 Jul 2013 18:28:46 +0000 (18:28 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 4 Jul 2013 18:28:46 +0000 (18:28 +0000)
This implements a proper PPCAsmBackend::writeNopData routine
that actually writes PowerPC nop instructions.

This fixes the last remaining difference in object file output
(text section) between the integrated assembler and GNU as
that I've seen anywhere.

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

lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
test/MC/PowerPC/ppc-nop.s [new file with mode: 0644]

index e01f14249d6e64fb8378dace3eb101fcaba838ae..b37a17933c1399704c38b099eaaa5154e217bacc 100644 (file)
@@ -148,10 +148,14 @@ public:
   }
 
   bool writeNopData(uint64_t Count, MCObjectWriter *OW) const {
-    // FIXME: Zero fill for now. That's not right, but at least will get the
-    // section size right.
-    for (uint64_t i = 0; i != Count; ++i)
-      OW->Write8(0);
+    // Can't emit NOP with size not multiple of 32-bits
+    if (Count % 4 != 0)
+      return false;
+
+    uint64_t NumNops = Count / 4;
+    for (uint64_t i = 0; i != NumNops; ++i)
+      OW->Write32(0x60000000);
+
     return true;
   }
 
diff --git a/test/MC/PowerPC/ppc-nop.s b/test/MC/PowerPC/ppc-nop.s
new file mode 100644 (file)
index 0000000..567943c
--- /dev/null
@@ -0,0 +1,9 @@
+# RUN: llvm-mc -filetype=obj -triple=powerpc-unknown-linux-gnu %s | llvm-readobj -s -sd - | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux-gnu %s | llvm-readobj -s -sd - | FileCheck %s
+
+blr
+.p2align 3
+blr
+
+# CHECK:  0000: 4E800020 60000000 4E800020
+